1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace Hhxsv5\LaravelS\Illuminate; |
4
|
|
|
|
5
|
|
|
use Illuminate\Container\Container; |
|
|
|
|
6
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
7
|
|
|
|
8
|
|
|
class ReflectionApp |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
|
|
|
|
11
|
|
|
* @var Container |
12
|
|
|
*/ |
13
|
|
|
protected $app; |
14
|
|
|
|
15
|
|
|
/** |
|
|
|
|
16
|
|
|
* @var \ReflectionObject |
17
|
|
|
*/ |
18
|
|
|
protected $reflectionApp; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* ReflectionApp constructor. |
22
|
|
|
* |
23
|
|
|
* @param Container $app |
|
|
|
|
24
|
|
|
*/ |
25
|
|
|
public function __construct(Container $app) |
26
|
|
|
{ |
27
|
|
|
$this->app = $app; |
28
|
|
|
|
29
|
|
|
$this->reflectionApp = new \ReflectionObject($app); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get all bindings from application container. |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
* @throws \ReflectionException |
37
|
|
|
*/ |
38
|
|
|
public function instances() |
39
|
|
|
{ |
40
|
|
|
$instances = $this->reflectionApp->getProperty('instances'); |
41
|
|
|
$instances->setAccessible(true); |
42
|
|
|
$instances = array_merge($this->app->getBindings(), $instances->getValue($this->app)); |
43
|
|
|
|
44
|
|
|
return $instances; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Call terminable middleware of Lumen. |
49
|
|
|
* |
50
|
|
|
* @param Response $response |
|
|
|
|
51
|
|
|
* @throws \ReflectionException |
|
|
|
|
52
|
|
|
*/ |
|
|
|
|
53
|
|
|
public function callTerminableMiddleware(Response $response) |
54
|
|
|
{ |
55
|
|
|
$middleware = $this->reflectionApp->getProperty('middleware'); |
56
|
|
|
$middleware->setAccessible(true); |
57
|
|
|
|
58
|
|
|
if (!empty($middleware->getValue($this->app))) { |
59
|
|
|
$callTerminableMiddleware = $this->reflectionApp->getMethod('callTerminableMiddleware'); |
60
|
|
|
$callTerminableMiddleware->setAccessible(true); |
61
|
|
|
$callTerminableMiddleware->invoke($this->app, $response); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* The parameter count of 'register' method in app container. |
67
|
|
|
* |
68
|
|
|
* @return int |
69
|
|
|
* @throws \ReflectionException |
70
|
|
|
*/ |
71
|
|
|
public function registerMethodParameterCount() |
72
|
|
|
{ |
73
|
|
|
return $this->reflectionApp->getMethod('register')->getNumberOfParameters(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get 'loadedProviders' of application container. |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
* @throws \ReflectionException |
81
|
|
|
*/ |
82
|
|
|
public function loadedProviders() |
83
|
|
|
{ |
84
|
|
|
$loadedProviders = $this->reflectLoadedProviders(); |
85
|
|
|
return $loadedProviders->getValue($this->app); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Set 'loadedProviders' of application container. |
90
|
|
|
* |
91
|
|
|
* @param array $loadedProviders |
|
|
|
|
92
|
|
|
* @throws \ReflectionException |
|
|
|
|
93
|
|
|
*/ |
|
|
|
|
94
|
|
|
public function setLoadedProviders(array $loadedProviders) |
95
|
|
|
{ |
96
|
|
|
$reflectLoadedProviders = $this->reflectLoadedProviders(); |
97
|
|
|
$reflectLoadedProviders->setValue($this->app, $loadedProviders); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get the reflect loadedProviders of application container. |
102
|
|
|
* |
103
|
|
|
* @return \ReflectionProperty |
104
|
|
|
* @throws \ReflectionException |
105
|
|
|
*/ |
106
|
|
|
protected function reflectLoadedProviders() |
107
|
|
|
{ |
108
|
|
|
$loadedProviders = $this->reflectionApp->getProperty('loadedProviders'); |
109
|
|
|
$loadedProviders->setAccessible(true); |
110
|
|
|
return $loadedProviders; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|