@@ -101,7 +101,7 @@ |
||
101 | 101 | |
102 | 102 | |
103 | 103 | /** |
104 | - * @param FullyQualifiedName|string $fqcn |
|
104 | + * @param string $fqcn |
|
105 | 105 | * @param array $arguments |
106 | 106 | * @return mixed |
107 | 107 | */ |
@@ -19,118 +19,118 @@ |
||
19 | 19 | class Loader implements LoaderInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var LoaderDecoratorInterface $new_loader |
|
24 | - */ |
|
25 | - private $new_loader; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var LoaderDecoratorInterface $shared_loader |
|
29 | - */ |
|
30 | - private $shared_loader; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var ClassInterfaceCache $class_cache |
|
34 | - */ |
|
35 | - private $class_cache; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Loader constructor. |
|
40 | - * |
|
41 | - * @param LoaderDecoratorInterface $new_loader |
|
42 | - * @param CachingLoaderDecoratorInterface $shared_loader |
|
43 | - * @param ClassInterfaceCache $class_cache |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - LoaderDecoratorInterface $new_loader, |
|
47 | - CachingLoaderDecoratorInterface $shared_loader, |
|
48 | - ClassInterfaceCache $class_cache |
|
49 | - ) { |
|
50 | - $this->new_loader = $new_loader; |
|
51 | - $this->shared_loader = $shared_loader; |
|
52 | - $this->class_cache = $class_cache; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @return LoaderDecoratorInterface |
|
58 | - */ |
|
59 | - public function getNewLoader() |
|
60 | - { |
|
61 | - return $this->new_loader; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @return CachingLoaderDecoratorInterface |
|
67 | - */ |
|
68 | - public function getSharedLoader() |
|
69 | - { |
|
70 | - return $this->shared_loader; |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @param FullyQualifiedName|string $fqcn |
|
76 | - * @param array $arguments |
|
77 | - * @param bool $shared |
|
78 | - * @return mixed |
|
79 | - */ |
|
80 | - public function load($fqcn, array $arguments = array(), $shared = true) |
|
81 | - { |
|
82 | - $fqcn = $this->class_cache->getFqn($fqcn); |
|
83 | - if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) { |
|
84 | - $shared = true; |
|
85 | - } |
|
86 | - return $shared |
|
87 | - ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
88 | - : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param FullyQualifiedName|string $fqcn |
|
94 | - * @param array $arguments |
|
95 | - * @return mixed |
|
96 | - */ |
|
97 | - public function getNew($fqcn, array $arguments = array()) |
|
98 | - { |
|
99 | - return $this->load($fqcn, $arguments, false); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @param FullyQualifiedName|string $fqcn |
|
105 | - * @param array $arguments |
|
106 | - * @return mixed |
|
107 | - */ |
|
108 | - public function getShared($fqcn, array $arguments = array()) |
|
109 | - { |
|
110 | - return $this->load($fqcn, $arguments); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @param FullyQualifiedName|string $fqcn |
|
116 | - * @param mixed $object |
|
117 | - * @return bool |
|
118 | - * @throws InvalidArgumentException |
|
119 | - */ |
|
120 | - public function share($fqcn, $object) |
|
121 | - { |
|
122 | - $fqcn = $this->class_cache->getFqn($fqcn); |
|
123 | - return $this->getSharedLoader()->share($fqcn, $object); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * calls reset() on loaders if that method exists |
|
129 | - */ |
|
130 | - public function reset() |
|
131 | - { |
|
132 | - $this->shared_loader->reset(); |
|
133 | - } |
|
22 | + /** |
|
23 | + * @var LoaderDecoratorInterface $new_loader |
|
24 | + */ |
|
25 | + private $new_loader; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var LoaderDecoratorInterface $shared_loader |
|
29 | + */ |
|
30 | + private $shared_loader; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var ClassInterfaceCache $class_cache |
|
34 | + */ |
|
35 | + private $class_cache; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Loader constructor. |
|
40 | + * |
|
41 | + * @param LoaderDecoratorInterface $new_loader |
|
42 | + * @param CachingLoaderDecoratorInterface $shared_loader |
|
43 | + * @param ClassInterfaceCache $class_cache |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + LoaderDecoratorInterface $new_loader, |
|
47 | + CachingLoaderDecoratorInterface $shared_loader, |
|
48 | + ClassInterfaceCache $class_cache |
|
49 | + ) { |
|
50 | + $this->new_loader = $new_loader; |
|
51 | + $this->shared_loader = $shared_loader; |
|
52 | + $this->class_cache = $class_cache; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @return LoaderDecoratorInterface |
|
58 | + */ |
|
59 | + public function getNewLoader() |
|
60 | + { |
|
61 | + return $this->new_loader; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @return CachingLoaderDecoratorInterface |
|
67 | + */ |
|
68 | + public function getSharedLoader() |
|
69 | + { |
|
70 | + return $this->shared_loader; |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @param FullyQualifiedName|string $fqcn |
|
76 | + * @param array $arguments |
|
77 | + * @param bool $shared |
|
78 | + * @return mixed |
|
79 | + */ |
|
80 | + public function load($fqcn, array $arguments = array(), $shared = true) |
|
81 | + { |
|
82 | + $fqcn = $this->class_cache->getFqn($fqcn); |
|
83 | + if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) { |
|
84 | + $shared = true; |
|
85 | + } |
|
86 | + return $shared |
|
87 | + ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
88 | + : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param FullyQualifiedName|string $fqcn |
|
94 | + * @param array $arguments |
|
95 | + * @return mixed |
|
96 | + */ |
|
97 | + public function getNew($fqcn, array $arguments = array()) |
|
98 | + { |
|
99 | + return $this->load($fqcn, $arguments, false); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @param FullyQualifiedName|string $fqcn |
|
105 | + * @param array $arguments |
|
106 | + * @return mixed |
|
107 | + */ |
|
108 | + public function getShared($fqcn, array $arguments = array()) |
|
109 | + { |
|
110 | + return $this->load($fqcn, $arguments); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @param FullyQualifiedName|string $fqcn |
|
116 | + * @param mixed $object |
|
117 | + * @return bool |
|
118 | + * @throws InvalidArgumentException |
|
119 | + */ |
|
120 | + public function share($fqcn, $object) |
|
121 | + { |
|
122 | + $fqcn = $this->class_cache->getFqn($fqcn); |
|
123 | + return $this->getSharedLoader()->share($fqcn, $object); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * calls reset() on loaders if that method exists |
|
129 | + */ |
|
130 | + public function reset() |
|
131 | + { |
|
132 | + $this->shared_loader->reset(); |
|
133 | + } |
|
134 | 134 | } |
135 | 135 | // End of file Loader.php |
136 | 136 | // Location: EventEspresso\core\services\loaders/Loader.php |
@@ -12,51 +12,51 @@ |
||
12 | 12 | interface LoaderInterface |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Can be for instantiating a new instance of a class, |
|
17 | - * or for getting a shared instance of a class (default) |
|
18 | - * |
|
19 | - * @param FullyQualifiedName|string $fqcn |
|
20 | - * @param array $arguments |
|
21 | - * @param bool $shared |
|
22 | - * @return mixed |
|
23 | - */ |
|
24 | - public function load($fqcn, array $arguments = array(), $shared = true); |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * Used for instantiating a new instance of a class |
|
29 | - * |
|
30 | - * @param FullyQualifiedName|string $fqcn |
|
31 | - * @param array $arguments |
|
32 | - * @return mixed |
|
33 | - */ |
|
34 | - public function getNew($fqcn, array $arguments = array()); |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Used for getting a shared instance of a class |
|
39 | - * |
|
40 | - * @param FullyQualifiedName|string $fqcn |
|
41 | - * @param array $arguments |
|
42 | - * @return mixed |
|
43 | - */ |
|
44 | - public function getShared($fqcn, array $arguments = array()); |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @param FullyQualifiedName|string $fqcn |
|
49 | - * @param mixed $object |
|
50 | - * @return bool |
|
51 | - * @throws InvalidArgumentException |
|
52 | - */ |
|
53 | - public function share($fqcn, $object); |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * calls reset() on loader if method exists |
|
58 | - */ |
|
59 | - public function reset(); |
|
15 | + /** |
|
16 | + * Can be for instantiating a new instance of a class, |
|
17 | + * or for getting a shared instance of a class (default) |
|
18 | + * |
|
19 | + * @param FullyQualifiedName|string $fqcn |
|
20 | + * @param array $arguments |
|
21 | + * @param bool $shared |
|
22 | + * @return mixed |
|
23 | + */ |
|
24 | + public function load($fqcn, array $arguments = array(), $shared = true); |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * Used for instantiating a new instance of a class |
|
29 | + * |
|
30 | + * @param FullyQualifiedName|string $fqcn |
|
31 | + * @param array $arguments |
|
32 | + * @return mixed |
|
33 | + */ |
|
34 | + public function getNew($fqcn, array $arguments = array()); |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Used for getting a shared instance of a class |
|
39 | + * |
|
40 | + * @param FullyQualifiedName|string $fqcn |
|
41 | + * @param array $arguments |
|
42 | + * @return mixed |
|
43 | + */ |
|
44 | + public function getShared($fqcn, array $arguments = array()); |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @param FullyQualifiedName|string $fqcn |
|
49 | + * @param mixed $object |
|
50 | + * @return bool |
|
51 | + * @throws InvalidArgumentException |
|
52 | + */ |
|
53 | + public function share($fqcn, $object); |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * calls reset() on loader if method exists |
|
58 | + */ |
|
59 | + public function reset(); |
|
60 | 60 | } |
61 | 61 | // End of file LoaderInterface.php |
62 | 62 | // Location: core/services/loaders/LoaderInterface.php |
@@ -20,130 +20,130 @@ |
||
20 | 20 | class Response implements ResponseInterface, ReservedInstanceInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var array $notice |
|
25 | - */ |
|
26 | - protected $notice = array(); |
|
23 | + /** |
|
24 | + * @var array $notice |
|
25 | + */ |
|
26 | + protected $notice = array(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * rendered output to be returned to WP |
|
30 | - * |
|
31 | - * @var string $output |
|
32 | - */ |
|
33 | - protected $output = ''; |
|
28 | + /** |
|
29 | + * rendered output to be returned to WP |
|
30 | + * |
|
31 | + * @var string $output |
|
32 | + */ |
|
33 | + protected $output = ''; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var bool |
|
37 | - */ |
|
38 | - protected $request_terminated = false; |
|
35 | + /** |
|
36 | + * @var bool |
|
37 | + */ |
|
38 | + protected $request_terminated = false; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var bool $deactivate_plugin |
|
42 | - */ |
|
43 | - protected $deactivate_plugin = false; |
|
40 | + /** |
|
41 | + * @var bool $deactivate_plugin |
|
42 | + */ |
|
43 | + protected $deactivate_plugin = false; |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * EE_Response constructor. |
|
48 | - */ |
|
49 | - public function __construct() |
|
50 | - { |
|
51 | - $this->terminateRequest(false); |
|
52 | - } |
|
46 | + /** |
|
47 | + * EE_Response constructor. |
|
48 | + */ |
|
49 | + public function __construct() |
|
50 | + { |
|
51 | + $this->terminateRequest(false); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * @param $key |
|
58 | - * @param $value |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - public function setNotice($key, $value) |
|
62 | - { |
|
63 | - $this->notice[ $key ] = $value; |
|
64 | - } |
|
56 | + /** |
|
57 | + * @param $key |
|
58 | + * @param $value |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + public function setNotice($key, $value) |
|
62 | + { |
|
63 | + $this->notice[ $key ] = $value; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * @param $key |
|
70 | - * @return mixed |
|
71 | - */ |
|
72 | - public function getNotice($key) |
|
73 | - { |
|
74 | - return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
75 | - } |
|
68 | + /** |
|
69 | + * @param $key |
|
70 | + * @return mixed |
|
71 | + */ |
|
72 | + public function getNotice($key) |
|
73 | + { |
|
74 | + return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getNotices() |
|
83 | - { |
|
84 | - return $this->notice; |
|
85 | - } |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getNotices() |
|
83 | + { |
|
84 | + return $this->notice; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @param string $string |
|
91 | - * @param bool $append |
|
92 | - */ |
|
93 | - public function addOutput($string, $append = true) |
|
94 | - { |
|
95 | - $this->output = $append ? $this->output . $string : $string . $this->output; |
|
96 | - } |
|
89 | + /** |
|
90 | + * @param string $string |
|
91 | + * @param bool $append |
|
92 | + */ |
|
93 | + public function addOutput($string, $append = true) |
|
94 | + { |
|
95 | + $this->output = $append ? $this->output . $string : $string . $this->output; |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | 99 | |
100 | - /** |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function getOutput() |
|
104 | - { |
|
105 | - return $this->output; |
|
106 | - } |
|
100 | + /** |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function getOutput() |
|
104 | + { |
|
105 | + return $this->output; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * @return boolean |
|
112 | - */ |
|
113 | - public function requestTerminated() |
|
114 | - { |
|
115 | - return $this->request_terminated; |
|
116 | - } |
|
110 | + /** |
|
111 | + * @return boolean |
|
112 | + */ |
|
113 | + public function requestTerminated() |
|
114 | + { |
|
115 | + return $this->request_terminated; |
|
116 | + } |
|
117 | 117 | |
118 | 118 | |
119 | 119 | |
120 | - /** |
|
121 | - * @param boolean $request_terminated |
|
122 | - */ |
|
123 | - public function terminateRequest($request_terminated = true) |
|
124 | - { |
|
125 | - $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
126 | - } |
|
120 | + /** |
|
121 | + * @param boolean $request_terminated |
|
122 | + */ |
|
123 | + public function terminateRequest($request_terminated = true) |
|
124 | + { |
|
125 | + $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | 129 | |
130 | - /** |
|
131 | - * @return boolean |
|
132 | - */ |
|
133 | - public function pluginDeactivated() |
|
134 | - { |
|
135 | - return $this->deactivate_plugin; |
|
136 | - } |
|
130 | + /** |
|
131 | + * @return boolean |
|
132 | + */ |
|
133 | + public function pluginDeactivated() |
|
134 | + { |
|
135 | + return $this->deactivate_plugin; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | 139 | |
140 | - /** |
|
141 | - * sets $deactivate_plugin to true |
|
142 | - */ |
|
143 | - public function deactivatePlugin() |
|
144 | - { |
|
145 | - $this->deactivate_plugin = true; |
|
146 | - } |
|
140 | + /** |
|
141 | + * sets $deactivate_plugin to true |
|
142 | + */ |
|
143 | + public function deactivatePlugin() |
|
144 | + { |
|
145 | + $this->deactivate_plugin = true; |
|
146 | + } |
|
147 | 147 | |
148 | 148 | |
149 | 149 | } |
@@ -78,13 +78,13 @@ |
||
78 | 78 | // EE_Dependency_Map: info about how to load classes required by other classes |
79 | 79 | espresso_load_required( |
80 | 80 | 'EE_Dependency_Map', |
81 | - EE_CORE . 'EE_Dependency_Map.core.php' |
|
81 | + EE_CORE.'EE_Dependency_Map.core.php' |
|
82 | 82 | ); |
83 | 83 | $this->dependency_map = EE_Dependency_Map::instance($this->class_cache); |
84 | 84 | // EE_Registry: central repository for classes (legacy) |
85 | 85 | espresso_load_required( |
86 | 86 | 'EE_Registry', |
87 | - EE_CORE . 'EE_Registry.core.php' |
|
87 | + EE_CORE.'EE_Registry.core.php' |
|
88 | 88 | ); |
89 | 89 | $this->registry = EE_Registry::instance( |
90 | 90 | $this->dependency_map, |
@@ -29,126 +29,126 @@ |
||
29 | 29 | class BootstrapDependencyInjectionContainer |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * @var EE_Dependency_Map $dependency_map |
|
34 | - */ |
|
35 | - protected $dependency_map; |
|
36 | - |
|
37 | - /** |
|
38 | - * @type LoaderInterface $loader |
|
39 | - */ |
|
40 | - protected $loader; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Registry $registry |
|
44 | - */ |
|
45 | - protected $registry; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var ClassInterfaceCache $class_cache |
|
49 | - */ |
|
50 | - private $class_cache; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var Mirror |
|
54 | - */ |
|
55 | - private $mirror; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var ObjectIdentifier |
|
59 | - */ |
|
60 | - private $object_identifier; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Can't use this just yet until we exorcise some more of our singleton usage from core |
|
65 | - */ |
|
66 | - public function buildDependencyInjectionContainer() |
|
67 | - { |
|
68 | - // build DI container |
|
69 | - // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
70 | - // $OpenCoffeeShop->addRecipes(); |
|
71 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Setups EE_Registry and EE_Dependency_Map |
|
77 | - * |
|
78 | - * @throws EE_Error |
|
79 | - */ |
|
80 | - public function buildLegacyDependencyInjectionContainer() |
|
81 | - { |
|
82 | - $this->class_cache = new ClassInterfaceCache(); |
|
83 | - $this->object_identifier = new ObjectIdentifier($this->class_cache); |
|
84 | - $this->mirror = new Mirror(); |
|
85 | - // EE_Dependency_Map: info about how to load classes required by other classes |
|
86 | - espresso_load_required( |
|
87 | - 'EE_Dependency_Map', |
|
88 | - EE_CORE . 'EE_Dependency_Map.core.php' |
|
89 | - ); |
|
90 | - $this->dependency_map = EE_Dependency_Map::instance($this->class_cache); |
|
91 | - // EE_Registry: central repository for classes (legacy) |
|
92 | - espresso_load_required( |
|
93 | - 'EE_Registry', |
|
94 | - EE_CORE . 'EE_Registry.core.php' |
|
95 | - ); |
|
96 | - $this->registry = EE_Registry::instance( |
|
97 | - $this->dependency_map, |
|
98 | - $this->mirror, |
|
99 | - $this->class_cache, |
|
100 | - $this->object_identifier |
|
101 | - ); |
|
102 | - |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Performs initial setup for the generic Loader |
|
108 | - * |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidInterfaceException |
|
111 | - * @throws InvalidArgumentException |
|
112 | - */ |
|
113 | - public function buildLoader() |
|
114 | - { |
|
115 | - $this->loader = LoaderFactory::getLoader( |
|
116 | - $this->registry, |
|
117 | - $this->class_cache, |
|
118 | - $this->object_identifier |
|
119 | - ); |
|
120 | - $this->loader->share('EventEspresso\core\services\loaders\ClassInterfaceCache', $this->class_cache); |
|
121 | - $this->loader->share('EventEspresso\core\services\loaders\ObjectIdentifier', $this->object_identifier); |
|
122 | - $this->loader->share('EventEspresso\core\services\container\Mirror', $this->mirror); |
|
123 | - $this->dependency_map->setLoader($this->loader); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @return EE_Dependency_Map |
|
129 | - */ |
|
130 | - public function getDependencyMap() |
|
131 | - { |
|
132 | - return $this->dependency_map; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return EE_Registry |
|
138 | - */ |
|
139 | - public function getRegistry() |
|
140 | - { |
|
141 | - return $this->registry; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return LoaderInterface |
|
148 | - */ |
|
149 | - public function getLoader() |
|
150 | - { |
|
151 | - return $this->loader; |
|
152 | - } |
|
32 | + /** |
|
33 | + * @var EE_Dependency_Map $dependency_map |
|
34 | + */ |
|
35 | + protected $dependency_map; |
|
36 | + |
|
37 | + /** |
|
38 | + * @type LoaderInterface $loader |
|
39 | + */ |
|
40 | + protected $loader; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Registry $registry |
|
44 | + */ |
|
45 | + protected $registry; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var ClassInterfaceCache $class_cache |
|
49 | + */ |
|
50 | + private $class_cache; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var Mirror |
|
54 | + */ |
|
55 | + private $mirror; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var ObjectIdentifier |
|
59 | + */ |
|
60 | + private $object_identifier; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Can't use this just yet until we exorcise some more of our singleton usage from core |
|
65 | + */ |
|
66 | + public function buildDependencyInjectionContainer() |
|
67 | + { |
|
68 | + // build DI container |
|
69 | + // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
70 | + // $OpenCoffeeShop->addRecipes(); |
|
71 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Setups EE_Registry and EE_Dependency_Map |
|
77 | + * |
|
78 | + * @throws EE_Error |
|
79 | + */ |
|
80 | + public function buildLegacyDependencyInjectionContainer() |
|
81 | + { |
|
82 | + $this->class_cache = new ClassInterfaceCache(); |
|
83 | + $this->object_identifier = new ObjectIdentifier($this->class_cache); |
|
84 | + $this->mirror = new Mirror(); |
|
85 | + // EE_Dependency_Map: info about how to load classes required by other classes |
|
86 | + espresso_load_required( |
|
87 | + 'EE_Dependency_Map', |
|
88 | + EE_CORE . 'EE_Dependency_Map.core.php' |
|
89 | + ); |
|
90 | + $this->dependency_map = EE_Dependency_Map::instance($this->class_cache); |
|
91 | + // EE_Registry: central repository for classes (legacy) |
|
92 | + espresso_load_required( |
|
93 | + 'EE_Registry', |
|
94 | + EE_CORE . 'EE_Registry.core.php' |
|
95 | + ); |
|
96 | + $this->registry = EE_Registry::instance( |
|
97 | + $this->dependency_map, |
|
98 | + $this->mirror, |
|
99 | + $this->class_cache, |
|
100 | + $this->object_identifier |
|
101 | + ); |
|
102 | + |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Performs initial setup for the generic Loader |
|
108 | + * |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidInterfaceException |
|
111 | + * @throws InvalidArgumentException |
|
112 | + */ |
|
113 | + public function buildLoader() |
|
114 | + { |
|
115 | + $this->loader = LoaderFactory::getLoader( |
|
116 | + $this->registry, |
|
117 | + $this->class_cache, |
|
118 | + $this->object_identifier |
|
119 | + ); |
|
120 | + $this->loader->share('EventEspresso\core\services\loaders\ClassInterfaceCache', $this->class_cache); |
|
121 | + $this->loader->share('EventEspresso\core\services\loaders\ObjectIdentifier', $this->object_identifier); |
|
122 | + $this->loader->share('EventEspresso\core\services\container\Mirror', $this->mirror); |
|
123 | + $this->dependency_map->setLoader($this->loader); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @return EE_Dependency_Map |
|
129 | + */ |
|
130 | + public function getDependencyMap() |
|
131 | + { |
|
132 | + return $this->dependency_map; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return EE_Registry |
|
138 | + */ |
|
139 | + public function getRegistry() |
|
140 | + { |
|
141 | + return $this->registry; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return LoaderInterface |
|
148 | + */ |
|
149 | + public function getLoader() |
|
150 | + { |
|
151 | + return $this->loader; |
|
152 | + } |
|
153 | 153 | |
154 | 154 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | // load interfaces |
209 | 209 | espresso_load_required( |
210 | 210 | 'EEH_Autoloader', |
211 | - EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
211 | + EE_CORE.'helpers'.DS.'EEH_Autoloader.helper.php' |
|
212 | 212 | ); |
213 | 213 | EEH_Autoloader::instance(); |
214 | 214 | } |
@@ -223,13 +223,13 @@ discard block |
||
223 | 223 | protected function setAutoloadersForRequiredFiles() |
224 | 224 | { |
225 | 225 | // load interfaces |
226 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
226 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces', true); |
|
227 | 227 | // load helpers |
228 | 228 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
229 | 229 | // register legacy request stack classes just in case |
230 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
230 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'request_stack'.DS); |
|
231 | 231 | // register legacy middleware classes just in case |
232 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
232 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'middleware'.DS); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * so items at the beginning of the final middleware stack will run last. |
248 | 248 | * First parameter is the middleware classname, second is an array of arguments |
249 | 249 | */ |
250 | - $stack_apps = apply_filters( |
|
250 | + $stack_apps = apply_filters( |
|
251 | 251 | 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
252 | 252 | array( |
253 | 253 | // first in last out |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | ) |
261 | 261 | ); |
262 | 262 | // legacy filter for backwards compatibility |
263 | - $stack_apps = apply_filters( |
|
263 | + $stack_apps = apply_filters( |
|
264 | 264 | 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
265 | 265 | $stack_apps |
266 | 266 | ); |
@@ -50,228 +50,228 @@ |
||
50 | 50 | class BootstrapCore |
51 | 51 | { |
52 | 52 | |
53 | - /** |
|
54 | - * @type LoaderInterface $loader |
|
55 | - */ |
|
56 | - private $loader; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var RequestInterface $request |
|
60 | - */ |
|
61 | - protected $request; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var ResponseInterface $response |
|
65 | - */ |
|
66 | - protected $response; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var RequestStackBuilder $request_stack_builder |
|
70 | - */ |
|
71 | - protected $request_stack_builder; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var RequestStack $request_stack |
|
75 | - */ |
|
76 | - protected $request_stack; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * BootstrapCore constructor. |
|
81 | - */ |
|
82 | - public function __construct() |
|
83 | - { |
|
84 | - do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct'); |
|
85 | - // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
86 | - add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @throws DomainException |
|
92 | - * @throws EE_Error |
|
93 | - * @throws Exception |
|
94 | - * @throws InvalidArgumentException |
|
95 | - * @throws InvalidClassException |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidFilePathException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - * @throws OutOfBoundsException |
|
100 | - * @throws ReflectionException |
|
101 | - */ |
|
102 | - public function initialize() |
|
103 | - { |
|
104 | - $this->bootstrapDependencyInjectionContainer(); |
|
105 | - $this->bootstrapDomain(); |
|
106 | - $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
107 | - add_action( |
|
108 | - 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
109 | - array($bootstrap_request, 'setupLegacyRequest') |
|
110 | - ); |
|
111 | - $this->runRequestStack(); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @throws ReflectionException |
|
117 | - * @throws EE_Error |
|
118 | - * @throws InvalidArgumentException |
|
119 | - * @throws InvalidDataTypeException |
|
120 | - * @throws InvalidInterfaceException |
|
121 | - * @throws OutOfBoundsException |
|
122 | - */ |
|
123 | - private function bootstrapDependencyInjectionContainer() |
|
124 | - { |
|
125 | - $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
126 | - $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
127 | - $bootstrap_di->buildLoader(); |
|
128 | - $registry = $bootstrap_di->getRegistry(); |
|
129 | - $dependency_map = $bootstrap_di->getDependencyMap(); |
|
130 | - $dependency_map->initialize(); |
|
131 | - $registry->initialize(); |
|
132 | - $this->loader = $bootstrap_di->getLoader(); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * configures the Domain object for core |
|
138 | - * |
|
139 | - * @return void |
|
140 | - * @throws DomainException |
|
141 | - * @throws InvalidArgumentException |
|
142 | - * @throws InvalidDataTypeException |
|
143 | - * @throws InvalidClassException |
|
144 | - * @throws InvalidFilePathException |
|
145 | - * @throws InvalidInterfaceException |
|
146 | - */ |
|
147 | - private function bootstrapDomain() |
|
148 | - { |
|
149 | - DomainFactory::getEventEspressoCoreDomain(); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * sets up the request and response objects |
|
155 | - * |
|
156 | - * @return BootstrapRequestResponseObjects |
|
157 | - * @throws InvalidArgumentException |
|
158 | - */ |
|
159 | - private function bootstrapRequestResponseObjects() |
|
160 | - { |
|
161 | - /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
162 | - $bootstrap_request = $this->loader->getShared( |
|
163 | - 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
164 | - array($this->loader) |
|
165 | - ); |
|
166 | - $bootstrap_request->buildRequestResponse(); |
|
167 | - $bootstrap_request->shareRequestResponse(); |
|
168 | - $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
169 | - $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
170 | - return $bootstrap_request; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * run_request_stack |
|
176 | - * construct request stack and run middleware apps |
|
177 | - * |
|
178 | - * @throws EE_Error |
|
179 | - * @throws Exception |
|
180 | - */ |
|
181 | - public function runRequestStack() |
|
182 | - { |
|
183 | - $this->loadAutoloader(); |
|
184 | - $this->setAutoloadersForRequiredFiles(); |
|
185 | - $this->request_stack_builder = $this->buildRequestStack(); |
|
186 | - $this->request_stack = $this->request_stack_builder->resolve( |
|
187 | - new RequestStackCoreApp() |
|
188 | - ); |
|
189 | - $this->request_stack->handleRequest($this->request, $this->response); |
|
190 | - $this->request_stack->handleResponse(); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * load_autoloader |
|
196 | - * |
|
197 | - * @throws EE_Error |
|
198 | - */ |
|
199 | - protected function loadAutoloader() |
|
200 | - { |
|
201 | - // load interfaces |
|
202 | - espresso_load_required( |
|
203 | - 'EEH_Autoloader', |
|
204 | - EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
205 | - ); |
|
206 | - EEH_Autoloader::instance(); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * load_required_files |
|
213 | - * |
|
214 | - * @throws EE_Error |
|
215 | - */ |
|
216 | - protected function setAutoloadersForRequiredFiles() |
|
217 | - { |
|
218 | - // load interfaces |
|
219 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
220 | - // load helpers |
|
221 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
222 | - // register legacy request stack classes just in case |
|
223 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
224 | - // register legacy middleware classes just in case |
|
225 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * build_request_stack |
|
232 | - * |
|
233 | - * @return RequestStackBuilder |
|
234 | - */ |
|
235 | - public function buildRequestStack() |
|
236 | - { |
|
237 | - $request_stack_builder = new RequestStackBuilder($this->loader); |
|
238 | - /** |
|
239 | - * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
240 | - * so items at the beginning of the final middleware stack will run last. |
|
241 | - * First parameter is the middleware classname, second is an array of arguments |
|
242 | - */ |
|
243 | - $stack_apps = apply_filters( |
|
244 | - 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
245 | - array( |
|
246 | - // first in last out |
|
247 | - 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
248 | - 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
249 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
250 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
251 | - // last in first out |
|
252 | - 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
253 | - ) |
|
254 | - ); |
|
255 | - // legacy filter for backwards compatibility |
|
256 | - $stack_apps = apply_filters( |
|
257 | - 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
258 | - $stack_apps |
|
259 | - ); |
|
260 | - // load middleware onto stack : FILO (First In Last Out) |
|
261 | - // items at the beginning of the $stack_apps array will run last |
|
262 | - foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
263 | - $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
264 | - } |
|
265 | - // finally, we'll add this on its own because we need it to always be part of the stack |
|
266 | - // and we also need it to always run first because the rest of the system relies on it |
|
267 | - $request_stack_builder->push( |
|
268 | - array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
269 | - ); |
|
270 | - return apply_filters( |
|
271 | - 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
272 | - $request_stack_builder |
|
273 | - ); |
|
274 | - } |
|
53 | + /** |
|
54 | + * @type LoaderInterface $loader |
|
55 | + */ |
|
56 | + private $loader; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var RequestInterface $request |
|
60 | + */ |
|
61 | + protected $request; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var ResponseInterface $response |
|
65 | + */ |
|
66 | + protected $response; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var RequestStackBuilder $request_stack_builder |
|
70 | + */ |
|
71 | + protected $request_stack_builder; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var RequestStack $request_stack |
|
75 | + */ |
|
76 | + protected $request_stack; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * BootstrapCore constructor. |
|
81 | + */ |
|
82 | + public function __construct() |
|
83 | + { |
|
84 | + do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct'); |
|
85 | + // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
86 | + add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @throws DomainException |
|
92 | + * @throws EE_Error |
|
93 | + * @throws Exception |
|
94 | + * @throws InvalidArgumentException |
|
95 | + * @throws InvalidClassException |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidFilePathException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + * @throws OutOfBoundsException |
|
100 | + * @throws ReflectionException |
|
101 | + */ |
|
102 | + public function initialize() |
|
103 | + { |
|
104 | + $this->bootstrapDependencyInjectionContainer(); |
|
105 | + $this->bootstrapDomain(); |
|
106 | + $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
107 | + add_action( |
|
108 | + 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
109 | + array($bootstrap_request, 'setupLegacyRequest') |
|
110 | + ); |
|
111 | + $this->runRequestStack(); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @throws ReflectionException |
|
117 | + * @throws EE_Error |
|
118 | + * @throws InvalidArgumentException |
|
119 | + * @throws InvalidDataTypeException |
|
120 | + * @throws InvalidInterfaceException |
|
121 | + * @throws OutOfBoundsException |
|
122 | + */ |
|
123 | + private function bootstrapDependencyInjectionContainer() |
|
124 | + { |
|
125 | + $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
126 | + $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
127 | + $bootstrap_di->buildLoader(); |
|
128 | + $registry = $bootstrap_di->getRegistry(); |
|
129 | + $dependency_map = $bootstrap_di->getDependencyMap(); |
|
130 | + $dependency_map->initialize(); |
|
131 | + $registry->initialize(); |
|
132 | + $this->loader = $bootstrap_di->getLoader(); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * configures the Domain object for core |
|
138 | + * |
|
139 | + * @return void |
|
140 | + * @throws DomainException |
|
141 | + * @throws InvalidArgumentException |
|
142 | + * @throws InvalidDataTypeException |
|
143 | + * @throws InvalidClassException |
|
144 | + * @throws InvalidFilePathException |
|
145 | + * @throws InvalidInterfaceException |
|
146 | + */ |
|
147 | + private function bootstrapDomain() |
|
148 | + { |
|
149 | + DomainFactory::getEventEspressoCoreDomain(); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * sets up the request and response objects |
|
155 | + * |
|
156 | + * @return BootstrapRequestResponseObjects |
|
157 | + * @throws InvalidArgumentException |
|
158 | + */ |
|
159 | + private function bootstrapRequestResponseObjects() |
|
160 | + { |
|
161 | + /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
162 | + $bootstrap_request = $this->loader->getShared( |
|
163 | + 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
164 | + array($this->loader) |
|
165 | + ); |
|
166 | + $bootstrap_request->buildRequestResponse(); |
|
167 | + $bootstrap_request->shareRequestResponse(); |
|
168 | + $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
169 | + $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
170 | + return $bootstrap_request; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * run_request_stack |
|
176 | + * construct request stack and run middleware apps |
|
177 | + * |
|
178 | + * @throws EE_Error |
|
179 | + * @throws Exception |
|
180 | + */ |
|
181 | + public function runRequestStack() |
|
182 | + { |
|
183 | + $this->loadAutoloader(); |
|
184 | + $this->setAutoloadersForRequiredFiles(); |
|
185 | + $this->request_stack_builder = $this->buildRequestStack(); |
|
186 | + $this->request_stack = $this->request_stack_builder->resolve( |
|
187 | + new RequestStackCoreApp() |
|
188 | + ); |
|
189 | + $this->request_stack->handleRequest($this->request, $this->response); |
|
190 | + $this->request_stack->handleResponse(); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * load_autoloader |
|
196 | + * |
|
197 | + * @throws EE_Error |
|
198 | + */ |
|
199 | + protected function loadAutoloader() |
|
200 | + { |
|
201 | + // load interfaces |
|
202 | + espresso_load_required( |
|
203 | + 'EEH_Autoloader', |
|
204 | + EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
205 | + ); |
|
206 | + EEH_Autoloader::instance(); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * load_required_files |
|
213 | + * |
|
214 | + * @throws EE_Error |
|
215 | + */ |
|
216 | + protected function setAutoloadersForRequiredFiles() |
|
217 | + { |
|
218 | + // load interfaces |
|
219 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
220 | + // load helpers |
|
221 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
222 | + // register legacy request stack classes just in case |
|
223 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
224 | + // register legacy middleware classes just in case |
|
225 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * build_request_stack |
|
232 | + * |
|
233 | + * @return RequestStackBuilder |
|
234 | + */ |
|
235 | + public function buildRequestStack() |
|
236 | + { |
|
237 | + $request_stack_builder = new RequestStackBuilder($this->loader); |
|
238 | + /** |
|
239 | + * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
240 | + * so items at the beginning of the final middleware stack will run last. |
|
241 | + * First parameter is the middleware classname, second is an array of arguments |
|
242 | + */ |
|
243 | + $stack_apps = apply_filters( |
|
244 | + 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
245 | + array( |
|
246 | + // first in last out |
|
247 | + 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
248 | + 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
249 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
250 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
251 | + // last in first out |
|
252 | + 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
253 | + ) |
|
254 | + ); |
|
255 | + // legacy filter for backwards compatibility |
|
256 | + $stack_apps = apply_filters( |
|
257 | + 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
258 | + $stack_apps |
|
259 | + ); |
|
260 | + // load middleware onto stack : FILO (First In Last Out) |
|
261 | + // items at the beginning of the $stack_apps array will run last |
|
262 | + foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
263 | + $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
264 | + } |
|
265 | + // finally, we'll add this on its own because we need it to always be part of the stack |
|
266 | + // and we also need it to always run first because the rest of the system relies on it |
|
267 | + $request_stack_builder->push( |
|
268 | + array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
269 | + ); |
|
270 | + return apply_filters( |
|
271 | + 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
272 | + $request_stack_builder |
|
273 | + ); |
|
274 | + } |
|
275 | 275 | |
276 | 276 | |
277 | 277 | } |
@@ -25,226 +25,226 @@ |
||
25 | 25 | class Mirror |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var ReflectionClass[] $classes |
|
30 | - */ |
|
31 | - private $classes = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * @var ReflectionMethod[] $constructors |
|
35 | - */ |
|
36 | - private $constructors = array(); |
|
37 | - |
|
38 | - /** |
|
39 | - * @var ReflectionParameter[][] $parameters |
|
40 | - */ |
|
41 | - private $parameters = array(); |
|
42 | - |
|
43 | - /** |
|
44 | - * @var ReflectionParameter[][] $parameters |
|
45 | - */ |
|
46 | - private $parameter_classes = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * @var ReflectionProperty[][] $properties |
|
50 | - */ |
|
51 | - private $properties = array(); |
|
52 | - |
|
53 | - /** |
|
54 | - * @var ReflectionMethod[][] $methods |
|
55 | - */ |
|
56 | - private $methods = array(); |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @param string $class_name |
|
61 | - * @return ReflectionClass |
|
62 | - * @throws ReflectionException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - */ |
|
65 | - public function getReflectionClass($class_name) |
|
66 | - { |
|
67 | - if (! is_string($class_name)) { |
|
68 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
69 | - } |
|
70 | - if (! isset($this->classes[ $class_name ])) { |
|
71 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
72 | - } |
|
73 | - return $this->classes[ $class_name ]; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @param string $class_name |
|
79 | - * @return ReflectionMethod |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - * @throws ReflectionException |
|
82 | - */ |
|
83 | - public function getConstructor($class_name) |
|
84 | - { |
|
85 | - if (! is_string($class_name)) { |
|
86 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
87 | - } |
|
88 | - if (! isset($this->constructors[ $class_name ])) { |
|
89 | - $reflection_class = $this->getReflectionClass($class_name); |
|
90 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
91 | - } |
|
92 | - return $this->constructors[ $class_name ]; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @param ReflectionClass $reflection_class |
|
98 | - * @return ReflectionMethod |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws ReflectionException |
|
101 | - */ |
|
102 | - public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
103 | - { |
|
104 | - return $this->getConstructor($reflection_class->getName()); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $class_name |
|
110 | - * @return ReflectionParameter[] |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - * @throws ReflectionException |
|
113 | - */ |
|
114 | - public function getParameters($class_name) |
|
115 | - { |
|
116 | - if (! isset($this->parameters[ $class_name ])) { |
|
117 | - $constructor = $this->getConstructor($class_name); |
|
118 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
119 | - } |
|
120 | - return $this->parameters[ $class_name ]; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @param ReflectionClass $reflection_class |
|
126 | - * @return ReflectionParameter[] |
|
127 | - * @throws InvalidDataTypeException |
|
128 | - * @throws ReflectionException |
|
129 | - */ |
|
130 | - public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
131 | - { |
|
132 | - return $this->getParameters($reflection_class->getName()); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param ReflectionMethod $constructor |
|
138 | - * @return ReflectionParameter[] |
|
139 | - * @throws InvalidDataTypeException |
|
140 | - * @throws ReflectionException |
|
141 | - */ |
|
142 | - public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
143 | - { |
|
144 | - return $this->getParameters($constructor->getDeclaringClass()); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @param ReflectionParameter $param |
|
150 | - * @param string $class_name |
|
151 | - * @param string $index |
|
152 | - * @return string|null |
|
153 | - */ |
|
154 | - public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
155 | - { |
|
156 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
157 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
158 | - } |
|
159 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
160 | - $this->parameter_classes[ $class_name ] = array(); |
|
161 | - } |
|
162 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
163 | - $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
164 | - } |
|
165 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass() |
|
166 | - ? $param->getClass()->name |
|
167 | - : null; |
|
168 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * @param ReflectionParameter $param |
|
174 | - * @param string $class_name |
|
175 | - * @param string $index |
|
176 | - * @return string|null |
|
177 | - */ |
|
178 | - public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
179 | - { |
|
180 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
181 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
182 | - } |
|
183 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
184 | - $this->parameter_classes[ $class_name ] = array(); |
|
185 | - } |
|
186 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
187 | - $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
188 | - } |
|
189 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
190 | - ? $param->getDefaultValue() |
|
191 | - : null; |
|
192 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @param string $class_name |
|
198 | - * @return ReflectionProperty[] |
|
199 | - * @throws InvalidDataTypeException |
|
200 | - * @throws ReflectionException |
|
201 | - */ |
|
202 | - public function getProperties($class_name) |
|
203 | - { |
|
204 | - if (! isset($this->properties[ $class_name ])) { |
|
205 | - $reflection_class = $this->getReflectionClass($class_name); |
|
206 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
207 | - } |
|
208 | - return $this->properties[ $class_name ]; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param ReflectionClass $reflection_class |
|
214 | - * @return ReflectionProperty[] |
|
215 | - * @throws InvalidDataTypeException |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
219 | - { |
|
220 | - return $this->getProperties($reflection_class->getName()); |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * @param string $class_name |
|
226 | - * @return ReflectionMethod[] |
|
227 | - * @throws InvalidDataTypeException |
|
228 | - * @throws ReflectionException |
|
229 | - */ |
|
230 | - public function getMethods($class_name) |
|
231 | - { |
|
232 | - if (! isset($this->methods[ $class_name ])) { |
|
233 | - $reflection_class = $this->getReflectionClass($class_name); |
|
234 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
235 | - } |
|
236 | - return $this->methods[ $class_name ]; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @param ReflectionClass $reflection_class ) |
|
242 | - * @return ReflectionMethod[] |
|
243 | - * @throws InvalidDataTypeException |
|
244 | - * @throws ReflectionException |
|
245 | - */ |
|
246 | - public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
247 | - { |
|
248 | - return $this->getMethods($reflection_class->getName()); |
|
249 | - } |
|
28 | + /** |
|
29 | + * @var ReflectionClass[] $classes |
|
30 | + */ |
|
31 | + private $classes = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * @var ReflectionMethod[] $constructors |
|
35 | + */ |
|
36 | + private $constructors = array(); |
|
37 | + |
|
38 | + /** |
|
39 | + * @var ReflectionParameter[][] $parameters |
|
40 | + */ |
|
41 | + private $parameters = array(); |
|
42 | + |
|
43 | + /** |
|
44 | + * @var ReflectionParameter[][] $parameters |
|
45 | + */ |
|
46 | + private $parameter_classes = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * @var ReflectionProperty[][] $properties |
|
50 | + */ |
|
51 | + private $properties = array(); |
|
52 | + |
|
53 | + /** |
|
54 | + * @var ReflectionMethod[][] $methods |
|
55 | + */ |
|
56 | + private $methods = array(); |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @param string $class_name |
|
61 | + * @return ReflectionClass |
|
62 | + * @throws ReflectionException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + */ |
|
65 | + public function getReflectionClass($class_name) |
|
66 | + { |
|
67 | + if (! is_string($class_name)) { |
|
68 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
69 | + } |
|
70 | + if (! isset($this->classes[ $class_name ])) { |
|
71 | + $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
72 | + } |
|
73 | + return $this->classes[ $class_name ]; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @param string $class_name |
|
79 | + * @return ReflectionMethod |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + * @throws ReflectionException |
|
82 | + */ |
|
83 | + public function getConstructor($class_name) |
|
84 | + { |
|
85 | + if (! is_string($class_name)) { |
|
86 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
87 | + } |
|
88 | + if (! isset($this->constructors[ $class_name ])) { |
|
89 | + $reflection_class = $this->getReflectionClass($class_name); |
|
90 | + $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
91 | + } |
|
92 | + return $this->constructors[ $class_name ]; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @param ReflectionClass $reflection_class |
|
98 | + * @return ReflectionMethod |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws ReflectionException |
|
101 | + */ |
|
102 | + public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
103 | + { |
|
104 | + return $this->getConstructor($reflection_class->getName()); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $class_name |
|
110 | + * @return ReflectionParameter[] |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + * @throws ReflectionException |
|
113 | + */ |
|
114 | + public function getParameters($class_name) |
|
115 | + { |
|
116 | + if (! isset($this->parameters[ $class_name ])) { |
|
117 | + $constructor = $this->getConstructor($class_name); |
|
118 | + $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
119 | + } |
|
120 | + return $this->parameters[ $class_name ]; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @param ReflectionClass $reflection_class |
|
126 | + * @return ReflectionParameter[] |
|
127 | + * @throws InvalidDataTypeException |
|
128 | + * @throws ReflectionException |
|
129 | + */ |
|
130 | + public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
131 | + { |
|
132 | + return $this->getParameters($reflection_class->getName()); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param ReflectionMethod $constructor |
|
138 | + * @return ReflectionParameter[] |
|
139 | + * @throws InvalidDataTypeException |
|
140 | + * @throws ReflectionException |
|
141 | + */ |
|
142 | + public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
143 | + { |
|
144 | + return $this->getParameters($constructor->getDeclaringClass()); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param ReflectionParameter $param |
|
150 | + * @param string $class_name |
|
151 | + * @param string $index |
|
152 | + * @return string|null |
|
153 | + */ |
|
154 | + public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
155 | + { |
|
156 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
157 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
158 | + } |
|
159 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
160 | + $this->parameter_classes[ $class_name ] = array(); |
|
161 | + } |
|
162 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
163 | + $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
164 | + } |
|
165 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass() |
|
166 | + ? $param->getClass()->name |
|
167 | + : null; |
|
168 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * @param ReflectionParameter $param |
|
174 | + * @param string $class_name |
|
175 | + * @param string $index |
|
176 | + * @return string|null |
|
177 | + */ |
|
178 | + public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
179 | + { |
|
180 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
181 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
182 | + } |
|
183 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
184 | + $this->parameter_classes[ $class_name ] = array(); |
|
185 | + } |
|
186 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
187 | + $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
188 | + } |
|
189 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
190 | + ? $param->getDefaultValue() |
|
191 | + : null; |
|
192 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @param string $class_name |
|
198 | + * @return ReflectionProperty[] |
|
199 | + * @throws InvalidDataTypeException |
|
200 | + * @throws ReflectionException |
|
201 | + */ |
|
202 | + public function getProperties($class_name) |
|
203 | + { |
|
204 | + if (! isset($this->properties[ $class_name ])) { |
|
205 | + $reflection_class = $this->getReflectionClass($class_name); |
|
206 | + $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
207 | + } |
|
208 | + return $this->properties[ $class_name ]; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param ReflectionClass $reflection_class |
|
214 | + * @return ReflectionProperty[] |
|
215 | + * @throws InvalidDataTypeException |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
219 | + { |
|
220 | + return $this->getProperties($reflection_class->getName()); |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * @param string $class_name |
|
226 | + * @return ReflectionMethod[] |
|
227 | + * @throws InvalidDataTypeException |
|
228 | + * @throws ReflectionException |
|
229 | + */ |
|
230 | + public function getMethods($class_name) |
|
231 | + { |
|
232 | + if (! isset($this->methods[ $class_name ])) { |
|
233 | + $reflection_class = $this->getReflectionClass($class_name); |
|
234 | + $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
235 | + } |
|
236 | + return $this->methods[ $class_name ]; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @param ReflectionClass $reflection_class ) |
|
242 | + * @return ReflectionMethod[] |
|
243 | + * @throws InvalidDataTypeException |
|
244 | + * @throws ReflectionException |
|
245 | + */ |
|
246 | + public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
247 | + { |
|
248 | + return $this->getMethods($reflection_class->getName()); |
|
249 | + } |
|
250 | 250 | } |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function getReflectionClass($class_name) |
66 | 66 | { |
67 | - if (! is_string($class_name)) { |
|
67 | + if ( ! is_string($class_name)) { |
|
68 | 68 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
69 | 69 | } |
70 | - if (! isset($this->classes[ $class_name ])) { |
|
71 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
70 | + if ( ! isset($this->classes[$class_name])) { |
|
71 | + $this->classes[$class_name] = new ReflectionClass($class_name); |
|
72 | 72 | } |
73 | - return $this->classes[ $class_name ]; |
|
73 | + return $this->classes[$class_name]; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | |
@@ -82,14 +82,14 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function getConstructor($class_name) |
84 | 84 | { |
85 | - if (! is_string($class_name)) { |
|
85 | + if ( ! is_string($class_name)) { |
|
86 | 86 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
87 | 87 | } |
88 | - if (! isset($this->constructors[ $class_name ])) { |
|
88 | + if ( ! isset($this->constructors[$class_name])) { |
|
89 | 89 | $reflection_class = $this->getReflectionClass($class_name); |
90 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
90 | + $this->constructors[$class_name] = $reflection_class->getConstructor(); |
|
91 | 91 | } |
92 | - return $this->constructors[ $class_name ]; |
|
92 | + return $this->constructors[$class_name]; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getParameters($class_name) |
115 | 115 | { |
116 | - if (! isset($this->parameters[ $class_name ])) { |
|
116 | + if ( ! isset($this->parameters[$class_name])) { |
|
117 | 117 | $constructor = $this->getConstructor($class_name); |
118 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
118 | + $this->parameters[$class_name] = $constructor->getParameters(); |
|
119 | 119 | } |
120 | - return $this->parameters[ $class_name ]; |
|
120 | + return $this->parameters[$class_name]; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
155 | 155 | { |
156 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
157 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
156 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_name'])) { |
|
157 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
158 | 158 | } |
159 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
160 | - $this->parameter_classes[ $class_name ] = array(); |
|
159 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
160 | + $this->parameter_classes[$class_name] = array(); |
|
161 | 161 | } |
162 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
163 | - $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
162 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
163 | + $this->parameter_classes[$class_name][$index] = array(); |
|
164 | 164 | } |
165 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass() |
|
165 | + $this->parameter_classes[$class_name][$index]['param_class_name'] = $param->getClass() |
|
166 | 166 | ? $param->getClass()->name |
167 | 167 | : null; |
168 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
168 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | |
@@ -177,19 +177,19 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
179 | 179 | { |
180 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
181 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
180 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_default'])) { |
|
181 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
182 | 182 | } |
183 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
184 | - $this->parameter_classes[ $class_name ] = array(); |
|
183 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
184 | + $this->parameter_classes[$class_name] = array(); |
|
185 | 185 | } |
186 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
187 | - $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
186 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
187 | + $this->parameter_classes[$class_name][$index] = array(); |
|
188 | 188 | } |
189 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
189 | + $this->parameter_classes[$class_name][$index]['param_class_default'] = $param->isDefaultValueAvailable() |
|
190 | 190 | ? $param->getDefaultValue() |
191 | 191 | : null; |
192 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
192 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | |
@@ -201,11 +201,11 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function getProperties($class_name) |
203 | 203 | { |
204 | - if (! isset($this->properties[ $class_name ])) { |
|
204 | + if ( ! isset($this->properties[$class_name])) { |
|
205 | 205 | $reflection_class = $this->getReflectionClass($class_name); |
206 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
206 | + $this->properties[$class_name] = $reflection_class->getProperties(); |
|
207 | 207 | } |
208 | - return $this->properties[ $class_name ]; |
|
208 | + return $this->properties[$class_name]; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -229,11 +229,11 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function getMethods($class_name) |
231 | 231 | { |
232 | - if (! isset($this->methods[ $class_name ])) { |
|
232 | + if ( ! isset($this->methods[$class_name])) { |
|
233 | 233 | $reflection_class = $this->getReflectionClass($class_name); |
234 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
234 | + $this->methods[$class_name] = $reflection_class->getMethods(); |
|
235 | 235 | } |
236 | - return $this->methods[ $class_name ]; |
|
236 | + return $this->methods[$class_name]; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 |
@@ -21,54 +21,54 @@ |
||
21 | 21 | class FullyQualifiedName |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var string $fully_qualified_name |
|
26 | - */ |
|
27 | - private $fully_qualified_name; |
|
24 | + /** |
|
25 | + * @var string $fully_qualified_name |
|
26 | + */ |
|
27 | + private $fully_qualified_name; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * FullyQualifiedName constructor. |
|
32 | - * |
|
33 | - * @param string $fully_qualified_name |
|
34 | - * @throws InvalidClassException |
|
35 | - * @throws InvalidInterfaceException |
|
36 | - * @throws InvalidDataTypeException |
|
37 | - */ |
|
38 | - public function __construct($fully_qualified_name) |
|
39 | - { |
|
40 | - if (! is_string($fully_qualified_name)) { |
|
41 | - throw new InvalidDataTypeException( |
|
42 | - '$fully_qualified_name', |
|
43 | - $fully_qualified_name, |
|
44 | - 'string' |
|
45 | - ); |
|
46 | - } |
|
47 | - if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
48 | - if (strpos($fully_qualified_name, 'Interface') !== false) { |
|
49 | - throw new InvalidInterfaceException($fully_qualified_name); |
|
50 | - } |
|
51 | - throw new InvalidClassException($fully_qualified_name); |
|
52 | - } |
|
53 | - $this->fully_qualified_name = $fully_qualified_name; |
|
54 | - } |
|
30 | + /** |
|
31 | + * FullyQualifiedName constructor. |
|
32 | + * |
|
33 | + * @param string $fully_qualified_name |
|
34 | + * @throws InvalidClassException |
|
35 | + * @throws InvalidInterfaceException |
|
36 | + * @throws InvalidDataTypeException |
|
37 | + */ |
|
38 | + public function __construct($fully_qualified_name) |
|
39 | + { |
|
40 | + if (! is_string($fully_qualified_name)) { |
|
41 | + throw new InvalidDataTypeException( |
|
42 | + '$fully_qualified_name', |
|
43 | + $fully_qualified_name, |
|
44 | + 'string' |
|
45 | + ); |
|
46 | + } |
|
47 | + if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
48 | + if (strpos($fully_qualified_name, 'Interface') !== false) { |
|
49 | + throw new InvalidInterfaceException($fully_qualified_name); |
|
50 | + } |
|
51 | + throw new InvalidClassException($fully_qualified_name); |
|
52 | + } |
|
53 | + $this->fully_qualified_name = $fully_qualified_name; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function string() |
|
61 | - { |
|
62 | - return $this->fully_qualified_name; |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function string() |
|
61 | + { |
|
62 | + return $this->fully_qualified_name; |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function __toString() |
|
70 | - { |
|
71 | - return $this->fully_qualified_name; |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function __toString() |
|
70 | + { |
|
71 | + return $this->fully_qualified_name; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | } |
@@ -21,590 +21,590 @@ |
||
21 | 21 | class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * $_GET parameters |
|
26 | - * |
|
27 | - * @var array $get |
|
28 | - */ |
|
29 | - private $get; |
|
30 | - |
|
31 | - /** |
|
32 | - * $_POST parameters |
|
33 | - * |
|
34 | - * @var array $post |
|
35 | - */ |
|
36 | - private $post; |
|
37 | - |
|
38 | - /** |
|
39 | - * $_COOKIE parameters |
|
40 | - * |
|
41 | - * @var array $cookie |
|
42 | - */ |
|
43 | - private $cookie; |
|
44 | - |
|
45 | - /** |
|
46 | - * $_SERVER parameters |
|
47 | - * |
|
48 | - * @var array $server |
|
49 | - */ |
|
50 | - private $server; |
|
51 | - |
|
52 | - /** |
|
53 | - * $_REQUEST parameters |
|
54 | - * |
|
55 | - * @var array $request |
|
56 | - */ |
|
57 | - private $request; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var RequestTypeContextCheckerInterface |
|
61 | - */ |
|
62 | - private $request_type; |
|
63 | - |
|
64 | - /** |
|
65 | - * IP address for request |
|
66 | - * |
|
67 | - * @var string $ip_address |
|
68 | - */ |
|
69 | - private $ip_address; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var string $user_agent |
|
73 | - */ |
|
74 | - private $user_agent; |
|
75 | - |
|
76 | - /** |
|
77 | - * true if current user appears to be some kind of bot |
|
78 | - * |
|
79 | - * @var bool $is_bot |
|
80 | - */ |
|
81 | - private $is_bot; |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param array $get |
|
87 | - * @param array $post |
|
88 | - * @param array $cookie |
|
89 | - * @param array $server |
|
90 | - */ |
|
91 | - public function __construct(array $get, array $post, array $cookie, array $server) |
|
92 | - { |
|
93 | - // grab request vars |
|
94 | - $this->get = $get; |
|
95 | - $this->post = $post; |
|
96 | - $this->cookie = $cookie; |
|
97 | - $this->server = $server; |
|
98 | - $this->request = array_merge($this->get, $this->post); |
|
99 | - $this->ip_address = $this->visitorIp(); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @param RequestTypeContextCheckerInterface $type |
|
105 | - */ |
|
106 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
107 | - { |
|
108 | - $this->request_type = $type; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - public function getParams() |
|
117 | - { |
|
118 | - return $this->get; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function postParams() |
|
127 | - { |
|
128 | - return $this->post; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function cookieParams() |
|
137 | - { |
|
138 | - return $this->cookie; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - public function serverParams() |
|
146 | - { |
|
147 | - return $this->server; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * returns contents of $_REQUEST |
|
154 | - * |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - public function requestParams() |
|
158 | - { |
|
159 | - return $this->request; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @param $key |
|
166 | - * @param $value |
|
167 | - * @param bool $override_ee |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - public function setRequestParam($key, $value, $override_ee = false) |
|
171 | - { |
|
172 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
173 | - if ( |
|
174 | - $key !== 'ee' |
|
175 | - || ($key === 'ee' && empty($this->request['ee'])) |
|
176 | - || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
177 | - ) { |
|
178 | - $this->request[ $key ] = $value; |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * returns the value for a request param if the given key exists |
|
186 | - * |
|
187 | - * @param $key |
|
188 | - * @param null $default |
|
189 | - * @return mixed |
|
190 | - */ |
|
191 | - public function getRequestParam($key, $default = null) |
|
192 | - { |
|
193 | - return $this->requestParameterDrillDown($key, $default, 'get'); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * check if param exists |
|
200 | - * |
|
201 | - * @param $key |
|
202 | - * @return bool |
|
203 | - */ |
|
204 | - public function requestParamIsSet($key) |
|
205 | - { |
|
206 | - return $this->requestParameterDrillDown($key); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
212 | - * and return the value for the first match found |
|
213 | - * wildcards can be either of the following: |
|
214 | - * ? to represent a single character of any type |
|
215 | - * * to represent one or more characters of any type |
|
216 | - * |
|
217 | - * @param string $pattern |
|
218 | - * @param null|mixed $default |
|
219 | - * @return false|int |
|
220 | - */ |
|
221 | - public function getMatch($pattern, $default = null) |
|
222 | - { |
|
223 | - return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
229 | - * wildcards can be either of the following: |
|
230 | - * ? to represent a single character of any type |
|
231 | - * * to represent one or more characters of any type |
|
232 | - * returns true if a match is found or false if not |
|
233 | - * |
|
234 | - * @param string $pattern |
|
235 | - * @return false|int |
|
236 | - */ |
|
237 | - public function matches($pattern) |
|
238 | - { |
|
239 | - return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
245 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
246 | - * and used to search through the current request's parameter keys |
|
247 | - * @param array $request_params The array of request parameters to search through |
|
248 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
249 | - * Default is null |
|
250 | - * @param string $return [optional] Controls what kind of value is returned. |
|
251 | - * Options are: |
|
252 | - * 'bool' will return true or false if match is found or not |
|
253 | - * 'key' will return the first key found that matches the supplied pattern |
|
254 | - * 'value' will return the value for the first request parameter |
|
255 | - * whose key matches the supplied pattern |
|
256 | - * Default is 'value' |
|
257 | - * @return boolean|string |
|
258 | - */ |
|
259 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
260 | - { |
|
261 | - $return = in_array($return, array('bool', 'key', 'value'), true) |
|
262 | - ? $return |
|
263 | - : 'is_set'; |
|
264 | - // replace wildcard chars with regex chars |
|
265 | - $pattern = str_replace( |
|
266 | - array("\*", "\?"), |
|
267 | - array('.*', '.'), |
|
268 | - preg_quote($pattern, '/') |
|
269 | - ); |
|
270 | - foreach ($request_params as $key => $request_param) { |
|
271 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
272 | - // return value for request param |
|
273 | - if ($return === 'value') { |
|
274 | - return $request_params[ $key ]; |
|
275 | - } |
|
276 | - // or actual key or true just to indicate it was found |
|
277 | - return $return === 'key' ? $key : true; |
|
278 | - } |
|
279 | - } |
|
280 | - // match not found so return default value or false |
|
281 | - return $return === 'value' ? $default : false; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
287 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
288 | - * by using square brackets to surround keys for deeper array elements. |
|
289 | - * For example : |
|
290 | - * if the supplied $key was: "first[second][third]" |
|
291 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
292 | - * Given the following request parameters: |
|
293 | - * array( |
|
294 | - * 'first' => array( |
|
295 | - * 'second' => array( |
|
296 | - * 'third' => 'has a value' |
|
297 | - * ) |
|
298 | - * ) |
|
299 | - * ) |
|
300 | - * would return true if default parameters were set |
|
301 | - * |
|
302 | - * @param string $callback |
|
303 | - * @param $key |
|
304 | - * @param null $default |
|
305 | - * @param array $request_params |
|
306 | - * @return bool|mixed|null |
|
307 | - */ |
|
308 | - private function requestParameterDrillDown( |
|
309 | - $key, |
|
310 | - $default = null, |
|
311 | - $callback = 'is_set', |
|
312 | - array $request_params = array() |
|
313 | - ) { |
|
314 | - $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
315 | - ? $callback |
|
316 | - : 'is_set'; |
|
317 | - $request_params = ! empty($request_params) |
|
318 | - ? $request_params |
|
319 | - : $this->request; |
|
320 | - // does incoming key represent an array like 'first[second][third]' ? |
|
321 | - if (strpos($key, '[') !== false) { |
|
322 | - // turn it into an actual array |
|
323 | - $key = str_replace(']', '', $key); |
|
324 | - $keys = explode('[', $key); |
|
325 | - $key = array_shift($keys); |
|
326 | - if ($callback === 'match') { |
|
327 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
328 | - $key = $real_key ? $real_key : $key; |
|
329 | - } |
|
330 | - // check if top level key exists |
|
331 | - if (isset($request_params[ $key ])) { |
|
332 | - // build a new key to pass along like: 'second[third]' |
|
333 | - // or just 'second' depending on depth of keys |
|
334 | - $key_string = array_shift($keys); |
|
335 | - if (! empty($keys)) { |
|
336 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
337 | - } |
|
338 | - return $this->requestParameterDrillDown( |
|
339 | - $key_string, |
|
340 | - $default, |
|
341 | - $callback, |
|
342 | - $request_params[ $key ] |
|
343 | - ); |
|
344 | - } |
|
345 | - } |
|
346 | - if ($callback === 'is_set') { |
|
347 | - return isset($request_params[ $key ]); |
|
348 | - } |
|
349 | - if ($callback === 'match') { |
|
350 | - return $this->match($key, $request_params, $default); |
|
351 | - } |
|
352 | - return isset($request_params[ $key ]) |
|
353 | - ? $request_params[ $key ] |
|
354 | - : $default; |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * remove param |
|
360 | - * |
|
361 | - * @param $key |
|
362 | - * @param bool $unset_from_global_too |
|
363 | - */ |
|
364 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
365 | - { |
|
366 | - unset($this->request[ $key ]); |
|
367 | - if ($unset_from_global_too) { |
|
368 | - unset($_REQUEST[ $key ]); |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * @return string |
|
376 | - */ |
|
377 | - public function ipAddress() |
|
378 | - { |
|
379 | - return $this->ip_address; |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * attempt to get IP address of current visitor from server |
|
385 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
386 | - * |
|
387 | - * @access public |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - private function visitorIp() |
|
391 | - { |
|
392 | - $visitor_ip = '0.0.0.0'; |
|
393 | - $server_keys = array( |
|
394 | - 'HTTP_CLIENT_IP', |
|
395 | - 'HTTP_X_FORWARDED_FOR', |
|
396 | - 'HTTP_X_FORWARDED', |
|
397 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
398 | - 'HTTP_FORWARDED_FOR', |
|
399 | - 'HTTP_FORWARDED', |
|
400 | - 'REMOTE_ADDR', |
|
401 | - ); |
|
402 | - foreach ($server_keys as $key) { |
|
403 | - if (isset($this->server[ $key ])) { |
|
404 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
405 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
406 | - $visitor_ip = $ip; |
|
407 | - } |
|
408 | - } |
|
409 | - } |
|
410 | - } |
|
411 | - return $visitor_ip; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function requestUri() |
|
419 | - { |
|
420 | - $request_uri = filter_input( |
|
421 | - INPUT_SERVER, |
|
422 | - 'REQUEST_URI', |
|
423 | - FILTER_SANITIZE_URL, |
|
424 | - FILTER_NULL_ON_FAILURE |
|
425 | - ); |
|
426 | - if (empty($request_uri)) { |
|
427 | - // fallback sanitization if the above fails |
|
428 | - $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
429 | - } |
|
430 | - return $request_uri; |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * @return string |
|
436 | - */ |
|
437 | - public function userAgent() |
|
438 | - { |
|
439 | - return $this->user_agent; |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * @param string $user_agent |
|
445 | - */ |
|
446 | - public function setUserAgent($user_agent = '') |
|
447 | - { |
|
448 | - if ($user_agent === '' || ! is_string($user_agent)) { |
|
449 | - $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
450 | - } |
|
451 | - $this->user_agent = $user_agent; |
|
452 | - } |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * @return bool |
|
457 | - */ |
|
458 | - public function isBot() |
|
459 | - { |
|
460 | - return $this->is_bot; |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * @param bool $is_bot |
|
466 | - */ |
|
467 | - public function setIsBot($is_bot) |
|
468 | - { |
|
469 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * @return bool |
|
475 | - */ |
|
476 | - public function isActivation() |
|
477 | - { |
|
478 | - return $this->request_type->isActivation(); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * @param $is_activation |
|
484 | - * @return bool |
|
485 | - */ |
|
486 | - public function setIsActivation($is_activation) |
|
487 | - { |
|
488 | - return $this->request_type->setIsActivation($is_activation); |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * @return bool |
|
494 | - */ |
|
495 | - public function isAdmin() |
|
496 | - { |
|
497 | - return $this->request_type->isAdmin(); |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * @return bool |
|
503 | - */ |
|
504 | - public function isAdminAjax() |
|
505 | - { |
|
506 | - return $this->request_type->isAdminAjax(); |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * @return bool |
|
512 | - */ |
|
513 | - public function isAjax() |
|
514 | - { |
|
515 | - return $this->request_type->isAjax(); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * @return bool |
|
521 | - */ |
|
522 | - public function isEeAjax() |
|
523 | - { |
|
524 | - return $this->request_type->isEeAjax(); |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * @return bool |
|
530 | - */ |
|
531 | - public function isOtherAjax() |
|
532 | - { |
|
533 | - return $this->request_type->isOtherAjax(); |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * @return bool |
|
539 | - */ |
|
540 | - public function isApi() |
|
541 | - { |
|
542 | - return $this->request_type->isApi(); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * @return bool |
|
548 | - */ |
|
549 | - public function isCli() |
|
550 | - { |
|
551 | - return $this->request_type->isCli(); |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * @return bool |
|
557 | - */ |
|
558 | - public function isCron() |
|
559 | - { |
|
560 | - return $this->request_type->isCron(); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * @return bool |
|
566 | - */ |
|
567 | - public function isFeed() |
|
568 | - { |
|
569 | - return $this->request_type->isFeed(); |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * @return bool |
|
575 | - */ |
|
576 | - public function isFrontend() |
|
577 | - { |
|
578 | - return $this->request_type->isFrontend(); |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * @return bool |
|
584 | - */ |
|
585 | - public function isFrontAjax() |
|
586 | - { |
|
587 | - return $this->request_type->isFrontAjax(); |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * @return bool |
|
594 | - */ |
|
595 | - public function isIframe() |
|
596 | - { |
|
597 | - return $this->request_type->isIframe(); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * @return string |
|
603 | - */ |
|
604 | - public function slug() |
|
605 | - { |
|
606 | - return $this->request_type->slug(); |
|
607 | - } |
|
24 | + /** |
|
25 | + * $_GET parameters |
|
26 | + * |
|
27 | + * @var array $get |
|
28 | + */ |
|
29 | + private $get; |
|
30 | + |
|
31 | + /** |
|
32 | + * $_POST parameters |
|
33 | + * |
|
34 | + * @var array $post |
|
35 | + */ |
|
36 | + private $post; |
|
37 | + |
|
38 | + /** |
|
39 | + * $_COOKIE parameters |
|
40 | + * |
|
41 | + * @var array $cookie |
|
42 | + */ |
|
43 | + private $cookie; |
|
44 | + |
|
45 | + /** |
|
46 | + * $_SERVER parameters |
|
47 | + * |
|
48 | + * @var array $server |
|
49 | + */ |
|
50 | + private $server; |
|
51 | + |
|
52 | + /** |
|
53 | + * $_REQUEST parameters |
|
54 | + * |
|
55 | + * @var array $request |
|
56 | + */ |
|
57 | + private $request; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var RequestTypeContextCheckerInterface |
|
61 | + */ |
|
62 | + private $request_type; |
|
63 | + |
|
64 | + /** |
|
65 | + * IP address for request |
|
66 | + * |
|
67 | + * @var string $ip_address |
|
68 | + */ |
|
69 | + private $ip_address; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var string $user_agent |
|
73 | + */ |
|
74 | + private $user_agent; |
|
75 | + |
|
76 | + /** |
|
77 | + * true if current user appears to be some kind of bot |
|
78 | + * |
|
79 | + * @var bool $is_bot |
|
80 | + */ |
|
81 | + private $is_bot; |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param array $get |
|
87 | + * @param array $post |
|
88 | + * @param array $cookie |
|
89 | + * @param array $server |
|
90 | + */ |
|
91 | + public function __construct(array $get, array $post, array $cookie, array $server) |
|
92 | + { |
|
93 | + // grab request vars |
|
94 | + $this->get = $get; |
|
95 | + $this->post = $post; |
|
96 | + $this->cookie = $cookie; |
|
97 | + $this->server = $server; |
|
98 | + $this->request = array_merge($this->get, $this->post); |
|
99 | + $this->ip_address = $this->visitorIp(); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @param RequestTypeContextCheckerInterface $type |
|
105 | + */ |
|
106 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
107 | + { |
|
108 | + $this->request_type = $type; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + public function getParams() |
|
117 | + { |
|
118 | + return $this->get; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function postParams() |
|
127 | + { |
|
128 | + return $this->post; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function cookieParams() |
|
137 | + { |
|
138 | + return $this->cookie; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + public function serverParams() |
|
146 | + { |
|
147 | + return $this->server; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * returns contents of $_REQUEST |
|
154 | + * |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + public function requestParams() |
|
158 | + { |
|
159 | + return $this->request; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @param $key |
|
166 | + * @param $value |
|
167 | + * @param bool $override_ee |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + public function setRequestParam($key, $value, $override_ee = false) |
|
171 | + { |
|
172 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
173 | + if ( |
|
174 | + $key !== 'ee' |
|
175 | + || ($key === 'ee' && empty($this->request['ee'])) |
|
176 | + || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
177 | + ) { |
|
178 | + $this->request[ $key ] = $value; |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * returns the value for a request param if the given key exists |
|
186 | + * |
|
187 | + * @param $key |
|
188 | + * @param null $default |
|
189 | + * @return mixed |
|
190 | + */ |
|
191 | + public function getRequestParam($key, $default = null) |
|
192 | + { |
|
193 | + return $this->requestParameterDrillDown($key, $default, 'get'); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * check if param exists |
|
200 | + * |
|
201 | + * @param $key |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | + public function requestParamIsSet($key) |
|
205 | + { |
|
206 | + return $this->requestParameterDrillDown($key); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
212 | + * and return the value for the first match found |
|
213 | + * wildcards can be either of the following: |
|
214 | + * ? to represent a single character of any type |
|
215 | + * * to represent one or more characters of any type |
|
216 | + * |
|
217 | + * @param string $pattern |
|
218 | + * @param null|mixed $default |
|
219 | + * @return false|int |
|
220 | + */ |
|
221 | + public function getMatch($pattern, $default = null) |
|
222 | + { |
|
223 | + return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
229 | + * wildcards can be either of the following: |
|
230 | + * ? to represent a single character of any type |
|
231 | + * * to represent one or more characters of any type |
|
232 | + * returns true if a match is found or false if not |
|
233 | + * |
|
234 | + * @param string $pattern |
|
235 | + * @return false|int |
|
236 | + */ |
|
237 | + public function matches($pattern) |
|
238 | + { |
|
239 | + return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
245 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
246 | + * and used to search through the current request's parameter keys |
|
247 | + * @param array $request_params The array of request parameters to search through |
|
248 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
249 | + * Default is null |
|
250 | + * @param string $return [optional] Controls what kind of value is returned. |
|
251 | + * Options are: |
|
252 | + * 'bool' will return true or false if match is found or not |
|
253 | + * 'key' will return the first key found that matches the supplied pattern |
|
254 | + * 'value' will return the value for the first request parameter |
|
255 | + * whose key matches the supplied pattern |
|
256 | + * Default is 'value' |
|
257 | + * @return boolean|string |
|
258 | + */ |
|
259 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
260 | + { |
|
261 | + $return = in_array($return, array('bool', 'key', 'value'), true) |
|
262 | + ? $return |
|
263 | + : 'is_set'; |
|
264 | + // replace wildcard chars with regex chars |
|
265 | + $pattern = str_replace( |
|
266 | + array("\*", "\?"), |
|
267 | + array('.*', '.'), |
|
268 | + preg_quote($pattern, '/') |
|
269 | + ); |
|
270 | + foreach ($request_params as $key => $request_param) { |
|
271 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
272 | + // return value for request param |
|
273 | + if ($return === 'value') { |
|
274 | + return $request_params[ $key ]; |
|
275 | + } |
|
276 | + // or actual key or true just to indicate it was found |
|
277 | + return $return === 'key' ? $key : true; |
|
278 | + } |
|
279 | + } |
|
280 | + // match not found so return default value or false |
|
281 | + return $return === 'value' ? $default : false; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
287 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
288 | + * by using square brackets to surround keys for deeper array elements. |
|
289 | + * For example : |
|
290 | + * if the supplied $key was: "first[second][third]" |
|
291 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
292 | + * Given the following request parameters: |
|
293 | + * array( |
|
294 | + * 'first' => array( |
|
295 | + * 'second' => array( |
|
296 | + * 'third' => 'has a value' |
|
297 | + * ) |
|
298 | + * ) |
|
299 | + * ) |
|
300 | + * would return true if default parameters were set |
|
301 | + * |
|
302 | + * @param string $callback |
|
303 | + * @param $key |
|
304 | + * @param null $default |
|
305 | + * @param array $request_params |
|
306 | + * @return bool|mixed|null |
|
307 | + */ |
|
308 | + private function requestParameterDrillDown( |
|
309 | + $key, |
|
310 | + $default = null, |
|
311 | + $callback = 'is_set', |
|
312 | + array $request_params = array() |
|
313 | + ) { |
|
314 | + $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
315 | + ? $callback |
|
316 | + : 'is_set'; |
|
317 | + $request_params = ! empty($request_params) |
|
318 | + ? $request_params |
|
319 | + : $this->request; |
|
320 | + // does incoming key represent an array like 'first[second][third]' ? |
|
321 | + if (strpos($key, '[') !== false) { |
|
322 | + // turn it into an actual array |
|
323 | + $key = str_replace(']', '', $key); |
|
324 | + $keys = explode('[', $key); |
|
325 | + $key = array_shift($keys); |
|
326 | + if ($callback === 'match') { |
|
327 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
328 | + $key = $real_key ? $real_key : $key; |
|
329 | + } |
|
330 | + // check if top level key exists |
|
331 | + if (isset($request_params[ $key ])) { |
|
332 | + // build a new key to pass along like: 'second[third]' |
|
333 | + // or just 'second' depending on depth of keys |
|
334 | + $key_string = array_shift($keys); |
|
335 | + if (! empty($keys)) { |
|
336 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
337 | + } |
|
338 | + return $this->requestParameterDrillDown( |
|
339 | + $key_string, |
|
340 | + $default, |
|
341 | + $callback, |
|
342 | + $request_params[ $key ] |
|
343 | + ); |
|
344 | + } |
|
345 | + } |
|
346 | + if ($callback === 'is_set') { |
|
347 | + return isset($request_params[ $key ]); |
|
348 | + } |
|
349 | + if ($callback === 'match') { |
|
350 | + return $this->match($key, $request_params, $default); |
|
351 | + } |
|
352 | + return isset($request_params[ $key ]) |
|
353 | + ? $request_params[ $key ] |
|
354 | + : $default; |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * remove param |
|
360 | + * |
|
361 | + * @param $key |
|
362 | + * @param bool $unset_from_global_too |
|
363 | + */ |
|
364 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
365 | + { |
|
366 | + unset($this->request[ $key ]); |
|
367 | + if ($unset_from_global_too) { |
|
368 | + unset($_REQUEST[ $key ]); |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * @return string |
|
376 | + */ |
|
377 | + public function ipAddress() |
|
378 | + { |
|
379 | + return $this->ip_address; |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * attempt to get IP address of current visitor from server |
|
385 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
386 | + * |
|
387 | + * @access public |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + private function visitorIp() |
|
391 | + { |
|
392 | + $visitor_ip = '0.0.0.0'; |
|
393 | + $server_keys = array( |
|
394 | + 'HTTP_CLIENT_IP', |
|
395 | + 'HTTP_X_FORWARDED_FOR', |
|
396 | + 'HTTP_X_FORWARDED', |
|
397 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
398 | + 'HTTP_FORWARDED_FOR', |
|
399 | + 'HTTP_FORWARDED', |
|
400 | + 'REMOTE_ADDR', |
|
401 | + ); |
|
402 | + foreach ($server_keys as $key) { |
|
403 | + if (isset($this->server[ $key ])) { |
|
404 | + foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
405 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
406 | + $visitor_ip = $ip; |
|
407 | + } |
|
408 | + } |
|
409 | + } |
|
410 | + } |
|
411 | + return $visitor_ip; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function requestUri() |
|
419 | + { |
|
420 | + $request_uri = filter_input( |
|
421 | + INPUT_SERVER, |
|
422 | + 'REQUEST_URI', |
|
423 | + FILTER_SANITIZE_URL, |
|
424 | + FILTER_NULL_ON_FAILURE |
|
425 | + ); |
|
426 | + if (empty($request_uri)) { |
|
427 | + // fallback sanitization if the above fails |
|
428 | + $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
429 | + } |
|
430 | + return $request_uri; |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * @return string |
|
436 | + */ |
|
437 | + public function userAgent() |
|
438 | + { |
|
439 | + return $this->user_agent; |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * @param string $user_agent |
|
445 | + */ |
|
446 | + public function setUserAgent($user_agent = '') |
|
447 | + { |
|
448 | + if ($user_agent === '' || ! is_string($user_agent)) { |
|
449 | + $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
450 | + } |
|
451 | + $this->user_agent = $user_agent; |
|
452 | + } |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * @return bool |
|
457 | + */ |
|
458 | + public function isBot() |
|
459 | + { |
|
460 | + return $this->is_bot; |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * @param bool $is_bot |
|
466 | + */ |
|
467 | + public function setIsBot($is_bot) |
|
468 | + { |
|
469 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * @return bool |
|
475 | + */ |
|
476 | + public function isActivation() |
|
477 | + { |
|
478 | + return $this->request_type->isActivation(); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * @param $is_activation |
|
484 | + * @return bool |
|
485 | + */ |
|
486 | + public function setIsActivation($is_activation) |
|
487 | + { |
|
488 | + return $this->request_type->setIsActivation($is_activation); |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * @return bool |
|
494 | + */ |
|
495 | + public function isAdmin() |
|
496 | + { |
|
497 | + return $this->request_type->isAdmin(); |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * @return bool |
|
503 | + */ |
|
504 | + public function isAdminAjax() |
|
505 | + { |
|
506 | + return $this->request_type->isAdminAjax(); |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * @return bool |
|
512 | + */ |
|
513 | + public function isAjax() |
|
514 | + { |
|
515 | + return $this->request_type->isAjax(); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * @return bool |
|
521 | + */ |
|
522 | + public function isEeAjax() |
|
523 | + { |
|
524 | + return $this->request_type->isEeAjax(); |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * @return bool |
|
530 | + */ |
|
531 | + public function isOtherAjax() |
|
532 | + { |
|
533 | + return $this->request_type->isOtherAjax(); |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * @return bool |
|
539 | + */ |
|
540 | + public function isApi() |
|
541 | + { |
|
542 | + return $this->request_type->isApi(); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * @return bool |
|
548 | + */ |
|
549 | + public function isCli() |
|
550 | + { |
|
551 | + return $this->request_type->isCli(); |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * @return bool |
|
557 | + */ |
|
558 | + public function isCron() |
|
559 | + { |
|
560 | + return $this->request_type->isCron(); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * @return bool |
|
566 | + */ |
|
567 | + public function isFeed() |
|
568 | + { |
|
569 | + return $this->request_type->isFeed(); |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * @return bool |
|
575 | + */ |
|
576 | + public function isFrontend() |
|
577 | + { |
|
578 | + return $this->request_type->isFrontend(); |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * @return bool |
|
584 | + */ |
|
585 | + public function isFrontAjax() |
|
586 | + { |
|
587 | + return $this->request_type->isFrontAjax(); |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * @return bool |
|
594 | + */ |
|
595 | + public function isIframe() |
|
596 | + { |
|
597 | + return $this->request_type->isIframe(); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * @return string |
|
603 | + */ |
|
604 | + public function slug() |
|
605 | + { |
|
606 | + return $this->request_type->slug(); |
|
607 | + } |
|
608 | 608 | |
609 | 609 | |
610 | 610 | } |
@@ -33,110 +33,110 @@ |
||
33 | 33 | class CoreLoader implements LoaderDecoratorInterface |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var EE_Registry|CoffeeShop $generator |
|
38 | - */ |
|
39 | - private $generator; |
|
36 | + /** |
|
37 | + * @var EE_Registry|CoffeeShop $generator |
|
38 | + */ |
|
39 | + private $generator; |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * CoreLoader constructor. |
|
44 | - * |
|
45 | - * @param EE_Registry|CoffeeShop $generator |
|
46 | - * @throws InvalidArgumentException |
|
47 | - */ |
|
48 | - public function __construct($generator) |
|
49 | - { |
|
50 | - if (! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
51 | - throw new InvalidArgumentException( |
|
52 | - esc_html__( |
|
53 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
54 | - 'event_espresso' |
|
55 | - ) |
|
56 | - ); |
|
57 | - } |
|
58 | - $this->generator = $generator; |
|
59 | - } |
|
42 | + /** |
|
43 | + * CoreLoader constructor. |
|
44 | + * |
|
45 | + * @param EE_Registry|CoffeeShop $generator |
|
46 | + * @throws InvalidArgumentException |
|
47 | + */ |
|
48 | + public function __construct($generator) |
|
49 | + { |
|
50 | + if (! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
51 | + throw new InvalidArgumentException( |
|
52 | + esc_html__( |
|
53 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
54 | + 'event_espresso' |
|
55 | + ) |
|
56 | + ); |
|
57 | + } |
|
58 | + $this->generator = $generator; |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Calls the appropriate loading method from the installed generator; |
|
64 | - * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method |
|
65 | - * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(), |
|
66 | - * but NOT to the class being instantiated. |
|
67 | - * This is done by adding the parameters to the $arguments array as follows: |
|
68 | - * array( |
|
69 | - * 'EE_Registry::create(from_db)' => true, // boolean value, default = false |
|
70 | - * 'EE_Registry::create(load_only)' => true, // boolean value, default = false |
|
71 | - * 'EE_Registry::create(addon)' => true, // boolean value, default = false |
|
72 | - * ) |
|
73 | - * |
|
74 | - * @param string $fqcn |
|
75 | - * @param array $arguments |
|
76 | - * @param bool $shared |
|
77 | - * @return mixed |
|
78 | - * @throws OutOfBoundsException |
|
79 | - * @throws ServiceExistsException |
|
80 | - * @throws InstantiationException |
|
81 | - * @throws InvalidIdentifierException |
|
82 | - * @throws InvalidDataTypeException |
|
83 | - * @throws InvalidClassException |
|
84 | - * @throws EE_Error |
|
85 | - * @throws ServiceNotFoundException |
|
86 | - * @throws ReflectionException |
|
87 | - * @throws InvalidInterfaceException |
|
88 | - * @throws InvalidArgumentException |
|
89 | - */ |
|
90 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
91 | - { |
|
92 | - $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN); |
|
93 | - if ($this->generator instanceof EE_Registry) { |
|
94 | - // check if additional EE_Registry::create() arguments have been passed |
|
95 | - // from_db |
|
96 | - $from_db = isset($arguments['EE_Registry::create(from_db)']) |
|
97 | - ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN) |
|
98 | - : false; |
|
99 | - // load_only |
|
100 | - $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
101 | - ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN) |
|
102 | - : false; |
|
103 | - // addon |
|
104 | - $addon = isset($arguments['EE_Registry::create(addon)']) |
|
105 | - ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN) |
|
106 | - : false; |
|
107 | - unset( |
|
108 | - $arguments['EE_Registry::create(from_db)'], |
|
109 | - $arguments['EE_Registry::create(load_only)'], |
|
110 | - $arguments['EE_Registry::create(addon)'] |
|
111 | - ); |
|
112 | - // addons need to be cached on EE_Registry |
|
113 | - $shared = $addon ? true : $shared; |
|
114 | - return $this->generator->create( |
|
115 | - $fqcn, |
|
116 | - $arguments, |
|
117 | - $shared, |
|
118 | - $from_db, |
|
119 | - $load_only, |
|
120 | - $addon |
|
121 | - ); |
|
122 | - } |
|
123 | - return $this->generator->brew( |
|
124 | - $fqcn, |
|
125 | - $arguments, |
|
126 | - $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
127 | - ); |
|
128 | - } |
|
62 | + /** |
|
63 | + * Calls the appropriate loading method from the installed generator; |
|
64 | + * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method |
|
65 | + * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(), |
|
66 | + * but NOT to the class being instantiated. |
|
67 | + * This is done by adding the parameters to the $arguments array as follows: |
|
68 | + * array( |
|
69 | + * 'EE_Registry::create(from_db)' => true, // boolean value, default = false |
|
70 | + * 'EE_Registry::create(load_only)' => true, // boolean value, default = false |
|
71 | + * 'EE_Registry::create(addon)' => true, // boolean value, default = false |
|
72 | + * ) |
|
73 | + * |
|
74 | + * @param string $fqcn |
|
75 | + * @param array $arguments |
|
76 | + * @param bool $shared |
|
77 | + * @return mixed |
|
78 | + * @throws OutOfBoundsException |
|
79 | + * @throws ServiceExistsException |
|
80 | + * @throws InstantiationException |
|
81 | + * @throws InvalidIdentifierException |
|
82 | + * @throws InvalidDataTypeException |
|
83 | + * @throws InvalidClassException |
|
84 | + * @throws EE_Error |
|
85 | + * @throws ServiceNotFoundException |
|
86 | + * @throws ReflectionException |
|
87 | + * @throws InvalidInterfaceException |
|
88 | + * @throws InvalidArgumentException |
|
89 | + */ |
|
90 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
91 | + { |
|
92 | + $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN); |
|
93 | + if ($this->generator instanceof EE_Registry) { |
|
94 | + // check if additional EE_Registry::create() arguments have been passed |
|
95 | + // from_db |
|
96 | + $from_db = isset($arguments['EE_Registry::create(from_db)']) |
|
97 | + ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN) |
|
98 | + : false; |
|
99 | + // load_only |
|
100 | + $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
101 | + ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN) |
|
102 | + : false; |
|
103 | + // addon |
|
104 | + $addon = isset($arguments['EE_Registry::create(addon)']) |
|
105 | + ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN) |
|
106 | + : false; |
|
107 | + unset( |
|
108 | + $arguments['EE_Registry::create(from_db)'], |
|
109 | + $arguments['EE_Registry::create(load_only)'], |
|
110 | + $arguments['EE_Registry::create(addon)'] |
|
111 | + ); |
|
112 | + // addons need to be cached on EE_Registry |
|
113 | + $shared = $addon ? true : $shared; |
|
114 | + return $this->generator->create( |
|
115 | + $fqcn, |
|
116 | + $arguments, |
|
117 | + $shared, |
|
118 | + $from_db, |
|
119 | + $load_only, |
|
120 | + $addon |
|
121 | + ); |
|
122 | + } |
|
123 | + return $this->generator->brew( |
|
124 | + $fqcn, |
|
125 | + $arguments, |
|
126 | + $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
127 | + ); |
|
128 | + } |
|
129 | 129 | |
130 | 130 | |
131 | - /** |
|
132 | - * calls reset() on generator if method exists |
|
133 | - */ |
|
134 | - public function reset() |
|
135 | - { |
|
136 | - if ($this->generator instanceof ResettableInterface) { |
|
137 | - $this->generator->reset(); |
|
138 | - } |
|
139 | - } |
|
131 | + /** |
|
132 | + * calls reset() on generator if method exists |
|
133 | + */ |
|
134 | + public function reset() |
|
135 | + { |
|
136 | + if ($this->generator instanceof ResettableInterface) { |
|
137 | + $this->generator->reset(); |
|
138 | + } |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | // End of file CoreLoader.php |
142 | 142 | // Location: core/services/loaders/CoreLoader.php |
@@ -47,7 +47,7 @@ |
||
47 | 47 | */ |
48 | 48 | public function __construct($generator) |
49 | 49 | { |
50 | - if (! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
50 | + if ( ! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
51 | 51 | throw new InvalidArgumentException( |
52 | 52 | esc_html__( |
53 | 53 | 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |