@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | foreach ($this->blocks as $block) { |
146 | 146 | $block->initialize(); |
147 | 147 | $this->trackAssetManagersForBlocks($block); |
148 | - if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
148 | + if ( ! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
149 | 149 | $this->block_asset_manager_collection->add($block->assetManager()); |
150 | 150 | $block->assetManager()->setAssetHandles(); |
151 | 151 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $supported_routes = $block->supportedRoutes(); |
168 | 168 | foreach ($supported_routes as $supported_route) { |
169 | 169 | if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
170 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
170 | + $this->block_asset_managers[$block->blockType()] = $block->assetManager()->assetNamespace(); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function matchesRoute(BlockInterface $block) |
185 | 185 | { |
186 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
186 | + if (isset($this->block_asset_managers[$block->blockType()])) { |
|
187 | 187 | return true; |
188 | 188 | } |
189 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
189 | + unset($this->block_asset_managers[$block->blockType()]); |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
@@ -202,12 +202,12 @@ discard block |
||
202 | 202 | try { |
203 | 203 | // cycle thru block loader folders |
204 | 204 | foreach ($this->blocks as $block) { |
205 | - if (! $this->matchesRoute($block)) { |
|
205 | + if ( ! $this->matchesRoute($block)) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | 208 | // perform any setup required for the block |
209 | 209 | $block_type = $block->registerBlock(); |
210 | - if (! $block_type instanceof WP_Block_Type) { |
|
210 | + if ( ! $block_type instanceof WP_Block_Type) { |
|
211 | 211 | throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
212 | 212 | } |
213 | 213 | do_action( |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $assets = array_flip($this->block_asset_managers); |
227 | 227 | foreach ($this->block_asset_manager_collection as $asset_manager) { |
228 | 228 | // if there are no longer any blocks that require these assets, |
229 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
229 | + if ( ! isset($assets[$asset_manager->assetNamespace()])) { |
|
230 | 230 | // then unset asset enqueueing and bail |
231 | 231 | remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
232 | 232 | remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
@@ -32,223 +32,223 @@ |
||
32 | 32 | class BlockRegistrationManager extends BlockManager |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
37 | - */ |
|
38 | - protected $block_asset_manager_collection; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var RouteMatchSpecificationManager $route_manager |
|
42 | - */ |
|
43 | - protected $route_manager; |
|
44 | - |
|
45 | - /** |
|
46 | - * array for tracking asset managers required by blocks for the current route |
|
47 | - * |
|
48 | - * @var array $block_asset_managers |
|
49 | - */ |
|
50 | - protected $block_asset_managers = array(); |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * BlockRegistrationManager constructor. |
|
55 | - * |
|
56 | - * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
57 | - * @param BlockCollection $blocks |
|
58 | - * @param RouteMatchSpecificationManager $route_manager |
|
59 | - * @param RequestInterface $request |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - BlockAssetManagerCollection $block_asset_manager_collection, |
|
63 | - BlockCollection $blocks, |
|
64 | - RouteMatchSpecificationManager $route_manager, |
|
65 | - RequestInterface $request |
|
66 | - ) { |
|
67 | - $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
68 | - $this->route_manager = $route_manager; |
|
69 | - parent::__construct($blocks, $request); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Returns the name of a hookpoint to be used to call initialize() |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function initHook() |
|
79 | - { |
|
80 | - return 'AHEE__EE_System__initialize'; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Perform any early setup required for block editors to functions |
|
86 | - * |
|
87 | - * @return void |
|
88 | - * @throws Exception |
|
89 | - */ |
|
90 | - public function initialize() |
|
91 | - { |
|
92 | - $this->initializeBlocks(); |
|
93 | - add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
94 | - add_action('wp_loaded', array($this, 'unloadAssets')); |
|
95 | - add_filter('block_categories', array($this, 'addEspressoBlockCategories')); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @param array $categories |
|
101 | - * @since $VID:$ |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function addEspressoBlockCategories(array $categories) |
|
105 | - { |
|
106 | - return array_merge( |
|
107 | - $categories, |
|
108 | - array( |
|
109 | - array( |
|
110 | - 'slug' => 'event-espresso', |
|
111 | - 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
112 | - ), |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return CollectionInterface|BlockInterface[] |
|
120 | - * @throws CollectionLoaderException |
|
121 | - * @throws CollectionDetailsException |
|
122 | - */ |
|
123 | - protected function populateBlockCollection() |
|
124 | - { |
|
125 | - $loader = new CollectionLoader( |
|
126 | - new CollectionDetails( |
|
127 | - // collection name |
|
128 | - 'editor_blocks', |
|
129 | - // collection interface |
|
130 | - 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
131 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
132 | - apply_filters( |
|
133 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
134 | - array('EventEspresso\core\domain\entities\editor\blocks') |
|
135 | - ), |
|
136 | - // filepaths to classes to add |
|
137 | - array(), |
|
138 | - // file mask to use if parsing folder for files to add |
|
139 | - '', |
|
140 | - // what to use as identifier for collection entities |
|
141 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
142 | - CollectionDetails::ID_CLASS_NAME |
|
143 | - ), |
|
144 | - $this->blocks |
|
145 | - ); |
|
146 | - return $loader->getCollection(); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * populates the BlockCollection and calls initialize() on all installed blocks |
|
152 | - * |
|
153 | - * @return void |
|
154 | - * @throws Exception |
|
155 | - */ |
|
156 | - public function initializeBlocks() |
|
157 | - { |
|
158 | - try { |
|
159 | - $this->populateBlockCollection(); |
|
160 | - // cycle thru block loaders and initialize each loader |
|
161 | - foreach ($this->blocks as $block) { |
|
162 | - $block->initialize(); |
|
163 | - $this->trackAssetManagersForBlocks($block); |
|
164 | - if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
165 | - $this->block_asset_manager_collection->add($block->assetManager()); |
|
166 | - $block->assetManager()->setAssetHandles(); |
|
167 | - } |
|
168 | - } |
|
169 | - } catch (Exception $exception) { |
|
170 | - new ExceptionStackTraceDisplay($exception); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * track blocks with routes that match the current request |
|
177 | - * |
|
178 | - * @param BlockInterface $block |
|
179 | - * @throws InvalidClassException |
|
180 | - */ |
|
181 | - private function trackAssetManagersForBlocks(BlockInterface $block) |
|
182 | - { |
|
183 | - $supported_routes = $block->supportedRoutes(); |
|
184 | - foreach ($supported_routes as $supported_route) { |
|
185 | - if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
186 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * returns true if the block should be registered for the current request |
|
194 | - * else removes block from block_routes array and returns false |
|
195 | - * |
|
196 | - * @param BlockInterface $block |
|
197 | - * @return boolean |
|
198 | - * @throws InvalidClassException |
|
199 | - */ |
|
200 | - public function matchesRoute(BlockInterface $block) |
|
201 | - { |
|
202 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
203 | - return true; |
|
204 | - } |
|
205 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
206 | - return false; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * calls registerBlock() and load assets for all installed blocks |
|
212 | - * |
|
213 | - * @return void |
|
214 | - * @throws Exception |
|
215 | - */ |
|
216 | - public function registerBlocks() |
|
217 | - { |
|
218 | - try { |
|
219 | - // cycle thru block loader folders |
|
220 | - foreach ($this->blocks as $block) { |
|
221 | - if (! $this->matchesRoute($block)) { |
|
222 | - continue; |
|
223 | - } |
|
224 | - // perform any setup required for the block |
|
225 | - $block_type = $block->registerBlock(); |
|
226 | - if (! $block_type instanceof WP_Block_Type) { |
|
227 | - throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
228 | - } |
|
229 | - do_action( |
|
230 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
231 | - $block, |
|
232 | - $block_type |
|
233 | - ); |
|
234 | - } |
|
235 | - } catch (Exception $exception) { |
|
236 | - new ExceptionStackTraceDisplay($exception); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - public function unloadAssets() |
|
241 | - { |
|
242 | - $assets = array_flip($this->block_asset_managers); |
|
243 | - foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
244 | - // if there are no longer any blocks that require these assets, |
|
245 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
246 | - // then unset asset enqueueing and bail |
|
247 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
248 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
249 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
250 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
251 | - } |
|
252 | - } |
|
253 | - } |
|
35 | + /** |
|
36 | + * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
37 | + */ |
|
38 | + protected $block_asset_manager_collection; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var RouteMatchSpecificationManager $route_manager |
|
42 | + */ |
|
43 | + protected $route_manager; |
|
44 | + |
|
45 | + /** |
|
46 | + * array for tracking asset managers required by blocks for the current route |
|
47 | + * |
|
48 | + * @var array $block_asset_managers |
|
49 | + */ |
|
50 | + protected $block_asset_managers = array(); |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * BlockRegistrationManager constructor. |
|
55 | + * |
|
56 | + * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
57 | + * @param BlockCollection $blocks |
|
58 | + * @param RouteMatchSpecificationManager $route_manager |
|
59 | + * @param RequestInterface $request |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + BlockAssetManagerCollection $block_asset_manager_collection, |
|
63 | + BlockCollection $blocks, |
|
64 | + RouteMatchSpecificationManager $route_manager, |
|
65 | + RequestInterface $request |
|
66 | + ) { |
|
67 | + $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
68 | + $this->route_manager = $route_manager; |
|
69 | + parent::__construct($blocks, $request); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Returns the name of a hookpoint to be used to call initialize() |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function initHook() |
|
79 | + { |
|
80 | + return 'AHEE__EE_System__initialize'; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Perform any early setup required for block editors to functions |
|
86 | + * |
|
87 | + * @return void |
|
88 | + * @throws Exception |
|
89 | + */ |
|
90 | + public function initialize() |
|
91 | + { |
|
92 | + $this->initializeBlocks(); |
|
93 | + add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
94 | + add_action('wp_loaded', array($this, 'unloadAssets')); |
|
95 | + add_filter('block_categories', array($this, 'addEspressoBlockCategories')); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @param array $categories |
|
101 | + * @since $VID:$ |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function addEspressoBlockCategories(array $categories) |
|
105 | + { |
|
106 | + return array_merge( |
|
107 | + $categories, |
|
108 | + array( |
|
109 | + array( |
|
110 | + 'slug' => 'event-espresso', |
|
111 | + 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
112 | + ), |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return CollectionInterface|BlockInterface[] |
|
120 | + * @throws CollectionLoaderException |
|
121 | + * @throws CollectionDetailsException |
|
122 | + */ |
|
123 | + protected function populateBlockCollection() |
|
124 | + { |
|
125 | + $loader = new CollectionLoader( |
|
126 | + new CollectionDetails( |
|
127 | + // collection name |
|
128 | + 'editor_blocks', |
|
129 | + // collection interface |
|
130 | + 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
131 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
132 | + apply_filters( |
|
133 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
134 | + array('EventEspresso\core\domain\entities\editor\blocks') |
|
135 | + ), |
|
136 | + // filepaths to classes to add |
|
137 | + array(), |
|
138 | + // file mask to use if parsing folder for files to add |
|
139 | + '', |
|
140 | + // what to use as identifier for collection entities |
|
141 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
142 | + CollectionDetails::ID_CLASS_NAME |
|
143 | + ), |
|
144 | + $this->blocks |
|
145 | + ); |
|
146 | + return $loader->getCollection(); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * populates the BlockCollection and calls initialize() on all installed blocks |
|
152 | + * |
|
153 | + * @return void |
|
154 | + * @throws Exception |
|
155 | + */ |
|
156 | + public function initializeBlocks() |
|
157 | + { |
|
158 | + try { |
|
159 | + $this->populateBlockCollection(); |
|
160 | + // cycle thru block loaders and initialize each loader |
|
161 | + foreach ($this->blocks as $block) { |
|
162 | + $block->initialize(); |
|
163 | + $this->trackAssetManagersForBlocks($block); |
|
164 | + if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
165 | + $this->block_asset_manager_collection->add($block->assetManager()); |
|
166 | + $block->assetManager()->setAssetHandles(); |
|
167 | + } |
|
168 | + } |
|
169 | + } catch (Exception $exception) { |
|
170 | + new ExceptionStackTraceDisplay($exception); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * track blocks with routes that match the current request |
|
177 | + * |
|
178 | + * @param BlockInterface $block |
|
179 | + * @throws InvalidClassException |
|
180 | + */ |
|
181 | + private function trackAssetManagersForBlocks(BlockInterface $block) |
|
182 | + { |
|
183 | + $supported_routes = $block->supportedRoutes(); |
|
184 | + foreach ($supported_routes as $supported_route) { |
|
185 | + if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
186 | + $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * returns true if the block should be registered for the current request |
|
194 | + * else removes block from block_routes array and returns false |
|
195 | + * |
|
196 | + * @param BlockInterface $block |
|
197 | + * @return boolean |
|
198 | + * @throws InvalidClassException |
|
199 | + */ |
|
200 | + public function matchesRoute(BlockInterface $block) |
|
201 | + { |
|
202 | + if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
203 | + return true; |
|
204 | + } |
|
205 | + unset($this->block_asset_managers[ $block->blockType() ]); |
|
206 | + return false; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * calls registerBlock() and load assets for all installed blocks |
|
212 | + * |
|
213 | + * @return void |
|
214 | + * @throws Exception |
|
215 | + */ |
|
216 | + public function registerBlocks() |
|
217 | + { |
|
218 | + try { |
|
219 | + // cycle thru block loader folders |
|
220 | + foreach ($this->blocks as $block) { |
|
221 | + if (! $this->matchesRoute($block)) { |
|
222 | + continue; |
|
223 | + } |
|
224 | + // perform any setup required for the block |
|
225 | + $block_type = $block->registerBlock(); |
|
226 | + if (! $block_type instanceof WP_Block_Type) { |
|
227 | + throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
228 | + } |
|
229 | + do_action( |
|
230 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
231 | + $block, |
|
232 | + $block_type |
|
233 | + ); |
|
234 | + } |
|
235 | + } catch (Exception $exception) { |
|
236 | + new ExceptionStackTraceDisplay($exception); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + public function unloadAssets() |
|
241 | + { |
|
242 | + $assets = array_flip($this->block_asset_managers); |
|
243 | + foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
244 | + // if there are no longer any blocks that require these assets, |
|
245 | + if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
246 | + // then unset asset enqueueing and bail |
|
247 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
248 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
249 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
250 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
251 | + } |
|
252 | + } |
|
253 | + } |
|
254 | 254 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | */ |
15 | 15 | class WordPressPostsEditorAddNew extends RouteMatchSpecification |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since $VID:$ |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - return strpos($this->request->requestUri(), 'wp-admin/post-new.php') !== false |
|
26 | - && $this->request->getRequestParam('post_type', 'post') === 'post'; |
|
27 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since $VID:$ |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + return strpos($this->request->requestUri(), 'wp-admin/post-new.php') !== false |
|
26 | + && $this->request->getRequestParam('post_type', 'post') === 'post'; |
|
27 | + } |
|
28 | 28 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | */ |
15 | 15 | class WordPressPostsListTable extends RouteMatchSpecification |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since $VID:$ |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - return strpos($this->request->requestUri(), 'wp-admin/edit.php') !== false |
|
26 | - && $this->request->getRequestParam('post_type', 'post') === 'post'; |
|
27 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since $VID:$ |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + return strpos($this->request->requestUri(), 'wp-admin/edit.php') !== false |
|
26 | + && $this->request->getRequestParam('post_type', 'post') === 'post'; |
|
27 | + } |
|
28 | 28 | } |
@@ -22,20 +22,20 @@ |
||
22 | 22 | class RouteMatchSpecificationDependencyResolver extends DependencyResolver |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Used to configure and/or setup any aliases or namespace roots required by the DependencyResolver |
|
27 | - * |
|
28 | - * @since $VID:$ |
|
29 | - * @throws InvalidAliasException |
|
30 | - */ |
|
31 | - public function initialize() |
|
32 | - { |
|
33 | - $this->addAlias( |
|
34 | - new ClassAlias( |
|
35 | - 'EventEspresso\core\services\request\RequestInterface', |
|
36 | - 'EventEspresso\core\services\request\Request' |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->addNamespaceRoot('EventEspresso\core\domain\entities\route_match\specifications'); |
|
40 | - } |
|
25 | + /** |
|
26 | + * Used to configure and/or setup any aliases or namespace roots required by the DependencyResolver |
|
27 | + * |
|
28 | + * @since $VID:$ |
|
29 | + * @throws InvalidAliasException |
|
30 | + */ |
|
31 | + public function initialize() |
|
32 | + { |
|
33 | + $this->addAlias( |
|
34 | + new ClassAlias( |
|
35 | + 'EventEspresso\core\services\request\RequestInterface', |
|
36 | + 'EventEspresso\core\services\request\Request' |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->addNamespaceRoot('EventEspresso\core\domain\entities\route_match\specifications'); |
|
40 | + } |
|
41 | 41 | } |
@@ -23,155 +23,155 @@ |
||
23 | 23 | abstract class DependencyResolver implements DependencyResolverInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var Mirror $mirror |
|
28 | - */ |
|
29 | - private $mirror; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var ClassInterfaceCache $class_cache |
|
33 | - */ |
|
34 | - private $class_cache; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var EE_Dependency_Map $dependency_map |
|
38 | - */ |
|
39 | - private $dependency_map; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var ClassAlias[] $aliases |
|
43 | - */ |
|
44 | - protected $aliases = array(); |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array $namespace_roots |
|
48 | - */ |
|
49 | - protected $namespace_roots = array(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * RouteMatchSpecificationDependencyResolver constructor. |
|
54 | - * |
|
55 | - * @param Mirror $mirror |
|
56 | - * @param ClassInterfaceCache $class_cache |
|
57 | - * @param EE_Dependency_Map $dependency_map |
|
58 | - */ |
|
59 | - public function __construct( |
|
60 | - Mirror $mirror, |
|
61 | - ClassInterfaceCache $class_cache, |
|
62 | - EE_Dependency_Map $dependency_map |
|
63 | - ) { |
|
64 | - $this->mirror = $mirror; |
|
65 | - $this->class_cache = $class_cache; |
|
66 | - $this->dependency_map = $dependency_map; |
|
67 | - $this->initialize(); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return Mirror |
|
72 | - */ |
|
73 | - public function mirror() |
|
74 | - { |
|
75 | - return $this->mirror; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return ClassInterfaceCache |
|
80 | - */ |
|
81 | - public function classCache() |
|
82 | - { |
|
83 | - return $this->class_cache; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @return EE_Dependency_Map |
|
88 | - */ |
|
89 | - public function dependencyMap() |
|
90 | - { |
|
91 | - return $this->dependency_map; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @param ClassAlias $alias |
|
96 | - * @throws InvalidAliasException |
|
97 | - */ |
|
98 | - public function addAlias(ClassAlias $alias) |
|
99 | - { |
|
100 | - $this->aliases[ $alias->alias() ] = $alias; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function resolveAlias($param_fqcn) |
|
108 | - { |
|
109 | - return isset($this->aliases[ $param_fqcn ]) |
|
110 | - ? $this->aliases[ $param_fqcn ]->fqcn() |
|
111 | - : $this->classCache()->getFqnForAlias($param_fqcn); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Primarily used to indicate the namespace root for composite objects |
|
116 | - * so that dependencies requiring the same DependencyResolver can be acquired |
|
117 | - * for example: |
|
118 | - * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
119 | - * may all implement Vendor\path\to\Interface, |
|
120 | - * but Vendor\path\to\class\C could be a composite object |
|
121 | - * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
122 | - * and needs both of those dependencies resolved, which would therefore require |
|
123 | - * the use of the same DependencyResolver. |
|
124 | - * |
|
125 | - * By specifying a namespace root of "Vendor\path\to\", |
|
126 | - * then all classes that are descendants of that namespace |
|
127 | - * will use DependencyResolver to acquire the classes they need |
|
128 | - * |
|
129 | - * @param string $namespace_root Partial namespace used for detecting other classes |
|
130 | - * that should employ this same DependencyResolver |
|
131 | - */ |
|
132 | - public function addNamespaceRoot($namespace_root) |
|
133 | - { |
|
134 | - $this->namespace_roots[] = $namespace_root; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Returns true if the parameter FQCN belongs to one of |
|
139 | - * the namespaces that utilizes this DependencyResolver |
|
140 | - * |
|
141 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
142 | - * @return boolean |
|
143 | - * @since $VID:$ |
|
144 | - */ |
|
145 | - public function dependencyRecursionExists($param_fqcn) |
|
146 | - { |
|
147 | - foreach ($this->namespace_roots as $namespace_root) { |
|
148 | - if (strpos($param_fqcn, $namespace_root) !== false) { |
|
149 | - return true; |
|
150 | - } |
|
151 | - } |
|
152 | - return false; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $fqcn Fully Qualified Class Name |
|
158 | - * @throws InvalidDataTypeException |
|
159 | - * @throws ReflectionException |
|
160 | - * @since $VID:$ |
|
161 | - */ |
|
162 | - public function resolveDependenciesForClass($fqcn) |
|
163 | - { |
|
164 | - $dependencies = array(); |
|
165 | - $params = $this->mirror()->getParameters($fqcn); |
|
166 | - foreach ($params as $index => $param) { |
|
167 | - // is this a dependency for a specific class ? |
|
168 | - $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
169 | - if ($this->dependencyRecursionExists($param_class)) { |
|
170 | - $this->resolveDependenciesForClass($param_class); |
|
171 | - } |
|
172 | - $param_class = $this->resolveAlias($param_class); |
|
173 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
174 | - } |
|
175 | - $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
176 | - } |
|
26 | + /** |
|
27 | + * @var Mirror $mirror |
|
28 | + */ |
|
29 | + private $mirror; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var ClassInterfaceCache $class_cache |
|
33 | + */ |
|
34 | + private $class_cache; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var EE_Dependency_Map $dependency_map |
|
38 | + */ |
|
39 | + private $dependency_map; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var ClassAlias[] $aliases |
|
43 | + */ |
|
44 | + protected $aliases = array(); |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array $namespace_roots |
|
48 | + */ |
|
49 | + protected $namespace_roots = array(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * RouteMatchSpecificationDependencyResolver constructor. |
|
54 | + * |
|
55 | + * @param Mirror $mirror |
|
56 | + * @param ClassInterfaceCache $class_cache |
|
57 | + * @param EE_Dependency_Map $dependency_map |
|
58 | + */ |
|
59 | + public function __construct( |
|
60 | + Mirror $mirror, |
|
61 | + ClassInterfaceCache $class_cache, |
|
62 | + EE_Dependency_Map $dependency_map |
|
63 | + ) { |
|
64 | + $this->mirror = $mirror; |
|
65 | + $this->class_cache = $class_cache; |
|
66 | + $this->dependency_map = $dependency_map; |
|
67 | + $this->initialize(); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return Mirror |
|
72 | + */ |
|
73 | + public function mirror() |
|
74 | + { |
|
75 | + return $this->mirror; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return ClassInterfaceCache |
|
80 | + */ |
|
81 | + public function classCache() |
|
82 | + { |
|
83 | + return $this->class_cache; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @return EE_Dependency_Map |
|
88 | + */ |
|
89 | + public function dependencyMap() |
|
90 | + { |
|
91 | + return $this->dependency_map; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @param ClassAlias $alias |
|
96 | + * @throws InvalidAliasException |
|
97 | + */ |
|
98 | + public function addAlias(ClassAlias $alias) |
|
99 | + { |
|
100 | + $this->aliases[ $alias->alias() ] = $alias; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function resolveAlias($param_fqcn) |
|
108 | + { |
|
109 | + return isset($this->aliases[ $param_fqcn ]) |
|
110 | + ? $this->aliases[ $param_fqcn ]->fqcn() |
|
111 | + : $this->classCache()->getFqnForAlias($param_fqcn); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Primarily used to indicate the namespace root for composite objects |
|
116 | + * so that dependencies requiring the same DependencyResolver can be acquired |
|
117 | + * for example: |
|
118 | + * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
119 | + * may all implement Vendor\path\to\Interface, |
|
120 | + * but Vendor\path\to\class\C could be a composite object |
|
121 | + * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
122 | + * and needs both of those dependencies resolved, which would therefore require |
|
123 | + * the use of the same DependencyResolver. |
|
124 | + * |
|
125 | + * By specifying a namespace root of "Vendor\path\to\", |
|
126 | + * then all classes that are descendants of that namespace |
|
127 | + * will use DependencyResolver to acquire the classes they need |
|
128 | + * |
|
129 | + * @param string $namespace_root Partial namespace used for detecting other classes |
|
130 | + * that should employ this same DependencyResolver |
|
131 | + */ |
|
132 | + public function addNamespaceRoot($namespace_root) |
|
133 | + { |
|
134 | + $this->namespace_roots[] = $namespace_root; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Returns true if the parameter FQCN belongs to one of |
|
139 | + * the namespaces that utilizes this DependencyResolver |
|
140 | + * |
|
141 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
142 | + * @return boolean |
|
143 | + * @since $VID:$ |
|
144 | + */ |
|
145 | + public function dependencyRecursionExists($param_fqcn) |
|
146 | + { |
|
147 | + foreach ($this->namespace_roots as $namespace_root) { |
|
148 | + if (strpos($param_fqcn, $namespace_root) !== false) { |
|
149 | + return true; |
|
150 | + } |
|
151 | + } |
|
152 | + return false; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @param string $fqcn Fully Qualified Class Name |
|
158 | + * @throws InvalidDataTypeException |
|
159 | + * @throws ReflectionException |
|
160 | + * @since $VID:$ |
|
161 | + */ |
|
162 | + public function resolveDependenciesForClass($fqcn) |
|
163 | + { |
|
164 | + $dependencies = array(); |
|
165 | + $params = $this->mirror()->getParameters($fqcn); |
|
166 | + foreach ($params as $index => $param) { |
|
167 | + // is this a dependency for a specific class ? |
|
168 | + $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
169 | + if ($this->dependencyRecursionExists($param_class)) { |
|
170 | + $this->resolveDependenciesForClass($param_class); |
|
171 | + } |
|
172 | + $param_class = $this->resolveAlias($param_class); |
|
173 | + $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
174 | + } |
|
175 | + $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
176 | + } |
|
177 | 177 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function addAlias(ClassAlias $alias) |
99 | 99 | { |
100 | - $this->aliases[ $alias->alias() ] = $alias; |
|
100 | + $this->aliases[$alias->alias()] = $alias; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function resolveAlias($param_fqcn) |
108 | 108 | { |
109 | - return isset($this->aliases[ $param_fqcn ]) |
|
110 | - ? $this->aliases[ $param_fqcn ]->fqcn() |
|
109 | + return isset($this->aliases[$param_fqcn]) |
|
110 | + ? $this->aliases[$param_fqcn]->fqcn() |
|
111 | 111 | : $this->classCache()->getFqnForAlias($param_fqcn); |
112 | 112 | } |
113 | 113 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $this->resolveDependenciesForClass($param_class); |
171 | 171 | } |
172 | 172 | $param_class = $this->resolveAlias($param_class); |
173 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
173 | + $dependencies[$param_class] = EE_Dependency_Map::load_from_cache; |
|
174 | 174 | } |
175 | 175 | $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
176 | 176 | } |
@@ -16,29 +16,29 @@ |
||
16 | 16 | abstract class MultiRouteSpecification extends RouteMatchSpecification |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var RouteMatchSpecificationInterface[] $specifications |
|
21 | - */ |
|
22 | - protected $specifications; |
|
19 | + /** |
|
20 | + * @var RouteMatchSpecificationInterface[] $specifications |
|
21 | + */ |
|
22 | + protected $specifications; |
|
23 | 23 | |
24 | - /** |
|
25 | - * MultiRouteSpecification constructor. |
|
26 | - * |
|
27 | - * @param RouteMatchSpecificationInterface[] $specifications |
|
28 | - * @param RequestInterface $request |
|
29 | - * @throws InvalidEntityException |
|
30 | - */ |
|
31 | - public function __construct(array $specifications, RequestInterface $request) |
|
32 | - { |
|
33 | - foreach ($specifications as $specification) { |
|
34 | - if (! $specification instanceof RouteMatchSpecificationInterface) { |
|
35 | - throw new InvalidEntityException( |
|
36 | - $specification, |
|
37 | - 'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface' |
|
38 | - ); |
|
39 | - } |
|
40 | - } |
|
41 | - $this->specifications = $specifications; |
|
42 | - parent::__construct($request); |
|
43 | - } |
|
24 | + /** |
|
25 | + * MultiRouteSpecification constructor. |
|
26 | + * |
|
27 | + * @param RouteMatchSpecificationInterface[] $specifications |
|
28 | + * @param RequestInterface $request |
|
29 | + * @throws InvalidEntityException |
|
30 | + */ |
|
31 | + public function __construct(array $specifications, RequestInterface $request) |
|
32 | + { |
|
33 | + foreach ($specifications as $specification) { |
|
34 | + if (! $specification instanceof RouteMatchSpecificationInterface) { |
|
35 | + throw new InvalidEntityException( |
|
36 | + $specification, |
|
37 | + 'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface' |
|
38 | + ); |
|
39 | + } |
|
40 | + } |
|
41 | + $this->specifications = $specifications; |
|
42 | + parent::__construct($request); |
|
43 | + } |
|
44 | 44 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | public function __construct(array $specifications, RequestInterface $request) |
32 | 32 | { |
33 | 33 | foreach ($specifications as $specification) { |
34 | - if (! $specification instanceof RouteMatchSpecificationInterface) { |
|
34 | + if ( ! $specification instanceof RouteMatchSpecificationInterface) { |
|
35 | 35 | throw new InvalidEntityException( |
36 | 36 | $specification, |
37 | 37 | 'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface' |
@@ -15,23 +15,23 @@ |
||
15 | 15 | */ |
16 | 16 | class WordPressPostsEditorEdit extends RouteMatchSpecification |
17 | 17 | { |
18 | - /** |
|
19 | - * returns true if current request matches specification |
|
20 | - * |
|
21 | - * @since $VID:$ |
|
22 | - * @return boolean |
|
23 | - */ |
|
24 | - public function isMatchingRoute() |
|
25 | - { |
|
26 | - global $post; |
|
27 | - return strpos($this->request->requestUri(), 'wp-admin/post.php') !== false |
|
28 | - && ( |
|
29 | - $this->request->getRequestParam('post_type', 'post') === 'post' |
|
30 | - || ( |
|
31 | - $post instanceof WP_Post |
|
32 | - && $post->post_type === 'post' |
|
33 | - ) |
|
34 | - ) |
|
35 | - && $this->request->getRequestParam('action') === 'edit'; |
|
36 | - } |
|
18 | + /** |
|
19 | + * returns true if current request matches specification |
|
20 | + * |
|
21 | + * @since $VID:$ |
|
22 | + * @return boolean |
|
23 | + */ |
|
24 | + public function isMatchingRoute() |
|
25 | + { |
|
26 | + global $post; |
|
27 | + return strpos($this->request->requestUri(), 'wp-admin/post.php') !== false |
|
28 | + && ( |
|
29 | + $this->request->getRequestParam('post_type', 'post') === 'post' |
|
30 | + || ( |
|
31 | + $post instanceof WP_Post |
|
32 | + && $post->post_type === 'post' |
|
33 | + ) |
|
34 | + ) |
|
35 | + && $this->request->getRequestParam('action') === 'edit'; |
|
36 | + } |
|
37 | 37 | } |
@@ -18,22 +18,22 @@ |
||
18 | 18 | */ |
19 | 19 | class WordPressPostsEditor extends MatchAnyRouteSpecification |
20 | 20 | { |
21 | - /** |
|
22 | - * WordPressPostsEditor constructor. |
|
23 | - * |
|
24 | - * @param WordPressPostsEditorEdit $edit_post_route_match |
|
25 | - * @param WordPressPostsEditorAddNew $create_post_route_match |
|
26 | - * @param RequestInterface $request |
|
27 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
28 | - */ |
|
29 | - public function __construct( |
|
30 | - WordPressPostsEditorEdit $edit_post_route_match, |
|
31 | - WordPressPostsEditorAddNew $create_post_route_match, |
|
32 | - RequestInterface $request |
|
33 | - ) { |
|
34 | - parent::__construct( |
|
35 | - array($edit_post_route_match, $create_post_route_match), |
|
36 | - $request |
|
37 | - ); |
|
38 | - } |
|
21 | + /** |
|
22 | + * WordPressPostsEditor constructor. |
|
23 | + * |
|
24 | + * @param WordPressPostsEditorEdit $edit_post_route_match |
|
25 | + * @param WordPressPostsEditorAddNew $create_post_route_match |
|
26 | + * @param RequestInterface $request |
|
27 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
28 | + */ |
|
29 | + public function __construct( |
|
30 | + WordPressPostsEditorEdit $edit_post_route_match, |
|
31 | + WordPressPostsEditorAddNew $create_post_route_match, |
|
32 | + RequestInterface $request |
|
33 | + ) { |
|
34 | + parent::__construct( |
|
35 | + array($edit_post_route_match, $create_post_route_match), |
|
36 | + $request |
|
37 | + ); |
|
38 | + } |
|
39 | 39 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | */ |
15 | 15 | class EspressoVenueEditorAddNew extends RouteMatchSpecification |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since $VID:$ |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - return $this->request->getRequestParam('page') === 'espresso_venues' |
|
26 | - && $this->request->getRequestParam('action') === 'create_new'; |
|
27 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since $VID:$ |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + return $this->request->getRequestParam('page') === 'espresso_venues' |
|
26 | + && $this->request->getRequestParam('action') === 'create_new'; |
|
27 | + } |
|
28 | 28 | } |