Passed
Push — master ( e07512...4b3fd5 )
by Atanas
03:23
created

Pipeline::getHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package   WPEmerge
4
 * @author    Atanas Angelov <[email protected]>
5
 * @copyright 2018 Atanas Angelov
6
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
7
 * @link      https://wpemerge.com/
8
 */
9
10
namespace WPEmerge\Routing;
11
12
use WPEmerge\Exceptions\Exception;
13
use WPEmerge\Middleware\HasMiddlewareInterface;
14
use WPEmerge\Middleware\HasMiddlewareTrait;
15
use WPEmerge\Requests\RequestInterface;
16
17
/**
18
 * Represent a route
19
 */
20
class Pipeline implements HasMiddlewareInterface {
21
	use HasMiddlewareTrait;
22
23
	/**
24
	 * Pipeline handler.
25
	 *
26
	 * @var PipelineHandler
27
	 */
28
	protected $handler = null;
29
30
	/**
31
	 * Constructor.
32
	 *
33
	 * @throws Exception
34
	 * @param  string|\Closure $handler
35
	 */
36 1
	public function __construct( $handler ) {
37 1
		$this->handler = new PipelineHandler( $handler );
38 1
	}
39
40
	/**
41
	 * Get handler.
42
	 *
43
	 * @return PipelineHandler
44
	 */
45 1
	public function getHandler() {
46 1
		return $this->handler;
47
	}
48
49
	/**
50
	 * Get a response for the given request.
51
	 *
52
	 * @param  RequestInterface                    $request
53
	 * @param  array                               $arguments
54
	 * @return \Psr\Http\Message\ResponseInterface
55
	 */
56
	public function run( RequestInterface $request, $arguments ) {
57 1
		return $this->executeMiddleware( $this->getMiddleware(), $request, function () use ( $arguments ) {
58 1
			return call_user_func_array( [$this->getHandler(), 'execute'], $arguments );
59 1
		} );
60
	}
61
}
62