@@ -23,246 +23,246 @@ |
||
23 | 23 | abstract class EditorBlock implements EditorBlockInterface |
24 | 24 | { |
25 | 25 | |
26 | - const NS = 'event-espresso/'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var DomainInterface $domain |
|
30 | - */ |
|
31 | - protected $domain; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var LoaderInterface $loader |
|
35 | - */ |
|
36 | - protected $loader; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @var Registry |
|
41 | - */ |
|
42 | - protected $assets_registry; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string $editor_block_type |
|
46 | - */ |
|
47 | - private $editor_block_type; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var WP_Block_Type $wp_block_type |
|
51 | - */ |
|
52 | - private $wp_block_type; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $supported_post_types |
|
56 | - */ |
|
57 | - private $supported_post_types; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var array $attributes |
|
61 | - */ |
|
62 | - private $attributes; |
|
63 | - |
|
64 | - /** |
|
65 | - * If set to true, then the block will render its content client side |
|
66 | - * If false, then the block will render its content server side using the renderBlock() method |
|
67 | - * |
|
68 | - * @var bool $dynamic |
|
69 | - */ |
|
70 | - private $dynamic = false; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * EditorBlockLoader constructor. |
|
75 | - * |
|
76 | - * @param DomainInterface $domain |
|
77 | - * @param LoaderInterface $loader |
|
78 | - * @param Registry $assets_registry |
|
79 | - */ |
|
80 | - public function __construct( |
|
81 | - DomainInterface $domain, |
|
82 | - LoaderInterface $loader, |
|
83 | - Registry $assets_registry |
|
84 | - ) { |
|
85 | - $this->domain = $domain; |
|
86 | - $this->loader = $loader; |
|
87 | - $this->assets_registry = $assets_registry; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function editorBlockType() |
|
95 | - { |
|
96 | - return $this->editor_block_type; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function namespacedEditorBlockType() |
|
104 | - { |
|
105 | - return EditorBlock::NS . $this->editor_block_type; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param string $editor_block_type |
|
111 | - */ |
|
112 | - protected function setEditorBlockType($editor_block_type) |
|
113 | - { |
|
114 | - $this->editor_block_type = $editor_block_type; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @param WP_Block_Type $wp_block_type |
|
120 | - */ |
|
121 | - protected function setWpBlockType($wp_block_type) |
|
122 | - { |
|
123 | - $this->wp_block_type = $wp_block_type; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param array $supported_post_types |
|
129 | - */ |
|
130 | - protected function setSupportedPostTypes(array $supported_post_types) |
|
131 | - { |
|
132 | - $this->supported_post_types = $supported_post_types; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function attributes() |
|
140 | - { |
|
141 | - return $this->attributes; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param array $attributes |
|
147 | - */ |
|
148 | - public function setAttributes(array $attributes) |
|
149 | - { |
|
150 | - $this->attributes = $attributes; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function isDynamic() |
|
158 | - { |
|
159 | - return $this->dynamic; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param bool $dynamic |
|
165 | - */ |
|
166 | - public function setDynamic($dynamic = true) |
|
167 | - { |
|
168 | - $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Registers the Editor Block with WP core; |
|
174 | - * Returns the registered block type on success, or false on failure. |
|
175 | - * |
|
176 | - * @return WP_Block_Type|false |
|
177 | - */ |
|
178 | - public function registerBlock() |
|
179 | - { |
|
180 | - $context ='core'; |
|
181 | - // todo add route detection (ie inject route) and change context based on route |
|
182 | - $args = array( |
|
183 | - 'attributes' => $this->attributes(), |
|
184 | - 'editor_script' => "ee-{$context}-blocks", |
|
185 | - 'editor_style' => "ee-{$context}-blocks", |
|
186 | - 'script' => "ee-{$context}-blocks", |
|
187 | - 'style' => "ee-{$context}-blocks", |
|
188 | - ); |
|
189 | - if (! $this->isDynamic()) { |
|
190 | - $args['render_callback'] = $this->renderBlock(); |
|
191 | - } |
|
192 | - $wp_block_type = register_block_type( |
|
193 | - new WP_Block_Type( |
|
194 | - $this->namespacedEditorBlockType(), |
|
195 | - $args |
|
196 | - ) |
|
197 | - ); |
|
198 | - $this->setWpBlockType($wp_block_type); |
|
199 | - return $wp_block_type; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
205 | - */ |
|
206 | - public function unRegisterBlock() |
|
207 | - { |
|
208 | - return unregister_block_type($this->namespacedEditorBlockType()); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * returns true if the block type applies for the supplied post type |
|
214 | - * and should be added to that post type's editor |
|
215 | - * |
|
216 | - * @param string $post_type |
|
217 | - * @return boolean |
|
218 | - */ |
|
219 | - public function appliesToPostType($post_type) |
|
220 | - { |
|
221 | - return in_array($post_type, $this->supported_post_types, true); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - public function getEditorContainer() |
|
229 | - { |
|
230 | - return array( |
|
231 | - $this->namespacedEditorBlockType(), |
|
232 | - array() |
|
233 | - ); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function registerScripts() |
|
241 | - { |
|
242 | - // wp_register_script( |
|
243 | - // 'core-blocks', |
|
244 | - // $this->domain->distributionAssetsUrl() . 'ee-core-blocks.dist.js', |
|
245 | - // array( |
|
246 | - // 'wp-blocks', // Provides useful functions and components for extending the editor |
|
247 | - // 'wp-i18n', // Provides localization functions |
|
248 | - // 'wp-element', // Provides React.Component |
|
249 | - // 'wp-components' // Provides many prebuilt components and controls |
|
250 | - // ), |
|
251 | - // filemtime($this->domain->distributionAssetsPath() . 'ee-core-blocks.dist.js') |
|
252 | - // ); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - public function registerStyles() |
|
260 | - { |
|
261 | - // wp_register_style( |
|
262 | - // 'ee-block-styles', |
|
263 | - // $this->domain->distributionAssetsUrl() . 'style.css', |
|
264 | - // array(), |
|
265 | - // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
266 | - // ); |
|
267 | - } |
|
26 | + const NS = 'event-espresso/'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var DomainInterface $domain |
|
30 | + */ |
|
31 | + protected $domain; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var LoaderInterface $loader |
|
35 | + */ |
|
36 | + protected $loader; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @var Registry |
|
41 | + */ |
|
42 | + protected $assets_registry; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string $editor_block_type |
|
46 | + */ |
|
47 | + private $editor_block_type; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var WP_Block_Type $wp_block_type |
|
51 | + */ |
|
52 | + private $wp_block_type; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $supported_post_types |
|
56 | + */ |
|
57 | + private $supported_post_types; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var array $attributes |
|
61 | + */ |
|
62 | + private $attributes; |
|
63 | + |
|
64 | + /** |
|
65 | + * If set to true, then the block will render its content client side |
|
66 | + * If false, then the block will render its content server side using the renderBlock() method |
|
67 | + * |
|
68 | + * @var bool $dynamic |
|
69 | + */ |
|
70 | + private $dynamic = false; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * EditorBlockLoader constructor. |
|
75 | + * |
|
76 | + * @param DomainInterface $domain |
|
77 | + * @param LoaderInterface $loader |
|
78 | + * @param Registry $assets_registry |
|
79 | + */ |
|
80 | + public function __construct( |
|
81 | + DomainInterface $domain, |
|
82 | + LoaderInterface $loader, |
|
83 | + Registry $assets_registry |
|
84 | + ) { |
|
85 | + $this->domain = $domain; |
|
86 | + $this->loader = $loader; |
|
87 | + $this->assets_registry = $assets_registry; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function editorBlockType() |
|
95 | + { |
|
96 | + return $this->editor_block_type; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function namespacedEditorBlockType() |
|
104 | + { |
|
105 | + return EditorBlock::NS . $this->editor_block_type; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param string $editor_block_type |
|
111 | + */ |
|
112 | + protected function setEditorBlockType($editor_block_type) |
|
113 | + { |
|
114 | + $this->editor_block_type = $editor_block_type; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @param WP_Block_Type $wp_block_type |
|
120 | + */ |
|
121 | + protected function setWpBlockType($wp_block_type) |
|
122 | + { |
|
123 | + $this->wp_block_type = $wp_block_type; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param array $supported_post_types |
|
129 | + */ |
|
130 | + protected function setSupportedPostTypes(array $supported_post_types) |
|
131 | + { |
|
132 | + $this->supported_post_types = $supported_post_types; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function attributes() |
|
140 | + { |
|
141 | + return $this->attributes; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param array $attributes |
|
147 | + */ |
|
148 | + public function setAttributes(array $attributes) |
|
149 | + { |
|
150 | + $this->attributes = $attributes; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function isDynamic() |
|
158 | + { |
|
159 | + return $this->dynamic; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param bool $dynamic |
|
165 | + */ |
|
166 | + public function setDynamic($dynamic = true) |
|
167 | + { |
|
168 | + $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Registers the Editor Block with WP core; |
|
174 | + * Returns the registered block type on success, or false on failure. |
|
175 | + * |
|
176 | + * @return WP_Block_Type|false |
|
177 | + */ |
|
178 | + public function registerBlock() |
|
179 | + { |
|
180 | + $context ='core'; |
|
181 | + // todo add route detection (ie inject route) and change context based on route |
|
182 | + $args = array( |
|
183 | + 'attributes' => $this->attributes(), |
|
184 | + 'editor_script' => "ee-{$context}-blocks", |
|
185 | + 'editor_style' => "ee-{$context}-blocks", |
|
186 | + 'script' => "ee-{$context}-blocks", |
|
187 | + 'style' => "ee-{$context}-blocks", |
|
188 | + ); |
|
189 | + if (! $this->isDynamic()) { |
|
190 | + $args['render_callback'] = $this->renderBlock(); |
|
191 | + } |
|
192 | + $wp_block_type = register_block_type( |
|
193 | + new WP_Block_Type( |
|
194 | + $this->namespacedEditorBlockType(), |
|
195 | + $args |
|
196 | + ) |
|
197 | + ); |
|
198 | + $this->setWpBlockType($wp_block_type); |
|
199 | + return $wp_block_type; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
205 | + */ |
|
206 | + public function unRegisterBlock() |
|
207 | + { |
|
208 | + return unregister_block_type($this->namespacedEditorBlockType()); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * returns true if the block type applies for the supplied post type |
|
214 | + * and should be added to that post type's editor |
|
215 | + * |
|
216 | + * @param string $post_type |
|
217 | + * @return boolean |
|
218 | + */ |
|
219 | + public function appliesToPostType($post_type) |
|
220 | + { |
|
221 | + return in_array($post_type, $this->supported_post_types, true); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + public function getEditorContainer() |
|
229 | + { |
|
230 | + return array( |
|
231 | + $this->namespacedEditorBlockType(), |
|
232 | + array() |
|
233 | + ); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function registerScripts() |
|
241 | + { |
|
242 | + // wp_register_script( |
|
243 | + // 'core-blocks', |
|
244 | + // $this->domain->distributionAssetsUrl() . 'ee-core-blocks.dist.js', |
|
245 | + // array( |
|
246 | + // 'wp-blocks', // Provides useful functions and components for extending the editor |
|
247 | + // 'wp-i18n', // Provides localization functions |
|
248 | + // 'wp-element', // Provides React.Component |
|
249 | + // 'wp-components' // Provides many prebuilt components and controls |
|
250 | + // ), |
|
251 | + // filemtime($this->domain->distributionAssetsPath() . 'ee-core-blocks.dist.js') |
|
252 | + // ); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + public function registerStyles() |
|
260 | + { |
|
261 | + // wp_register_style( |
|
262 | + // 'ee-block-styles', |
|
263 | + // $this->domain->distributionAssetsUrl() . 'style.css', |
|
264 | + // array(), |
|
265 | + // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
266 | + // ); |
|
267 | + } |
|
268 | 268 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function namespacedEditorBlockType() |
104 | 104 | { |
105 | - return EditorBlock::NS . $this->editor_block_type; |
|
105 | + return EditorBlock::NS.$this->editor_block_type; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function registerBlock() |
179 | 179 | { |
180 | - $context ='core'; |
|
180 | + $context = 'core'; |
|
181 | 181 | // todo add route detection (ie inject route) and change context based on route |
182 | - $args = array( |
|
182 | + $args = array( |
|
183 | 183 | 'attributes' => $this->attributes(), |
184 | 184 | 'editor_script' => "ee-{$context}-blocks", |
185 | 185 | 'editor_style' => "ee-{$context}-blocks", |
186 | 186 | 'script' => "ee-{$context}-blocks", |
187 | 187 | 'style' => "ee-{$context}-blocks", |
188 | 188 | ); |
189 | - if (! $this->isDynamic()) { |
|
189 | + if ( ! $this->isDynamic()) { |
|
190 | 190 | $args['render_callback'] = $this->renderBlock(); |
191 | 191 | } |
192 | 192 | $wp_block_type = register_block_type( |
@@ -20,94 +20,94 @@ |
||
20 | 20 | abstract class EditorBlockManager |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var CollectionInterface|EditorBlockInterface[] $blocks |
|
25 | - */ |
|
26 | - protected $blocks; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var RequestInterface $request |
|
30 | - */ |
|
31 | - protected $request; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var DomainInterface $domain |
|
35 | - */ |
|
36 | - protected $domain; |
|
37 | - |
|
38 | - /** |
|
39 | - * the post type that the current request applies to |
|
40 | - * |
|
41 | - * @var string $request_post_type |
|
42 | - */ |
|
43 | - protected $request_post_type; |
|
44 | - |
|
45 | - /** |
|
46 | - * value of the 'page' $_GET param |
|
47 | - * |
|
48 | - * @var string $page |
|
49 | - */ |
|
50 | - protected $page; |
|
51 | - |
|
52 | - /** |
|
53 | - * value of the 'action' $_GET param |
|
54 | - * |
|
55 | - * @var string $action |
|
56 | - */ |
|
57 | - protected $action; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @var Registry |
|
62 | - */ |
|
63 | - protected $assets_registry; |
|
64 | - |
|
65 | - /** |
|
66 | - * EditorBlockManager constructor. |
|
67 | - * |
|
68 | - * @param EditorBlockCollection $blocks |
|
69 | - * @param RequestInterface $request |
|
70 | - * @param DomainInterface $domain |
|
71 | - * @param Registry $assets_registry |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - EditorBlockCollection $blocks, |
|
75 | - RequestInterface $request, |
|
76 | - DomainInterface $domain, |
|
77 | - Registry $assets_registry |
|
78 | - ) { |
|
79 | - $this->blocks = $blocks; |
|
80 | - $this->request = $request; |
|
81 | - $this->domain = $domain; |
|
82 | - $this->assets_registry = $assets_registry; |
|
83 | - $this->request_post_type = $this->request->getRequestParam('post_type', ''); |
|
84 | - $this->page = $this->request->getRequestParam('page', ''); |
|
85 | - $this->action = $this->request->getRequestParam('action', ''); |
|
86 | - add_action($this->init_hook(), array($this, 'initialize')); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns the name of a hookpoint to be used to call initialize() |
|
92 | - * |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - abstract public function initHook(); |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Perform any early setup required for block editors to functions |
|
100 | - * |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - abstract public function initialize(); |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function currentRequestPostType() |
|
110 | - { |
|
111 | - return $this->request_post_type; |
|
112 | - } |
|
23 | + /** |
|
24 | + * @var CollectionInterface|EditorBlockInterface[] $blocks |
|
25 | + */ |
|
26 | + protected $blocks; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var RequestInterface $request |
|
30 | + */ |
|
31 | + protected $request; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var DomainInterface $domain |
|
35 | + */ |
|
36 | + protected $domain; |
|
37 | + |
|
38 | + /** |
|
39 | + * the post type that the current request applies to |
|
40 | + * |
|
41 | + * @var string $request_post_type |
|
42 | + */ |
|
43 | + protected $request_post_type; |
|
44 | + |
|
45 | + /** |
|
46 | + * value of the 'page' $_GET param |
|
47 | + * |
|
48 | + * @var string $page |
|
49 | + */ |
|
50 | + protected $page; |
|
51 | + |
|
52 | + /** |
|
53 | + * value of the 'action' $_GET param |
|
54 | + * |
|
55 | + * @var string $action |
|
56 | + */ |
|
57 | + protected $action; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @var Registry |
|
62 | + */ |
|
63 | + protected $assets_registry; |
|
64 | + |
|
65 | + /** |
|
66 | + * EditorBlockManager constructor. |
|
67 | + * |
|
68 | + * @param EditorBlockCollection $blocks |
|
69 | + * @param RequestInterface $request |
|
70 | + * @param DomainInterface $domain |
|
71 | + * @param Registry $assets_registry |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + EditorBlockCollection $blocks, |
|
75 | + RequestInterface $request, |
|
76 | + DomainInterface $domain, |
|
77 | + Registry $assets_registry |
|
78 | + ) { |
|
79 | + $this->blocks = $blocks; |
|
80 | + $this->request = $request; |
|
81 | + $this->domain = $domain; |
|
82 | + $this->assets_registry = $assets_registry; |
|
83 | + $this->request_post_type = $this->request->getRequestParam('post_type', ''); |
|
84 | + $this->page = $this->request->getRequestParam('page', ''); |
|
85 | + $this->action = $this->request->getRequestParam('action', ''); |
|
86 | + add_action($this->init_hook(), array($this, 'initialize')); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns the name of a hookpoint to be used to call initialize() |
|
92 | + * |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + abstract public function initHook(); |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Perform any early setup required for block editors to functions |
|
100 | + * |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + abstract public function initialize(); |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function currentRequestPostType() |
|
110 | + { |
|
111 | + return $this->request_post_type; |
|
112 | + } |
|
113 | 113 | } |
@@ -34,153 +34,153 @@ |
||
34 | 34 | class EditorBlockRegistrationManager extends EditorBlockManager |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * Returns the name of a hookpoint to be used to call initialize() |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function initHook() |
|
43 | - { |
|
44 | - return 'AHEE__EE_System__set_hooks_for_core'; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Perform any early setup required for block editors to functions |
|
50 | - * |
|
51 | - * @return void |
|
52 | - * @throws Exception |
|
53 | - */ |
|
54 | - public function initialize() |
|
55 | - { |
|
56 | - $this->loadEditorBlocks(); |
|
57 | - add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks')); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @return CollectionInterface|EditorBlockInterface[] |
|
63 | - * @throws ReflectionException |
|
64 | - * @throws InvalidArgumentException |
|
65 | - * @throws EE_Error |
|
66 | - * @throws InvalidClassException |
|
67 | - * @throws InvalidDataTypeException |
|
68 | - * @throws InvalidEntityException |
|
69 | - * @throws InvalidFilePathException |
|
70 | - * @throws InvalidIdentifierException |
|
71 | - * @throws InvalidInterfaceException |
|
72 | - */ |
|
73 | - protected function populateEditorBlockCollection() |
|
74 | - { |
|
75 | - $loader = new CollectionLoader( |
|
76 | - new CollectionDetails( |
|
77 | - // collection name |
|
78 | - 'shortcodes', |
|
79 | - // collection interface |
|
80 | - 'EventEspresso\core\domain\entities\editor\EditorBlockInterface', |
|
81 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
82 | - apply_filters( |
|
83 | - 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs', |
|
84 | - array() |
|
85 | - // array( |
|
86 | - // 'EventEspresso\core\domain\entities\editor\blocks\common', |
|
87 | - // 'EventEspresso\core\domain\entities\editor\blocks\editor', |
|
88 | - // 'EventEspresso\core\domain\entities\editor\blocks\shortcodes', |
|
89 | - // 'EventEspresso\core\domain\entities\editor\blocks\widgets', |
|
90 | - // ) |
|
91 | - ), |
|
92 | - // filepaths to classes to add |
|
93 | - array(), |
|
94 | - // file mask to use if parsing folder for files to add |
|
95 | - '', |
|
96 | - // what to use as identifier for collection entities |
|
97 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
98 | - CollectionDetails::ID_CLASS_NAME |
|
99 | - ), |
|
100 | - $this->blocks |
|
101 | - ); |
|
102 | - return $loader->getCollection(); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * populates the EditorBlockCollection and calls initialize() on all installed blocks |
|
108 | - * |
|
109 | - * @return void |
|
110 | - * @throws Exception |
|
111 | - */ |
|
112 | - public function loadEditorBlocks() |
|
113 | - { |
|
114 | - try { |
|
115 | - $this->populateEditorBlockCollection(); |
|
116 | - // cycle thru block loaders and initialize each loader |
|
117 | - foreach ($this->blocks as $block) { |
|
118 | - $block->initialize(); |
|
119 | - } |
|
120 | - } catch (Exception $exception) { |
|
121 | - new ExceptionStackTraceDisplay($exception); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * calls registerBlock() and load assets for all installed blocks |
|
128 | - * |
|
129 | - * @return void |
|
130 | - * @throws Exception |
|
131 | - */ |
|
132 | - public function registerEditorBlocks() |
|
133 | - { |
|
134 | - try { |
|
135 | - // register primary assets |
|
136 | - add_action('enqueue_block_assets', array($this, 'registerStyles')); |
|
137 | - add_action('enqueue_block_assets', array($this, 'registerScripts')); |
|
138 | - // cycle thru block loader folders |
|
139 | - foreach ($this->blocks as $block) { |
|
140 | - // perform any setup required for the block |
|
141 | - $block_type = $block->registerBlock(); |
|
142 | - if (! $block_type instanceof WP_Block_Type) { |
|
143 | - throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
144 | - } |
|
145 | - add_action('enqueue_block_assets', array($block, 'registerStyles')); |
|
146 | - add_action('enqueue_block_assets', array($block, 'registerScripts')); |
|
147 | - do_action( |
|
148 | - 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered', |
|
149 | - $block, |
|
150 | - $block_type |
|
151 | - ); |
|
152 | - } |
|
153 | - } catch (Exception $exception) { |
|
154 | - new ExceptionStackTraceDisplay($exception); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - public function registerStyles() |
|
160 | - { |
|
161 | - // wp_register_style( |
|
162 | - // 'ee-block-styles', |
|
163 | - // $this->domain->distributionAssetsUrl() . 'style.css', |
|
164 | - // array(), |
|
165 | - // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
166 | - // ); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - public function registerScripts() |
|
171 | - { |
|
172 | - wp_register_script( |
|
173 | - 'ee-core-blocks', |
|
174 | - $this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS), |
|
175 | - array( |
|
176 | - 'eejs-core', |
|
177 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
178 | - 'wp-i18n', // Provides localization functions |
|
179 | - 'wp-element', // Provides React.Component |
|
180 | - 'wp-components' // Provides many prebuilt components and controls |
|
181 | - ), |
|
182 | - null, |
|
183 | - true |
|
184 | - ); |
|
185 | - } |
|
37 | + /** |
|
38 | + * Returns the name of a hookpoint to be used to call initialize() |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function initHook() |
|
43 | + { |
|
44 | + return 'AHEE__EE_System__set_hooks_for_core'; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Perform any early setup required for block editors to functions |
|
50 | + * |
|
51 | + * @return void |
|
52 | + * @throws Exception |
|
53 | + */ |
|
54 | + public function initialize() |
|
55 | + { |
|
56 | + $this->loadEditorBlocks(); |
|
57 | + add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks')); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @return CollectionInterface|EditorBlockInterface[] |
|
63 | + * @throws ReflectionException |
|
64 | + * @throws InvalidArgumentException |
|
65 | + * @throws EE_Error |
|
66 | + * @throws InvalidClassException |
|
67 | + * @throws InvalidDataTypeException |
|
68 | + * @throws InvalidEntityException |
|
69 | + * @throws InvalidFilePathException |
|
70 | + * @throws InvalidIdentifierException |
|
71 | + * @throws InvalidInterfaceException |
|
72 | + */ |
|
73 | + protected function populateEditorBlockCollection() |
|
74 | + { |
|
75 | + $loader = new CollectionLoader( |
|
76 | + new CollectionDetails( |
|
77 | + // collection name |
|
78 | + 'shortcodes', |
|
79 | + // collection interface |
|
80 | + 'EventEspresso\core\domain\entities\editor\EditorBlockInterface', |
|
81 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
82 | + apply_filters( |
|
83 | + 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs', |
|
84 | + array() |
|
85 | + // array( |
|
86 | + // 'EventEspresso\core\domain\entities\editor\blocks\common', |
|
87 | + // 'EventEspresso\core\domain\entities\editor\blocks\editor', |
|
88 | + // 'EventEspresso\core\domain\entities\editor\blocks\shortcodes', |
|
89 | + // 'EventEspresso\core\domain\entities\editor\blocks\widgets', |
|
90 | + // ) |
|
91 | + ), |
|
92 | + // filepaths to classes to add |
|
93 | + array(), |
|
94 | + // file mask to use if parsing folder for files to add |
|
95 | + '', |
|
96 | + // what to use as identifier for collection entities |
|
97 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
98 | + CollectionDetails::ID_CLASS_NAME |
|
99 | + ), |
|
100 | + $this->blocks |
|
101 | + ); |
|
102 | + return $loader->getCollection(); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * populates the EditorBlockCollection and calls initialize() on all installed blocks |
|
108 | + * |
|
109 | + * @return void |
|
110 | + * @throws Exception |
|
111 | + */ |
|
112 | + public function loadEditorBlocks() |
|
113 | + { |
|
114 | + try { |
|
115 | + $this->populateEditorBlockCollection(); |
|
116 | + // cycle thru block loaders and initialize each loader |
|
117 | + foreach ($this->blocks as $block) { |
|
118 | + $block->initialize(); |
|
119 | + } |
|
120 | + } catch (Exception $exception) { |
|
121 | + new ExceptionStackTraceDisplay($exception); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * calls registerBlock() and load assets for all installed blocks |
|
128 | + * |
|
129 | + * @return void |
|
130 | + * @throws Exception |
|
131 | + */ |
|
132 | + public function registerEditorBlocks() |
|
133 | + { |
|
134 | + try { |
|
135 | + // register primary assets |
|
136 | + add_action('enqueue_block_assets', array($this, 'registerStyles')); |
|
137 | + add_action('enqueue_block_assets', array($this, 'registerScripts')); |
|
138 | + // cycle thru block loader folders |
|
139 | + foreach ($this->blocks as $block) { |
|
140 | + // perform any setup required for the block |
|
141 | + $block_type = $block->registerBlock(); |
|
142 | + if (! $block_type instanceof WP_Block_Type) { |
|
143 | + throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
144 | + } |
|
145 | + add_action('enqueue_block_assets', array($block, 'registerStyles')); |
|
146 | + add_action('enqueue_block_assets', array($block, 'registerScripts')); |
|
147 | + do_action( |
|
148 | + 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered', |
|
149 | + $block, |
|
150 | + $block_type |
|
151 | + ); |
|
152 | + } |
|
153 | + } catch (Exception $exception) { |
|
154 | + new ExceptionStackTraceDisplay($exception); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + public function registerStyles() |
|
160 | + { |
|
161 | + // wp_register_style( |
|
162 | + // 'ee-block-styles', |
|
163 | + // $this->domain->distributionAssetsUrl() . 'style.css', |
|
164 | + // array(), |
|
165 | + // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
166 | + // ); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + public function registerScripts() |
|
171 | + { |
|
172 | + wp_register_script( |
|
173 | + 'ee-core-blocks', |
|
174 | + $this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS), |
|
175 | + array( |
|
176 | + 'eejs-core', |
|
177 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
178 | + 'wp-i18n', // Provides localization functions |
|
179 | + 'wp-element', // Provides React.Component |
|
180 | + 'wp-components' // Provides many prebuilt components and controls |
|
181 | + ), |
|
182 | + null, |
|
183 | + true |
|
184 | + ); |
|
185 | + } |
|
186 | 186 | } |
@@ -27,276 +27,276 @@ |
||
27 | 27 | class CollectionLoader |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * possible return value when adding entities to a collection. |
|
32 | - * denotes that the entity was NOT ADDED to the collection |
|
33 | - */ |
|
34 | - const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
30 | + /** |
|
31 | + * possible return value when adding entities to a collection. |
|
32 | + * denotes that the entity was NOT ADDED to the collection |
|
33 | + */ |
|
34 | + const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * possible return value when adding entities to a collection. |
|
38 | - * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
39 | - */ |
|
40 | - const ENTITY_ADDED = 'entity-added-to-collection'; |
|
36 | + /** |
|
37 | + * possible return value when adding entities to a collection. |
|
38 | + * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
39 | + */ |
|
40 | + const ENTITY_ADDED = 'entity-added-to-collection'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * possible return value when adding entities to a collection. |
|
44 | - * denotes that the entity was ALREADY ADDED to the collection, |
|
45 | - * and therefore could not be added again. |
|
46 | - */ |
|
47 | - const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
42 | + /** |
|
43 | + * possible return value when adding entities to a collection. |
|
44 | + * denotes that the entity was ALREADY ADDED to the collection, |
|
45 | + * and therefore could not be added again. |
|
46 | + */ |
|
47 | + const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @var CollectionDetailsInterface $collection_details |
|
52 | - */ |
|
53 | - protected $collection_details; |
|
50 | + /** |
|
51 | + * @var CollectionDetailsInterface $collection_details |
|
52 | + */ |
|
53 | + protected $collection_details; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var CollectionInterface $collection |
|
57 | - */ |
|
58 | - protected $collection; |
|
55 | + /** |
|
56 | + * @var CollectionInterface $collection |
|
57 | + */ |
|
58 | + protected $collection; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var FileLocator $file_locator |
|
62 | - */ |
|
63 | - protected $file_locator; |
|
60 | + /** |
|
61 | + * @var FileLocator $file_locator |
|
62 | + */ |
|
63 | + protected $file_locator; |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * CollectionLoader constructor. |
|
68 | - * |
|
69 | - * @param CollectionDetailsInterface $collection_details |
|
70 | - * @param CollectionInterface $collection |
|
71 | - * @param LocatorInterface $file_locator |
|
72 | - * @throws ReflectionException |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws EE_Error |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws InvalidClassException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidFilePathException |
|
79 | - * @throws InvalidEntityException |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - CollectionDetailsInterface $collection_details, |
|
83 | - CollectionInterface $collection = null, |
|
84 | - LocatorInterface $file_locator = null |
|
85 | - ) { |
|
86 | - $this->collection_details = $collection_details; |
|
87 | - if (! $collection instanceof CollectionInterface) { |
|
88 | - $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
89 | - } |
|
90 | - $this->collection = $collection; |
|
91 | - $this->file_locator = $file_locator; |
|
92 | - $this->loadAllFromFilepaths(); |
|
93 | - $this->loadFromFQCNs(); |
|
94 | - } |
|
66 | + /** |
|
67 | + * CollectionLoader constructor. |
|
68 | + * |
|
69 | + * @param CollectionDetailsInterface $collection_details |
|
70 | + * @param CollectionInterface $collection |
|
71 | + * @param LocatorInterface $file_locator |
|
72 | + * @throws ReflectionException |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws EE_Error |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws InvalidClassException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidFilePathException |
|
79 | + * @throws InvalidEntityException |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + CollectionDetailsInterface $collection_details, |
|
83 | + CollectionInterface $collection = null, |
|
84 | + LocatorInterface $file_locator = null |
|
85 | + ) { |
|
86 | + $this->collection_details = $collection_details; |
|
87 | + if (! $collection instanceof CollectionInterface) { |
|
88 | + $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
89 | + } |
|
90 | + $this->collection = $collection; |
|
91 | + $this->file_locator = $file_locator; |
|
92 | + $this->loadAllFromFilepaths(); |
|
93 | + $this->loadFromFQCNs(); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * @return CollectionInterface |
|
99 | - */ |
|
100 | - public function getCollection() |
|
101 | - { |
|
102 | - return $this->collection; |
|
103 | - } |
|
97 | + /** |
|
98 | + * @return CollectionInterface |
|
99 | + */ |
|
100 | + public function getCollection() |
|
101 | + { |
|
102 | + return $this->collection; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * @throws InvalidClassException |
|
108 | - * @throws InvalidFilePathException |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidEntityException |
|
111 | - */ |
|
112 | - protected function loadAllFromFilepaths() |
|
113 | - { |
|
114 | - if (! $this->file_locator instanceof FileLocator) { |
|
115 | - $this->file_locator = new FileLocator(); |
|
116 | - } |
|
117 | - $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
118 | - // find all of the files that match the file mask in the specified folder |
|
119 | - $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
120 | - // filter the results |
|
121 | - $filepaths = (array) apply_filters( |
|
122 | - 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
123 | - $this->file_locator->getFilePaths(), |
|
124 | - $this->collection_details->collectionName(), |
|
125 | - $this->collection_details |
|
126 | - ); |
|
127 | - if (empty($filepaths)) { |
|
128 | - return; |
|
129 | - } |
|
130 | - foreach ($filepaths as $filepath) { |
|
131 | - $this->loadClassFromFilepath($filepath); |
|
132 | - } |
|
133 | - } |
|
106 | + /** |
|
107 | + * @throws InvalidClassException |
|
108 | + * @throws InvalidFilePathException |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidEntityException |
|
111 | + */ |
|
112 | + protected function loadAllFromFilepaths() |
|
113 | + { |
|
114 | + if (! $this->file_locator instanceof FileLocator) { |
|
115 | + $this->file_locator = new FileLocator(); |
|
116 | + } |
|
117 | + $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
118 | + // find all of the files that match the file mask in the specified folder |
|
119 | + $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
120 | + // filter the results |
|
121 | + $filepaths = (array) apply_filters( |
|
122 | + 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
123 | + $this->file_locator->getFilePaths(), |
|
124 | + $this->collection_details->collectionName(), |
|
125 | + $this->collection_details |
|
126 | + ); |
|
127 | + if (empty($filepaths)) { |
|
128 | + return; |
|
129 | + } |
|
130 | + foreach ($filepaths as $filepath) { |
|
131 | + $this->loadClassFromFilepath($filepath); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * @param string $filepath |
|
138 | - * @return string |
|
139 | - * @throws InvalidEntityException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidFilePathException |
|
142 | - * @throws InvalidClassException |
|
143 | - */ |
|
144 | - protected function loadClassFromFilepath($filepath) |
|
145 | - { |
|
146 | - if (! is_string($filepath)) { |
|
147 | - throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
148 | - } |
|
149 | - if (! is_readable($filepath)) { |
|
150 | - throw new InvalidFilePathException($filepath); |
|
151 | - } |
|
152 | - require_once $filepath; |
|
153 | - // extract filename from path |
|
154 | - $file_name = basename($filepath); |
|
155 | - // now remove any file extensions |
|
156 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
157 | - if (! class_exists($class_name)) { |
|
158 | - throw new InvalidClassException($class_name); |
|
159 | - } |
|
160 | - return $this->addEntityToCollection(new $class_name(), $file_name); |
|
161 | - } |
|
136 | + /** |
|
137 | + * @param string $filepath |
|
138 | + * @return string |
|
139 | + * @throws InvalidEntityException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidFilePathException |
|
142 | + * @throws InvalidClassException |
|
143 | + */ |
|
144 | + protected function loadClassFromFilepath($filepath) |
|
145 | + { |
|
146 | + if (! is_string($filepath)) { |
|
147 | + throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
148 | + } |
|
149 | + if (! is_readable($filepath)) { |
|
150 | + throw new InvalidFilePathException($filepath); |
|
151 | + } |
|
152 | + require_once $filepath; |
|
153 | + // extract filename from path |
|
154 | + $file_name = basename($filepath); |
|
155 | + // now remove any file extensions |
|
156 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
157 | + if (! class_exists($class_name)) { |
|
158 | + throw new InvalidClassException($class_name); |
|
159 | + } |
|
160 | + return $this->addEntityToCollection(new $class_name(), $file_name); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * @param $entity |
|
166 | - * @param mixed $identifier |
|
167 | - * @return string |
|
168 | - * @throws InvalidEntityException |
|
169 | - */ |
|
170 | - protected function addEntityToCollection($entity, $identifier) |
|
171 | - { |
|
172 | - do_action( |
|
173 | - 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
174 | - $entity, |
|
175 | - $this->collection_details->collectionName(), |
|
176 | - $this->collection_details |
|
177 | - ); |
|
178 | - $identifier = $this->setIdentifier($entity, $identifier); |
|
179 | - if ($this->collection->has($identifier)) { |
|
180 | - do_action( |
|
181 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
182 | - $this, |
|
183 | - $this->collection_details->collectionName(), |
|
184 | - $this->collection_details |
|
185 | - ); |
|
186 | - return CollectionLoader::ENTITY_EXISTS; |
|
187 | - } |
|
188 | - if ($this->collection->add($entity, $identifier)) { |
|
189 | - do_action( |
|
190 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
191 | - $this, |
|
192 | - $this->collection_details->collectionName(), |
|
193 | - $this->collection_details |
|
194 | - ); |
|
195 | - return CollectionLoader::ENTITY_ADDED; |
|
196 | - } |
|
197 | - do_action( |
|
198 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
199 | - $this, |
|
200 | - $this->collection_details->collectionName(), |
|
201 | - $this->collection_details |
|
202 | - ); |
|
203 | - return CollectionLoader::ENTITY_NOT_ADDED; |
|
204 | - } |
|
164 | + /** |
|
165 | + * @param $entity |
|
166 | + * @param mixed $identifier |
|
167 | + * @return string |
|
168 | + * @throws InvalidEntityException |
|
169 | + */ |
|
170 | + protected function addEntityToCollection($entity, $identifier) |
|
171 | + { |
|
172 | + do_action( |
|
173 | + 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
174 | + $entity, |
|
175 | + $this->collection_details->collectionName(), |
|
176 | + $this->collection_details |
|
177 | + ); |
|
178 | + $identifier = $this->setIdentifier($entity, $identifier); |
|
179 | + if ($this->collection->has($identifier)) { |
|
180 | + do_action( |
|
181 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
182 | + $this, |
|
183 | + $this->collection_details->collectionName(), |
|
184 | + $this->collection_details |
|
185 | + ); |
|
186 | + return CollectionLoader::ENTITY_EXISTS; |
|
187 | + } |
|
188 | + if ($this->collection->add($entity, $identifier)) { |
|
189 | + do_action( |
|
190 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
191 | + $this, |
|
192 | + $this->collection_details->collectionName(), |
|
193 | + $this->collection_details |
|
194 | + ); |
|
195 | + return CollectionLoader::ENTITY_ADDED; |
|
196 | + } |
|
197 | + do_action( |
|
198 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
199 | + $this, |
|
200 | + $this->collection_details->collectionName(), |
|
201 | + $this->collection_details |
|
202 | + ); |
|
203 | + return CollectionLoader::ENTITY_NOT_ADDED; |
|
204 | + } |
|
205 | 205 | |
206 | 206 | |
207 | - /** |
|
208 | - * @param $entity |
|
209 | - * @param mixed $identifier |
|
210 | - * @return string |
|
211 | - * @throws InvalidEntityException |
|
212 | - */ |
|
213 | - protected function setIdentifier($entity, $identifier) |
|
214 | - { |
|
215 | - switch ($this->collection_details->identifierType()) { |
|
216 | - // every unique object gets added to the collection, but not duplicates of the exact same object |
|
217 | - case CollectionDetails::ID_OBJECT_HASH: |
|
218 | - $identifier = spl_object_hash($entity); |
|
219 | - break; |
|
220 | - // only one entity per class can be added to collection, like a singleton |
|
221 | - case CollectionDetails::ID_CLASS_NAME: |
|
222 | - $identifier = get_class($entity); |
|
223 | - break; |
|
224 | - // objects added to the collection based on entity callback, so the entity itself decides |
|
225 | - case CollectionDetails::ID_CALLBACK_METHOD: |
|
226 | - $identifier_callback = $this->collection_details->identifierCallback(); |
|
227 | - if (! method_exists($entity, $identifier_callback)) { |
|
228 | - throw new InvalidEntityException( |
|
229 | - $entity, |
|
230 | - $this->collection_details->getCollectionInterface(), |
|
231 | - sprintf( |
|
232 | - __( |
|
233 | - 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
207 | + /** |
|
208 | + * @param $entity |
|
209 | + * @param mixed $identifier |
|
210 | + * @return string |
|
211 | + * @throws InvalidEntityException |
|
212 | + */ |
|
213 | + protected function setIdentifier($entity, $identifier) |
|
214 | + { |
|
215 | + switch ($this->collection_details->identifierType()) { |
|
216 | + // every unique object gets added to the collection, but not duplicates of the exact same object |
|
217 | + case CollectionDetails::ID_OBJECT_HASH: |
|
218 | + $identifier = spl_object_hash($entity); |
|
219 | + break; |
|
220 | + // only one entity per class can be added to collection, like a singleton |
|
221 | + case CollectionDetails::ID_CLASS_NAME: |
|
222 | + $identifier = get_class($entity); |
|
223 | + break; |
|
224 | + // objects added to the collection based on entity callback, so the entity itself decides |
|
225 | + case CollectionDetails::ID_CALLBACK_METHOD: |
|
226 | + $identifier_callback = $this->collection_details->identifierCallback(); |
|
227 | + if (! method_exists($entity, $identifier_callback)) { |
|
228 | + throw new InvalidEntityException( |
|
229 | + $entity, |
|
230 | + $this->collection_details->getCollectionInterface(), |
|
231 | + sprintf( |
|
232 | + __( |
|
233 | + 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
234 | 234 | of "%2$s", but does not contain this method.', |
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - $identifier_callback, |
|
238 | - get_class($entity) |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - $identifier = $entity->{$identifier_callback}(); |
|
243 | - break; |
|
244 | - } |
|
245 | - return apply_filters( |
|
246 | - 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
247 | - $identifier, |
|
248 | - $this->collection_details->collectionName(), |
|
249 | - $this->collection_details |
|
250 | - ); |
|
251 | - } |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + $identifier_callback, |
|
238 | + get_class($entity) |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + $identifier = $entity->{$identifier_callback}(); |
|
243 | + break; |
|
244 | + } |
|
245 | + return apply_filters( |
|
246 | + 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
247 | + $identifier, |
|
248 | + $this->collection_details->collectionName(), |
|
249 | + $this->collection_details |
|
250 | + ); |
|
251 | + } |
|
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * @throws ReflectionException |
|
256 | - * @throws InvalidArgumentException |
|
257 | - * @throws InvalidInterfaceException |
|
258 | - * @throws EE_Error |
|
259 | - * @throws InvalidClassException |
|
260 | - * @throws InvalidDataTypeException |
|
261 | - * @throws InvalidEntityException |
|
262 | - */ |
|
263 | - protected function loadFromFQCNs() |
|
264 | - { |
|
265 | - $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
266 | - $FQCNs = (array) apply_filters( |
|
267 | - 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
268 | - $FQCNs, |
|
269 | - $this->collection_details->collectionName(), |
|
270 | - $this->collection_details |
|
271 | - ); |
|
272 | - foreach ($FQCNs as $FQCN) { |
|
273 | - $this->loadClassFromFQCN($FQCN); |
|
274 | - } |
|
275 | - } |
|
254 | + /** |
|
255 | + * @throws ReflectionException |
|
256 | + * @throws InvalidArgumentException |
|
257 | + * @throws InvalidInterfaceException |
|
258 | + * @throws EE_Error |
|
259 | + * @throws InvalidClassException |
|
260 | + * @throws InvalidDataTypeException |
|
261 | + * @throws InvalidEntityException |
|
262 | + */ |
|
263 | + protected function loadFromFQCNs() |
|
264 | + { |
|
265 | + $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
266 | + $FQCNs = (array) apply_filters( |
|
267 | + 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
268 | + $FQCNs, |
|
269 | + $this->collection_details->collectionName(), |
|
270 | + $this->collection_details |
|
271 | + ); |
|
272 | + foreach ($FQCNs as $FQCN) { |
|
273 | + $this->loadClassFromFQCN($FQCN); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | 277 | |
278 | - /** |
|
279 | - * @param string $FQCN Fully Qualified Class Name |
|
280 | - * @return string |
|
281 | - * @throws InvalidArgumentException |
|
282 | - * @throws InvalidInterfaceException |
|
283 | - * @throws ReflectionException |
|
284 | - * @throws EE_Error |
|
285 | - * @throws InvalidEntityException |
|
286 | - * @throws InvalidDataTypeException |
|
287 | - * @throws InvalidClassException |
|
288 | - */ |
|
289 | - protected function loadClassFromFQCN($FQCN) |
|
290 | - { |
|
291 | - if (! is_string($FQCN)) { |
|
292 | - throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
293 | - } |
|
294 | - if (! class_exists($FQCN)) { |
|
295 | - throw new InvalidClassException($FQCN); |
|
296 | - } |
|
297 | - return $this->addEntityToCollection( |
|
298 | - EE_Registry::instance()->create($FQCN), |
|
299 | - $FQCN |
|
300 | - ); |
|
301 | - } |
|
278 | + /** |
|
279 | + * @param string $FQCN Fully Qualified Class Name |
|
280 | + * @return string |
|
281 | + * @throws InvalidArgumentException |
|
282 | + * @throws InvalidInterfaceException |
|
283 | + * @throws ReflectionException |
|
284 | + * @throws EE_Error |
|
285 | + * @throws InvalidEntityException |
|
286 | + * @throws InvalidDataTypeException |
|
287 | + * @throws InvalidClassException |
|
288 | + */ |
|
289 | + protected function loadClassFromFQCN($FQCN) |
|
290 | + { |
|
291 | + if (! is_string($FQCN)) { |
|
292 | + throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
293 | + } |
|
294 | + if (! class_exists($FQCN)) { |
|
295 | + throw new InvalidClassException($FQCN); |
|
296 | + } |
|
297 | + return $this->addEntityToCollection( |
|
298 | + EE_Registry::instance()->create($FQCN), |
|
299 | + $FQCN |
|
300 | + ); |
|
301 | + } |
|
302 | 302 | } |