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