Completed
Push — master ( 487726...07c1c1 )
by Michael
01:44
created

Stack::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Schnittstabil\Psr7\Middleware;
4
5
/**
6
 * Immutable middleware stack.
7
 */
8
class Stack implements StackInterface
9
{
10
    use CallableStackTrait;
11
12
    /**
13
     * Create new stack.
14
     *
15
     * @param callable $bottomMiddleware last middleware to be called
16
     */
17
    public function __construct(callable $bottomMiddleware = null)
18
    {
19
        $this->middlewareStack = $bottomMiddleware;
20
    }
21
22
    /**
23
     * Push a middleware onto the top of a new Stack instance.
24
     *
25
     * @param callable $newTopMiddleware the middleware to be pushed onto the top.
26
     *
27
     * @return static the new instance
28
     */
29
    public function add(callable $newTopMiddleware)
30
    {
31
        $clone = clone $this;
32
33
        return $clone->push($newTopMiddleware);
34
    }
35
36
    /**
37
     * Create new stack.
38
     *
39
     * @param callable $bottomMiddleware last middleware to be called
40
     *
41
     * @return static a new stack instance
42
     */
43
    public static function create(callable $bottomMiddleware = null)
44
    {
45
        return new self($bottomMiddleware);
46
    }
47
}
48