Failed Conditions
Branch refactor/kernels (fbf61a)
by Atanas
01:47
created

src/Routing/Pipeline.php (1 issue)

Labels
Severity
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\Middleware\ExecutesMiddlewareTrait;
13
use WPEmerge\Middleware\HasMiddlewareInterface;
14
use WPEmerge\Middleware\HasMiddlewareTrait;
15
use WPEmerge\Requests\RequestInterface;
16
17
/**
18
 * Represent middleware that envelops a handler.
19
 */
20
class Pipeline implements HasMiddlewareInterface {
21
	use HasMiddlewareTrait;
22
	use ExecutesMiddlewareTrait;
23
24
	/**
25
	 * Pipeline handler.
26
	 *
27
	 * @var PipelineHandler
28
	 */
29
	protected $handler = null;
30
31
	/**
32
	 * Get handler.
33
	 *
34
	 * @codeCoverageIgnore
35
	 * @return PipelineHandler
36
	 */
37
	public function getHandler() {
38
		return $this->handler;
39
	}
40
41
	/**
42
	 * Set handler.
43
	 *
44
	 * @codeCoverageIgnore
45
	 * @param  string|\Closure $handler
46
	 * @return void
47
	 */
48
	public function setHandler( $handler ) {
49
		$this->handler = new PipelineHandler( $handler );
50
	}
51
52
	/**
53
	 * Fluent alias for setHandler().
54
	 *
55
	 * @codeCoverageIgnore
56
	 * @param  string|\Closure $handler
57
	 * @return static          $this
58
	 */
59
	public function to( $handler ) {
60
		call_user_func_array( [$this, 'setHandler'], func_get_args() );
61
62
		return $this;
63
	}
64
65
	/**
66
	 * Get a response for the given request.
67
	 *
68
	 * @param  RequestInterface                    $request
69
	 * @param  array                               $arguments
70
	 * @return \Psr\Http\Message\ResponseInterface
71
	 */
72
	public function run( RequestInterface $request, $arguments ) {
73 1
		return $this->executeMiddleware( $this->getMiddleware(), $request, function () use ( $arguments ) {
0 ignored issues
show
$this->getMiddleware() of type string[] is incompatible with the type array<mixed,string[]> expected by parameter $middleware of WPEmerge\Routing\Pipeline::executeMiddleware(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

73
		return $this->executeMiddleware( /** @scrutinizer ignore-type */ $this->getMiddleware(), $request, function () use ( $arguments ) {
Loading history...
74 1
			return call_user_func_array( [$this->getHandler(), 'execute'], $arguments );
75 1
		} );
76
	}
77
}
78