@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\services\collections; |
3 | 3 | |
4 | -use EventEspresso\core\exceptions\InvalidEntityException; |
|
5 | -use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
4 | +use EventEspresso\core\exceptions\InvalidEntityException; |
|
5 | +use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
6 | 6 | use LimitIterator; |
7 | 7 | use SplObjectStorage; |
8 | 8 |
@@ -47,37 +47,37 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct( $collection_interface ) { |
49 | 49 | $this->setCollectionInterface( $collection_interface ); |
50 | - $this->setCollectionIdentifier(); |
|
50 | + $this->setCollectionIdentifier(); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function collectionIdentifier() |
|
58 | - { |
|
59 | - return $this->collection_identifier; |
|
60 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function collectionIdentifier() |
|
58 | + { |
|
59 | + return $this->collection_identifier; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | 63 | |
64 | 64 | /** |
65 | - * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
66 | - * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
67 | - * |
|
65 | + * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
66 | + * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
67 | + * |
|
68 | 68 | * @return void |
69 | 69 | */ |
70 | 70 | protected function setCollectionIdentifier() { |
71 | - // hash a few collection details |
|
72 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
73 | - // grab a few characters from the start, middle, and end of the hash |
|
74 | - $id = array(); |
|
75 | - for($x=0; $x<19; $x+=9){ |
|
76 | - $id[] = substr($identifier, $x, 3); |
|
77 | - } |
|
78 | - $identifier = basename(str_replace('\\', '/', get_class($this))); |
|
79 | - $identifier .= '-' . strtoupper(implode('-', $id)); |
|
80 | - $this->collection_identifier = $identifier; |
|
71 | + // hash a few collection details |
|
72 | + $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
73 | + // grab a few characters from the start, middle, and end of the hash |
|
74 | + $id = array(); |
|
75 | + for($x=0; $x<19; $x+=9){ |
|
76 | + $id[] = substr($identifier, $x, 3); |
|
77 | + } |
|
78 | + $identifier = basename(str_replace('\\', '/', get_class($this))); |
|
79 | + $identifier .= '-' . strtoupper(implode('-', $id)); |
|
80 | + $this->collection_identifier = $identifier; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -123,7 +123,6 @@ discard block |
||
123 | 123 | |
124 | 124 | /** |
125 | 125 | * setIdentifier |
126 | - |
|
127 | 126 | * Sets the data associated with an object in the Collection |
128 | 127 | * if no $identifier is supplied, then the spl_object_hash() is used |
129 | 128 | * |
@@ -212,9 +211,9 @@ discard block |
||
212 | 211 | |
213 | 212 | /** |
214 | 213 | * hasObjects |
215 | - * returns true if there are objects within the Collection, and false if it is empty |
|
216 | - * |
|
217 | - * @access public |
|
214 | + * returns true if there are objects within the Collection, and false if it is empty |
|
215 | + * |
|
216 | + * @access public |
|
218 | 217 | * @return bool |
219 | 218 | */ |
220 | 219 | public function hasObjects() { |
@@ -418,34 +417,34 @@ discard block |
||
418 | 417 | |
419 | 418 | |
420 | 419 | |
421 | - /** |
|
422 | - * detaches ALL objects from the Collection |
|
423 | - */ |
|
424 | - public function detachAll() |
|
425 | - { |
|
426 | - $this->rewind(); |
|
427 | - while ($this->valid()) { |
|
428 | - $object = $this->current(); |
|
429 | - $this->next(); |
|
430 | - $this->detach($object); |
|
431 | - } |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * unsets and detaches ALL objects from the Collection |
|
438 | - */ |
|
439 | - public function trashAndDetachAll() |
|
440 | - { |
|
441 | - $this->rewind(); |
|
442 | - while ($this->valid()) { |
|
443 | - $object = $this->current(); |
|
444 | - $this->next(); |
|
445 | - $this->detach($object); |
|
446 | - unset($object); |
|
447 | - } |
|
448 | - } |
|
420 | + /** |
|
421 | + * detaches ALL objects from the Collection |
|
422 | + */ |
|
423 | + public function detachAll() |
|
424 | + { |
|
425 | + $this->rewind(); |
|
426 | + while ($this->valid()) { |
|
427 | + $object = $this->current(); |
|
428 | + $this->next(); |
|
429 | + $this->detach($object); |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * unsets and detaches ALL objects from the Collection |
|
437 | + */ |
|
438 | + public function trashAndDetachAll() |
|
439 | + { |
|
440 | + $this->rewind(); |
|
441 | + while ($this->valid()) { |
|
442 | + $object = $this->current(); |
|
443 | + $this->next(); |
|
444 | + $this->detach($object); |
|
445 | + unset($object); |
|
446 | + } |
|
447 | + } |
|
449 | 448 | |
450 | 449 | |
451 | 450 |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | use LimitIterator; |
7 | 7 | use SplObjectStorage; |
8 | 8 | |
9 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
10 | - exit( 'No direct script access allowed' ); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | /** |
13 | 13 | * Class Collection |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @param string $collection_interface |
46 | 46 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
47 | 47 | */ |
48 | - public function __construct( $collection_interface ) { |
|
49 | - $this->setCollectionInterface( $collection_interface ); |
|
48 | + public function __construct($collection_interface) { |
|
49 | + $this->setCollectionInterface($collection_interface); |
|
50 | 50 | $this->setCollectionIdentifier(); |
51 | 51 | } |
52 | 52 | |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function setCollectionIdentifier() { |
71 | 71 | // hash a few collection details |
72 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
72 | + $identifier = md5(spl_object_hash($this).$this->collection_interface.time()); |
|
73 | 73 | // grab a few characters from the start, middle, and end of the hash |
74 | 74 | $id = array(); |
75 | - for($x=0; $x<19; $x+=9){ |
|
75 | + for ($x = 0; $x < 19; $x += 9) { |
|
76 | 76 | $id[] = substr($identifier, $x, 3); |
77 | 77 | } |
78 | 78 | $identifier = basename(str_replace('\\', '/', get_class($this))); |
79 | - $identifier .= '-' . strtoupper(implode('-', $id)); |
|
79 | + $identifier .= '-'.strtoupper(implode('-', $id)); |
|
80 | 80 | $this->collection_identifier = $identifier; |
81 | 81 | } |
82 | 82 | |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | * @param string $collection_interface |
90 | 90 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
91 | 91 | */ |
92 | - protected function setCollectionInterface( $collection_interface ) { |
|
93 | - if ( ! ( interface_exists( $collection_interface ) || class_exists( $collection_interface ) ) ) { |
|
94 | - throw new InvalidInterfaceException( $collection_interface ); |
|
92 | + protected function setCollectionInterface($collection_interface) { |
|
93 | + if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
94 | + throw new InvalidInterfaceException($collection_interface); |
|
95 | 95 | } |
96 | 96 | $this->collection_interface = $collection_interface; |
97 | 97 | } |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | * @return bool |
111 | 111 | * @throws \EventEspresso\core\exceptions\InvalidEntityException |
112 | 112 | */ |
113 | - public function add( $object, $identifier = null ) { |
|
114 | - if ( ! $object instanceof $this->collection_interface ) { |
|
115 | - throw new InvalidEntityException( $object, $this->collection_interface ); |
|
113 | + public function add($object, $identifier = null) { |
|
114 | + if ( ! $object instanceof $this->collection_interface) { |
|
115 | + throw new InvalidEntityException($object, $this->collection_interface); |
|
116 | 116 | } |
117 | - $this->attach( $object ); |
|
118 | - $this->setIdentifier( $object, $identifier ); |
|
119 | - return $this->contains( $object ); |
|
117 | + $this->attach($object); |
|
118 | + $this->setIdentifier($object, $identifier); |
|
119 | + return $this->contains($object); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | * @param mixed $identifier |
133 | 133 | * @return bool |
134 | 134 | */ |
135 | - public function setIdentifier( $object, $identifier = null ) { |
|
136 | - $identifier = ! empty( $identifier ) ? $identifier : spl_object_hash( $object ); |
|
135 | + public function setIdentifier($object, $identifier = null) { |
|
136 | + $identifier = ! empty($identifier) ? $identifier : spl_object_hash($object); |
|
137 | 137 | $this->rewind(); |
138 | - while ( $this->valid() ) { |
|
139 | - if ( $object === $this->current() ) { |
|
140 | - $this->setInfo( $identifier ); |
|
138 | + while ($this->valid()) { |
|
139 | + if ($object === $this->current()) { |
|
140 | + $this->setInfo($identifier); |
|
141 | 141 | $this->rewind(); |
142 | 142 | return true; |
143 | 143 | } |
@@ -157,10 +157,10 @@ discard block |
||
157 | 157 | * @param mixed $identifier |
158 | 158 | * @return mixed |
159 | 159 | */ |
160 | - public function get( $identifier ) { |
|
160 | + public function get($identifier) { |
|
161 | 161 | $this->rewind(); |
162 | - while ( $this->valid() ) { |
|
163 | - if ( $identifier === $this->getInfo() ) { |
|
162 | + while ($this->valid()) { |
|
163 | + if ($identifier === $this->getInfo()) { |
|
164 | 164 | $object = $this->current(); |
165 | 165 | $this->rewind(); |
166 | 166 | return $object; |
@@ -182,10 +182,10 @@ discard block |
||
182 | 182 | * @param mixed $identifier |
183 | 183 | * @return bool |
184 | 184 | */ |
185 | - public function has( $identifier ) { |
|
185 | + public function has($identifier) { |
|
186 | 186 | $this->rewind(); |
187 | - while ( $this->valid() ) { |
|
188 | - if ( $identifier === $this->getInfo() ) { |
|
187 | + while ($this->valid()) { |
|
188 | + if ($identifier === $this->getInfo()) { |
|
189 | 189 | $this->rewind(); |
190 | 190 | return true; |
191 | 191 | } |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * @param $object |
205 | 205 | * @return bool |
206 | 206 | */ |
207 | - public function hasObject( $object ) { |
|
208 | - return $this->contains( $object ); |
|
207 | + public function hasObject($object) { |
|
208 | + return $this->contains($object); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @param $object |
245 | 245 | * @return bool |
246 | 246 | */ |
247 | - public function remove( $object ) { |
|
248 | - $this->detach( $object ); |
|
247 | + public function remove($object) { |
|
248 | + $this->detach($object); |
|
249 | 249 | return true; |
250 | 250 | } |
251 | 251 | |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | * @param mixed $identifier |
260 | 260 | * @return boolean |
261 | 261 | */ |
262 | - public function setCurrent( $identifier ) { |
|
262 | + public function setCurrent($identifier) { |
|
263 | 263 | $this->rewind(); |
264 | - while ( $this->valid() ) { |
|
265 | - if ( $identifier === $this->getInfo() ) { |
|
264 | + while ($this->valid()) { |
|
265 | + if ($identifier === $this->getInfo()) { |
|
266 | 266 | return true; |
267 | 267 | } |
268 | 268 | $this->next(); |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | * @param $object |
281 | 281 | * @return boolean |
282 | 282 | */ |
283 | - public function setCurrentUsingObject( $object ) { |
|
283 | + public function setCurrentUsingObject($object) { |
|
284 | 284 | $this->rewind(); |
285 | - while ( $this->valid() ) { |
|
286 | - if ( $this->current() === $object ) { |
|
285 | + while ($this->valid()) { |
|
286 | + if ($this->current() === $object) { |
|
287 | 287 | return true; |
288 | 288 | } |
289 | 289 | $this->next(); |
@@ -300,12 +300,12 @@ discard block |
||
300 | 300 | * @return mixed |
301 | 301 | */ |
302 | 302 | public function previous() { |
303 | - $index = $this->indexOf( $this->current() ); |
|
304 | - if ( $index === 0 ) { |
|
303 | + $index = $this->indexOf($this->current()); |
|
304 | + if ($index === 0) { |
|
305 | 305 | return $this->current(); |
306 | 306 | } |
307 | 307 | $index--; |
308 | - return $this->objectAtIndex( $index ); |
|
308 | + return $this->objectAtIndex($index); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -317,12 +317,12 @@ discard block |
||
317 | 317 | * @param $object |
318 | 318 | * @return boolean|int|string |
319 | 319 | */ |
320 | - public function indexOf( $object ) { |
|
321 | - if ( ! $this->contains( $object ) ) { |
|
320 | + public function indexOf($object) { |
|
321 | + if ( ! $this->contains($object)) { |
|
322 | 322 | return false; |
323 | 323 | } |
324 | - foreach ( $this as $index => $obj ) { |
|
325 | - if ( $obj === $object ) { |
|
324 | + foreach ($this as $index => $obj) { |
|
325 | + if ($obj === $object) { |
|
326 | 326 | return $index; |
327 | 327 | } |
328 | 328 | } |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | * @param int $index |
339 | 339 | * @return mixed |
340 | 340 | */ |
341 | - public function objectAtIndex( $index ) { |
|
342 | - $iterator = new LimitIterator( $this, $index, 1 ); |
|
341 | + public function objectAtIndex($index) { |
|
342 | + $iterator = new LimitIterator($this, $index, 1); |
|
343 | 343 | $iterator->rewind(); |
344 | 344 | return $iterator->current(); |
345 | 345 | } |
@@ -354,10 +354,10 @@ discard block |
||
354 | 354 | * @param int $length |
355 | 355 | * @return array |
356 | 356 | */ |
357 | - public function slice( $offset, $length ) { |
|
357 | + public function slice($offset, $length) { |
|
358 | 358 | $slice = array(); |
359 | - $iterator = new LimitIterator( $this, $offset, $length ); |
|
360 | - foreach ( $iterator as $object ) { |
|
359 | + $iterator = new LimitIterator($this, $offset, $length); |
|
360 | + foreach ($iterator as $object) { |
|
361 | 361 | $slice[] = $object; |
362 | 362 | } |
363 | 363 | return $slice; |
@@ -372,35 +372,35 @@ discard block |
||
372 | 372 | * @param mixed $objects A single object or an array of objects |
373 | 373 | * @param int $index |
374 | 374 | */ |
375 | - public function insertAt( $objects, $index ) { |
|
376 | - if ( ! is_array( $objects ) ) { |
|
377 | - $objects = array( $objects ); |
|
375 | + public function insertAt($objects, $index) { |
|
376 | + if ( ! is_array($objects)) { |
|
377 | + $objects = array($objects); |
|
378 | 378 | } |
379 | 379 | // check to ensure that objects don't already exist in the collection |
380 | - foreach ( $objects as $key => $object ) { |
|
381 | - if ( $this->contains( $object ) ) { |
|
382 | - unset( $objects[ $key ] ); |
|
380 | + foreach ($objects as $key => $object) { |
|
381 | + if ($this->contains($object)) { |
|
382 | + unset($objects[$key]); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | // do we have any objects left? |
386 | - if ( ! $objects ) { |
|
386 | + if ( ! $objects) { |
|
387 | 387 | return; |
388 | 388 | } |
389 | 389 | // detach any objects at or past this index |
390 | 390 | $remaining = array(); |
391 | - if ( $index < $this->count() ) { |
|
392 | - $remaining = $this->slice( $index, $this->count() - $index ); |
|
393 | - foreach ( $remaining as $object ) { |
|
394 | - $this->detach( $object ); |
|
391 | + if ($index < $this->count()) { |
|
392 | + $remaining = $this->slice($index, $this->count() - $index); |
|
393 | + foreach ($remaining as $object) { |
|
394 | + $this->detach($object); |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 | // add the new objects we're splicing in |
398 | - foreach ( $objects as $object ) { |
|
399 | - $this->attach( $object ); |
|
398 | + foreach ($objects as $object) { |
|
399 | + $this->attach($object); |
|
400 | 400 | } |
401 | 401 | // attach the objects we previously detached |
402 | - foreach ( $remaining as $object ) { |
|
403 | - $this->attach( $object ); |
|
402 | + foreach ($remaining as $object) { |
|
403 | + $this->attach($object); |
|
404 | 404 | } |
405 | 405 | } |
406 | 406 | |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | * @see http://stackoverflow.com/a/8736013 |
413 | 413 | * @param int $index |
414 | 414 | */ |
415 | - public function removeAt( $index ) { |
|
416 | - $this->detach( $this->objectAtIndex( $index ) ); |
|
415 | + public function removeAt($index) { |
|
416 | + $this->detach($this->objectAtIndex($index)); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 |
@@ -176,7 +176,7 @@ |
||
176 | 176 | * |
177 | 177 | * @access protected |
178 | 178 | * @param $entity |
179 | - * @param mixed $identifier |
|
179 | + * @param string $identifier |
|
180 | 180 | * @return string |
181 | 181 | * @throws InvalidEntityException |
182 | 182 | */ |
@@ -3,10 +3,10 @@ |
||
3 | 3 | |
4 | 4 | use EE_Error; |
5 | 5 | use EE_Registry; |
6 | -use EventEspresso\core\exceptions\InvalidClassException; |
|
7 | -use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
8 | -use EventEspresso\core\exceptions\InvalidEntityException; |
|
9 | -use EventEspresso\core\exceptions\InvalidFilePathException; |
|
6 | +use EventEspresso\core\exceptions\InvalidClassException; |
|
7 | +use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
8 | +use EventEspresso\core\exceptions\InvalidEntityException; |
|
9 | +use EventEspresso\core\exceptions\InvalidFilePathException; |
|
10 | 10 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
11 | 11 | use EventEspresso\core\services\locators\LocatorInterface; |
12 | 12 | use EventEspresso\core\services\locators\FileLocator; |
@@ -67,21 +67,21 @@ discard block |
||
67 | 67 | protected $file_locator; |
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * CollectionLoader constructor. |
|
72 | - * |
|
73 | - * @param CollectionDetailsInterface $collection_details |
|
74 | - * @param CollectionInterface $collection |
|
75 | - * @param LocatorInterface $file_locator |
|
76 | - * @throws ReflectionException |
|
77 | - * @throws InvalidArgumentException |
|
78 | - * @throws EE_Error |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - * @throws InvalidClassException |
|
81 | - * @throws InvalidDataTypeException |
|
82 | - * @throws InvalidFilePathException |
|
83 | - * @throws InvalidEntityException |
|
84 | - */ |
|
70 | + /** |
|
71 | + * CollectionLoader constructor. |
|
72 | + * |
|
73 | + * @param CollectionDetailsInterface $collection_details |
|
74 | + * @param CollectionInterface $collection |
|
75 | + * @param LocatorInterface $file_locator |
|
76 | + * @throws ReflectionException |
|
77 | + * @throws InvalidArgumentException |
|
78 | + * @throws EE_Error |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + * @throws InvalidClassException |
|
81 | + * @throws InvalidDataTypeException |
|
82 | + * @throws InvalidFilePathException |
|
83 | + * @throws InvalidEntityException |
|
84 | + */ |
|
85 | 85 | public function __construct( |
86 | 86 | CollectionDetailsInterface $collection_details, |
87 | 87 | CollectionInterface $collection = null, |
@@ -206,13 +206,13 @@ discard block |
||
206 | 206 | ); |
207 | 207 | return CollectionLoader::ENTITY_ADDED; |
208 | 208 | } |
209 | - do_action( |
|
210 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
211 | - $this, |
|
212 | - $this->collection_details->collectionName(), |
|
213 | - $this->collection_details |
|
214 | - ); |
|
215 | - return CollectionLoader::ENTITY_NOT_ADDED; |
|
209 | + do_action( |
|
210 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
211 | + $this, |
|
212 | + $this->collection_details->collectionName(), |
|
213 | + $this->collection_details |
|
214 | + ); |
|
215 | + return CollectionLoader::ENTITY_NOT_ADDED; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | |
@@ -227,37 +227,37 @@ discard block |
||
227 | 227 | * @throws InvalidEntityException |
228 | 228 | */ |
229 | 229 | protected function setIdentifier( $entity, $identifier ) { |
230 | - switch($this->collection_details->identifierType()) { |
|
231 | - // every unique object gets added to the collection, but not duplicates of the exact same object |
|
232 | - case CollectionDetails::ID_OBJECT_HASH : |
|
233 | - $identifier = spl_object_hash($entity); |
|
234 | - break; |
|
235 | - // only one entity per class can be added to collection, like a singleton |
|
236 | - case CollectionDetails::ID_CLASS_NAME : |
|
237 | - $identifier = get_class($entity); |
|
238 | - break; |
|
239 | - // objects added to the collection based on entity callback, so the entity itself decides |
|
240 | - case CollectionDetails::ID_CALLBACK_METHOD : |
|
241 | - $identifier_callback = $this->collection_details->identifierCallback(); |
|
242 | - if ( ! method_exists($entity, $identifier_callback)) { |
|
243 | - throw new InvalidEntityException( |
|
244 | - $entity, |
|
245 | - $this->collection_details->getCollectionInterface(), |
|
246 | - sprintf( |
|
247 | - __( |
|
248 | - 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
230 | + switch($this->collection_details->identifierType()) { |
|
231 | + // every unique object gets added to the collection, but not duplicates of the exact same object |
|
232 | + case CollectionDetails::ID_OBJECT_HASH : |
|
233 | + $identifier = spl_object_hash($entity); |
|
234 | + break; |
|
235 | + // only one entity per class can be added to collection, like a singleton |
|
236 | + case CollectionDetails::ID_CLASS_NAME : |
|
237 | + $identifier = get_class($entity); |
|
238 | + break; |
|
239 | + // objects added to the collection based on entity callback, so the entity itself decides |
|
240 | + case CollectionDetails::ID_CALLBACK_METHOD : |
|
241 | + $identifier_callback = $this->collection_details->identifierCallback(); |
|
242 | + if ( ! method_exists($entity, $identifier_callback)) { |
|
243 | + throw new InvalidEntityException( |
|
244 | + $entity, |
|
245 | + $this->collection_details->getCollectionInterface(), |
|
246 | + sprintf( |
|
247 | + __( |
|
248 | + 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
249 | 249 | of "%2$s", but does not contain this method.', |
250 | - 'event_espresso' |
|
251 | - ), |
|
252 | - $identifier_callback, |
|
253 | - get_class($entity) |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - $identifier = $entity->{$identifier_callback}(); |
|
258 | - break; |
|
259 | - |
|
260 | - } |
|
250 | + 'event_espresso' |
|
251 | + ), |
|
252 | + $identifier_callback, |
|
253 | + get_class($entity) |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + $identifier = $entity->{$identifier_callback}(); |
|
258 | + break; |
|
259 | + |
|
260 | + } |
|
261 | 261 | return apply_filters( |
262 | 262 | 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
263 | 263 | $identifier, |
@@ -267,18 +267,18 @@ discard block |
||
267 | 267 | } |
268 | 268 | |
269 | 269 | |
270 | - /** |
|
271 | - * loadFromFQCNs |
|
272 | - * |
|
273 | - * @access protected |
|
274 | - * @throws ReflectionException |
|
275 | - * @throws InvalidArgumentException |
|
276 | - * @throws InvalidInterfaceException |
|
277 | - * @throws EE_Error |
|
278 | - * @throws InvalidClassException |
|
279 | - * @throws InvalidDataTypeException |
|
280 | - * @throws InvalidEntityException |
|
281 | - */ |
|
270 | + /** |
|
271 | + * loadFromFQCNs |
|
272 | + * |
|
273 | + * @access protected |
|
274 | + * @throws ReflectionException |
|
275 | + * @throws InvalidArgumentException |
|
276 | + * @throws InvalidInterfaceException |
|
277 | + * @throws EE_Error |
|
278 | + * @throws InvalidClassException |
|
279 | + * @throws InvalidDataTypeException |
|
280 | + * @throws InvalidEntityException |
|
281 | + */ |
|
282 | 282 | protected function loadFromFQCNs() { |
283 | 283 | $FQCNs = $this->collection_details->getCollectionFQCNs(); |
284 | 284 | $FQCNs = (array) apply_filters( |
@@ -293,20 +293,20 @@ discard block |
||
293 | 293 | } |
294 | 294 | |
295 | 295 | |
296 | - /** |
|
297 | - * loadClassFromFQCN |
|
298 | - * |
|
299 | - * @access protected |
|
300 | - * @param string $FQCN Fully Qualified Class Name |
|
301 | - * @return string |
|
302 | - * @throws InvalidArgumentException |
|
303 | - * @throws InvalidInterfaceException |
|
304 | - * @throws ReflectionException |
|
305 | - * @throws EE_Error |
|
306 | - * @throws InvalidEntityException |
|
307 | - * @throws InvalidDataTypeException |
|
308 | - * @throws InvalidClassException |
|
309 | - */ |
|
296 | + /** |
|
297 | + * loadClassFromFQCN |
|
298 | + * |
|
299 | + * @access protected |
|
300 | + * @param string $FQCN Fully Qualified Class Name |
|
301 | + * @return string |
|
302 | + * @throws InvalidArgumentException |
|
303 | + * @throws InvalidInterfaceException |
|
304 | + * @throws ReflectionException |
|
305 | + * @throws EE_Error |
|
306 | + * @throws InvalidEntityException |
|
307 | + * @throws InvalidDataTypeException |
|
308 | + * @throws InvalidClassException |
|
309 | + */ |
|
310 | 310 | protected function loadClassFromFQCN( $FQCN ) { |
311 | 311 | if ( ! is_string( $FQCN ) ) { |
312 | 312 | throw new InvalidDataTypeException( '$FQCN', $FQCN, 'string' ); |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | use InvalidArgumentException; |
14 | 14 | use ReflectionException; |
15 | 15 | |
16 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
17 | - exit( 'No direct script access allowed' ); |
|
16 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
17 | + exit('No direct script access allowed'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | LocatorInterface $file_locator = null |
89 | 89 | ) { |
90 | 90 | $this->collection_details = $collection_details; |
91 | - if ( ! $collection instanceof CollectionInterface ) { |
|
92 | - $collection = new Collection( $this->collection_details->getCollectionInterface() ); |
|
91 | + if ( ! $collection instanceof CollectionInterface) { |
|
92 | + $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
93 | 93 | } |
94 | 94 | $this->collection = $collection; |
95 | 95 | $this->file_locator = $file_locator; |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | * @throws InvalidEntityException |
118 | 118 | */ |
119 | 119 | protected function loadAllFromFilepaths() { |
120 | - if ( ! $this->file_locator instanceof FileLocator ) { |
|
120 | + if ( ! $this->file_locator instanceof FileLocator) { |
|
121 | 121 | $this->file_locator = new FileLocator(); |
122 | 122 | } |
123 | - $this->file_locator->setFileMask( $this->collection_details->getFileMask() ); |
|
123 | + $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
124 | 124 | // find all of the files that match the file mask in the specified folder |
125 | - $this->file_locator->locate( $this->collection_details->getCollectionPaths() ); |
|
125 | + $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
126 | 126 | // filter the results |
127 | 127 | $filepaths = (array) apply_filters( |
128 | 128 | 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | $this->collection_details->collectionName(), |
131 | 131 | $this->collection_details |
132 | 132 | ); |
133 | - if ( empty( $filepaths ) ) { |
|
133 | + if (empty($filepaths)) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | - foreach ( $filepaths as $filepath ) { |
|
137 | - $this->loadClassFromFilepath( $filepath ); |
|
136 | + foreach ($filepaths as $filepath) { |
|
137 | + $this->loadClassFromFilepath($filepath); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -151,22 +151,22 @@ discard block |
||
151 | 151 | * @throws InvalidFilePathException |
152 | 152 | * @throws InvalidClassException |
153 | 153 | */ |
154 | - protected function loadClassFromFilepath( $filepath ) { |
|
155 | - if ( ! is_string( $filepath ) ) { |
|
156 | - throw new InvalidDataTypeException( '$filepath', $filepath, 'string' ); |
|
154 | + protected function loadClassFromFilepath($filepath) { |
|
155 | + if ( ! is_string($filepath)) { |
|
156 | + throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
157 | 157 | } |
158 | - if ( ! is_readable( $filepath ) ) { |
|
159 | - throw new InvalidFilePathException( $filepath ); |
|
158 | + if ( ! is_readable($filepath)) { |
|
159 | + throw new InvalidFilePathException($filepath); |
|
160 | 160 | } |
161 | 161 | require_once $filepath; |
162 | 162 | // extract filename from path |
163 | - $file_name = basename( $filepath ); |
|
163 | + $file_name = basename($filepath); |
|
164 | 164 | // now remove any file extensions |
165 | - $class_name = \EEH_File::get_classname_from_filepath_with_standard_filename( $file_name ); |
|
166 | - if ( ! class_exists( $class_name ) ) { |
|
167 | - throw new InvalidClassException( $class_name ); |
|
165 | + $class_name = \EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
166 | + if ( ! class_exists($class_name)) { |
|
167 | + throw new InvalidClassException($class_name); |
|
168 | 168 | } |
169 | - return $this->addEntityToCollection( new $class_name(), $file_name ); |
|
169 | + return $this->addEntityToCollection(new $class_name(), $file_name); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | |
@@ -180,15 +180,15 @@ discard block |
||
180 | 180 | * @return string |
181 | 181 | * @throws InvalidEntityException |
182 | 182 | */ |
183 | - protected function addEntityToCollection( $entity, $identifier ) { |
|
183 | + protected function addEntityToCollection($entity, $identifier) { |
|
184 | 184 | do_action( |
185 | 185 | 'FHEE__CollectionLoader__addEntityToCollection__entity', |
186 | 186 | $entity, |
187 | 187 | $this->collection_details->collectionName(), |
188 | 188 | $this->collection_details |
189 | 189 | ); |
190 | - $identifier = $this->setIdentifier( $entity, $identifier ); |
|
191 | - if ( $this->collection->has( $identifier ) ) { |
|
190 | + $identifier = $this->setIdentifier($entity, $identifier); |
|
191 | + if ($this->collection->has($identifier)) { |
|
192 | 192 | do_action( |
193 | 193 | 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
194 | 194 | $this, |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | ); |
198 | 198 | return CollectionLoader::ENTITY_EXISTS; |
199 | 199 | } |
200 | - if( $this->collection->add( $entity, $identifier ) ) { |
|
200 | + if ($this->collection->add($entity, $identifier)) { |
|
201 | 201 | do_action( |
202 | 202 | 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
203 | 203 | $this, |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | * @return string |
227 | 227 | * @throws InvalidEntityException |
228 | 228 | */ |
229 | - protected function setIdentifier( $entity, $identifier ) { |
|
230 | - switch($this->collection_details->identifierType()) { |
|
229 | + protected function setIdentifier($entity, $identifier) { |
|
230 | + switch ($this->collection_details->identifierType()) { |
|
231 | 231 | // every unique object gets added to the collection, but not duplicates of the exact same object |
232 | 232 | case CollectionDetails::ID_OBJECT_HASH : |
233 | 233 | $identifier = spl_object_hash($entity); |
@@ -287,8 +287,8 @@ discard block |
||
287 | 287 | $this->collection_details->collectionName(), |
288 | 288 | $this->collection_details |
289 | 289 | ); |
290 | - foreach ( $FQCNs as $FQCN ) { |
|
291 | - $this->loadClassFromFQCN( $FQCN ); |
|
290 | + foreach ($FQCNs as $FQCN) { |
|
291 | + $this->loadClassFromFQCN($FQCN); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
@@ -307,15 +307,15 @@ discard block |
||
307 | 307 | * @throws InvalidDataTypeException |
308 | 308 | * @throws InvalidClassException |
309 | 309 | */ |
310 | - protected function loadClassFromFQCN( $FQCN ) { |
|
311 | - if ( ! is_string( $FQCN ) ) { |
|
312 | - throw new InvalidDataTypeException( '$FQCN', $FQCN, 'string' ); |
|
310 | + protected function loadClassFromFQCN($FQCN) { |
|
311 | + if ( ! is_string($FQCN)) { |
|
312 | + throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
313 | 313 | } |
314 | - if ( ! class_exists( $FQCN ) ) { |
|
315 | - throw new InvalidClassException( $FQCN ); |
|
314 | + if ( ! class_exists($FQCN)) { |
|
315 | + throw new InvalidClassException($FQCN); |
|
316 | 316 | } |
317 | 317 | return $this->addEntityToCollection( |
318 | - EE_Registry::instance()->create( $FQCN ), |
|
318 | + EE_Registry::instance()->create($FQCN), |
|
319 | 319 | $FQCN |
320 | 320 | ); |
321 | 321 | } |
@@ -20,32 +20,32 @@ |
||
20 | 20 | class InvalidEntityException extends InvalidArgumentException |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * InvalidEntityException constructor. |
|
25 | - * |
|
26 | - * @param mixed $actual the actual object (or thing) we got |
|
27 | - * @param string $expected classname of the entity we wanted |
|
28 | - * @param string $message |
|
29 | - * @param int $code |
|
30 | - * @param Exception $previous |
|
31 | - */ |
|
32 | - public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
33 | - { |
|
34 | - if (empty($message)) { |
|
35 | - $message = sprintf( |
|
36 | - __( |
|
37 | - 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
38 | - 'event_espresso' |
|
39 | - ), |
|
40 | - is_object($actual) |
|
41 | - ? get_class($actual) |
|
42 | - : gettype($actual), |
|
43 | - $expected, |
|
44 | - var_export($actual, true) |
|
45 | - ); |
|
46 | - } |
|
47 | - parent::__construct($message, $code, $previous); |
|
48 | - } |
|
23 | + /** |
|
24 | + * InvalidEntityException constructor. |
|
25 | + * |
|
26 | + * @param mixed $actual the actual object (or thing) we got |
|
27 | + * @param string $expected classname of the entity we wanted |
|
28 | + * @param string $message |
|
29 | + * @param int $code |
|
30 | + * @param Exception $previous |
|
31 | + */ |
|
32 | + public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
33 | + { |
|
34 | + if (empty($message)) { |
|
35 | + $message = sprintf( |
|
36 | + __( |
|
37 | + 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
38 | + 'event_espresso' |
|
39 | + ), |
|
40 | + is_object($actual) |
|
41 | + ? get_class($actual) |
|
42 | + : gettype($actual), |
|
43 | + $expected, |
|
44 | + var_export($actual, true) |
|
45 | + ); |
|
46 | + } |
|
47 | + parent::__construct($message, $code, $previous); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | } |
51 | 51 | // End of file InvalidEntityException.php |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | use Iterator; |
8 | 8 | use Serializable; |
9 | 9 | |
10 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
11 | - exit( 'No direct script access allowed' ); |
|
10 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
11 | + exit('No direct script access allowed'); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param mixed $identifier |
34 | 34 | * @return bool |
35 | 35 | */ |
36 | - public function add( $object, $identifier = null ); |
|
36 | + public function add($object, $identifier = null); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * setIdentifier |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param mixed $identifier |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public function setIdentifier( $object, $identifier = null ); |
|
48 | + public function setIdentifier($object, $identifier = null); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * get |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @param mixed $identifier |
57 | 57 | * @return mixed |
58 | 58 | */ |
59 | - public function get( $identifier ); |
|
59 | + public function get($identifier); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * has |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param mixed $identifier |
69 | 69 | * @return bool |
70 | 70 | */ |
71 | - public function has( $identifier ); |
|
71 | + public function has($identifier); |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * hasObject |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param $object |
79 | 79 | * @return bool |
80 | 80 | */ |
81 | - public function hasObject( $object ); |
|
81 | + public function hasObject($object); |
|
82 | 82 | |
83 | 83 | /** |
84 | 84 | * remove |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @param $object |
89 | 89 | * @return bool |
90 | 90 | */ |
91 | - public function remove( $object ); |
|
91 | + public function remove($object); |
|
92 | 92 | |
93 | 93 | /** |
94 | 94 | * setCurrent |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param mixed $identifier |
99 | 99 | * @return boolean |
100 | 100 | */ |
101 | - public function setCurrent( $identifier ) ; |
|
101 | + public function setCurrent($identifier); |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * setCurrentUsingObject |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @param $object |
109 | 109 | * @return boolean |
110 | 110 | */ |
111 | - public function setCurrentUsingObject( $object ); |
|
111 | + public function setCurrentUsingObject($object); |
|
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Returns the object occupying the index before the current object, |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param $object |
126 | 126 | * @return boolean|int|string |
127 | 127 | */ |
128 | - public function indexOf( $object ); |
|
128 | + public function indexOf($object); |
|
129 | 129 | |
130 | 130 | |
131 | 131 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @param $index |
136 | 136 | * @return mixed |
137 | 137 | */ |
138 | - public function objectAtIndex( $index ); |
|
138 | + public function objectAtIndex($index); |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Returns the sequence of objects as specified by the offset and length |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @param int $length |
146 | 146 | * @return array |
147 | 147 | */ |
148 | - public function slice( $offset, $length ); |
|
148 | + public function slice($offset, $length); |
|
149 | 149 | |
150 | 150 | /** |
151 | 151 | * Inserts an object (or an array of objects) at a certain point |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param mixed $objects A single object or an array of objects |
155 | 155 | * @param integer $index |
156 | 156 | */ |
157 | - public function insertAt( $objects, $index ); |
|
157 | + public function insertAt($objects, $index); |
|
158 | 158 | |
159 | 159 | /** |
160 | 160 | * Removes the object at the given index |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @see http://stackoverflow.com/a/8736013 |
163 | 163 | * @param integer $index |
164 | 164 | */ |
165 | - public function removeAt( $index ) ; |
|
165 | + public function removeAt($index); |
|
166 | 166 | |
167 | 167 | |
168 | 168 |
@@ -20,55 +20,55 @@ |
||
20 | 20 | class EditorBlockCollection extends Collection |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Collection constructor |
|
25 | - * |
|
26 | - * @throws InvalidInterfaceException |
|
27 | - */ |
|
28 | - public function __construct() |
|
29 | - { |
|
30 | - parent::__construct('EventEspresso\core\domain\entities\editor\EditorBlockInterface'); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Collection constructor |
|
25 | + * |
|
26 | + * @throws InvalidInterfaceException |
|
27 | + */ |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + parent::__construct('EventEspresso\core\domain\entities\editor\EditorBlockInterface'); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * unRegisterBlock |
|
36 | - * finds block in the Collection based on the identifier that was set using addObject() |
|
37 | - * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found. |
|
38 | - * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
39 | - * |
|
40 | - * @param mixed $identifier |
|
41 | - * @return boolean |
|
42 | - */ |
|
43 | - public function unRegisterBlock($identifier) |
|
44 | - { |
|
45 | - $this->rewind(); |
|
46 | - while ($this->valid()) { |
|
47 | - if ($identifier === $this->getInfo()) { |
|
48 | - $object = $this->current(); |
|
49 | - $this->rewind(); |
|
50 | - return $object->unRegisterBlock(); |
|
51 | - } |
|
52 | - $this->next(); |
|
53 | - } |
|
54 | - return false; |
|
55 | - } |
|
34 | + /** |
|
35 | + * unRegisterBlock |
|
36 | + * finds block in the Collection based on the identifier that was set using addObject() |
|
37 | + * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found. |
|
38 | + * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
39 | + * |
|
40 | + * @param mixed $identifier |
|
41 | + * @return boolean |
|
42 | + */ |
|
43 | + public function unRegisterBlock($identifier) |
|
44 | + { |
|
45 | + $this->rewind(); |
|
46 | + while ($this->valid()) { |
|
47 | + if ($identifier === $this->getInfo()) { |
|
48 | + $object = $this->current(); |
|
49 | + $this->rewind(); |
|
50 | + return $object->unRegisterBlock(); |
|
51 | + } |
|
52 | + $this->next(); |
|
53 | + } |
|
54 | + return false; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * unRegisterAllBlocks |
|
60 | - * calls unRegisterBlock() on all blocks in Collection. |
|
61 | - * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function unRegisterAllBlocks() |
|
66 | - { |
|
67 | - $this->rewind(); |
|
68 | - while ($this->valid()) { |
|
69 | - $this->current()->unRegisterBlock(); |
|
70 | - $this->next(); |
|
71 | - } |
|
72 | - $this->rewind(); |
|
73 | - } |
|
58 | + /** |
|
59 | + * unRegisterAllBlocks |
|
60 | + * calls unRegisterBlock() on all blocks in Collection. |
|
61 | + * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function unRegisterAllBlocks() |
|
66 | + { |
|
67 | + $this->rewind(); |
|
68 | + while ($this->valid()) { |
|
69 | + $this->current()->unRegisterBlock(); |
|
70 | + $this->next(); |
|
71 | + } |
|
72 | + $this->rewind(); |
|
73 | + } |
|
74 | 74 | } |
@@ -25,72 +25,72 @@ |
||
25 | 25 | interface EditorBlockInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Perform any early setup required by the block |
|
30 | - * including setting the block type and supported post types |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function initialize(); |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function editorBlockType(); |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Registers the Editor Block with WP core; |
|
45 | - * Returns the registered block type on success, or false on failure. |
|
46 | - * |
|
47 | - * @return WP_Block_Type|false |
|
48 | - */ |
|
49 | - public function registerBlock(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Un-registers the Editor Block with WP core; |
|
54 | - * Returns the registered block type on success, or false on failure. |
|
55 | - * |
|
56 | - * @return WP_Block_Type|false |
|
57 | - */ |
|
58 | - public function unRegisterBlock(); |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * returns true if the block type applies for the supplied post type |
|
63 | - * and should be added to that post type's editor |
|
64 | - * |
|
65 | - * @param string $post_type |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public function appliesToPostType($post_type); |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function getEditorContainer(); |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - public function registerScripts(); |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function registerStyles(); |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * returns the rendered HTML for the block |
|
91 | - * |
|
92 | - * @param array $attributes |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function renderBlock(array $attributes = array()); |
|
28 | + /** |
|
29 | + * Perform any early setup required by the block |
|
30 | + * including setting the block type and supported post types |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function initialize(); |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function editorBlockType(); |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Registers the Editor Block with WP core; |
|
45 | + * Returns the registered block type on success, or false on failure. |
|
46 | + * |
|
47 | + * @return WP_Block_Type|false |
|
48 | + */ |
|
49 | + public function registerBlock(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Un-registers the Editor Block with WP core; |
|
54 | + * Returns the registered block type on success, or false on failure. |
|
55 | + * |
|
56 | + * @return WP_Block_Type|false |
|
57 | + */ |
|
58 | + public function unRegisterBlock(); |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * returns true if the block type applies for the supplied post type |
|
63 | + * and should be added to that post type's editor |
|
64 | + * |
|
65 | + * @param string $post_type |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public function appliesToPostType($post_type); |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function getEditorContainer(); |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + public function registerScripts(); |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function registerStyles(); |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * returns the rendered HTML for the block |
|
91 | + * |
|
92 | + * @param array $attributes |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function renderBlock(array $attributes = array()); |
|
96 | 96 | } |
@@ -16,61 +16,61 @@ |
||
16 | 16 | interface DomainInterface extends InterminableInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @return string |
|
21 | - * @throws DomainException |
|
22 | - */ |
|
23 | - public function pluginFile(); |
|
19 | + /** |
|
20 | + * @return string |
|
21 | + * @throws DomainException |
|
22 | + */ |
|
23 | + public function pluginFile(); |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @return string |
|
28 | - * @throws DomainException |
|
29 | - */ |
|
30 | - public function pluginBasename(); |
|
26 | + /** |
|
27 | + * @return string |
|
28 | + * @throws DomainException |
|
29 | + */ |
|
30 | + public function pluginBasename(); |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function pluginPath(); |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function pluginPath(); |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - * @throws DomainException |
|
42 | - */ |
|
43 | - public function pluginUrl(); |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + * @throws DomainException |
|
42 | + */ |
|
43 | + public function pluginUrl(); |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @return string |
|
48 | - * @throws DomainException |
|
49 | - */ |
|
50 | - public function version(); |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + * @throws DomainException |
|
49 | + */ |
|
50 | + public function version(); |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function sourceAssetsPath(); |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function sourceAssetsPath(); |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function sourceAssetsUrl(); |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function sourceAssetsUrl(); |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function distributionAssetsPath(); |
|
65 | + /** |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function distributionAssetsPath(); |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function distributionAssetsUrl(); |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function distributionAssetsUrl(); |
|
75 | 75 | |
76 | 76 | } |
@@ -19,144 +19,144 @@ |
||
19 | 19 | abstract class DomainBase implements DomainInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Equivalent to `__FILE__` for main plugin file. |
|
24 | - * |
|
25 | - * @var FilePath |
|
26 | - */ |
|
27 | - private $plugin_file; |
|
22 | + /** |
|
23 | + * Equivalent to `__FILE__` for main plugin file. |
|
24 | + * |
|
25 | + * @var FilePath |
|
26 | + */ |
|
27 | + private $plugin_file; |
|
28 | 28 | |
29 | - /** |
|
30 | - * String indicating version for plugin |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - private $version; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string $plugin_basename |
|
38 | - */ |
|
39 | - private $plugin_basename; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string $plugin_path |
|
43 | - */ |
|
44 | - private $plugin_path; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string $plugin_url |
|
48 | - */ |
|
49 | - private $plugin_url; |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Initializes internal properties. |
|
55 | - * |
|
56 | - * @param FilePath $plugin_file |
|
57 | - * @param Version $version |
|
58 | - */ |
|
59 | - public function __construct(FilePath $plugin_file, Version $version) |
|
60 | - { |
|
61 | - $this->plugin_file = $plugin_file; |
|
62 | - $this->version = $version; |
|
63 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
64 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
65 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function pluginFile() |
|
73 | - { |
|
74 | - return (string) $this->plugin_file; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function pluginBasename() |
|
83 | - { |
|
84 | - return $this->plugin_basename; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function pluginPath() |
|
93 | - { |
|
94 | - return $this->plugin_path; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function pluginUrl() |
|
103 | - { |
|
104 | - return $this->plugin_url; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function version() |
|
113 | - { |
|
114 | - return (string) $this->version; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return Version |
|
121 | - */ |
|
122 | - public function versionValueObject() |
|
123 | - { |
|
124 | - return $this->version; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function sourceAssetsPath() |
|
132 | - { |
|
133 | - return $this->pluginPath() . 'assets/src/'; |
|
134 | - } |
|
29 | + /** |
|
30 | + * String indicating version for plugin |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + private $version; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string $plugin_basename |
|
38 | + */ |
|
39 | + private $plugin_basename; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string $plugin_path |
|
43 | + */ |
|
44 | + private $plugin_path; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string $plugin_url |
|
48 | + */ |
|
49 | + private $plugin_url; |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Initializes internal properties. |
|
55 | + * |
|
56 | + * @param FilePath $plugin_file |
|
57 | + * @param Version $version |
|
58 | + */ |
|
59 | + public function __construct(FilePath $plugin_file, Version $version) |
|
60 | + { |
|
61 | + $this->plugin_file = $plugin_file; |
|
62 | + $this->version = $version; |
|
63 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
64 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
65 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function pluginFile() |
|
73 | + { |
|
74 | + return (string) $this->plugin_file; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function pluginBasename() |
|
83 | + { |
|
84 | + return $this->plugin_basename; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function pluginPath() |
|
93 | + { |
|
94 | + return $this->plugin_path; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function pluginUrl() |
|
103 | + { |
|
104 | + return $this->plugin_url; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function version() |
|
113 | + { |
|
114 | + return (string) $this->version; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return Version |
|
121 | + */ |
|
122 | + public function versionValueObject() |
|
123 | + { |
|
124 | + return $this->version; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function sourceAssetsPath() |
|
132 | + { |
|
133 | + return $this->pluginPath() . 'assets/src/'; |
|
134 | + } |
|
135 | 135 | |
136 | - |
|
137 | - /** |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function sourceAssetsUrl() |
|
141 | - { |
|
142 | - return $this->pluginUrl() . 'assets/src/'; |
|
143 | - } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function sourceAssetsUrl() |
|
141 | + { |
|
142 | + return $this->pluginUrl() . 'assets/src/'; |
|
143 | + } |
|
144 | 144 | |
145 | 145 | |
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function distributionAssetsPath() |
|
150 | - { |
|
151 | - return $this->pluginPath() . 'assets/dist/'; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function distributionAssetsUrl() |
|
159 | - { |
|
160 | - return $this->pluginUrl() . 'assets/dist/'; |
|
161 | - } |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function distributionAssetsPath() |
|
150 | + { |
|
151 | + return $this->pluginPath() . 'assets/dist/'; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function distributionAssetsUrl() |
|
159 | + { |
|
160 | + return $this->pluginUrl() . 'assets/dist/'; |
|
161 | + } |
|
162 | 162 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function sourceAssetsPath() |
132 | 132 | { |
133 | - return $this->pluginPath() . 'assets/src/'; |
|
133 | + return $this->pluginPath().'assets/src/'; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function sourceAssetsUrl() |
141 | 141 | { |
142 | - return $this->pluginUrl() . 'assets/src/'; |
|
142 | + return $this->pluginUrl().'assets/src/'; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | */ |
149 | 149 | public function distributionAssetsPath() |
150 | 150 | { |
151 | - return $this->pluginPath() . 'assets/dist/'; |
|
151 | + return $this->pluginPath().'assets/dist/'; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | |
@@ -157,6 +157,6 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function distributionAssetsUrl() |
159 | 159 | { |
160 | - return $this->pluginUrl() . 'assets/dist/'; |
|
160 | + return $this->pluginUrl().'assets/dist/'; |
|
161 | 161 | } |
162 | 162 | } |
@@ -52,235 +52,235 @@ |
||
52 | 52 | class BootstrapCore |
53 | 53 | { |
54 | 54 | |
55 | - /** |
|
56 | - * @type LoaderInterface $loader |
|
57 | - */ |
|
58 | - private $loader; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var RequestInterface $request |
|
62 | - */ |
|
63 | - protected $request; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var ResponseInterface $response |
|
67 | - */ |
|
68 | - protected $response; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var RequestStackBuilder $request_stack_builder |
|
72 | - */ |
|
73 | - protected $request_stack_builder; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var RequestStack $request_stack |
|
77 | - */ |
|
78 | - protected $request_stack; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * BootstrapCore constructor. |
|
83 | - */ |
|
84 | - public function __construct() |
|
85 | - { |
|
86 | - // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
87 | - add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @throws InvalidRequestStackMiddlewareException |
|
93 | - * @throws InvalidFilePathException |
|
94 | - * @throws InvalidClassException |
|
95 | - * @throws DomainException |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - * @throws ReflectionException |
|
101 | - */ |
|
102 | - public function initialize() |
|
103 | - { |
|
104 | - $this->bootstrapDependencyInjectionContainer(); |
|
105 | - $this->bootstrapDomain(); |
|
106 | - $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
107 | - add_action( |
|
108 | - 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
109 | - array($bootstrap_request, 'setupLegacyRequest') |
|
110 | - ); |
|
111 | - $this->runRequestStack(); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @throws ReflectionException |
|
117 | - * @throws EE_Error |
|
118 | - * @throws InvalidArgumentException |
|
119 | - * @throws InvalidDataTypeException |
|
120 | - * @throws InvalidInterfaceException |
|
121 | - */ |
|
122 | - private function bootstrapDependencyInjectionContainer() |
|
123 | - { |
|
124 | - $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
125 | - $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
126 | - $bootstrap_di->buildLoader(); |
|
127 | - $registry = $bootstrap_di->getRegistry(); |
|
128 | - $dependency_map = $bootstrap_di->getDependencyMap(); |
|
129 | - $dependency_map->initialize(); |
|
130 | - $registry->initialize(); |
|
131 | - $this->loader = $bootstrap_di->getLoader(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * configures the Domain object for core |
|
137 | - * |
|
138 | - * @return void |
|
139 | - * @throws DomainException |
|
140 | - * @throws InvalidArgumentException |
|
141 | - * @throws InvalidDataTypeException |
|
142 | - * @throws InvalidClassException |
|
143 | - * @throws InvalidFilePathException |
|
144 | - * @throws InvalidInterfaceException |
|
145 | - */ |
|
146 | - private function bootstrapDomain() |
|
147 | - { |
|
148 | - DomainFactory::getShared( |
|
149 | - new FullyQualifiedName( |
|
150 | - 'EventEspresso\core\domain\Domain' |
|
151 | - ), |
|
152 | - array( |
|
153 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
154 | - Version::fromString(espresso_version()) |
|
155 | - ) |
|
156 | - ); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * sets up the request and response objects |
|
162 | - * |
|
163 | - * @return BootstrapRequestResponseObjects |
|
164 | - * @throws InvalidArgumentException |
|
165 | - */ |
|
166 | - private function bootstrapRequestResponseObjects() |
|
167 | - { |
|
168 | - /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
169 | - $bootstrap_request = $this->loader->getShared( |
|
170 | - 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
171 | - array($this->loader) |
|
172 | - ); |
|
173 | - $bootstrap_request->buildRequestResponse(); |
|
174 | - $bootstrap_request->shareRequestResponse(); |
|
175 | - $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
176 | - $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
177 | - return $bootstrap_request; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * run_request_stack |
|
183 | - * construct request stack and run middleware apps |
|
184 | - * |
|
185 | - * @throws InvalidRequestStackMiddlewareException |
|
186 | - * @throws InvalidInterfaceException |
|
187 | - * @throws InvalidDataTypeException |
|
188 | - * @throws EE_Error |
|
189 | - */ |
|
190 | - public function runRequestStack() |
|
191 | - { |
|
192 | - $this->loadAutoloader(); |
|
193 | - $this->setAutoloadersForRequiredFiles(); |
|
194 | - $this->request_stack_builder = $this->buildRequestStack(); |
|
195 | - $this->request_stack = $this->request_stack_builder->resolve( |
|
196 | - new RequestStackCoreApp() |
|
197 | - ); |
|
198 | - $this->request_stack->handleRequest($this->request, $this->response); |
|
199 | - $this->request_stack->handleResponse(); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * load_autoloader |
|
205 | - * |
|
206 | - * @throws EE_Error |
|
207 | - */ |
|
208 | - protected function loadAutoloader() |
|
209 | - { |
|
210 | - // load interfaces |
|
211 | - espresso_load_required( |
|
212 | - 'EEH_Autoloader', |
|
213 | - EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
214 | - ); |
|
215 | - EEH_Autoloader::instance(); |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * load_required_files |
|
222 | - * |
|
223 | - * @throws EE_Error |
|
224 | - */ |
|
225 | - protected function setAutoloadersForRequiredFiles() |
|
226 | - { |
|
227 | - // load interfaces |
|
228 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
229 | - // load helpers |
|
230 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
231 | - // load request stack |
|
232 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
233 | - // load middleware |
|
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * build_request_stack |
|
241 | - * |
|
242 | - * @return RequestStackBuilder |
|
243 | - */ |
|
244 | - public function buildRequestStack() |
|
245 | - { |
|
246 | - $request_stack_builder = new RequestStackBuilder($this->loader); |
|
247 | - /** |
|
248 | - * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
249 | - * so items at the beginning of the final middleware stack will run last. |
|
250 | - * First parameter is the middleware classname, second is an array of arguments |
|
251 | - */ |
|
252 | - $stack_apps = apply_filters( |
|
253 | - 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
254 | - array( |
|
255 | - // first in last out |
|
256 | - 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
257 | - 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
258 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
259 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
260 | - // last in first out |
|
261 | - 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
262 | - ) |
|
263 | - ); |
|
264 | - // legacy filter for backwards compatibility |
|
265 | - $stack_apps = apply_filters( |
|
266 | - 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
267 | - $stack_apps |
|
268 | - ); |
|
269 | - // load middleware onto stack : FILO (First In Last Out) |
|
270 | - // items at the beginning of the $stack_apps array will run last |
|
271 | - foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
272 | - $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
273 | - } |
|
274 | - // finally, we'll add this on its own because we need it to always be part of the stack |
|
275 | - // and we also need it to always run first because the rest of the system relies on it |
|
276 | - $request_stack_builder->push( |
|
277 | - array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
278 | - ); |
|
279 | - return apply_filters( |
|
280 | - 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
281 | - $request_stack_builder |
|
282 | - ); |
|
283 | - } |
|
55 | + /** |
|
56 | + * @type LoaderInterface $loader |
|
57 | + */ |
|
58 | + private $loader; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var RequestInterface $request |
|
62 | + */ |
|
63 | + protected $request; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var ResponseInterface $response |
|
67 | + */ |
|
68 | + protected $response; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var RequestStackBuilder $request_stack_builder |
|
72 | + */ |
|
73 | + protected $request_stack_builder; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var RequestStack $request_stack |
|
77 | + */ |
|
78 | + protected $request_stack; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * BootstrapCore constructor. |
|
83 | + */ |
|
84 | + public function __construct() |
|
85 | + { |
|
86 | + // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
87 | + add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @throws InvalidRequestStackMiddlewareException |
|
93 | + * @throws InvalidFilePathException |
|
94 | + * @throws InvalidClassException |
|
95 | + * @throws DomainException |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + * @throws ReflectionException |
|
101 | + */ |
|
102 | + public function initialize() |
|
103 | + { |
|
104 | + $this->bootstrapDependencyInjectionContainer(); |
|
105 | + $this->bootstrapDomain(); |
|
106 | + $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
107 | + add_action( |
|
108 | + 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
109 | + array($bootstrap_request, 'setupLegacyRequest') |
|
110 | + ); |
|
111 | + $this->runRequestStack(); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @throws ReflectionException |
|
117 | + * @throws EE_Error |
|
118 | + * @throws InvalidArgumentException |
|
119 | + * @throws InvalidDataTypeException |
|
120 | + * @throws InvalidInterfaceException |
|
121 | + */ |
|
122 | + private function bootstrapDependencyInjectionContainer() |
|
123 | + { |
|
124 | + $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
125 | + $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
126 | + $bootstrap_di->buildLoader(); |
|
127 | + $registry = $bootstrap_di->getRegistry(); |
|
128 | + $dependency_map = $bootstrap_di->getDependencyMap(); |
|
129 | + $dependency_map->initialize(); |
|
130 | + $registry->initialize(); |
|
131 | + $this->loader = $bootstrap_di->getLoader(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * configures the Domain object for core |
|
137 | + * |
|
138 | + * @return void |
|
139 | + * @throws DomainException |
|
140 | + * @throws InvalidArgumentException |
|
141 | + * @throws InvalidDataTypeException |
|
142 | + * @throws InvalidClassException |
|
143 | + * @throws InvalidFilePathException |
|
144 | + * @throws InvalidInterfaceException |
|
145 | + */ |
|
146 | + private function bootstrapDomain() |
|
147 | + { |
|
148 | + DomainFactory::getShared( |
|
149 | + new FullyQualifiedName( |
|
150 | + 'EventEspresso\core\domain\Domain' |
|
151 | + ), |
|
152 | + array( |
|
153 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
154 | + Version::fromString(espresso_version()) |
|
155 | + ) |
|
156 | + ); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * sets up the request and response objects |
|
162 | + * |
|
163 | + * @return BootstrapRequestResponseObjects |
|
164 | + * @throws InvalidArgumentException |
|
165 | + */ |
|
166 | + private function bootstrapRequestResponseObjects() |
|
167 | + { |
|
168 | + /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
169 | + $bootstrap_request = $this->loader->getShared( |
|
170 | + 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
171 | + array($this->loader) |
|
172 | + ); |
|
173 | + $bootstrap_request->buildRequestResponse(); |
|
174 | + $bootstrap_request->shareRequestResponse(); |
|
175 | + $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
176 | + $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
177 | + return $bootstrap_request; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * run_request_stack |
|
183 | + * construct request stack and run middleware apps |
|
184 | + * |
|
185 | + * @throws InvalidRequestStackMiddlewareException |
|
186 | + * @throws InvalidInterfaceException |
|
187 | + * @throws InvalidDataTypeException |
|
188 | + * @throws EE_Error |
|
189 | + */ |
|
190 | + public function runRequestStack() |
|
191 | + { |
|
192 | + $this->loadAutoloader(); |
|
193 | + $this->setAutoloadersForRequiredFiles(); |
|
194 | + $this->request_stack_builder = $this->buildRequestStack(); |
|
195 | + $this->request_stack = $this->request_stack_builder->resolve( |
|
196 | + new RequestStackCoreApp() |
|
197 | + ); |
|
198 | + $this->request_stack->handleRequest($this->request, $this->response); |
|
199 | + $this->request_stack->handleResponse(); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * load_autoloader |
|
205 | + * |
|
206 | + * @throws EE_Error |
|
207 | + */ |
|
208 | + protected function loadAutoloader() |
|
209 | + { |
|
210 | + // load interfaces |
|
211 | + espresso_load_required( |
|
212 | + 'EEH_Autoloader', |
|
213 | + EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
214 | + ); |
|
215 | + EEH_Autoloader::instance(); |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * load_required_files |
|
222 | + * |
|
223 | + * @throws EE_Error |
|
224 | + */ |
|
225 | + protected function setAutoloadersForRequiredFiles() |
|
226 | + { |
|
227 | + // load interfaces |
|
228 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
229 | + // load helpers |
|
230 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
231 | + // load request stack |
|
232 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
233 | + // load middleware |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * build_request_stack |
|
241 | + * |
|
242 | + * @return RequestStackBuilder |
|
243 | + */ |
|
244 | + public function buildRequestStack() |
|
245 | + { |
|
246 | + $request_stack_builder = new RequestStackBuilder($this->loader); |
|
247 | + /** |
|
248 | + * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
249 | + * so items at the beginning of the final middleware stack will run last. |
|
250 | + * First parameter is the middleware classname, second is an array of arguments |
|
251 | + */ |
|
252 | + $stack_apps = apply_filters( |
|
253 | + 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
254 | + array( |
|
255 | + // first in last out |
|
256 | + 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
257 | + 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
258 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
259 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
260 | + // last in first out |
|
261 | + 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
262 | + ) |
|
263 | + ); |
|
264 | + // legacy filter for backwards compatibility |
|
265 | + $stack_apps = apply_filters( |
|
266 | + 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
267 | + $stack_apps |
|
268 | + ); |
|
269 | + // load middleware onto stack : FILO (First In Last Out) |
|
270 | + // items at the beginning of the $stack_apps array will run last |
|
271 | + foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
272 | + $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
273 | + } |
|
274 | + // finally, we'll add this on its own because we need it to always be part of the stack |
|
275 | + // and we also need it to always run first because the rest of the system relies on it |
|
276 | + $request_stack_builder->push( |
|
277 | + array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
278 | + ); |
|
279 | + return apply_filters( |
|
280 | + 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
281 | + $request_stack_builder |
|
282 | + ); |
|
283 | + } |
|
284 | 284 | |
285 | 285 | |
286 | 286 | } |