PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / DI / Container.php
wp-staging / Framework / DI Last commit date
Container.php 1 day ago FeatureProviderInterface.php 1 day ago FeatureServiceProvider.php 1 day ago Resolver.php 1 day ago ServiceProvider.php 1 day ago
Container.php
184 lines
1 <?php
2
3 namespace WPStaging\Framework\DI;
4
5 use WPStaging\Framework\Interfaces\ShutdownableInterface;
6 use WPStaging\Framework\DI\Resolver;
7 use WPStaging\Vendor\lucatume\DI52\Builders\Factory;
8 use WPStaging\Vendor\Psr\Container\ContainerInterface;
9 use WPStaging\Vendor\lucatume\DI52\Container as BaseContainer;
10
11 class Container extends BaseContainer
12 {
13
14
15
16 protected $prefix = 'WPStaging\\Vendor\\';
17
18
19
20
21
22
23
24 public function __construct($resolveUnboundAsSingletons = false, $useBaseContainer = false)
25 {
26 if ($useBaseContainer) {
27 parent::__construct($resolveUnboundAsSingletons);
28 return;
29 }
30
31 $this->resolver = new Resolver($resolveUnboundAsSingletons);
32 $this->builders = new Factory($this, $this->resolver);
33 $this->bindThis();
34 }
35
36
37
38
39
40
41
42
43
44
45 public function _get($offset)
46 {
47 try {
48 return $this->offsetGet($offset);
49 } catch (\Exception $e) {
50 \WPStaging\functions\debug_log($e->getMessage());
51
52 return null;
53 }
54 }
55
56
57
58
59
60
61 public function get($classOrInterface)
62 {
63 $instance = parent::get($classOrInterface);
64 if (is_object($instance) && $instance instanceof ShutdownableInterface) {
65 if (!has_action('shutdown', [$instance, 'onWpShutdown'])) {
66 add_action('shutdown', [$instance, 'onWpShutdown'], ShutdownableInterface::SHUTDOWN_PRIORITY);
67 }
68 }
69
70 return $instance;
71 }
72
73
74
75
76
77 public function make($classOrInterface)
78 {
79 return $this->get($classOrInterface);
80 }
81
82
83
84
85
86
87
88
89
90
91 public function pushToArray($arrayName, $value)
92 {
93 try {
94 $arrayValues = (array)$this->offsetGet($arrayName);
95
96 if (in_array($value, $arrayValues)) {
97
98 return false;
99 }
100 } catch (\Exception $e) {
101
102 $this->setVar($arrayName, []);
103 $arrayValues = [];
104 }
105
106
107 $arrayValues[] = $value;
108
109 $this->setVar($arrayName, $arrayValues);
110
111 return true;
112 }
113
114
115
116
117
118
119
120
121
122 public function getFromArray($arrayName)
123 {
124 try {
125 return (array)$this->offsetGet($arrayName);
126 } catch (\Exception $e) {
127 return [];
128 }
129 }
130
131
132
133
134
135
136
137
138 public function bind($classOrInterface, $implementation = null, $afterBuildMethods = null)
139 {
140 if ($this->isDevAutoloader()) {
141 parent::bind(str_replace($this->prefix, '', $classOrInterface), $implementation, $afterBuildMethods);
142 }
143
144 parent::bind($classOrInterface, $implementation, $afterBuildMethods);
145 }
146
147
148
149
150
151
152
153
154 public function singleton($classOrInterface, $implementation = null, $afterBuildMethods = null)
155 {
156 if ($this->isDevAutoloader()) {
157 parent::singleton(str_replace($this->prefix, '', $classOrInterface), $implementation, $afterBuildMethods);
158 }
159
160 parent::singleton($classOrInterface, $implementation, $afterBuildMethods);
161 }
162
163 private function isDevAutoloader()
164 {
165 if (defined('WPSTG_IS_DEV') && constant('WPSTG_IS_DEV')) {
166 return true;
167 }
168
169 return defined('WPSTG_IS_DEV_AUTOLOADER') && constant('WPSTG_IS_DEV_AUTOLOADER');
170 }
171
172
173
174
175
176
177 private function bindThis()
178 {
179 $this->singleton(ContainerInterface::class, $this);
180 $this->singleton(BaseContainer::class, $this);
181 $this->singleton(Container::class, $this);
182 }
183 }
184