@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function namespacedBlockType() |
86 | 86 | { |
87 | - return Block::NAME_SPACE . '/' . $this->block_type; |
|
87 | + return Block::NAME_SPACE.'/'.$this->block_type; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | */ |
219 | 219 | protected function loadGraphQLRelayAutoloader() |
220 | 220 | { |
221 | - if (! class_exists('GraphQLRelay')) { |
|
222 | - $autoloader = EE_THIRD_PARTY . 'wp-graphql/vendor/autoload.php'; |
|
223 | - if (! file_exists($autoloader)) { |
|
221 | + if ( ! class_exists('GraphQLRelay')) { |
|
222 | + $autoloader = EE_THIRD_PARTY.'wp-graphql/vendor/autoload.php'; |
|
223 | + if ( ! file_exists($autoloader)) { |
|
224 | 224 | return; |
225 | 225 | } |
226 | 226 | require_once $autoloader; |
@@ -20,209 +20,209 @@ |
||
20 | 20 | */ |
21 | 21 | abstract class Block implements BlockInterface |
22 | 22 | { |
23 | - /** |
|
24 | - * BlockAssetManager that this editor block uses for asset registration |
|
25 | - * |
|
26 | - * @var BlockAssetManagerInterface $block_asset_manager |
|
27 | - */ |
|
28 | - protected $block_asset_manager; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var RequestInterface $request |
|
32 | - */ |
|
33 | - protected $request; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array $attributes |
|
37 | - */ |
|
38 | - private $attributes; |
|
39 | - |
|
40 | - /** |
|
41 | - * If set to true, then the block will render its content client side |
|
42 | - * If false, then the block will render its content server side using the renderBlock() method |
|
43 | - * |
|
44 | - * @var bool $dynamic |
|
45 | - */ |
|
46 | - private $dynamic = false; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string $block_type |
|
50 | - */ |
|
51 | - private $block_type; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var array $supported_routes |
|
55 | - */ |
|
56 | - private $supported_routes; |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Block constructor. |
|
61 | - * |
|
62 | - * @param BlockAssetManagerInterface $block_asset_manager |
|
63 | - * @param RequestInterface $request |
|
64 | - */ |
|
65 | - public function __construct(BlockAssetManagerInterface $block_asset_manager, RequestInterface $request) |
|
66 | - { |
|
67 | - $this->block_asset_manager = $block_asset_manager; |
|
68 | - $this->request = $request; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function blockType() |
|
76 | - { |
|
77 | - return $this->block_type; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function namespacedBlockType() |
|
85 | - { |
|
86 | - return Block::NAME_SPACE . '/' . $this->block_type; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string $block_type |
|
92 | - */ |
|
93 | - protected function setBlockType($block_type) |
|
94 | - { |
|
95 | - $this->block_type = $block_type; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * BlockAssetManager that this editor block uses for asset registration |
|
101 | - * |
|
102 | - * @return BlockAssetManagerInterface |
|
103 | - */ |
|
104 | - public function assetManager() |
|
105 | - { |
|
106 | - return $this->block_asset_manager; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * returns an array of fully qualified class names |
|
112 | - * for RouteMatchSpecificationInterface objects |
|
113 | - * that specify routes that the block should be loaded for. |
|
114 | - * |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - public function supportedRoutes() |
|
118 | - { |
|
119 | - return $this->supported_routes; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @param array $supported_routes |
|
125 | - */ |
|
126 | - protected function setSupportedRoutes(array $supported_routes) |
|
127 | - { |
|
128 | - $this->supported_routes = $supported_routes; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function attributes() |
|
136 | - { |
|
137 | - return $this->attributes; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param array $attributes |
|
143 | - */ |
|
144 | - public function setAttributes(array $attributes) |
|
145 | - { |
|
146 | - $this->attributes = $attributes; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - public function isDynamic() |
|
154 | - { |
|
155 | - return $this->dynamic; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @param bool $dynamic |
|
161 | - */ |
|
162 | - public function setDynamic($dynamic = true) |
|
163 | - { |
|
164 | - $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Registers the Editor Block with WP core; |
|
170 | - * Returns the registered block type on success, or false on failure. |
|
171 | - * |
|
172 | - * @return WP_Block_Type|false |
|
173 | - */ |
|
174 | - public function registerBlock() |
|
175 | - { |
|
176 | - $args = array( |
|
177 | - 'attributes' => $this->attributes(), |
|
178 | - 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
179 | - 'script' => $this->block_asset_manager->getScriptHandle(), |
|
180 | - ); |
|
181 | - if ($this->isDynamic()) { |
|
182 | - $args['render_callback'] = array($this, 'renderBlock'); |
|
183 | - } |
|
184 | - return register_block_type( |
|
185 | - new WP_Block_Type( |
|
186 | - $this->namespacedBlockType(), |
|
187 | - $args |
|
188 | - ) |
|
189 | - ); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
195 | - */ |
|
196 | - public function unRegisterBlock() |
|
197 | - { |
|
198 | - return unregister_block_type($this->namespacedBlockType()); |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return array |
|
205 | - */ |
|
206 | - public function getEditorContainer() |
|
207 | - { |
|
208 | - return array( |
|
209 | - $this->namespacedBlockType(), |
|
210 | - array(), |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * @since $VID:$ |
|
217 | - */ |
|
218 | - protected function loadGraphQLRelayAutoloader() |
|
219 | - { |
|
220 | - if (! class_exists('GraphQLRelay')) { |
|
221 | - $autoloader = EE_THIRD_PARTY . 'wp-graphql/vendor/autoload.php'; |
|
222 | - if (! file_exists($autoloader)) { |
|
223 | - return; |
|
224 | - } |
|
225 | - require_once $autoloader; |
|
226 | - } |
|
227 | - } |
|
23 | + /** |
|
24 | + * BlockAssetManager that this editor block uses for asset registration |
|
25 | + * |
|
26 | + * @var BlockAssetManagerInterface $block_asset_manager |
|
27 | + */ |
|
28 | + protected $block_asset_manager; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var RequestInterface $request |
|
32 | + */ |
|
33 | + protected $request; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array $attributes |
|
37 | + */ |
|
38 | + private $attributes; |
|
39 | + |
|
40 | + /** |
|
41 | + * If set to true, then the block will render its content client side |
|
42 | + * If false, then the block will render its content server side using the renderBlock() method |
|
43 | + * |
|
44 | + * @var bool $dynamic |
|
45 | + */ |
|
46 | + private $dynamic = false; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string $block_type |
|
50 | + */ |
|
51 | + private $block_type; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var array $supported_routes |
|
55 | + */ |
|
56 | + private $supported_routes; |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Block constructor. |
|
61 | + * |
|
62 | + * @param BlockAssetManagerInterface $block_asset_manager |
|
63 | + * @param RequestInterface $request |
|
64 | + */ |
|
65 | + public function __construct(BlockAssetManagerInterface $block_asset_manager, RequestInterface $request) |
|
66 | + { |
|
67 | + $this->block_asset_manager = $block_asset_manager; |
|
68 | + $this->request = $request; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function blockType() |
|
76 | + { |
|
77 | + return $this->block_type; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function namespacedBlockType() |
|
85 | + { |
|
86 | + return Block::NAME_SPACE . '/' . $this->block_type; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string $block_type |
|
92 | + */ |
|
93 | + protected function setBlockType($block_type) |
|
94 | + { |
|
95 | + $this->block_type = $block_type; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * BlockAssetManager that this editor block uses for asset registration |
|
101 | + * |
|
102 | + * @return BlockAssetManagerInterface |
|
103 | + */ |
|
104 | + public function assetManager() |
|
105 | + { |
|
106 | + return $this->block_asset_manager; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * returns an array of fully qualified class names |
|
112 | + * for RouteMatchSpecificationInterface objects |
|
113 | + * that specify routes that the block should be loaded for. |
|
114 | + * |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + public function supportedRoutes() |
|
118 | + { |
|
119 | + return $this->supported_routes; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @param array $supported_routes |
|
125 | + */ |
|
126 | + protected function setSupportedRoutes(array $supported_routes) |
|
127 | + { |
|
128 | + $this->supported_routes = $supported_routes; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function attributes() |
|
136 | + { |
|
137 | + return $this->attributes; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param array $attributes |
|
143 | + */ |
|
144 | + public function setAttributes(array $attributes) |
|
145 | + { |
|
146 | + $this->attributes = $attributes; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + public function isDynamic() |
|
154 | + { |
|
155 | + return $this->dynamic; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @param bool $dynamic |
|
161 | + */ |
|
162 | + public function setDynamic($dynamic = true) |
|
163 | + { |
|
164 | + $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Registers the Editor Block with WP core; |
|
170 | + * Returns the registered block type on success, or false on failure. |
|
171 | + * |
|
172 | + * @return WP_Block_Type|false |
|
173 | + */ |
|
174 | + public function registerBlock() |
|
175 | + { |
|
176 | + $args = array( |
|
177 | + 'attributes' => $this->attributes(), |
|
178 | + 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
179 | + 'script' => $this->block_asset_manager->getScriptHandle(), |
|
180 | + ); |
|
181 | + if ($this->isDynamic()) { |
|
182 | + $args['render_callback'] = array($this, 'renderBlock'); |
|
183 | + } |
|
184 | + return register_block_type( |
|
185 | + new WP_Block_Type( |
|
186 | + $this->namespacedBlockType(), |
|
187 | + $args |
|
188 | + ) |
|
189 | + ); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
195 | + */ |
|
196 | + public function unRegisterBlock() |
|
197 | + { |
|
198 | + return unregister_block_type($this->namespacedBlockType()); |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return array |
|
205 | + */ |
|
206 | + public function getEditorContainer() |
|
207 | + { |
|
208 | + return array( |
|
209 | + $this->namespacedBlockType(), |
|
210 | + array(), |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * @since $VID:$ |
|
217 | + */ |
|
218 | + protected function loadGraphQLRelayAutoloader() |
|
219 | + { |
|
220 | + if (! class_exists('GraphQLRelay')) { |
|
221 | + $autoloader = EE_THIRD_PARTY . 'wp-graphql/vendor/autoload.php'; |
|
222 | + if (! file_exists($autoloader)) { |
|
223 | + return; |
|
224 | + } |
|
225 | + require_once $autoloader; |
|
226 | + } |
|
227 | + } |
|
228 | 228 | } |
@@ -183,7 +183,7 @@ |
||
183 | 183 | $this->resolveDependenciesForClass($param_class); |
184 | 184 | } |
185 | 185 | $param_class = $this->resolveAlias($param_class); |
186 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
186 | + $dependencies[$param_class] = EE_Dependency_Map::load_from_cache; |
|
187 | 187 | } |
188 | 188 | $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
189 | 189 | } |
@@ -22,168 +22,168 @@ |
||
22 | 22 | */ |
23 | 23 | class DependencyResolver implements DependencyResolverInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * @var Mirror $mirror |
|
27 | - */ |
|
28 | - private $mirror; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var ClassInterfaceCache $class_cache |
|
32 | - */ |
|
33 | - protected $class_cache; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var EE_Dependency_Map $dependency_map |
|
37 | - */ |
|
38 | - private $dependency_map; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var ClassAlias[] $aliases |
|
42 | - */ |
|
43 | - protected $aliases = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array $namespace_roots |
|
47 | - */ |
|
48 | - protected $namespace_roots = array(); |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * RouteMatchSpecificationDependencyResolver constructor. |
|
53 | - * |
|
54 | - * @param Mirror $mirror |
|
55 | - * @param ClassInterfaceCache $class_cache |
|
56 | - * @param EE_Dependency_Map $dependency_map |
|
57 | - */ |
|
58 | - public function __construct( |
|
59 | - Mirror $mirror, |
|
60 | - ClassInterfaceCache $class_cache, |
|
61 | - EE_Dependency_Map $dependency_map |
|
62 | - ) { |
|
63 | - $this->mirror = $mirror; |
|
64 | - $this->class_cache = $class_cache; |
|
65 | - $this->dependency_map = $dependency_map; |
|
66 | - $this->initialize(); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Used to configure and/or setup any aliases or namespace roots required by the DependencyResolver |
|
72 | - * |
|
73 | - * @throws InvalidAliasException |
|
74 | - * @since 4.9.71.p |
|
75 | - */ |
|
76 | - public function initialize() |
|
77 | - { |
|
78 | - // nothing to do here for default resolver |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return Mirror |
|
84 | - */ |
|
85 | - public function mirror() |
|
86 | - { |
|
87 | - return $this->mirror; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @return ClassInterfaceCache |
|
92 | - */ |
|
93 | - public function classCache() |
|
94 | - { |
|
95 | - return $this->class_cache; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @return EE_Dependency_Map |
|
100 | - */ |
|
101 | - public function dependencyMap() |
|
102 | - { |
|
103 | - return $this->dependency_map; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
108 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
109 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
110 | - * @throws InvalidAliasException |
|
111 | - */ |
|
112 | - public function addAlias($fqcn, $alias, $for_class = '') |
|
113 | - { |
|
114 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public function resolveAlias($param_fqcn) |
|
122 | - { |
|
123 | - return $this->class_cache->getFqnForAlias($param_fqcn); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Primarily used to indicate the namespace root for composite objects |
|
128 | - * so that dependencies requiring the same DependencyResolver can be acquired |
|
129 | - * for example: |
|
130 | - * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
131 | - * may all implement Vendor\path\to\Interface, |
|
132 | - * but Vendor\path\to\class\C could be a composite object |
|
133 | - * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
134 | - * and needs both of those dependencies resolved, which would therefore require |
|
135 | - * the use of the same DependencyResolver. |
|
136 | - * |
|
137 | - * By specifying a namespace root of "Vendor\path\to\", |
|
138 | - * then all classes that are descendants of that namespace |
|
139 | - * will use DependencyResolver to acquire the classes they need |
|
140 | - * |
|
141 | - * @param string $namespace_root Partial namespace used for detecting other classes |
|
142 | - * that should employ this same DependencyResolver |
|
143 | - */ |
|
144 | - public function addNamespaceRoot($namespace_root) |
|
145 | - { |
|
146 | - $this->namespace_roots[] = $namespace_root; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Returns true if the parameter FQCN belongs to one of |
|
151 | - * the namespaces that utilizes this DependencyResolver |
|
152 | - * |
|
153 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
154 | - * @return boolean |
|
155 | - * @since 4.9.71.p |
|
156 | - */ |
|
157 | - public function dependencyRecursionExists($param_fqcn) |
|
158 | - { |
|
159 | - foreach ($this->namespace_roots as $namespace_root) { |
|
160 | - if (strpos($param_fqcn, $namespace_root) !== false) { |
|
161 | - return true; |
|
162 | - } |
|
163 | - } |
|
164 | - return false; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @param string $fqcn Fully Qualified Class Name |
|
170 | - * @throws InvalidDataTypeException |
|
171 | - * @throws ReflectionException |
|
172 | - * @since 4.9.71.p |
|
173 | - */ |
|
174 | - public function resolveDependenciesForClass($fqcn) |
|
175 | - { |
|
176 | - $dependencies = array(); |
|
177 | - $params = $this->mirror()->getParameters($fqcn); |
|
178 | - foreach ($params as $index => $param) { |
|
179 | - // is this a dependency for a specific class ? |
|
180 | - $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
181 | - if ($this->dependencyRecursionExists($param_class)) { |
|
182 | - $this->resolveDependenciesForClass($param_class); |
|
183 | - } |
|
184 | - $param_class = $this->resolveAlias($param_class); |
|
185 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
186 | - } |
|
187 | - $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
188 | - } |
|
25 | + /** |
|
26 | + * @var Mirror $mirror |
|
27 | + */ |
|
28 | + private $mirror; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var ClassInterfaceCache $class_cache |
|
32 | + */ |
|
33 | + protected $class_cache; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var EE_Dependency_Map $dependency_map |
|
37 | + */ |
|
38 | + private $dependency_map; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var ClassAlias[] $aliases |
|
42 | + */ |
|
43 | + protected $aliases = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array $namespace_roots |
|
47 | + */ |
|
48 | + protected $namespace_roots = array(); |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * RouteMatchSpecificationDependencyResolver constructor. |
|
53 | + * |
|
54 | + * @param Mirror $mirror |
|
55 | + * @param ClassInterfaceCache $class_cache |
|
56 | + * @param EE_Dependency_Map $dependency_map |
|
57 | + */ |
|
58 | + public function __construct( |
|
59 | + Mirror $mirror, |
|
60 | + ClassInterfaceCache $class_cache, |
|
61 | + EE_Dependency_Map $dependency_map |
|
62 | + ) { |
|
63 | + $this->mirror = $mirror; |
|
64 | + $this->class_cache = $class_cache; |
|
65 | + $this->dependency_map = $dependency_map; |
|
66 | + $this->initialize(); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Used to configure and/or setup any aliases or namespace roots required by the DependencyResolver |
|
72 | + * |
|
73 | + * @throws InvalidAliasException |
|
74 | + * @since 4.9.71.p |
|
75 | + */ |
|
76 | + public function initialize() |
|
77 | + { |
|
78 | + // nothing to do here for default resolver |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return Mirror |
|
84 | + */ |
|
85 | + public function mirror() |
|
86 | + { |
|
87 | + return $this->mirror; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @return ClassInterfaceCache |
|
92 | + */ |
|
93 | + public function classCache() |
|
94 | + { |
|
95 | + return $this->class_cache; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @return EE_Dependency_Map |
|
100 | + */ |
|
101 | + public function dependencyMap() |
|
102 | + { |
|
103 | + return $this->dependency_map; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
108 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
109 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
110 | + * @throws InvalidAliasException |
|
111 | + */ |
|
112 | + public function addAlias($fqcn, $alias, $for_class = '') |
|
113 | + { |
|
114 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public function resolveAlias($param_fqcn) |
|
122 | + { |
|
123 | + return $this->class_cache->getFqnForAlias($param_fqcn); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Primarily used to indicate the namespace root for composite objects |
|
128 | + * so that dependencies requiring the same DependencyResolver can be acquired |
|
129 | + * for example: |
|
130 | + * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
131 | + * may all implement Vendor\path\to\Interface, |
|
132 | + * but Vendor\path\to\class\C could be a composite object |
|
133 | + * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
134 | + * and needs both of those dependencies resolved, which would therefore require |
|
135 | + * the use of the same DependencyResolver. |
|
136 | + * |
|
137 | + * By specifying a namespace root of "Vendor\path\to\", |
|
138 | + * then all classes that are descendants of that namespace |
|
139 | + * will use DependencyResolver to acquire the classes they need |
|
140 | + * |
|
141 | + * @param string $namespace_root Partial namespace used for detecting other classes |
|
142 | + * that should employ this same DependencyResolver |
|
143 | + */ |
|
144 | + public function addNamespaceRoot($namespace_root) |
|
145 | + { |
|
146 | + $this->namespace_roots[] = $namespace_root; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Returns true if the parameter FQCN belongs to one of |
|
151 | + * the namespaces that utilizes this DependencyResolver |
|
152 | + * |
|
153 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
154 | + * @return boolean |
|
155 | + * @since 4.9.71.p |
|
156 | + */ |
|
157 | + public function dependencyRecursionExists($param_fqcn) |
|
158 | + { |
|
159 | + foreach ($this->namespace_roots as $namespace_root) { |
|
160 | + if (strpos($param_fqcn, $namespace_root) !== false) { |
|
161 | + return true; |
|
162 | + } |
|
163 | + } |
|
164 | + return false; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @param string $fqcn Fully Qualified Class Name |
|
170 | + * @throws InvalidDataTypeException |
|
171 | + * @throws ReflectionException |
|
172 | + * @since 4.9.71.p |
|
173 | + */ |
|
174 | + public function resolveDependenciesForClass($fqcn) |
|
175 | + { |
|
176 | + $dependencies = array(); |
|
177 | + $params = $this->mirror()->getParameters($fqcn); |
|
178 | + foreach ($params as $index => $param) { |
|
179 | + // is this a dependency for a specific class ? |
|
180 | + $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
181 | + if ($this->dependencyRecursionExists($param_class)) { |
|
182 | + $this->resolveDependenciesForClass($param_class); |
|
183 | + } |
|
184 | + $param_class = $this->resolveAlias($param_class); |
|
185 | + $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
186 | + } |
|
187 | + $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
188 | + } |
|
189 | 189 | } |
@@ -14,8 +14,8 @@ |
||
14 | 14 | */ |
15 | 15 | class AnyFrontendRequest extends RouteMatchSpecification |
16 | 16 | { |
17 | - public function isMatchingRoute() |
|
18 | - { |
|
19 | - return $this->request->isFrontend(); |
|
20 | - } |
|
17 | + public function isMatchingRoute() |
|
18 | + { |
|
19 | + return $this->request->isFrontend(); |
|
20 | + } |
|
21 | 21 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | public function isMatchingRoute() |
24 | 24 | { |
25 | 25 | foreach ($this->specifications as $specification) { |
26 | - if (! $specification->isMatchingRoute()) { |
|
26 | + if ( ! $specification->isMatchingRoute()) { |
|
27 | 27 | return false; |
28 | 28 | } |
29 | 29 | } |
@@ -13,19 +13,19 @@ |
||
13 | 13 | */ |
14 | 14 | class MatchAllRouteSpecifications extends MultiRouteSpecification |
15 | 15 | { |
16 | - /** |
|
17 | - * returns true if current request matches specification |
|
18 | - * |
|
19 | - * @since 4.9.71.p |
|
20 | - * @return boolean |
|
21 | - */ |
|
22 | - public function isMatchingRoute() |
|
23 | - { |
|
24 | - foreach ($this->specifications as $specification) { |
|
25 | - if (! $specification->isMatchingRoute()) { |
|
26 | - return false; |
|
27 | - } |
|
28 | - } |
|
29 | - return true; |
|
30 | - } |
|
16 | + /** |
|
17 | + * returns true if current request matches specification |
|
18 | + * |
|
19 | + * @since 4.9.71.p |
|
20 | + * @return boolean |
|
21 | + */ |
|
22 | + public function isMatchingRoute() |
|
23 | + { |
|
24 | + foreach ($this->specifications as $specification) { |
|
25 | + if (! $specification->isMatchingRoute()) { |
|
26 | + return false; |
|
27 | + } |
|
28 | + } |
|
29 | + return true; |
|
30 | + } |
|
31 | 31 | } |
@@ -14,14 +14,14 @@ |
||
14 | 14 | */ |
15 | 15 | class DoesNotMatchRouteSpecification extends RouteMatchSpecificationDecorator |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since 4.9.71.p |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - return ! $this->specification->isMatchingRoute(); |
|
26 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since 4.9.71.p |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + return ! $this->specification->isMatchingRoute(); |
|
26 | + } |
|
27 | 27 | } |
@@ -19,22 +19,22 @@ |
||
19 | 19 | */ |
20 | 20 | class EspressoVenueEditor extends MatchAnyRouteSpecification |
21 | 21 | { |
22 | - /** |
|
23 | - * EspressoVenueEditor constructor. |
|
24 | - * |
|
25 | - * @param EspressoVenueEditorEdit $edit_venue_route_match |
|
26 | - * @param EspressoVenueEditorAddNew $create_venue_route_match |
|
27 | - * @param RequestInterface $request |
|
28 | - * @throws InvalidEntityException |
|
29 | - */ |
|
30 | - public function __construct( |
|
31 | - EspressoVenueEditorEdit $edit_venue_route_match, |
|
32 | - EspressoVenueEditorAddNew $create_venue_route_match, |
|
33 | - RequestInterface $request |
|
34 | - ) { |
|
35 | - parent::__construct( |
|
36 | - array($edit_venue_route_match, $create_venue_route_match), |
|
37 | - $request |
|
38 | - ); |
|
39 | - } |
|
22 | + /** |
|
23 | + * EspressoVenueEditor constructor. |
|
24 | + * |
|
25 | + * @param EspressoVenueEditorEdit $edit_venue_route_match |
|
26 | + * @param EspressoVenueEditorAddNew $create_venue_route_match |
|
27 | + * @param RequestInterface $request |
|
28 | + * @throws InvalidEntityException |
|
29 | + */ |
|
30 | + public function __construct( |
|
31 | + EspressoVenueEditorEdit $edit_venue_route_match, |
|
32 | + EspressoVenueEditorAddNew $create_venue_route_match, |
|
33 | + RequestInterface $request |
|
34 | + ) { |
|
35 | + parent::__construct( |
|
36 | + array($edit_venue_route_match, $create_venue_route_match), |
|
37 | + $request |
|
38 | + ); |
|
39 | + } |
|
40 | 40 | } |
@@ -18,22 +18,22 @@ |
||
18 | 18 | */ |
19 | 19 | class EspressoPostTypeEditor extends MatchAnyRouteSpecification |
20 | 20 | { |
21 | - /** |
|
22 | - * EspressoEventEditor constructor. |
|
23 | - * |
|
24 | - * @param EspressoStandardPostTypeEditor $standard_route_match |
|
25 | - * @param EspressoAttendeePostTypeEditor $attendee_route_match |
|
26 | - * @param RequestInterface $request |
|
27 | - * @throws InvalidEntityException |
|
28 | - */ |
|
29 | - public function __construct( |
|
30 | - EspressoStandardPostTypeEditor $standard_route_match, |
|
31 | - EspressoAttendeePostTypeEditor $attendee_route_match, |
|
32 | - RequestInterface $request |
|
33 | - ) { |
|
34 | - parent::__construct( |
|
35 | - array($standard_route_match, $attendee_route_match), |
|
36 | - $request |
|
37 | - ); |
|
38 | - } |
|
21 | + /** |
|
22 | + * EspressoEventEditor constructor. |
|
23 | + * |
|
24 | + * @param EspressoStandardPostTypeEditor $standard_route_match |
|
25 | + * @param EspressoAttendeePostTypeEditor $attendee_route_match |
|
26 | + * @param RequestInterface $request |
|
27 | + * @throws InvalidEntityException |
|
28 | + */ |
|
29 | + public function __construct( |
|
30 | + EspressoStandardPostTypeEditor $standard_route_match, |
|
31 | + EspressoAttendeePostTypeEditor $attendee_route_match, |
|
32 | + RequestInterface $request |
|
33 | + ) { |
|
34 | + parent::__construct( |
|
35 | + array($standard_route_match, $attendee_route_match), |
|
36 | + $request |
|
37 | + ); |
|
38 | + } |
|
39 | 39 | } |
@@ -19,22 +19,22 @@ |
||
19 | 19 | */ |
20 | 20 | class EspressoEventEditor extends MatchAnyRouteSpecification |
21 | 21 | { |
22 | - /** |
|
23 | - * EspressoEventEditor constructor. |
|
24 | - * |
|
25 | - * @param EspressoEventEditorEdit $edit_event_route_match |
|
26 | - * @param EspressoEventEditorAddNew $create_event_route_match |
|
27 | - * @param RequestInterface $request |
|
28 | - * @throws InvalidEntityException |
|
29 | - */ |
|
30 | - public function __construct( |
|
31 | - EspressoEventEditorEdit $edit_event_route_match, |
|
32 | - EspressoEventEditorAddNew $create_event_route_match, |
|
33 | - RequestInterface $request |
|
34 | - ) { |
|
35 | - parent::__construct( |
|
36 | - array($edit_event_route_match, $create_event_route_match), |
|
37 | - $request |
|
38 | - ); |
|
39 | - } |
|
22 | + /** |
|
23 | + * EspressoEventEditor constructor. |
|
24 | + * |
|
25 | + * @param EspressoEventEditorEdit $edit_event_route_match |
|
26 | + * @param EspressoEventEditorAddNew $create_event_route_match |
|
27 | + * @param RequestInterface $request |
|
28 | + * @throws InvalidEntityException |
|
29 | + */ |
|
30 | + public function __construct( |
|
31 | + EspressoEventEditorEdit $edit_event_route_match, |
|
32 | + EspressoEventEditorAddNew $create_event_route_match, |
|
33 | + RequestInterface $request |
|
34 | + ) { |
|
35 | + parent::__construct( |
|
36 | + array($edit_event_route_match, $create_event_route_match), |
|
37 | + $request |
|
38 | + ); |
|
39 | + } |
|
40 | 40 | } |
@@ -12,11 +12,11 @@ |
||
12 | 12 | */ |
13 | 13 | interface RouteMatchSpecificationInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * returns true if current request matches specification |
|
17 | - * |
|
18 | - * @since 4.9.71.p |
|
19 | - * @return boolean |
|
20 | - */ |
|
21 | - public function isMatchingRoute(); |
|
15 | + /** |
|
16 | + * returns true if current request matches specification |
|
17 | + * |
|
18 | + * @since 4.9.71.p |
|
19 | + * @return boolean |
|
20 | + */ |
|
21 | + public function isMatchingRoute(); |
|
22 | 22 | } |