Completed
Push — master ( 988ea9...868c80 )
by smiley
07:26
created

QueueRunner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1
1
<?php
2
/**
3
 * Class QueueRunner
4
 *
5
 * @link https://www.php-fig.org/psr/psr-15/meta/
6
 *
7
 * @filesource   QueueRunner.php
8
 * @created      10.03.2019
9
 * @package      chillerlan\HTTP\Psr15
10
 * @author       smiley <[email protected]>
11
 * @copyright    2019 smiley
12
 * @license      MIT
13
 */
14
15
namespace chillerlan\HTTP\Psr15;
16
17
use Psr\Http\Server\MiddlewareInterface;
18
use Psr\Http\Message\{ResponseInterface, ServerRequestInterface};
19
use Psr\Http\Server\RequestHandlerInterface;
20
21
use function array_pop;
22
23
class QueueRunner implements RequestHandlerInterface{
24
25
	/**
26
	 * @var \Psr\Http\Server\MiddlewareInterface[]
27
	 */
28
	private array $middlewareStack;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
29
30
	/**
31
	 * @var \Psr\Http\Server\RequestHandlerInterface
32
	 */
33
	private RequestHandlerInterface $fallbackHandler;
34
35
	/**
36
	 *  constructor.
37
	 *
38
	 * @param array                                    $middlewareStack
39
	 * @param \Psr\Http\Server\RequestHandlerInterface $fallbackHandler
40
	 */
41
	public function __construct(array $middlewareStack, RequestHandlerInterface $fallbackHandler){
42
		$this->middlewareStack = $middlewareStack;
43
		$this->fallbackHandler = $fallbackHandler;
44
	}
45
46
	/**
47
	 * @inheritDoc
48
	 */
49
	public function handle(ServerRequestInterface $request):ResponseInterface{
50
51
		if(empty($this->middlewareStack)){
52
			return $this->fallbackHandler->handle($request);
53
		}
54
55
		return $this->getMiddleware()->process($request, $this);
56
	}
57
58
	/**
59
	 * @return \Psr\Http\Server\MiddlewareInterface
60
	 */
61
	protected function getMiddleware():MiddlewareInterface{
62
		return array_pop($this->middlewareStack);
63
	}
64
65
}
66