@@ -16,36 +16,36 @@ |
||
16 | 16 | class RouteMatchSpecificationCollection extends Collection |
17 | 17 | { |
18 | 18 | |
19 | - const COLLECTION_NAME = 'route_match_specifications'; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * RouteMatchSpecificationCollection constructor |
|
24 | - * |
|
25 | - * @throws InvalidInterfaceException |
|
26 | - */ |
|
27 | - public function __construct() |
|
28 | - { |
|
29 | - parent::__construct( |
|
30 | - 'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface', |
|
31 | - RouteMatchSpecificationCollection::COLLECTION_NAME |
|
32 | - ); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * getIdentifier |
|
38 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
39 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
40 | - * |
|
41 | - * @param $object |
|
42 | - * @param mixed $identifier |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function getIdentifier($object, $identifier = null) |
|
46 | - { |
|
47 | - return ! empty($identifier) |
|
48 | - ? $identifier |
|
49 | - : get_class($object); |
|
50 | - } |
|
19 | + const COLLECTION_NAME = 'route_match_specifications'; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * RouteMatchSpecificationCollection constructor |
|
24 | + * |
|
25 | + * @throws InvalidInterfaceException |
|
26 | + */ |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | + parent::__construct( |
|
30 | + 'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface', |
|
31 | + RouteMatchSpecificationCollection::COLLECTION_NAME |
|
32 | + ); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * getIdentifier |
|
38 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
39 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
40 | + * |
|
41 | + * @param $object |
|
42 | + * @param mixed $identifier |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function getIdentifier($object, $identifier = null) |
|
46 | + { |
|
47 | + return ! empty($identifier) |
|
48 | + ? $identifier |
|
49 | + : get_class($object); |
|
50 | + } |
|
51 | 51 | } |
@@ -12,42 +12,42 @@ |
||
12 | 12 | */ |
13 | 13 | interface BlockAssetManagerInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * @since $VID:$ |
|
17 | - * @return string |
|
18 | - */ |
|
19 | - public function assetNamespace(); |
|
20 | - |
|
21 | - /** |
|
22 | - * @since $VID:$ |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - public function setAssetHandles(); |
|
26 | - |
|
27 | - /** |
|
28 | - * @since $VID:$ |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function getEditorScriptHandle(); |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @since $VID:$ |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getEditorStyleHandle(); |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @since $VID:$ |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function getScriptHandle(); |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @since $VID:$ |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function getStyleHandle(); |
|
15 | + /** |
|
16 | + * @since $VID:$ |
|
17 | + * @return string |
|
18 | + */ |
|
19 | + public function assetNamespace(); |
|
20 | + |
|
21 | + /** |
|
22 | + * @since $VID:$ |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + public function setAssetHandles(); |
|
26 | + |
|
27 | + /** |
|
28 | + * @since $VID:$ |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function getEditorScriptHandle(); |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @since $VID:$ |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getEditorStyleHandle(); |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @since $VID:$ |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function getScriptHandle(); |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @since $VID:$ |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function getStyleHandle(); |
|
53 | 53 | } |
54 | 54 | \ No newline at end of file |
@@ -43,351 +43,351 @@ |
||
43 | 43 | class CollectionDetails implements CollectionDetailsInterface |
44 | 44 | { |
45 | 45 | |
46 | - /** |
|
47 | - * if $identifier_type is set to this, |
|
48 | - * then the collection will use each object's spl_object_hash() as it's identifier |
|
49 | - */ |
|
50 | - const ID_OBJECT_HASH = 'identifier-uses-spl-object-hash'; |
|
51 | - |
|
52 | - /** |
|
53 | - * if $identifier_type is set to this, |
|
54 | - * then the collection will use each object's class name as it's identifier |
|
55 | - */ |
|
56 | - const ID_CLASS_NAME = 'identifier-uses-object-class-name'; |
|
57 | - |
|
58 | - /** |
|
59 | - * if $identifier_type is set to this, |
|
60 | - * then the collection will use the return value from a specified callback method on each object |
|
61 | - */ |
|
62 | - const ID_CALLBACK_METHOD = 'identifier-uses-callback-method'; |
|
63 | - |
|
64 | - /** |
|
65 | - * The interface used for controlling what gets added to the collection |
|
66 | - * |
|
67 | - * @var string $collection_interface |
|
68 | - */ |
|
69 | - protected $collection_interface = ''; |
|
70 | - |
|
71 | - /** |
|
72 | - * a unique name used to identify the collection in filter names |
|
73 | - * supplied value is run through sanitize_title_with_dashes(), |
|
74 | - * but then also converts dashes to underscores |
|
75 | - * |
|
76 | - * @var string $collection_name |
|
77 | - */ |
|
78 | - protected $collection_name = ''; |
|
79 | - |
|
80 | - /** |
|
81 | - * what the collection uses for the object identifier. |
|
82 | - * corresponds to one of the class constants above. |
|
83 | - * CollectionDetails::ID_OBJECT_HASH will use spl_object_hash( object ) for the identifier |
|
84 | - * CollectionDetails::ID_CLASS_NAME will use get_class( object ) for the identifier |
|
85 | - * CollectionDetails::ID_CALLBACK_METHOD will use a callback for the identifier |
|
86 | - * defaults to using spl_object_hash() so that multiple objects of the same class can be added |
|
87 | - * |
|
88 | - * @var string $identifier_type |
|
89 | - */ |
|
90 | - protected $identifier_type = CollectionDetails::ID_OBJECT_HASH; |
|
91 | - |
|
92 | - /** |
|
93 | - * the pattern applied to paths when searching for class files to add to the collection |
|
94 | - * ie: "My_Awesome_*.class.php" |
|
95 | - * defaults to "*.php" |
|
96 | - * |
|
97 | - * @var string $file_mask |
|
98 | - */ |
|
99 | - protected $file_mask = ''; |
|
100 | - |
|
101 | - /** |
|
102 | - * if the $identifier_type above is set to CollectionDetails::ID_CALLBACK_METHOD, |
|
103 | - * then this specifies the method to use on each entity. |
|
104 | - * If the callback method does not exist, then an exception will be thrown |
|
105 | - * |
|
106 | - * @var string $identifier_callback |
|
107 | - */ |
|
108 | - protected $identifier_callback = ''; |
|
109 | - |
|
110 | - /** |
|
111 | - * an array of Fully Qualified Class Names |
|
112 | - * for example: |
|
113 | - * $FQCNs = array( |
|
114 | - * '/Fully/Qualified/ClassNameA' |
|
115 | - * '/Fully/Qualified/Other/ClassNameB' |
|
116 | - * ); |
|
117 | - * |
|
118 | - * @var array $collection_FQCNs |
|
119 | - */ |
|
120 | - protected $collection_FQCNs = array(); |
|
121 | - |
|
122 | - /** |
|
123 | - * an array of full server paths to folders containing files to be loaded into collection |
|
124 | - * for example: |
|
125 | - * $paths = array( |
|
126 | - * '/full/server/path/to/ClassNameA.ext.php' // for class ClassNameA |
|
127 | - * '/full/server/path/to/other/ClassNameB.php' // for class ClassNameB |
|
128 | - * ); |
|
129 | - * |
|
130 | - * @var array $collection_paths |
|
131 | - */ |
|
132 | - protected $collection_paths = array(); |
|
133 | - |
|
134 | - /** |
|
135 | - * @var LocatorInterface $file_locator |
|
136 | - */ |
|
137 | - protected $file_locator; |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * CollectionDetails constructor. |
|
142 | - * |
|
143 | - * @access public |
|
144 | - * @param string $collection_name |
|
145 | - * @param string $collection_interface |
|
146 | - * @param array $collection_FQCNs |
|
147 | - * @param array $collection_paths |
|
148 | - * @param string $file_mask |
|
149 | - * @param string $identifier_type |
|
150 | - * @param string $identifier_callback |
|
151 | - * @param LocatorInterface $file_locator |
|
152 | - * @throws CollectionDetailsException |
|
153 | - */ |
|
154 | - public function __construct( |
|
155 | - $collection_name, |
|
156 | - $collection_interface, |
|
157 | - array $collection_FQCNs = array(), |
|
158 | - array $collection_paths = array(), |
|
159 | - $file_mask = '', |
|
160 | - $identifier_type = CollectionDetails::ID_OBJECT_HASH, |
|
161 | - $identifier_callback = '', |
|
162 | - LocatorInterface $file_locator = null |
|
163 | - ) { |
|
164 | - try { |
|
165 | - $this->setCollectionName($collection_name); |
|
166 | - $this->setCollectionInterface($collection_interface); |
|
167 | - $this->setCollectionFQCNs($collection_FQCNs); |
|
168 | - $this->setCollectionPaths($collection_paths); |
|
169 | - $this->setFileMasks($file_mask); |
|
170 | - $this->setIdentifierType($identifier_type); |
|
171 | - $this->setIdentifierCallback($identifier_callback); |
|
172 | - $this->file_locator = $file_locator; |
|
173 | - } catch (Exception $exception) { |
|
174 | - throw new CollectionDetailsException($exception); |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @access public |
|
181 | - * @return mixed |
|
182 | - */ |
|
183 | - public function getCollectionInterface() |
|
184 | - { |
|
185 | - return $this->collection_interface; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * @access protected |
|
191 | - * @param string $collection_interface |
|
192 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
193 | - */ |
|
194 | - protected function setCollectionInterface($collection_interface) |
|
195 | - { |
|
196 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
197 | - throw new InvalidInterfaceException($collection_interface); |
|
198 | - } |
|
199 | - $this->collection_interface = $collection_interface; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * the collection name will be used for creating dynamic filters |
|
205 | - * |
|
206 | - * @access public |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - public function collectionName() |
|
210 | - { |
|
211 | - return $this->collection_name; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * sanitizes collection name and converts spaces and dashes to underscores |
|
217 | - * |
|
218 | - * @access protected |
|
219 | - * @param string $collection_name |
|
220 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
221 | - */ |
|
222 | - protected function setCollectionName($collection_name) |
|
223 | - { |
|
224 | - if (! is_string($collection_name)) { |
|
225 | - throw new InvalidDataTypeException('$collection_name', $collection_name, 'string'); |
|
226 | - } |
|
227 | - $this->collection_name = str_replace( |
|
228 | - '-', |
|
229 | - '_', |
|
230 | - sanitize_title_with_dashes($collection_name, '', 'save') |
|
231 | - ); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @access public |
|
237 | - * @return string |
|
238 | - */ |
|
239 | - public function identifierType() |
|
240 | - { |
|
241 | - return $this->identifier_type; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @access protected |
|
247 | - * @param string $identifier_type |
|
248 | - * @throws InvalidIdentifierException |
|
249 | - */ |
|
250 | - protected function setIdentifierType($identifier_type) |
|
251 | - { |
|
252 | - if (! ($identifier_type === CollectionDetails::ID_CLASS_NAME |
|
253 | - || $identifier_type === CollectionDetails::ID_OBJECT_HASH |
|
254 | - || $identifier_type === CollectionDetails::ID_CALLBACK_METHOD |
|
255 | - )) { |
|
256 | - throw new InvalidIdentifierException( |
|
257 | - $identifier_type, |
|
258 | - 'CollectionDetails::ID_CLASS_NAME or CollectionDetails::ID_OBJECT_HASH or CollectionDetails::ID_CALLBACK_METHOD' |
|
259 | - ); |
|
260 | - } |
|
261 | - $this->identifier_type = $identifier_type; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @access public |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function identifierCallback() |
|
270 | - { |
|
271 | - return $this->identifier_callback; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @access protected |
|
277 | - * @param string $identifier_callback |
|
278 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
279 | - */ |
|
280 | - protected function setIdentifierCallback($identifier_callback = 'identifier') |
|
281 | - { |
|
282 | - if (! is_string($identifier_callback)) { |
|
283 | - throw new InvalidDataTypeException('$identifier_callback', $identifier_callback, 'string'); |
|
284 | - } |
|
285 | - $this->identifier_callback = $identifier_callback; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * @access public |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - public function getFileMask() |
|
294 | - { |
|
295 | - return $this->file_mask; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * sets the file mask which is then used to filter what files get loaded |
|
301 | - * when searching for classes to add to the collection. Defaults to '*.php' |
|
302 | - * |
|
303 | - * @access protected |
|
304 | - * @param string $file_mask |
|
305 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
306 | - */ |
|
307 | - protected function setFileMasks($file_mask) |
|
308 | - { |
|
309 | - $this->file_mask = ! empty($file_mask) ? $file_mask : '*.php'; |
|
310 | - // we know our default is a string, so if it's not a string now, |
|
311 | - // then that means the incoming parameter was something else |
|
312 | - if (! is_string($this->file_mask)) { |
|
313 | - throw new InvalidDataTypeException('$file_mask', $this->file_mask, 'string'); |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * @access public |
|
320 | - * @return array |
|
321 | - */ |
|
322 | - public function getCollectionFQCNs() |
|
323 | - { |
|
324 | - return $this->collection_FQCNs; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @access public |
|
330 | - * @param string|array $collection_FQCNs |
|
331 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
332 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
333 | - */ |
|
334 | - public function setCollectionFQCNs($collection_FQCNs) |
|
335 | - { |
|
336 | - foreach ((array) $collection_FQCNs as $collection_FQCN) { |
|
337 | - if (! empty($collection_FQCN)) { |
|
338 | - if (class_exists($collection_FQCN)) { |
|
339 | - $this->collection_FQCNs[] = $collection_FQCN; |
|
340 | - } else { |
|
341 | - foreach ($this->getFQCNsFromPartialNamespace($collection_FQCN) as $FQCN) { |
|
342 | - $this->collection_FQCNs[] = $FQCN; |
|
343 | - } |
|
344 | - } |
|
345 | - } |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * @access protected |
|
352 | - * @param string $partial_FQCN |
|
353 | - * @return array |
|
354 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
355 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
356 | - */ |
|
357 | - protected function getFQCNsFromPartialNamespace($partial_FQCN) |
|
358 | - { |
|
359 | - if (! $this->file_locator instanceof FqcnLocator) { |
|
360 | - $this->file_locator = new FqcnLocator(); |
|
361 | - } |
|
362 | - $this->file_locator->locate($partial_FQCN); |
|
363 | - return $this->file_locator->getFQCNs(); |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * @access public |
|
369 | - * @return array |
|
370 | - */ |
|
371 | - public function getCollectionPaths() |
|
372 | - { |
|
373 | - return $this->collection_paths; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @access public |
|
379 | - * @param string|array $collection_paths |
|
380 | - * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
381 | - */ |
|
382 | - public function setCollectionPaths($collection_paths) |
|
383 | - { |
|
384 | - foreach ((array) $collection_paths as $collection_path) { |
|
385 | - if (! empty($collection_path)) { |
|
386 | - if (! is_readable($collection_path)) { |
|
387 | - throw new InvalidFilePathException($collection_path); |
|
388 | - } |
|
389 | - $this->collection_paths[] = $collection_path; |
|
390 | - } |
|
391 | - } |
|
392 | - } |
|
46 | + /** |
|
47 | + * if $identifier_type is set to this, |
|
48 | + * then the collection will use each object's spl_object_hash() as it's identifier |
|
49 | + */ |
|
50 | + const ID_OBJECT_HASH = 'identifier-uses-spl-object-hash'; |
|
51 | + |
|
52 | + /** |
|
53 | + * if $identifier_type is set to this, |
|
54 | + * then the collection will use each object's class name as it's identifier |
|
55 | + */ |
|
56 | + const ID_CLASS_NAME = 'identifier-uses-object-class-name'; |
|
57 | + |
|
58 | + /** |
|
59 | + * if $identifier_type is set to this, |
|
60 | + * then the collection will use the return value from a specified callback method on each object |
|
61 | + */ |
|
62 | + const ID_CALLBACK_METHOD = 'identifier-uses-callback-method'; |
|
63 | + |
|
64 | + /** |
|
65 | + * The interface used for controlling what gets added to the collection |
|
66 | + * |
|
67 | + * @var string $collection_interface |
|
68 | + */ |
|
69 | + protected $collection_interface = ''; |
|
70 | + |
|
71 | + /** |
|
72 | + * a unique name used to identify the collection in filter names |
|
73 | + * supplied value is run through sanitize_title_with_dashes(), |
|
74 | + * but then also converts dashes to underscores |
|
75 | + * |
|
76 | + * @var string $collection_name |
|
77 | + */ |
|
78 | + protected $collection_name = ''; |
|
79 | + |
|
80 | + /** |
|
81 | + * what the collection uses for the object identifier. |
|
82 | + * corresponds to one of the class constants above. |
|
83 | + * CollectionDetails::ID_OBJECT_HASH will use spl_object_hash( object ) for the identifier |
|
84 | + * CollectionDetails::ID_CLASS_NAME will use get_class( object ) for the identifier |
|
85 | + * CollectionDetails::ID_CALLBACK_METHOD will use a callback for the identifier |
|
86 | + * defaults to using spl_object_hash() so that multiple objects of the same class can be added |
|
87 | + * |
|
88 | + * @var string $identifier_type |
|
89 | + */ |
|
90 | + protected $identifier_type = CollectionDetails::ID_OBJECT_HASH; |
|
91 | + |
|
92 | + /** |
|
93 | + * the pattern applied to paths when searching for class files to add to the collection |
|
94 | + * ie: "My_Awesome_*.class.php" |
|
95 | + * defaults to "*.php" |
|
96 | + * |
|
97 | + * @var string $file_mask |
|
98 | + */ |
|
99 | + protected $file_mask = ''; |
|
100 | + |
|
101 | + /** |
|
102 | + * if the $identifier_type above is set to CollectionDetails::ID_CALLBACK_METHOD, |
|
103 | + * then this specifies the method to use on each entity. |
|
104 | + * If the callback method does not exist, then an exception will be thrown |
|
105 | + * |
|
106 | + * @var string $identifier_callback |
|
107 | + */ |
|
108 | + protected $identifier_callback = ''; |
|
109 | + |
|
110 | + /** |
|
111 | + * an array of Fully Qualified Class Names |
|
112 | + * for example: |
|
113 | + * $FQCNs = array( |
|
114 | + * '/Fully/Qualified/ClassNameA' |
|
115 | + * '/Fully/Qualified/Other/ClassNameB' |
|
116 | + * ); |
|
117 | + * |
|
118 | + * @var array $collection_FQCNs |
|
119 | + */ |
|
120 | + protected $collection_FQCNs = array(); |
|
121 | + |
|
122 | + /** |
|
123 | + * an array of full server paths to folders containing files to be loaded into collection |
|
124 | + * for example: |
|
125 | + * $paths = array( |
|
126 | + * '/full/server/path/to/ClassNameA.ext.php' // for class ClassNameA |
|
127 | + * '/full/server/path/to/other/ClassNameB.php' // for class ClassNameB |
|
128 | + * ); |
|
129 | + * |
|
130 | + * @var array $collection_paths |
|
131 | + */ |
|
132 | + protected $collection_paths = array(); |
|
133 | + |
|
134 | + /** |
|
135 | + * @var LocatorInterface $file_locator |
|
136 | + */ |
|
137 | + protected $file_locator; |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * CollectionDetails constructor. |
|
142 | + * |
|
143 | + * @access public |
|
144 | + * @param string $collection_name |
|
145 | + * @param string $collection_interface |
|
146 | + * @param array $collection_FQCNs |
|
147 | + * @param array $collection_paths |
|
148 | + * @param string $file_mask |
|
149 | + * @param string $identifier_type |
|
150 | + * @param string $identifier_callback |
|
151 | + * @param LocatorInterface $file_locator |
|
152 | + * @throws CollectionDetailsException |
|
153 | + */ |
|
154 | + public function __construct( |
|
155 | + $collection_name, |
|
156 | + $collection_interface, |
|
157 | + array $collection_FQCNs = array(), |
|
158 | + array $collection_paths = array(), |
|
159 | + $file_mask = '', |
|
160 | + $identifier_type = CollectionDetails::ID_OBJECT_HASH, |
|
161 | + $identifier_callback = '', |
|
162 | + LocatorInterface $file_locator = null |
|
163 | + ) { |
|
164 | + try { |
|
165 | + $this->setCollectionName($collection_name); |
|
166 | + $this->setCollectionInterface($collection_interface); |
|
167 | + $this->setCollectionFQCNs($collection_FQCNs); |
|
168 | + $this->setCollectionPaths($collection_paths); |
|
169 | + $this->setFileMasks($file_mask); |
|
170 | + $this->setIdentifierType($identifier_type); |
|
171 | + $this->setIdentifierCallback($identifier_callback); |
|
172 | + $this->file_locator = $file_locator; |
|
173 | + } catch (Exception $exception) { |
|
174 | + throw new CollectionDetailsException($exception); |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @access public |
|
181 | + * @return mixed |
|
182 | + */ |
|
183 | + public function getCollectionInterface() |
|
184 | + { |
|
185 | + return $this->collection_interface; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * @access protected |
|
191 | + * @param string $collection_interface |
|
192 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
193 | + */ |
|
194 | + protected function setCollectionInterface($collection_interface) |
|
195 | + { |
|
196 | + if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
197 | + throw new InvalidInterfaceException($collection_interface); |
|
198 | + } |
|
199 | + $this->collection_interface = $collection_interface; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * the collection name will be used for creating dynamic filters |
|
205 | + * |
|
206 | + * @access public |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public function collectionName() |
|
210 | + { |
|
211 | + return $this->collection_name; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * sanitizes collection name and converts spaces and dashes to underscores |
|
217 | + * |
|
218 | + * @access protected |
|
219 | + * @param string $collection_name |
|
220 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
221 | + */ |
|
222 | + protected function setCollectionName($collection_name) |
|
223 | + { |
|
224 | + if (! is_string($collection_name)) { |
|
225 | + throw new InvalidDataTypeException('$collection_name', $collection_name, 'string'); |
|
226 | + } |
|
227 | + $this->collection_name = str_replace( |
|
228 | + '-', |
|
229 | + '_', |
|
230 | + sanitize_title_with_dashes($collection_name, '', 'save') |
|
231 | + ); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @access public |
|
237 | + * @return string |
|
238 | + */ |
|
239 | + public function identifierType() |
|
240 | + { |
|
241 | + return $this->identifier_type; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @access protected |
|
247 | + * @param string $identifier_type |
|
248 | + * @throws InvalidIdentifierException |
|
249 | + */ |
|
250 | + protected function setIdentifierType($identifier_type) |
|
251 | + { |
|
252 | + if (! ($identifier_type === CollectionDetails::ID_CLASS_NAME |
|
253 | + || $identifier_type === CollectionDetails::ID_OBJECT_HASH |
|
254 | + || $identifier_type === CollectionDetails::ID_CALLBACK_METHOD |
|
255 | + )) { |
|
256 | + throw new InvalidIdentifierException( |
|
257 | + $identifier_type, |
|
258 | + 'CollectionDetails::ID_CLASS_NAME or CollectionDetails::ID_OBJECT_HASH or CollectionDetails::ID_CALLBACK_METHOD' |
|
259 | + ); |
|
260 | + } |
|
261 | + $this->identifier_type = $identifier_type; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @access public |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function identifierCallback() |
|
270 | + { |
|
271 | + return $this->identifier_callback; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @access protected |
|
277 | + * @param string $identifier_callback |
|
278 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
279 | + */ |
|
280 | + protected function setIdentifierCallback($identifier_callback = 'identifier') |
|
281 | + { |
|
282 | + if (! is_string($identifier_callback)) { |
|
283 | + throw new InvalidDataTypeException('$identifier_callback', $identifier_callback, 'string'); |
|
284 | + } |
|
285 | + $this->identifier_callback = $identifier_callback; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * @access public |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + public function getFileMask() |
|
294 | + { |
|
295 | + return $this->file_mask; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * sets the file mask which is then used to filter what files get loaded |
|
301 | + * when searching for classes to add to the collection. Defaults to '*.php' |
|
302 | + * |
|
303 | + * @access protected |
|
304 | + * @param string $file_mask |
|
305 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
306 | + */ |
|
307 | + protected function setFileMasks($file_mask) |
|
308 | + { |
|
309 | + $this->file_mask = ! empty($file_mask) ? $file_mask : '*.php'; |
|
310 | + // we know our default is a string, so if it's not a string now, |
|
311 | + // then that means the incoming parameter was something else |
|
312 | + if (! is_string($this->file_mask)) { |
|
313 | + throw new InvalidDataTypeException('$file_mask', $this->file_mask, 'string'); |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * @access public |
|
320 | + * @return array |
|
321 | + */ |
|
322 | + public function getCollectionFQCNs() |
|
323 | + { |
|
324 | + return $this->collection_FQCNs; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @access public |
|
330 | + * @param string|array $collection_FQCNs |
|
331 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
332 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
333 | + */ |
|
334 | + public function setCollectionFQCNs($collection_FQCNs) |
|
335 | + { |
|
336 | + foreach ((array) $collection_FQCNs as $collection_FQCN) { |
|
337 | + if (! empty($collection_FQCN)) { |
|
338 | + if (class_exists($collection_FQCN)) { |
|
339 | + $this->collection_FQCNs[] = $collection_FQCN; |
|
340 | + } else { |
|
341 | + foreach ($this->getFQCNsFromPartialNamespace($collection_FQCN) as $FQCN) { |
|
342 | + $this->collection_FQCNs[] = $FQCN; |
|
343 | + } |
|
344 | + } |
|
345 | + } |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * @access protected |
|
352 | + * @param string $partial_FQCN |
|
353 | + * @return array |
|
354 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
355 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
356 | + */ |
|
357 | + protected function getFQCNsFromPartialNamespace($partial_FQCN) |
|
358 | + { |
|
359 | + if (! $this->file_locator instanceof FqcnLocator) { |
|
360 | + $this->file_locator = new FqcnLocator(); |
|
361 | + } |
|
362 | + $this->file_locator->locate($partial_FQCN); |
|
363 | + return $this->file_locator->getFQCNs(); |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * @access public |
|
369 | + * @return array |
|
370 | + */ |
|
371 | + public function getCollectionPaths() |
|
372 | + { |
|
373 | + return $this->collection_paths; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @access public |
|
379 | + * @param string|array $collection_paths |
|
380 | + * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
381 | + */ |
|
382 | + public function setCollectionPaths($collection_paths) |
|
383 | + { |
|
384 | + foreach ((array) $collection_paths as $collection_path) { |
|
385 | + if (! empty($collection_path)) { |
|
386 | + if (! is_readable($collection_path)) { |
|
387 | + throw new InvalidFilePathException($collection_path); |
|
388 | + } |
|
389 | + $this->collection_paths[] = $collection_path; |
|
390 | + } |
|
391 | + } |
|
392 | + } |
|
393 | 393 | } |
@@ -16,25 +16,25 @@ |
||
16 | 16 | class CollectionLoaderException extends RuntimeException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * DuplicateCollectionIdentifierException constructor. |
|
21 | - * |
|
22 | - * @param Exception $previous |
|
23 | - * @param string $message |
|
24 | - * @param int $code |
|
25 | - */ |
|
26 | - public function __construct(Exception $previous, $message = '', $code = 0) |
|
27 | - { |
|
28 | - if (empty($message)) { |
|
29 | - $message = sprintf( |
|
30 | - __( |
|
31 | - 'The following error occurred during the creation and/or loading of this collection: %1$s %2$s', |
|
32 | - 'event_espresso' |
|
33 | - ), |
|
34 | - '<br />', |
|
35 | - $previous->getMessage() |
|
36 | - ); |
|
37 | - } |
|
38 | - parent::__construct($message, $code, $previous); |
|
39 | - } |
|
19 | + /** |
|
20 | + * DuplicateCollectionIdentifierException constructor. |
|
21 | + * |
|
22 | + * @param Exception $previous |
|
23 | + * @param string $message |
|
24 | + * @param int $code |
|
25 | + */ |
|
26 | + public function __construct(Exception $previous, $message = '', $code = 0) |
|
27 | + { |
|
28 | + if (empty($message)) { |
|
29 | + $message = sprintf( |
|
30 | + __( |
|
31 | + 'The following error occurred during the creation and/or loading of this collection: %1$s %2$s', |
|
32 | + 'event_espresso' |
|
33 | + ), |
|
34 | + '<br />', |
|
35 | + $previous->getMessage() |
|
36 | + ); |
|
37 | + } |
|
38 | + parent::__construct($message, $code, $previous); |
|
39 | + } |
|
40 | 40 | } |
@@ -16,25 +16,25 @@ |
||
16 | 16 | class CollectionDetailsException extends RuntimeException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * DuplicateCollectionIdentifierException constructor. |
|
21 | - * |
|
22 | - * @param Exception $previous |
|
23 | - * @param string $message |
|
24 | - * @param int $code |
|
25 | - */ |
|
26 | - public function __construct(Exception $previous, $message = '', $code = 0) |
|
27 | - { |
|
28 | - if (empty($message)) { |
|
29 | - $message = sprintf( |
|
30 | - __( |
|
31 | - 'The following error occurred during the collection details generation: %1$s %2$s', |
|
32 | - 'event_espresso' |
|
33 | - ), |
|
34 | - '<br />', |
|
35 | - $previous->getMessage() |
|
36 | - ); |
|
37 | - } |
|
38 | - parent::__construct($message, $code, $previous); |
|
39 | - } |
|
19 | + /** |
|
20 | + * DuplicateCollectionIdentifierException constructor. |
|
21 | + * |
|
22 | + * @param Exception $previous |
|
23 | + * @param string $message |
|
24 | + * @param int $code |
|
25 | + */ |
|
26 | + public function __construct(Exception $previous, $message = '', $code = 0) |
|
27 | + { |
|
28 | + if (empty($message)) { |
|
29 | + $message = sprintf( |
|
30 | + __( |
|
31 | + 'The following error occurred during the collection details generation: %1$s %2$s', |
|
32 | + 'event_espresso' |
|
33 | + ), |
|
34 | + '<br />', |
|
35 | + $previous->getMessage() |
|
36 | + ); |
|
37 | + } |
|
38 | + parent::__construct($message, $code, $previous); |
|
39 | + } |
|
40 | 40 | } |
@@ -16,27 +16,27 @@ |
||
16 | 16 | class InvalidAliasException extends DomainException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidClassException constructor. |
|
21 | - * |
|
22 | - * @param string $fqcn |
|
23 | - * @param string $alias |
|
24 | - * @param string $message |
|
25 | - * @param int $code |
|
26 | - * @param Exception $previous |
|
27 | - */ |
|
28 | - public function __construct($fqcn, $alias, $message = '', $code = 0, Exception $previous = null) |
|
29 | - { |
|
30 | - if (empty($message)) { |
|
31 | - $message = sprintf( |
|
32 | - __( |
|
33 | - '"%1$s" can not be used as an alias because the "%2$s" class does not extend or implement it.', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - $alias, |
|
37 | - $fqcn |
|
38 | - ); |
|
39 | - } |
|
40 | - parent::__construct($message, $code, $previous); |
|
41 | - } |
|
19 | + /** |
|
20 | + * InvalidClassException constructor. |
|
21 | + * |
|
22 | + * @param string $fqcn |
|
23 | + * @param string $alias |
|
24 | + * @param string $message |
|
25 | + * @param int $code |
|
26 | + * @param Exception $previous |
|
27 | + */ |
|
28 | + public function __construct($fqcn, $alias, $message = '', $code = 0, Exception $previous = null) |
|
29 | + { |
|
30 | + if (empty($message)) { |
|
31 | + $message = sprintf( |
|
32 | + __( |
|
33 | + '"%1$s" can not be used as an alias because the "%2$s" class does not extend or implement it.', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + $alias, |
|
37 | + $fqcn |
|
38 | + ); |
|
39 | + } |
|
40 | + parent::__construct($message, $code, $previous); |
|
41 | + } |
|
42 | 42 | } |
@@ -24,46 +24,46 @@ |
||
24 | 24 | class RouteMatchSpecificationFactory extends FactoryWithDependencyResolver |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * RouteMatchSpecificationFactory constructor |
|
29 | - * |
|
30 | - * @param RouteMatchSpecificationDependencyResolver $dependency_resolver |
|
31 | - * @param LoaderInterface $loader |
|
32 | - */ |
|
33 | - public function __construct(RouteMatchSpecificationDependencyResolver $dependency_resolver, LoaderInterface $loader) |
|
34 | - { |
|
35 | - parent::__construct($dependency_resolver, $loader); |
|
36 | - } |
|
27 | + /** |
|
28 | + * RouteMatchSpecificationFactory constructor |
|
29 | + * |
|
30 | + * @param RouteMatchSpecificationDependencyResolver $dependency_resolver |
|
31 | + * @param LoaderInterface $loader |
|
32 | + */ |
|
33 | + public function __construct(RouteMatchSpecificationDependencyResolver $dependency_resolver, LoaderInterface $loader) |
|
34 | + { |
|
35 | + parent::__construct($dependency_resolver, $loader); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param $fqcn |
|
40 | - * @return RouteMatchSpecification |
|
41 | - * @throws InvalidDataTypeException |
|
42 | - * @throws ReflectionException |
|
43 | - * @since $VID:$ |
|
44 | - */ |
|
45 | - public function createNewRouteMatchSpecification($fqcn) |
|
46 | - { |
|
47 | - $this->dependencyResolver()->resolveDependenciesForClass($fqcn); |
|
48 | - return $this->loader()->getShared($fqcn); |
|
49 | - } |
|
38 | + /** |
|
39 | + * @param $fqcn |
|
40 | + * @return RouteMatchSpecification |
|
41 | + * @throws InvalidDataTypeException |
|
42 | + * @throws ReflectionException |
|
43 | + * @since $VID:$ |
|
44 | + */ |
|
45 | + public function createNewRouteMatchSpecification($fqcn) |
|
46 | + { |
|
47 | + $this->dependencyResolver()->resolveDependenciesForClass($fqcn); |
|
48 | + return $this->loader()->getShared($fqcn); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @param $fqcn |
|
54 | - * @return RouteMatchSpecification |
|
55 | - * @throws InvalidArgumentException |
|
56 | - * @throws InvalidDataTypeException |
|
57 | - * @throws InvalidInterfaceException |
|
58 | - * @throws ReflectionException |
|
59 | - * @since $VID:$ |
|
60 | - */ |
|
61 | - public static function create($fqcn) |
|
62 | - { |
|
63 | - /** @var RouteMatchSpecificationFactory $specification_factory */ |
|
64 | - $specification_factory = LoaderFactory::getLoader()->getShared( |
|
65 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' |
|
66 | - ); |
|
67 | - return $specification_factory->createNewRouteMatchSpecification($fqcn); |
|
68 | - } |
|
52 | + /** |
|
53 | + * @param $fqcn |
|
54 | + * @return RouteMatchSpecification |
|
55 | + * @throws InvalidArgumentException |
|
56 | + * @throws InvalidDataTypeException |
|
57 | + * @throws InvalidInterfaceException |
|
58 | + * @throws ReflectionException |
|
59 | + * @since $VID:$ |
|
60 | + */ |
|
61 | + public static function create($fqcn) |
|
62 | + { |
|
63 | + /** @var RouteMatchSpecificationFactory $specification_factory */ |
|
64 | + $specification_factory = LoaderFactory::getLoader()->getShared( |
|
65 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' |
|
66 | + ); |
|
67 | + return $specification_factory->createNewRouteMatchSpecification($fqcn); |
|
68 | + } |
|
69 | 69 | } |
@@ -15,16 +15,16 @@ |
||
15 | 15 | */ |
16 | 16 | interface DependencyResolverInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * Used to configure and/or setup any aliases or recursions required by the DependencyResolver |
|
20 | - * |
|
21 | - * @since $VID:$ |
|
22 | - */ |
|
23 | - public function initialize(); |
|
18 | + /** |
|
19 | + * Used to configure and/or setup any aliases or recursions required by the DependencyResolver |
|
20 | + * |
|
21 | + * @since $VID:$ |
|
22 | + */ |
|
23 | + public function initialize(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $fqcn Fully Qualified Class Name |
|
27 | - * @since $VID:$ |
|
28 | - */ |
|
29 | - public function resolveDependenciesForClass($fqcn); |
|
25 | + /** |
|
26 | + * @param string $fqcn Fully Qualified Class Name |
|
27 | + * @since $VID:$ |
|
28 | + */ |
|
29 | + public function resolveDependenciesForClass($fqcn); |
|
30 | 30 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct($alias, $fqcn) |
36 | 36 | { |
37 | - if (! is_subclass_of($fqcn, $alias)) { |
|
37 | + if ( ! is_subclass_of($fqcn, $alias)) { |
|
38 | 38 | throw new InvalidAliasException($fqcn, $alias); |
39 | 39 | } |
40 | 40 | $this->alias = $alias; |
@@ -17,46 +17,46 @@ |
||
17 | 17 | class ClassAlias |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $alias an interface or base class representing what object |
|
22 | - * can be utilized by another object and/or function |
|
23 | - */ |
|
24 | - private $alias; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string $fqcn the actual class that should be substituted for the alias above |
|
28 | - */ |
|
29 | - private $fqcn; |
|
30 | - |
|
31 | - /** |
|
32 | - * ClassAlias constructor. |
|
33 | - * |
|
34 | - * @param string $alias Interface specified by implementing class |
|
35 | - * @param string $fqcn Concrete class that satisfies interface |
|
36 | - * @throws InvalidAliasException |
|
37 | - */ |
|
38 | - public function __construct($alias, $fqcn) |
|
39 | - { |
|
40 | - if (! is_subclass_of($fqcn, $alias)) { |
|
41 | - throw new InvalidAliasException($fqcn, $alias); |
|
42 | - } |
|
43 | - $this->alias = $alias; |
|
44 | - $this->fqcn = $fqcn; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function alias() |
|
51 | - { |
|
52 | - return $this->alias; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function fqcn() |
|
59 | - { |
|
60 | - return $this->fqcn; |
|
61 | - } |
|
20 | + /** |
|
21 | + * @var string $alias an interface or base class representing what object |
|
22 | + * can be utilized by another object and/or function |
|
23 | + */ |
|
24 | + private $alias; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string $fqcn the actual class that should be substituted for the alias above |
|
28 | + */ |
|
29 | + private $fqcn; |
|
30 | + |
|
31 | + /** |
|
32 | + * ClassAlias constructor. |
|
33 | + * |
|
34 | + * @param string $alias Interface specified by implementing class |
|
35 | + * @param string $fqcn Concrete class that satisfies interface |
|
36 | + * @throws InvalidAliasException |
|
37 | + */ |
|
38 | + public function __construct($alias, $fqcn) |
|
39 | + { |
|
40 | + if (! is_subclass_of($fqcn, $alias)) { |
|
41 | + throw new InvalidAliasException($fqcn, $alias); |
|
42 | + } |
|
43 | + $this->alias = $alias; |
|
44 | + $this->fqcn = $fqcn; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function alias() |
|
51 | + { |
|
52 | + return $this->alias; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function fqcn() |
|
59 | + { |
|
60 | + return $this->fqcn; |
|
61 | + } |
|
62 | 62 | } |