RequestStack::getMasterRequest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Veto.
4
 * PHP Microframework.
5
 *
6
 * @author Damien Walsh <[email protected]>
7
 * @copyright Damien Walsh 2013-2014
8
 * @version 0.1
9
 * @package veto
10
 */
11
namespace Veto\HTTP;
12
13
use Psr\Http\Message\RequestInterface;
14
15
/**
16
 * RequestStack - a stack of requests being handled by the application.
17
 */
18
class RequestStack
19
{
20
    /**
21
     * @var RequestInterface[]
22
     */
23
    private $stack = array();
24
25
    /**
26
     * @param RequestInterface $request
27
     */
28
    public function push(RequestInterface $request)
29
    {
30
        array_push($this->stack, $request);
31
    }
32
33
    /**
34
     * @return RequestInterface
35
     */
36
    public function pop()
37
    {
38
        array_pop($this->stack);
39
    }
40
41
    /**
42
     * Check if this request is the master request.
43
     * 
44
     * @return bool
45
     */
46
    public function isMasterRequest()
47
    {
48
        return count($this->stack) === 1;
49
    }
50
51
    /**
52
     * Get the master request, or null if no requests are being handled.
53
     * 
54
     * @return null|RequestInterface
55
     */
56
    public function getMasterRequest()
57
    {
58
        return count($this->stack) > 0 ? $this->stack[0] : null;
59
    }
60
}
61