1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Equip; |
4
|
|
|
|
5
|
|
|
use Auryn\Injector; |
6
|
|
|
use Equip\Configuration\ConfigurationSet; |
7
|
|
|
use Equip\Middleware\MiddlewareSet; |
8
|
|
|
use Equip\Router; |
9
|
|
|
|
10
|
|
|
class Application |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Create a new application |
14
|
|
|
* |
15
|
|
|
* @param Injector $injector |
16
|
|
|
* @param ConfigurationSet $configuration |
17
|
|
|
* @param MiddlewareSet $middleware |
18
|
|
|
* |
19
|
|
|
* @return static |
20
|
|
|
*/ |
21
|
2 |
|
public static function build( |
22
|
|
|
Injector $injector = null, |
23
|
|
|
ConfigurationSet $configuration = null, |
24
|
|
|
MiddlewareSet $middleware = null |
25
|
|
|
) { |
26
|
2 |
|
return new static($injector, $configuration, $middleware); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Injector |
31
|
|
|
*/ |
32
|
|
|
private $injector; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ConfigurationSet |
36
|
|
|
*/ |
37
|
|
|
private $configuration; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var MiddlewareSet |
41
|
|
|
*/ |
42
|
|
|
private $middleware; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var callable|string |
46
|
|
|
*/ |
47
|
|
|
private $routing; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param Injector $injector |
51
|
|
|
* @param ConfigurationSet $configuration |
52
|
|
|
* @param MiddlewareSet $middleware |
53
|
|
|
*/ |
54
|
6 |
|
public function __construct( |
55
|
|
|
Injector $injector = null, |
56
|
|
|
ConfigurationSet $configuration = null, |
57
|
|
|
MiddlewareSet $middleware = null |
58
|
|
|
) { |
59
|
6 |
|
$this->injector = $injector ?: new Injector; |
|
|
|
|
60
|
6 |
|
$this->configuration = $configuration ?: new ConfigurationSet; |
61
|
6 |
|
$this->middleware = $middleware ?: new MiddlewareSet; |
|
|
|
|
62
|
6 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Change configuration values |
66
|
|
|
* |
67
|
|
|
* @param array $configuration |
68
|
|
|
* |
69
|
|
|
* @return self |
70
|
|
|
*/ |
71
|
2 |
|
public function setConfiguration(array $configuration) |
72
|
|
|
{ |
73
|
2 |
|
$this->configuration = $this->configuration->withData($configuration); |
74
|
2 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Change middleware |
79
|
|
|
* |
80
|
|
|
* @param array $middleware |
81
|
|
|
* |
82
|
|
|
* @return self |
83
|
|
|
*/ |
84
|
1 |
|
public function setMiddleware(array $middleware) |
85
|
|
|
{ |
86
|
1 |
|
$this->middleware = $this->middleware->withData($middleware); |
87
|
1 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Change routing |
92
|
|
|
* |
93
|
|
|
* @param callable|string $routing |
94
|
|
|
* |
95
|
|
|
* @return self |
96
|
|
|
*/ |
97
|
2 |
|
public function setRouting($routing) |
98
|
|
|
{ |
99
|
2 |
|
$this->routing = $routing; |
100
|
2 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Run the application |
105
|
|
|
* |
106
|
|
|
* @param string $runner |
107
|
|
|
* |
108
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
109
|
|
|
*/ |
110
|
1 |
|
public function run($runner = 'Relay\Relay') |
111
|
|
|
{ |
112
|
1 |
|
$this->configuration->apply($this->injector); |
113
|
|
|
|
114
|
1 |
|
return $this->injector |
115
|
1 |
|
->share($this->middleware) |
116
|
1 |
|
->prepare('Equip\Directory', $this->routing) |
117
|
1 |
|
->execute($runner); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.