@@ -19,94 +19,94 @@ |
||
19 | 19 | class ExitModal |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var Registry |
|
24 | - */ |
|
25 | - private $assets_registry; |
|
22 | + /** |
|
23 | + * @var Registry |
|
24 | + */ |
|
25 | + private $assets_registry; |
|
26 | 26 | |
27 | - /** |
|
28 | - * ExitModal constructor. |
|
29 | - * |
|
30 | - * @param Registry $assets_registry |
|
31 | - */ |
|
32 | - public function __construct(Registry $assets_registry) |
|
33 | - { |
|
34 | - $this->assets_registry = $assets_registry; |
|
35 | - add_action('in_admin_footer', array($this, 'modalContainer')); |
|
36 | - add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
37 | - } |
|
27 | + /** |
|
28 | + * ExitModal constructor. |
|
29 | + * |
|
30 | + * @param Registry $assets_registry |
|
31 | + */ |
|
32 | + public function __construct(Registry $assets_registry) |
|
33 | + { |
|
34 | + $this->assets_registry = $assets_registry; |
|
35 | + add_action('in_admin_footer', array($this, 'modalContainer')); |
|
36 | + add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Callback on in_admin_footer that is used to output the exit modal container. |
|
42 | - */ |
|
43 | - public function modalContainer() |
|
44 | - { |
|
45 | - echo '<div id="ee-exit-survey-modal"></div>'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * Callback on in_admin_footer that is used to output the exit modal container. |
|
42 | + */ |
|
43 | + public function modalContainer() |
|
44 | + { |
|
45 | + echo '<div id="ee-exit-survey-modal"></div>'; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
51 | - * |
|
52 | - * @throws InvalidArgumentException |
|
53 | - */ |
|
54 | - public function enqueues() |
|
55 | - { |
|
56 | - $current_user = new WP_User(get_current_user_id()); |
|
57 | - $this->assets_registry->addData( |
|
58 | - 'exitModali18n', |
|
59 | - array( |
|
60 | - 'introText' => htmlspecialchars( |
|
61 | - __( |
|
62 | - 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
63 | - 'event_espresso' |
|
64 | - ), |
|
65 | - ENT_NOQUOTES |
|
66 | - ), |
|
67 | - 'doSurveyButtonText' => htmlspecialchars( |
|
68 | - __( |
|
69 | - 'Sure I\'ll help', |
|
70 | - 'event_espresso' |
|
71 | - ), |
|
72 | - ENT_NOQUOTES |
|
73 | - ), |
|
74 | - 'skipButtonText' => htmlspecialchars( |
|
75 | - __( |
|
76 | - 'Skip', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - ENT_NOQUOTES |
|
80 | - ) |
|
81 | - ) |
|
82 | - ); |
|
83 | - $this->assets_registry->addData( |
|
84 | - 'exitModalInfo', |
|
85 | - array( |
|
86 | - 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
87 | - 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
88 | - 'website' => htmlspecialchars(site_url()), |
|
89 | - 'isModalActive' => $this->isModalActive() |
|
90 | - ) |
|
91 | - ); |
|
49 | + /** |
|
50 | + * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
51 | + * |
|
52 | + * @throws InvalidArgumentException |
|
53 | + */ |
|
54 | + public function enqueues() |
|
55 | + { |
|
56 | + $current_user = new WP_User(get_current_user_id()); |
|
57 | + $this->assets_registry->addData( |
|
58 | + 'exitModali18n', |
|
59 | + array( |
|
60 | + 'introText' => htmlspecialchars( |
|
61 | + __( |
|
62 | + 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
63 | + 'event_espresso' |
|
64 | + ), |
|
65 | + ENT_NOQUOTES |
|
66 | + ), |
|
67 | + 'doSurveyButtonText' => htmlspecialchars( |
|
68 | + __( |
|
69 | + 'Sure I\'ll help', |
|
70 | + 'event_espresso' |
|
71 | + ), |
|
72 | + ENT_NOQUOTES |
|
73 | + ), |
|
74 | + 'skipButtonText' => htmlspecialchars( |
|
75 | + __( |
|
76 | + 'Skip', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + ENT_NOQUOTES |
|
80 | + ) |
|
81 | + ) |
|
82 | + ); |
|
83 | + $this->assets_registry->addData( |
|
84 | + 'exitModalInfo', |
|
85 | + array( |
|
86 | + 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
87 | + 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
88 | + 'website' => htmlspecialchars(site_url()), |
|
89 | + 'isModalActive' => $this->isModalActive() |
|
90 | + ) |
|
91 | + ); |
|
92 | 92 | |
93 | - wp_enqueue_script('ee-wp-plugins-page'); |
|
94 | - wp_enqueue_style('ee-wp-plugins-page'); |
|
95 | - } |
|
93 | + wp_enqueue_script('ee-wp-plugins-page'); |
|
94 | + wp_enqueue_style('ee-wp-plugins-page'); |
|
95 | + } |
|
96 | 96 | |
97 | 97 | |
98 | - /** |
|
99 | - * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - private function isModalActive() |
|
103 | - { |
|
104 | - return filter_var( |
|
105 | - apply_filters( |
|
106 | - 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
107 | - true |
|
108 | - ), |
|
109 | - FILTER_VALIDATE_BOOLEAN |
|
110 | - ); |
|
111 | - } |
|
98 | + /** |
|
99 | + * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + private function isModalActive() |
|
103 | + { |
|
104 | + return filter_var( |
|
105 | + apply_filters( |
|
106 | + 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
107 | + true |
|
108 | + ), |
|
109 | + FILTER_VALIDATE_BOOLEAN |
|
110 | + ); |
|
111 | + } |
|
112 | 112 | } |
@@ -20,55 +20,55 @@ |
||
20 | 20 | class BlockCollection 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\BlockInterface'); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Collection constructor |
|
25 | + * |
|
26 | + * @throws InvalidInterfaceException |
|
27 | + */ |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + parent::__construct('EventEspresso\core\domain\entities\editor\BlockInterface'); |
|
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 | } |
@@ -163,7 +163,7 @@ |
||
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @param $entity |
166 | - * @param mixed $identifier |
|
166 | + * @param string $identifier |
|
167 | 167 | * @return string |
168 | 168 | * @throws InvalidEntityException |
169 | 169 | */ |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | LocatorInterface $file_locator = null |
85 | 85 | ) { |
86 | 86 | $this->collection_details = $collection_details; |
87 | - if (! $collection instanceof CollectionInterface) { |
|
87 | + if ( ! $collection instanceof CollectionInterface) { |
|
88 | 88 | $collection = new Collection($this->collection_details->getCollectionInterface()); |
89 | 89 | } |
90 | 90 | $this->collection = $collection; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function loadAllFromFilepaths() |
113 | 113 | { |
114 | - if (! $this->file_locator instanceof FileLocator) { |
|
114 | + if ( ! $this->file_locator instanceof FileLocator) { |
|
115 | 115 | $this->file_locator = new FileLocator(); |
116 | 116 | } |
117 | 117 | $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function loadClassFromFilepath($filepath) |
145 | 145 | { |
146 | - if (! is_string($filepath)) { |
|
146 | + if ( ! is_string($filepath)) { |
|
147 | 147 | throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
148 | 148 | } |
149 | - if (! is_readable($filepath)) { |
|
149 | + if ( ! is_readable($filepath)) { |
|
150 | 150 | throw new InvalidFilePathException($filepath); |
151 | 151 | } |
152 | 152 | require_once $filepath; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $file_name = basename($filepath); |
155 | 155 | // now remove any file extensions |
156 | 156 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
157 | - if (! class_exists($class_name)) { |
|
157 | + if ( ! class_exists($class_name)) { |
|
158 | 158 | throw new InvalidClassException($class_name); |
159 | 159 | } |
160 | 160 | return $this->addEntityToCollection(new $class_name(), $file_name); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | // objects added to the collection based on entity callback, so the entity itself decides |
225 | 225 | case CollectionDetails::ID_CALLBACK_METHOD: |
226 | 226 | $identifier_callback = $this->collection_details->identifierCallback(); |
227 | - if (! method_exists($entity, $identifier_callback)) { |
|
227 | + if ( ! method_exists($entity, $identifier_callback)) { |
|
228 | 228 | throw new InvalidEntityException( |
229 | 229 | $entity, |
230 | 230 | $this->collection_details->getCollectionInterface(), |
@@ -288,10 +288,10 @@ discard block |
||
288 | 288 | */ |
289 | 289 | protected function loadClassFromFQCN($FQCN) |
290 | 290 | { |
291 | - if (! is_string($FQCN)) { |
|
291 | + if ( ! is_string($FQCN)) { |
|
292 | 292 | throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
293 | 293 | } |
294 | - if (! class_exists($FQCN)) { |
|
294 | + if ( ! class_exists($FQCN)) { |
|
295 | 295 | throw new InvalidClassException($FQCN); |
296 | 296 | } |
297 | 297 | return $this->addEntityToCollection( |
@@ -27,276 +27,276 @@ |
||
27 | 27 | class CollectionLoader |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * possible return value when adding entities to a collection. |
|
32 | - * denotes that the entity was NOT ADDED to the collection |
|
33 | - */ |
|
34 | - const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
30 | + /** |
|
31 | + * possible return value when adding entities to a collection. |
|
32 | + * denotes that the entity was NOT ADDED to the collection |
|
33 | + */ |
|
34 | + const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * possible return value when adding entities to a collection. |
|
38 | - * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
39 | - */ |
|
40 | - const ENTITY_ADDED = 'entity-added-to-collection'; |
|
36 | + /** |
|
37 | + * possible return value when adding entities to a collection. |
|
38 | + * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
39 | + */ |
|
40 | + const ENTITY_ADDED = 'entity-added-to-collection'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * possible return value when adding entities to a collection. |
|
44 | - * denotes that the entity was ALREADY ADDED to the collection, |
|
45 | - * and therefore could not be added again. |
|
46 | - */ |
|
47 | - const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
42 | + /** |
|
43 | + * possible return value when adding entities to a collection. |
|
44 | + * denotes that the entity was ALREADY ADDED to the collection, |
|
45 | + * and therefore could not be added again. |
|
46 | + */ |
|
47 | + const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @var CollectionDetailsInterface $collection_details |
|
52 | - */ |
|
53 | - protected $collection_details; |
|
50 | + /** |
|
51 | + * @var CollectionDetailsInterface $collection_details |
|
52 | + */ |
|
53 | + protected $collection_details; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var CollectionInterface $collection |
|
57 | - */ |
|
58 | - protected $collection; |
|
55 | + /** |
|
56 | + * @var CollectionInterface $collection |
|
57 | + */ |
|
58 | + protected $collection; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var FileLocator $file_locator |
|
62 | - */ |
|
63 | - protected $file_locator; |
|
60 | + /** |
|
61 | + * @var FileLocator $file_locator |
|
62 | + */ |
|
63 | + protected $file_locator; |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * CollectionLoader constructor. |
|
68 | - * |
|
69 | - * @param CollectionDetailsInterface $collection_details |
|
70 | - * @param CollectionInterface $collection |
|
71 | - * @param LocatorInterface $file_locator |
|
72 | - * @throws ReflectionException |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws EE_Error |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws InvalidClassException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidFilePathException |
|
79 | - * @throws InvalidEntityException |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - CollectionDetailsInterface $collection_details, |
|
83 | - CollectionInterface $collection = null, |
|
84 | - LocatorInterface $file_locator = null |
|
85 | - ) { |
|
86 | - $this->collection_details = $collection_details; |
|
87 | - if (! $collection instanceof CollectionInterface) { |
|
88 | - $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
89 | - } |
|
90 | - $this->collection = $collection; |
|
91 | - $this->file_locator = $file_locator; |
|
92 | - $this->loadAllFromFilepaths(); |
|
93 | - $this->loadFromFQCNs(); |
|
94 | - } |
|
66 | + /** |
|
67 | + * CollectionLoader constructor. |
|
68 | + * |
|
69 | + * @param CollectionDetailsInterface $collection_details |
|
70 | + * @param CollectionInterface $collection |
|
71 | + * @param LocatorInterface $file_locator |
|
72 | + * @throws ReflectionException |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws EE_Error |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws InvalidClassException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidFilePathException |
|
79 | + * @throws InvalidEntityException |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + CollectionDetailsInterface $collection_details, |
|
83 | + CollectionInterface $collection = null, |
|
84 | + LocatorInterface $file_locator = null |
|
85 | + ) { |
|
86 | + $this->collection_details = $collection_details; |
|
87 | + if (! $collection instanceof CollectionInterface) { |
|
88 | + $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
89 | + } |
|
90 | + $this->collection = $collection; |
|
91 | + $this->file_locator = $file_locator; |
|
92 | + $this->loadAllFromFilepaths(); |
|
93 | + $this->loadFromFQCNs(); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * @return CollectionInterface |
|
99 | - */ |
|
100 | - public function getCollection() |
|
101 | - { |
|
102 | - return $this->collection; |
|
103 | - } |
|
97 | + /** |
|
98 | + * @return CollectionInterface |
|
99 | + */ |
|
100 | + public function getCollection() |
|
101 | + { |
|
102 | + return $this->collection; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * @throws InvalidClassException |
|
108 | - * @throws InvalidFilePathException |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidEntityException |
|
111 | - */ |
|
112 | - protected function loadAllFromFilepaths() |
|
113 | - { |
|
114 | - if (! $this->file_locator instanceof FileLocator) { |
|
115 | - $this->file_locator = new FileLocator(); |
|
116 | - } |
|
117 | - $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
118 | - // find all of the files that match the file mask in the specified folder |
|
119 | - $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
120 | - // filter the results |
|
121 | - $filepaths = (array) apply_filters( |
|
122 | - 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
123 | - $this->file_locator->getFilePaths(), |
|
124 | - $this->collection_details->collectionName(), |
|
125 | - $this->collection_details |
|
126 | - ); |
|
127 | - if (empty($filepaths)) { |
|
128 | - return; |
|
129 | - } |
|
130 | - foreach ($filepaths as $filepath) { |
|
131 | - $this->loadClassFromFilepath($filepath); |
|
132 | - } |
|
133 | - } |
|
106 | + /** |
|
107 | + * @throws InvalidClassException |
|
108 | + * @throws InvalidFilePathException |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidEntityException |
|
111 | + */ |
|
112 | + protected function loadAllFromFilepaths() |
|
113 | + { |
|
114 | + if (! $this->file_locator instanceof FileLocator) { |
|
115 | + $this->file_locator = new FileLocator(); |
|
116 | + } |
|
117 | + $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
118 | + // find all of the files that match the file mask in the specified folder |
|
119 | + $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
120 | + // filter the results |
|
121 | + $filepaths = (array) apply_filters( |
|
122 | + 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
123 | + $this->file_locator->getFilePaths(), |
|
124 | + $this->collection_details->collectionName(), |
|
125 | + $this->collection_details |
|
126 | + ); |
|
127 | + if (empty($filepaths)) { |
|
128 | + return; |
|
129 | + } |
|
130 | + foreach ($filepaths as $filepath) { |
|
131 | + $this->loadClassFromFilepath($filepath); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * @param string $filepath |
|
138 | - * @return string |
|
139 | - * @throws InvalidEntityException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidFilePathException |
|
142 | - * @throws InvalidClassException |
|
143 | - */ |
|
144 | - protected function loadClassFromFilepath($filepath) |
|
145 | - { |
|
146 | - if (! is_string($filepath)) { |
|
147 | - throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
148 | - } |
|
149 | - if (! is_readable($filepath)) { |
|
150 | - throw new InvalidFilePathException($filepath); |
|
151 | - } |
|
152 | - require_once $filepath; |
|
153 | - // extract filename from path |
|
154 | - $file_name = basename($filepath); |
|
155 | - // now remove any file extensions |
|
156 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
157 | - if (! class_exists($class_name)) { |
|
158 | - throw new InvalidClassException($class_name); |
|
159 | - } |
|
160 | - return $this->addEntityToCollection(new $class_name(), $file_name); |
|
161 | - } |
|
136 | + /** |
|
137 | + * @param string $filepath |
|
138 | + * @return string |
|
139 | + * @throws InvalidEntityException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidFilePathException |
|
142 | + * @throws InvalidClassException |
|
143 | + */ |
|
144 | + protected function loadClassFromFilepath($filepath) |
|
145 | + { |
|
146 | + if (! is_string($filepath)) { |
|
147 | + throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
148 | + } |
|
149 | + if (! is_readable($filepath)) { |
|
150 | + throw new InvalidFilePathException($filepath); |
|
151 | + } |
|
152 | + require_once $filepath; |
|
153 | + // extract filename from path |
|
154 | + $file_name = basename($filepath); |
|
155 | + // now remove any file extensions |
|
156 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
157 | + if (! class_exists($class_name)) { |
|
158 | + throw new InvalidClassException($class_name); |
|
159 | + } |
|
160 | + return $this->addEntityToCollection(new $class_name(), $file_name); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * @param $entity |
|
166 | - * @param mixed $identifier |
|
167 | - * @return string |
|
168 | - * @throws InvalidEntityException |
|
169 | - */ |
|
170 | - protected function addEntityToCollection($entity, $identifier) |
|
171 | - { |
|
172 | - do_action( |
|
173 | - 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
174 | - $entity, |
|
175 | - $this->collection_details->collectionName(), |
|
176 | - $this->collection_details |
|
177 | - ); |
|
178 | - $identifier = $this->setIdentifier($entity, $identifier); |
|
179 | - if ($this->collection->has($identifier)) { |
|
180 | - do_action( |
|
181 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
182 | - $this, |
|
183 | - $this->collection_details->collectionName(), |
|
184 | - $this->collection_details |
|
185 | - ); |
|
186 | - return CollectionLoader::ENTITY_EXISTS; |
|
187 | - } |
|
188 | - if ($this->collection->add($entity, $identifier)) { |
|
189 | - do_action( |
|
190 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
191 | - $this, |
|
192 | - $this->collection_details->collectionName(), |
|
193 | - $this->collection_details |
|
194 | - ); |
|
195 | - return CollectionLoader::ENTITY_ADDED; |
|
196 | - } |
|
197 | - do_action( |
|
198 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
199 | - $this, |
|
200 | - $this->collection_details->collectionName(), |
|
201 | - $this->collection_details |
|
202 | - ); |
|
203 | - return CollectionLoader::ENTITY_NOT_ADDED; |
|
204 | - } |
|
164 | + /** |
|
165 | + * @param $entity |
|
166 | + * @param mixed $identifier |
|
167 | + * @return string |
|
168 | + * @throws InvalidEntityException |
|
169 | + */ |
|
170 | + protected function addEntityToCollection($entity, $identifier) |
|
171 | + { |
|
172 | + do_action( |
|
173 | + 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
174 | + $entity, |
|
175 | + $this->collection_details->collectionName(), |
|
176 | + $this->collection_details |
|
177 | + ); |
|
178 | + $identifier = $this->setIdentifier($entity, $identifier); |
|
179 | + if ($this->collection->has($identifier)) { |
|
180 | + do_action( |
|
181 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
182 | + $this, |
|
183 | + $this->collection_details->collectionName(), |
|
184 | + $this->collection_details |
|
185 | + ); |
|
186 | + return CollectionLoader::ENTITY_EXISTS; |
|
187 | + } |
|
188 | + if ($this->collection->add($entity, $identifier)) { |
|
189 | + do_action( |
|
190 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
191 | + $this, |
|
192 | + $this->collection_details->collectionName(), |
|
193 | + $this->collection_details |
|
194 | + ); |
|
195 | + return CollectionLoader::ENTITY_ADDED; |
|
196 | + } |
|
197 | + do_action( |
|
198 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
199 | + $this, |
|
200 | + $this->collection_details->collectionName(), |
|
201 | + $this->collection_details |
|
202 | + ); |
|
203 | + return CollectionLoader::ENTITY_NOT_ADDED; |
|
204 | + } |
|
205 | 205 | |
206 | 206 | |
207 | - /** |
|
208 | - * @param $entity |
|
209 | - * @param mixed $identifier |
|
210 | - * @return string |
|
211 | - * @throws InvalidEntityException |
|
212 | - */ |
|
213 | - protected function setIdentifier($entity, $identifier) |
|
214 | - { |
|
215 | - switch ($this->collection_details->identifierType()) { |
|
216 | - // every unique object gets added to the collection, but not duplicates of the exact same object |
|
217 | - case CollectionDetails::ID_OBJECT_HASH: |
|
218 | - $identifier = spl_object_hash($entity); |
|
219 | - break; |
|
220 | - // only one entity per class can be added to collection, like a singleton |
|
221 | - case CollectionDetails::ID_CLASS_NAME: |
|
222 | - $identifier = get_class($entity); |
|
223 | - break; |
|
224 | - // objects added to the collection based on entity callback, so the entity itself decides |
|
225 | - case CollectionDetails::ID_CALLBACK_METHOD: |
|
226 | - $identifier_callback = $this->collection_details->identifierCallback(); |
|
227 | - if (! method_exists($entity, $identifier_callback)) { |
|
228 | - throw new InvalidEntityException( |
|
229 | - $entity, |
|
230 | - $this->collection_details->getCollectionInterface(), |
|
231 | - sprintf( |
|
232 | - __( |
|
233 | - 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
207 | + /** |
|
208 | + * @param $entity |
|
209 | + * @param mixed $identifier |
|
210 | + * @return string |
|
211 | + * @throws InvalidEntityException |
|
212 | + */ |
|
213 | + protected function setIdentifier($entity, $identifier) |
|
214 | + { |
|
215 | + switch ($this->collection_details->identifierType()) { |
|
216 | + // every unique object gets added to the collection, but not duplicates of the exact same object |
|
217 | + case CollectionDetails::ID_OBJECT_HASH: |
|
218 | + $identifier = spl_object_hash($entity); |
|
219 | + break; |
|
220 | + // only one entity per class can be added to collection, like a singleton |
|
221 | + case CollectionDetails::ID_CLASS_NAME: |
|
222 | + $identifier = get_class($entity); |
|
223 | + break; |
|
224 | + // objects added to the collection based on entity callback, so the entity itself decides |
|
225 | + case CollectionDetails::ID_CALLBACK_METHOD: |
|
226 | + $identifier_callback = $this->collection_details->identifierCallback(); |
|
227 | + if (! method_exists($entity, $identifier_callback)) { |
|
228 | + throw new InvalidEntityException( |
|
229 | + $entity, |
|
230 | + $this->collection_details->getCollectionInterface(), |
|
231 | + sprintf( |
|
232 | + __( |
|
233 | + 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
234 | 234 | of "%2$s", but does not contain this method.', |
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - $identifier_callback, |
|
238 | - get_class($entity) |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - $identifier = $entity->{$identifier_callback}(); |
|
243 | - break; |
|
244 | - } |
|
245 | - return apply_filters( |
|
246 | - 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
247 | - $identifier, |
|
248 | - $this->collection_details->collectionName(), |
|
249 | - $this->collection_details |
|
250 | - ); |
|
251 | - } |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + $identifier_callback, |
|
238 | + get_class($entity) |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + $identifier = $entity->{$identifier_callback}(); |
|
243 | + break; |
|
244 | + } |
|
245 | + return apply_filters( |
|
246 | + 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
247 | + $identifier, |
|
248 | + $this->collection_details->collectionName(), |
|
249 | + $this->collection_details |
|
250 | + ); |
|
251 | + } |
|
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * @throws ReflectionException |
|
256 | - * @throws InvalidArgumentException |
|
257 | - * @throws InvalidInterfaceException |
|
258 | - * @throws EE_Error |
|
259 | - * @throws InvalidClassException |
|
260 | - * @throws InvalidDataTypeException |
|
261 | - * @throws InvalidEntityException |
|
262 | - */ |
|
263 | - protected function loadFromFQCNs() |
|
264 | - { |
|
265 | - $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
266 | - $FQCNs = (array) apply_filters( |
|
267 | - 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
268 | - $FQCNs, |
|
269 | - $this->collection_details->collectionName(), |
|
270 | - $this->collection_details |
|
271 | - ); |
|
272 | - foreach ($FQCNs as $FQCN) { |
|
273 | - $this->loadClassFromFQCN($FQCN); |
|
274 | - } |
|
275 | - } |
|
254 | + /** |
|
255 | + * @throws ReflectionException |
|
256 | + * @throws InvalidArgumentException |
|
257 | + * @throws InvalidInterfaceException |
|
258 | + * @throws EE_Error |
|
259 | + * @throws InvalidClassException |
|
260 | + * @throws InvalidDataTypeException |
|
261 | + * @throws InvalidEntityException |
|
262 | + */ |
|
263 | + protected function loadFromFQCNs() |
|
264 | + { |
|
265 | + $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
266 | + $FQCNs = (array) apply_filters( |
|
267 | + 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
268 | + $FQCNs, |
|
269 | + $this->collection_details->collectionName(), |
|
270 | + $this->collection_details |
|
271 | + ); |
|
272 | + foreach ($FQCNs as $FQCN) { |
|
273 | + $this->loadClassFromFQCN($FQCN); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | 277 | |
278 | - /** |
|
279 | - * @param string $FQCN Fully Qualified Class Name |
|
280 | - * @return string |
|
281 | - * @throws InvalidArgumentException |
|
282 | - * @throws InvalidInterfaceException |
|
283 | - * @throws ReflectionException |
|
284 | - * @throws EE_Error |
|
285 | - * @throws InvalidEntityException |
|
286 | - * @throws InvalidDataTypeException |
|
287 | - * @throws InvalidClassException |
|
288 | - */ |
|
289 | - protected function loadClassFromFQCN($FQCN) |
|
290 | - { |
|
291 | - if (! is_string($FQCN)) { |
|
292 | - throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
293 | - } |
|
294 | - if (! class_exists($FQCN)) { |
|
295 | - throw new InvalidClassException($FQCN); |
|
296 | - } |
|
297 | - return $this->addEntityToCollection( |
|
298 | - EE_Registry::instance()->create($FQCN), |
|
299 | - $FQCN |
|
300 | - ); |
|
301 | - } |
|
278 | + /** |
|
279 | + * @param string $FQCN Fully Qualified Class Name |
|
280 | + * @return string |
|
281 | + * @throws InvalidArgumentException |
|
282 | + * @throws InvalidInterfaceException |
|
283 | + * @throws ReflectionException |
|
284 | + * @throws EE_Error |
|
285 | + * @throws InvalidEntityException |
|
286 | + * @throws InvalidDataTypeException |
|
287 | + * @throws InvalidClassException |
|
288 | + */ |
|
289 | + protected function loadClassFromFQCN($FQCN) |
|
290 | + { |
|
291 | + if (! is_string($FQCN)) { |
|
292 | + throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
293 | + } |
|
294 | + if (! class_exists($FQCN)) { |
|
295 | + throw new InvalidClassException($FQCN); |
|
296 | + } |
|
297 | + return $this->addEntityToCollection( |
|
298 | + EE_Registry::instance()->create($FQCN), |
|
299 | + $FQCN |
|
300 | + ); |
|
301 | + } |
|
302 | 302 | } |
@@ -16,30 +16,30 @@ |
||
16 | 16 | class InvalidEntityException extends InvalidArgumentException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidEntityException constructor. |
|
21 | - * |
|
22 | - * @param mixed $actual the actual object (or thing) we got |
|
23 | - * @param string $expected classname of the entity we wanted |
|
24 | - * @param string $message |
|
25 | - * @param int $code |
|
26 | - * @param Exception $previous |
|
27 | - */ |
|
28 | - public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | - { |
|
30 | - if (empty($message)) { |
|
31 | - $message = sprintf( |
|
32 | - __( |
|
33 | - 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - is_object($actual) |
|
37 | - ? get_class($actual) |
|
38 | - : gettype($actual), |
|
39 | - $expected, |
|
40 | - var_export($actual, true) |
|
41 | - ); |
|
42 | - } |
|
43 | - parent::__construct($message, $code, $previous); |
|
44 | - } |
|
19 | + /** |
|
20 | + * InvalidEntityException constructor. |
|
21 | + * |
|
22 | + * @param mixed $actual the actual object (or thing) we got |
|
23 | + * @param string $expected classname of the entity we wanted |
|
24 | + * @param string $message |
|
25 | + * @param int $code |
|
26 | + * @param Exception $previous |
|
27 | + */ |
|
28 | + public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | + { |
|
30 | + if (empty($message)) { |
|
31 | + $message = sprintf( |
|
32 | + __( |
|
33 | + 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + is_object($actual) |
|
37 | + ? get_class($actual) |
|
38 | + : gettype($actual), |
|
39 | + $expected, |
|
40 | + var_export($actual, true) |
|
41 | + ); |
|
42 | + } |
|
43 | + parent::__construct($message, $code, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -16,159 +16,159 @@ |
||
16 | 16 | interface CollectionInterface extends Countable, Iterator, Serializable, ArrayAccess |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * add |
|
21 | - * attaches an object to the Collection |
|
22 | - * and sets any supplied data associated with the current iterator entry |
|
23 | - * by calling EE_Object_Collection::set_identifier() |
|
24 | - * |
|
25 | - * @access public |
|
26 | - * @param $object |
|
27 | - * @param mixed $identifier |
|
28 | - * @return bool |
|
29 | - */ |
|
30 | - public function add($object, $identifier = null); |
|
31 | - |
|
32 | - /** |
|
33 | - * setIdentifier |
|
34 | - * Sets the data associated with an object in the Collection |
|
35 | - * if no $identifier is supplied, then the spl_object_hash() is used |
|
36 | - * |
|
37 | - * @access public |
|
38 | - * @param $object |
|
39 | - * @param mixed $identifier |
|
40 | - * @return bool |
|
41 | - */ |
|
42 | - public function setIdentifier($object, $identifier = null); |
|
43 | - |
|
44 | - /** |
|
45 | - * get |
|
46 | - * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
47 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
48 | - * |
|
49 | - * @access public |
|
50 | - * @param mixed $identifier |
|
51 | - * @return mixed |
|
52 | - */ |
|
53 | - public function get($identifier); |
|
54 | - |
|
55 | - /** |
|
56 | - * has |
|
57 | - * returns TRUE or FALSE |
|
58 | - * depending on whether the object is within the Collection |
|
59 | - * based on the supplied $identifier |
|
60 | - * |
|
61 | - * @access public |
|
62 | - * @param mixed $identifier |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - public function has($identifier); |
|
66 | - |
|
67 | - /** |
|
68 | - * hasObject |
|
69 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
70 | - * |
|
71 | - * @access public |
|
72 | - * @param $object |
|
73 | - * @return bool |
|
74 | - */ |
|
75 | - public function hasObject($object); |
|
76 | - |
|
77 | - /** |
|
78 | - * remove |
|
79 | - * detaches an object from the Collection |
|
80 | - * |
|
81 | - * @access public |
|
82 | - * @param $object |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function remove($object); |
|
86 | - |
|
87 | - /** |
|
88 | - * setCurrent |
|
89 | - * advances pointer to the object whose identifier matches that which was provided |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @param mixed $identifier |
|
93 | - * @return boolean |
|
94 | - */ |
|
95 | - public function setCurrent($identifier); |
|
96 | - |
|
97 | - /** |
|
98 | - * setCurrentUsingObject |
|
99 | - * advances pointer to the provided object |
|
100 | - * |
|
101 | - * @access public |
|
102 | - * @param $object |
|
103 | - * @return boolean |
|
104 | - */ |
|
105 | - public function setCurrentUsingObject($object); |
|
106 | - |
|
107 | - /** |
|
108 | - * Returns the object occupying the index before the current object, |
|
109 | - * unless this is already the first object, in which case it just returns the first object |
|
110 | - * |
|
111 | - * @return mixed |
|
112 | - */ |
|
113 | - public function previous(); |
|
114 | - |
|
115 | - /** |
|
116 | - * Returns the index of a given object, or false if not found |
|
117 | - * |
|
118 | - * @see http://stackoverflow.com/a/8736013 |
|
119 | - * @param $object |
|
120 | - * @return boolean|int|string |
|
121 | - */ |
|
122 | - public function indexOf($object); |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns the object at the given index |
|
127 | - * |
|
128 | - * @see http://stackoverflow.com/a/8736013 |
|
129 | - * @param $index |
|
130 | - * @return mixed |
|
131 | - */ |
|
132 | - public function objectAtIndex($index); |
|
133 | - |
|
134 | - /** |
|
135 | - * Returns the sequence of objects as specified by the offset and length |
|
136 | - * |
|
137 | - * @see http://stackoverflow.com/a/8736013 |
|
138 | - * @param int $offset |
|
139 | - * @param int $length |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - public function slice($offset, $length); |
|
143 | - |
|
144 | - /** |
|
145 | - * Inserts an object (or an array of objects) at a certain point |
|
146 | - * |
|
147 | - * @see http://stackoverflow.com/a/8736013 |
|
148 | - * @param mixed $objects A single object or an array of objects |
|
149 | - * @param integer $index |
|
150 | - */ |
|
151 | - public function insertAt($objects, $index); |
|
152 | - |
|
153 | - /** |
|
154 | - * Removes the object at the given index |
|
155 | - * |
|
156 | - * @see http://stackoverflow.com/a/8736013 |
|
157 | - * @param integer $index |
|
158 | - */ |
|
159 | - public function removeAt($index); |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * detaches ALL objects from the Collection |
|
165 | - */ |
|
166 | - public function detachAll(); |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * unsets and detaches ALL objects from the Collection |
|
172 | - */ |
|
173 | - public function trashAndDetachAll(); |
|
19 | + /** |
|
20 | + * add |
|
21 | + * attaches an object to the Collection |
|
22 | + * and sets any supplied data associated with the current iterator entry |
|
23 | + * by calling EE_Object_Collection::set_identifier() |
|
24 | + * |
|
25 | + * @access public |
|
26 | + * @param $object |
|
27 | + * @param mixed $identifier |
|
28 | + * @return bool |
|
29 | + */ |
|
30 | + public function add($object, $identifier = null); |
|
31 | + |
|
32 | + /** |
|
33 | + * setIdentifier |
|
34 | + * Sets the data associated with an object in the Collection |
|
35 | + * if no $identifier is supplied, then the spl_object_hash() is used |
|
36 | + * |
|
37 | + * @access public |
|
38 | + * @param $object |
|
39 | + * @param mixed $identifier |
|
40 | + * @return bool |
|
41 | + */ |
|
42 | + public function setIdentifier($object, $identifier = null); |
|
43 | + |
|
44 | + /** |
|
45 | + * get |
|
46 | + * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
47 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
48 | + * |
|
49 | + * @access public |
|
50 | + * @param mixed $identifier |
|
51 | + * @return mixed |
|
52 | + */ |
|
53 | + public function get($identifier); |
|
54 | + |
|
55 | + /** |
|
56 | + * has |
|
57 | + * returns TRUE or FALSE |
|
58 | + * depending on whether the object is within the Collection |
|
59 | + * based on the supplied $identifier |
|
60 | + * |
|
61 | + * @access public |
|
62 | + * @param mixed $identifier |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + public function has($identifier); |
|
66 | + |
|
67 | + /** |
|
68 | + * hasObject |
|
69 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
70 | + * |
|
71 | + * @access public |
|
72 | + * @param $object |
|
73 | + * @return bool |
|
74 | + */ |
|
75 | + public function hasObject($object); |
|
76 | + |
|
77 | + /** |
|
78 | + * remove |
|
79 | + * detaches an object from the Collection |
|
80 | + * |
|
81 | + * @access public |
|
82 | + * @param $object |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function remove($object); |
|
86 | + |
|
87 | + /** |
|
88 | + * setCurrent |
|
89 | + * advances pointer to the object whose identifier matches that which was provided |
|
90 | + * |
|
91 | + * @access public |
|
92 | + * @param mixed $identifier |
|
93 | + * @return boolean |
|
94 | + */ |
|
95 | + public function setCurrent($identifier); |
|
96 | + |
|
97 | + /** |
|
98 | + * setCurrentUsingObject |
|
99 | + * advances pointer to the provided object |
|
100 | + * |
|
101 | + * @access public |
|
102 | + * @param $object |
|
103 | + * @return boolean |
|
104 | + */ |
|
105 | + public function setCurrentUsingObject($object); |
|
106 | + |
|
107 | + /** |
|
108 | + * Returns the object occupying the index before the current object, |
|
109 | + * unless this is already the first object, in which case it just returns the first object |
|
110 | + * |
|
111 | + * @return mixed |
|
112 | + */ |
|
113 | + public function previous(); |
|
114 | + |
|
115 | + /** |
|
116 | + * Returns the index of a given object, or false if not found |
|
117 | + * |
|
118 | + * @see http://stackoverflow.com/a/8736013 |
|
119 | + * @param $object |
|
120 | + * @return boolean|int|string |
|
121 | + */ |
|
122 | + public function indexOf($object); |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns the object at the given index |
|
127 | + * |
|
128 | + * @see http://stackoverflow.com/a/8736013 |
|
129 | + * @param $index |
|
130 | + * @return mixed |
|
131 | + */ |
|
132 | + public function objectAtIndex($index); |
|
133 | + |
|
134 | + /** |
|
135 | + * Returns the sequence of objects as specified by the offset and length |
|
136 | + * |
|
137 | + * @see http://stackoverflow.com/a/8736013 |
|
138 | + * @param int $offset |
|
139 | + * @param int $length |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + public function slice($offset, $length); |
|
143 | + |
|
144 | + /** |
|
145 | + * Inserts an object (or an array of objects) at a certain point |
|
146 | + * |
|
147 | + * @see http://stackoverflow.com/a/8736013 |
|
148 | + * @param mixed $objects A single object or an array of objects |
|
149 | + * @param integer $index |
|
150 | + */ |
|
151 | + public function insertAt($objects, $index); |
|
152 | + |
|
153 | + /** |
|
154 | + * Removes the object at the given index |
|
155 | + * |
|
156 | + * @see http://stackoverflow.com/a/8736013 |
|
157 | + * @param integer $index |
|
158 | + */ |
|
159 | + public function removeAt($index); |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * detaches ALL objects from the Collection |
|
165 | + */ |
|
166 | + public function detachAll(); |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * unsets and detaches ALL objects from the Collection |
|
172 | + */ |
|
173 | + public function trashAndDetachAll(); |
|
174 | 174 | } |
@@ -46,225 +46,225 @@ |
||
46 | 46 | class BootstrapCore |
47 | 47 | { |
48 | 48 | |
49 | - /** |
|
50 | - * @type LoaderInterface $loader |
|
51 | - */ |
|
52 | - private $loader; |
|
49 | + /** |
|
50 | + * @type LoaderInterface $loader |
|
51 | + */ |
|
52 | + private $loader; |
|
53 | 53 | |
54 | - /** |
|
55 | - * @var RequestInterface $request |
|
56 | - */ |
|
57 | - protected $request; |
|
54 | + /** |
|
55 | + * @var RequestInterface $request |
|
56 | + */ |
|
57 | + protected $request; |
|
58 | 58 | |
59 | - /** |
|
60 | - * @var ResponseInterface $response |
|
61 | - */ |
|
62 | - protected $response; |
|
59 | + /** |
|
60 | + * @var ResponseInterface $response |
|
61 | + */ |
|
62 | + protected $response; |
|
63 | 63 | |
64 | - /** |
|
65 | - * @var RequestStackBuilder $request_stack_builder |
|
66 | - */ |
|
67 | - protected $request_stack_builder; |
|
64 | + /** |
|
65 | + * @var RequestStackBuilder $request_stack_builder |
|
66 | + */ |
|
67 | + protected $request_stack_builder; |
|
68 | 68 | |
69 | - /** |
|
70 | - * @var RequestStack $request_stack |
|
71 | - */ |
|
72 | - protected $request_stack; |
|
69 | + /** |
|
70 | + * @var RequestStack $request_stack |
|
71 | + */ |
|
72 | + protected $request_stack; |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * BootstrapCore constructor. |
|
77 | - */ |
|
78 | - public function __construct() |
|
79 | - { |
|
80 | - do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct'); |
|
81 | - // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
82 | - add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
83 | - } |
|
75 | + /** |
|
76 | + * BootstrapCore constructor. |
|
77 | + */ |
|
78 | + public function __construct() |
|
79 | + { |
|
80 | + do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct'); |
|
81 | + // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
82 | + add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | - /** |
|
87 | - * @throws DomainException |
|
88 | - * @throws EE_Error |
|
89 | - * @throws Exception |
|
90 | - * @throws InvalidArgumentException |
|
91 | - * @throws InvalidClassException |
|
92 | - * @throws InvalidDataTypeException |
|
93 | - * @throws InvalidFilePathException |
|
94 | - * @throws InvalidInterfaceException |
|
95 | - * @throws InvalidRequestStackMiddlewareException |
|
96 | - * @throws OutOfBoundsException |
|
97 | - * @throws ReflectionException |
|
98 | - */ |
|
99 | - public function initialize() |
|
100 | - { |
|
101 | - $this->bootstrapDependencyInjectionContainer(); |
|
102 | - $this->bootstrapDomain(); |
|
103 | - $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
104 | - add_action( |
|
105 | - 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
106 | - array($bootstrap_request, 'setupLegacyRequest') |
|
107 | - ); |
|
108 | - $this->runRequestStack(); |
|
109 | - } |
|
86 | + /** |
|
87 | + * @throws DomainException |
|
88 | + * @throws EE_Error |
|
89 | + * @throws Exception |
|
90 | + * @throws InvalidArgumentException |
|
91 | + * @throws InvalidClassException |
|
92 | + * @throws InvalidDataTypeException |
|
93 | + * @throws InvalidFilePathException |
|
94 | + * @throws InvalidInterfaceException |
|
95 | + * @throws InvalidRequestStackMiddlewareException |
|
96 | + * @throws OutOfBoundsException |
|
97 | + * @throws ReflectionException |
|
98 | + */ |
|
99 | + public function initialize() |
|
100 | + { |
|
101 | + $this->bootstrapDependencyInjectionContainer(); |
|
102 | + $this->bootstrapDomain(); |
|
103 | + $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
104 | + add_action( |
|
105 | + 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
106 | + array($bootstrap_request, 'setupLegacyRequest') |
|
107 | + ); |
|
108 | + $this->runRequestStack(); |
|
109 | + } |
|
110 | 110 | |
111 | 111 | |
112 | - /** |
|
113 | - * @throws ReflectionException |
|
114 | - * @throws EE_Error |
|
115 | - * @throws InvalidArgumentException |
|
116 | - * @throws InvalidDataTypeException |
|
117 | - * @throws InvalidInterfaceException |
|
118 | - * @throws OutOfBoundsException |
|
119 | - */ |
|
120 | - private function bootstrapDependencyInjectionContainer() |
|
121 | - { |
|
122 | - $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
123 | - $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
124 | - $bootstrap_di->buildLoader(); |
|
125 | - $registry = $bootstrap_di->getRegistry(); |
|
126 | - $dependency_map = $bootstrap_di->getDependencyMap(); |
|
127 | - $dependency_map->initialize(); |
|
128 | - $registry->initialize(); |
|
129 | - $this->loader = $bootstrap_di->getLoader(); |
|
130 | - } |
|
112 | + /** |
|
113 | + * @throws ReflectionException |
|
114 | + * @throws EE_Error |
|
115 | + * @throws InvalidArgumentException |
|
116 | + * @throws InvalidDataTypeException |
|
117 | + * @throws InvalidInterfaceException |
|
118 | + * @throws OutOfBoundsException |
|
119 | + */ |
|
120 | + private function bootstrapDependencyInjectionContainer() |
|
121 | + { |
|
122 | + $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
123 | + $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
124 | + $bootstrap_di->buildLoader(); |
|
125 | + $registry = $bootstrap_di->getRegistry(); |
|
126 | + $dependency_map = $bootstrap_di->getDependencyMap(); |
|
127 | + $dependency_map->initialize(); |
|
128 | + $registry->initialize(); |
|
129 | + $this->loader = $bootstrap_di->getLoader(); |
|
130 | + } |
|
131 | 131 | |
132 | 132 | |
133 | - /** |
|
134 | - * configures the Domain object for core |
|
135 | - * |
|
136 | - * @return void |
|
137 | - * @throws DomainException |
|
138 | - * @throws InvalidArgumentException |
|
139 | - * @throws InvalidDataTypeException |
|
140 | - * @throws InvalidClassException |
|
141 | - * @throws InvalidFilePathException |
|
142 | - * @throws InvalidInterfaceException |
|
143 | - */ |
|
144 | - private function bootstrapDomain() |
|
145 | - { |
|
146 | - DomainFactory::getEventEspressoCoreDomain(); |
|
147 | - } |
|
133 | + /** |
|
134 | + * configures the Domain object for core |
|
135 | + * |
|
136 | + * @return void |
|
137 | + * @throws DomainException |
|
138 | + * @throws InvalidArgumentException |
|
139 | + * @throws InvalidDataTypeException |
|
140 | + * @throws InvalidClassException |
|
141 | + * @throws InvalidFilePathException |
|
142 | + * @throws InvalidInterfaceException |
|
143 | + */ |
|
144 | + private function bootstrapDomain() |
|
145 | + { |
|
146 | + DomainFactory::getEventEspressoCoreDomain(); |
|
147 | + } |
|
148 | 148 | |
149 | 149 | |
150 | - /** |
|
151 | - * sets up the request and response objects |
|
152 | - * |
|
153 | - * @return BootstrapRequestResponseObjects |
|
154 | - * @throws InvalidArgumentException |
|
155 | - */ |
|
156 | - private function bootstrapRequestResponseObjects() |
|
157 | - { |
|
158 | - /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
159 | - $bootstrap_request = $this->loader->getShared( |
|
160 | - 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
161 | - array($this->loader) |
|
162 | - ); |
|
163 | - $bootstrap_request->buildRequestResponse(); |
|
164 | - $bootstrap_request->shareRequestResponse(); |
|
165 | - $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
166 | - $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
167 | - return $bootstrap_request; |
|
168 | - } |
|
150 | + /** |
|
151 | + * sets up the request and response objects |
|
152 | + * |
|
153 | + * @return BootstrapRequestResponseObjects |
|
154 | + * @throws InvalidArgumentException |
|
155 | + */ |
|
156 | + private function bootstrapRequestResponseObjects() |
|
157 | + { |
|
158 | + /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
159 | + $bootstrap_request = $this->loader->getShared( |
|
160 | + 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
161 | + array($this->loader) |
|
162 | + ); |
|
163 | + $bootstrap_request->buildRequestResponse(); |
|
164 | + $bootstrap_request->shareRequestResponse(); |
|
165 | + $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
166 | + $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
167 | + return $bootstrap_request; |
|
168 | + } |
|
169 | 169 | |
170 | 170 | |
171 | - /** |
|
172 | - * run_request_stack |
|
173 | - * construct request stack and run middleware apps |
|
174 | - * |
|
175 | - * @throws EE_Error |
|
176 | - * @throws Exception |
|
177 | - */ |
|
178 | - public function runRequestStack() |
|
179 | - { |
|
180 | - $this->loadAutoloader(); |
|
181 | - $this->setAutoloadersForRequiredFiles(); |
|
182 | - $this->request_stack_builder = $this->buildRequestStack(); |
|
183 | - $this->request_stack = $this->request_stack_builder->resolve( |
|
184 | - new RequestStackCoreApp() |
|
185 | - ); |
|
186 | - $this->request_stack->handleRequest($this->request, $this->response); |
|
187 | - $this->request_stack->handleResponse(); |
|
188 | - } |
|
171 | + /** |
|
172 | + * run_request_stack |
|
173 | + * construct request stack and run middleware apps |
|
174 | + * |
|
175 | + * @throws EE_Error |
|
176 | + * @throws Exception |
|
177 | + */ |
|
178 | + public function runRequestStack() |
|
179 | + { |
|
180 | + $this->loadAutoloader(); |
|
181 | + $this->setAutoloadersForRequiredFiles(); |
|
182 | + $this->request_stack_builder = $this->buildRequestStack(); |
|
183 | + $this->request_stack = $this->request_stack_builder->resolve( |
|
184 | + new RequestStackCoreApp() |
|
185 | + ); |
|
186 | + $this->request_stack->handleRequest($this->request, $this->response); |
|
187 | + $this->request_stack->handleResponse(); |
|
188 | + } |
|
189 | 189 | |
190 | 190 | |
191 | - /** |
|
192 | - * load_autoloader |
|
193 | - * |
|
194 | - * @throws EE_Error |
|
195 | - */ |
|
196 | - protected function loadAutoloader() |
|
197 | - { |
|
198 | - // load interfaces |
|
199 | - espresso_load_required( |
|
200 | - 'EEH_Autoloader', |
|
201 | - EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
202 | - ); |
|
203 | - EEH_Autoloader::instance(); |
|
204 | - } |
|
191 | + /** |
|
192 | + * load_autoloader |
|
193 | + * |
|
194 | + * @throws EE_Error |
|
195 | + */ |
|
196 | + protected function loadAutoloader() |
|
197 | + { |
|
198 | + // load interfaces |
|
199 | + espresso_load_required( |
|
200 | + 'EEH_Autoloader', |
|
201 | + EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
202 | + ); |
|
203 | + EEH_Autoloader::instance(); |
|
204 | + } |
|
205 | 205 | |
206 | 206 | |
207 | - /** |
|
208 | - * load_required_files |
|
209 | - * |
|
210 | - * @throws EE_Error |
|
211 | - */ |
|
212 | - protected function setAutoloadersForRequiredFiles() |
|
213 | - { |
|
214 | - // load interfaces |
|
215 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
216 | - // load helpers |
|
217 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
218 | - // register legacy request stack classes just in case |
|
219 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
220 | - // register legacy middleware classes just in case |
|
221 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
222 | - } |
|
207 | + /** |
|
208 | + * load_required_files |
|
209 | + * |
|
210 | + * @throws EE_Error |
|
211 | + */ |
|
212 | + protected function setAutoloadersForRequiredFiles() |
|
213 | + { |
|
214 | + // load interfaces |
|
215 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
216 | + // load helpers |
|
217 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
218 | + // register legacy request stack classes just in case |
|
219 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
220 | + // register legacy middleware classes just in case |
|
221 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
222 | + } |
|
223 | 223 | |
224 | 224 | |
225 | - /** |
|
226 | - * build_request_stack |
|
227 | - * |
|
228 | - * @return RequestStackBuilder |
|
229 | - */ |
|
230 | - public function buildRequestStack() |
|
231 | - { |
|
232 | - $request_stack_builder = new RequestStackBuilder($this->loader); |
|
233 | - /** |
|
234 | - * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
235 | - * so items at the beginning of the final middleware stack will run last. |
|
236 | - * First parameter is the middleware classname, second is an array of arguments |
|
237 | - */ |
|
238 | - $stack_apps = apply_filters( |
|
239 | - 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
240 | - array( |
|
241 | - // first in last out |
|
242 | - 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
243 | - 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
244 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
245 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
246 | - // last in first out |
|
247 | - 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
248 | - ) |
|
249 | - ); |
|
250 | - // legacy filter for backwards compatibility |
|
251 | - $stack_apps = apply_filters( |
|
252 | - 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
253 | - $stack_apps |
|
254 | - ); |
|
255 | - // load middleware onto stack : FILO (First In Last Out) |
|
256 | - // items at the beginning of the $stack_apps array will run last |
|
257 | - foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
258 | - $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
259 | - } |
|
260 | - // finally, we'll add this on its own because we need it to always be part of the stack |
|
261 | - // and we also need it to always run first because the rest of the system relies on it |
|
262 | - $request_stack_builder->push( |
|
263 | - array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
264 | - ); |
|
265 | - return apply_filters( |
|
266 | - 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
267 | - $request_stack_builder |
|
268 | - ); |
|
269 | - } |
|
225 | + /** |
|
226 | + * build_request_stack |
|
227 | + * |
|
228 | + * @return RequestStackBuilder |
|
229 | + */ |
|
230 | + public function buildRequestStack() |
|
231 | + { |
|
232 | + $request_stack_builder = new RequestStackBuilder($this->loader); |
|
233 | + /** |
|
234 | + * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
235 | + * so items at the beginning of the final middleware stack will run last. |
|
236 | + * First parameter is the middleware classname, second is an array of arguments |
|
237 | + */ |
|
238 | + $stack_apps = apply_filters( |
|
239 | + 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
240 | + array( |
|
241 | + // first in last out |
|
242 | + 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
243 | + 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
244 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
245 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
246 | + // last in first out |
|
247 | + 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
248 | + ) |
|
249 | + ); |
|
250 | + // legacy filter for backwards compatibility |
|
251 | + $stack_apps = apply_filters( |
|
252 | + 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
253 | + $stack_apps |
|
254 | + ); |
|
255 | + // load middleware onto stack : FILO (First In Last Out) |
|
256 | + // items at the beginning of the $stack_apps array will run last |
|
257 | + foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
258 | + $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
259 | + } |
|
260 | + // finally, we'll add this on its own because we need it to always be part of the stack |
|
261 | + // and we also need it to always run first because the rest of the system relies on it |
|
262 | + $request_stack_builder->push( |
|
263 | + array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
264 | + ); |
|
265 | + return apply_filters( |
|
266 | + 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
267 | + $request_stack_builder |
|
268 | + ); |
|
269 | + } |
|
270 | 270 | } |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use EventEspresso\core\domain\values\FilePath; |
6 | 6 | use EventEspresso\core\domain\values\Version; |
7 | -use EventEspresso\core\services\assets\Registry; |
|
8 | 7 | |
9 | 8 | /** |
10 | 9 | * DomainBase Class |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | |
115 | 115 | /** |
116 | - * @param $handle |
|
116 | + * @param string $handle |
|
117 | 117 | * @param array $dependencies |
118 | 118 | * @since $VID:$ |
119 | 119 | * @return JavascriptAsset |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | |
138 | 138 | /** |
139 | - * @param $handle |
|
139 | + * @param string $handle |
|
140 | 140 | * @param array $dependencies |
141 | 141 | * @since $VID:$ |
142 | 142 | * @return StylesheetAsset |
@@ -22,310 +22,310 @@ |
||
22 | 22 | abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var string $editor_script_handle |
|
27 | - */ |
|
28 | - private $editor_script_handle; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $editor_style_handle |
|
32 | - */ |
|
33 | - private $editor_style_handle; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string $script_handle |
|
37 | - */ |
|
38 | - private $script_handle; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string $style_handle |
|
42 | - */ |
|
43 | - private $style_handle; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function getEditorScriptHandle() |
|
50 | - { |
|
51 | - return $this->editor_script_handle; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $editor_script_handle |
|
57 | - */ |
|
58 | - public function setEditorScriptHandle($editor_script_handle) |
|
59 | - { |
|
60 | - if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
61 | - $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
62 | - } |
|
63 | - $this->editor_script_handle = $editor_script_handle; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getEditorStyleHandle() |
|
71 | - { |
|
72 | - return $this->editor_style_handle; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $editor_style_handle |
|
78 | - */ |
|
79 | - public function setEditorStyleHandle($editor_style_handle) |
|
80 | - { |
|
81 | - if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
82 | - $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
83 | - } |
|
84 | - $this->editor_style_handle = $editor_style_handle; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getScriptHandle() |
|
92 | - { |
|
93 | - return $this->script_handle; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param string $script_handle |
|
99 | - */ |
|
100 | - public function setScriptHandle($script_handle) |
|
101 | - { |
|
102 | - if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
103 | - $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
104 | - } |
|
105 | - $this->script_handle = $script_handle; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function getStyleHandle() |
|
113 | - { |
|
114 | - return $this->style_handle; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @param string $style_handle |
|
120 | - */ |
|
121 | - public function setStyleHandle($style_handle) |
|
122 | - { |
|
123 | - if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
124 | - $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
125 | - } |
|
126 | - $this->style_handle = $style_handle; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @since $VID:$ |
|
131 | - * @throws InvalidDataTypeException |
|
132 | - * @throws InvalidEntityException |
|
133 | - * @throws DuplicateCollectionIdentifierException |
|
134 | - */ |
|
135 | - public function addAssets() |
|
136 | - { |
|
137 | - $this->addEditorScript($this->getEditorScriptHandle()); |
|
138 | - $this->addEditorStyle($this->getEditorStyleHandle()); |
|
139 | - $this->setScriptHandle($this->getScriptHandle()); |
|
140 | - $this->setStyleHandle($this->getStyleHandle()); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param $handle |
|
146 | - * @param array $dependencies |
|
147 | - * @since $VID:$ |
|
148 | - * @return JavascriptAsset |
|
149 | - * @throws InvalidDataTypeException |
|
150 | - * @throws InvalidEntityException |
|
151 | - * @throws DuplicateCollectionIdentifierException |
|
152 | - */ |
|
153 | - public function addEditorScript($handle, array $dependencies = array()) |
|
154 | - { |
|
155 | - if($this->assets->has($handle)){ |
|
156 | - return $this->assets->get($handle); |
|
157 | - } |
|
158 | - return parent::addJavascript( |
|
159 | - $handle, |
|
160 | - $this->registry->getJsUrl( |
|
161 | - $this->domain->assetNamespace(), |
|
162 | - $handle |
|
163 | - ), |
|
164 | - $this->addDefaultBlockScriptDependencies($dependencies) |
|
165 | - ) |
|
166 | - ->setRequiresTranslation(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param $handle |
|
172 | - * @param array $dependencies |
|
173 | - * @since $VID:$ |
|
174 | - * @return StylesheetAsset |
|
175 | - * @throws InvalidDataTypeException |
|
176 | - * @throws InvalidEntityException |
|
177 | - * @throws DuplicateCollectionIdentifierException |
|
178 | - */ |
|
179 | - public function addEditorStyle($handle, array $dependencies = array()) |
|
180 | - { |
|
181 | - if ($this->assets->has($handle)) { |
|
182 | - return $this->assets->get($handle); |
|
183 | - } |
|
184 | - return parent::addStylesheet( |
|
185 | - $handle, |
|
186 | - $this->registry->getCssUrl( |
|
187 | - $this->domain->assetNamespace(), |
|
188 | - $handle |
|
189 | - ), |
|
190 | - $dependencies |
|
191 | - ); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @param $handle |
|
197 | - * @param array $dependencies |
|
198 | - * @since $VID:$ |
|
199 | - * @return JavascriptAsset |
|
200 | - * @throws InvalidDataTypeException |
|
201 | - * @throws InvalidEntityException |
|
202 | - * @throws DuplicateCollectionIdentifierException |
|
203 | - */ |
|
204 | - public function addScript($handle, array $dependencies = array()) |
|
205 | - { |
|
206 | - if ($this->assets->has($handle)) { |
|
207 | - return $this->assets->get($handle); |
|
208 | - } |
|
209 | - return parent::addJavascript( |
|
210 | - $handle, |
|
211 | - $this->registry->getJsUrl( |
|
212 | - $this->domain->assetNamespace(), |
|
213 | - $handle |
|
214 | - ), |
|
215 | - $this->addDefaultBlockScriptDependencies($dependencies) |
|
216 | - ) |
|
217 | - ->setRequiresTranslation(); |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * @param $handle |
|
223 | - * @param array $dependencies |
|
224 | - * @since $VID:$ |
|
225 | - * @return StylesheetAsset |
|
226 | - * @throws InvalidDataTypeException |
|
227 | - * @throws InvalidEntityException |
|
228 | - * @throws DuplicateCollectionIdentifierException |
|
229 | - */ |
|
230 | - public function addStyle($handle, array $dependencies = array()) |
|
231 | - { |
|
232 | - if ($this->assets->has($handle)) { |
|
233 | - return $this->assets->get($handle); |
|
234 | - } |
|
235 | - return parent::addStylesheet( |
|
236 | - $handle, |
|
237 | - $this->registry->getCssUrl( |
|
238 | - $this->domain->assetNamespace(), |
|
239 | - $handle |
|
240 | - ), |
|
241 | - $dependencies |
|
242 | - ); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @param array $dependencies |
|
248 | - * @return array |
|
249 | - */ |
|
250 | - protected function addDefaultBlockScriptDependencies(array $dependencies) |
|
251 | - { |
|
252 | - $dependencies += array( |
|
253 | - CoreAssetManager::JS_HANDLE_EE_DATA_STORES, |
|
254 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | - 'wp-i18n', // Provides localization functions |
|
256 | - 'wp-element', // Provides React.Component |
|
257 | - 'wp-components' // Provides many prebuilt components and controls |
|
258 | - ); |
|
259 | - return $dependencies; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * @param string $handle |
|
265 | - * @since $VID:$ |
|
266 | - * @return mixed|null |
|
267 | - */ |
|
268 | - public function getAsset($handle) |
|
269 | - { |
|
270 | - if ($this->assets->has($handle)) { |
|
271 | - return $this->assets->get($handle); |
|
272 | - } |
|
273 | - return null; |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * @return JavascriptAsset|null |
|
279 | - */ |
|
280 | - public function getEditorScript() |
|
281 | - { |
|
282 | - return $this->getAsset($this->editor_script_handle); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @return StylesheetAsset|null |
|
288 | - */ |
|
289 | - public function getEditorStyle() |
|
290 | - { |
|
291 | - return $this->getAsset($this->editor_style_handle); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @return JavascriptAsset|null |
|
297 | - */ |
|
298 | - public function getScript() |
|
299 | - { |
|
300 | - return $this->getAsset($this->script_handle); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * @return StylesheetAsset|null |
|
306 | - */ |
|
307 | - public function getStyle() |
|
308 | - { |
|
309 | - return $this->getAsset($this->style_handle); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * @return void |
|
315 | - */ |
|
316 | - public function enqueueAssets() |
|
317 | - { |
|
318 | - $assets = array( |
|
319 | - $this->getEditorScript(), |
|
320 | - $this->getEditorStyle(), |
|
321 | - $this->getScript(), |
|
322 | - $this->getStyle(), |
|
323 | - ); |
|
324 | - foreach ($assets as $asset) { |
|
325 | - if ($asset instanceof BrowserAsset && $asset->isRegistered()) { |
|
326 | - $asset->enqueueAsset(); |
|
327 | - } |
|
328 | - } |
|
329 | - } |
|
25 | + /** |
|
26 | + * @var string $editor_script_handle |
|
27 | + */ |
|
28 | + private $editor_script_handle; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $editor_style_handle |
|
32 | + */ |
|
33 | + private $editor_style_handle; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string $script_handle |
|
37 | + */ |
|
38 | + private $script_handle; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string $style_handle |
|
42 | + */ |
|
43 | + private $style_handle; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function getEditorScriptHandle() |
|
50 | + { |
|
51 | + return $this->editor_script_handle; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $editor_script_handle |
|
57 | + */ |
|
58 | + public function setEditorScriptHandle($editor_script_handle) |
|
59 | + { |
|
60 | + if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
61 | + $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
62 | + } |
|
63 | + $this->editor_script_handle = $editor_script_handle; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getEditorStyleHandle() |
|
71 | + { |
|
72 | + return $this->editor_style_handle; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $editor_style_handle |
|
78 | + */ |
|
79 | + public function setEditorStyleHandle($editor_style_handle) |
|
80 | + { |
|
81 | + if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
82 | + $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
83 | + } |
|
84 | + $this->editor_style_handle = $editor_style_handle; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getScriptHandle() |
|
92 | + { |
|
93 | + return $this->script_handle; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param string $script_handle |
|
99 | + */ |
|
100 | + public function setScriptHandle($script_handle) |
|
101 | + { |
|
102 | + if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
103 | + $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
104 | + } |
|
105 | + $this->script_handle = $script_handle; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function getStyleHandle() |
|
113 | + { |
|
114 | + return $this->style_handle; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @param string $style_handle |
|
120 | + */ |
|
121 | + public function setStyleHandle($style_handle) |
|
122 | + { |
|
123 | + if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
124 | + $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
125 | + } |
|
126 | + $this->style_handle = $style_handle; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @since $VID:$ |
|
131 | + * @throws InvalidDataTypeException |
|
132 | + * @throws InvalidEntityException |
|
133 | + * @throws DuplicateCollectionIdentifierException |
|
134 | + */ |
|
135 | + public function addAssets() |
|
136 | + { |
|
137 | + $this->addEditorScript($this->getEditorScriptHandle()); |
|
138 | + $this->addEditorStyle($this->getEditorStyleHandle()); |
|
139 | + $this->setScriptHandle($this->getScriptHandle()); |
|
140 | + $this->setStyleHandle($this->getStyleHandle()); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param $handle |
|
146 | + * @param array $dependencies |
|
147 | + * @since $VID:$ |
|
148 | + * @return JavascriptAsset |
|
149 | + * @throws InvalidDataTypeException |
|
150 | + * @throws InvalidEntityException |
|
151 | + * @throws DuplicateCollectionIdentifierException |
|
152 | + */ |
|
153 | + public function addEditorScript($handle, array $dependencies = array()) |
|
154 | + { |
|
155 | + if($this->assets->has($handle)){ |
|
156 | + return $this->assets->get($handle); |
|
157 | + } |
|
158 | + return parent::addJavascript( |
|
159 | + $handle, |
|
160 | + $this->registry->getJsUrl( |
|
161 | + $this->domain->assetNamespace(), |
|
162 | + $handle |
|
163 | + ), |
|
164 | + $this->addDefaultBlockScriptDependencies($dependencies) |
|
165 | + ) |
|
166 | + ->setRequiresTranslation(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param $handle |
|
172 | + * @param array $dependencies |
|
173 | + * @since $VID:$ |
|
174 | + * @return StylesheetAsset |
|
175 | + * @throws InvalidDataTypeException |
|
176 | + * @throws InvalidEntityException |
|
177 | + * @throws DuplicateCollectionIdentifierException |
|
178 | + */ |
|
179 | + public function addEditorStyle($handle, array $dependencies = array()) |
|
180 | + { |
|
181 | + if ($this->assets->has($handle)) { |
|
182 | + return $this->assets->get($handle); |
|
183 | + } |
|
184 | + return parent::addStylesheet( |
|
185 | + $handle, |
|
186 | + $this->registry->getCssUrl( |
|
187 | + $this->domain->assetNamespace(), |
|
188 | + $handle |
|
189 | + ), |
|
190 | + $dependencies |
|
191 | + ); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @param $handle |
|
197 | + * @param array $dependencies |
|
198 | + * @since $VID:$ |
|
199 | + * @return JavascriptAsset |
|
200 | + * @throws InvalidDataTypeException |
|
201 | + * @throws InvalidEntityException |
|
202 | + * @throws DuplicateCollectionIdentifierException |
|
203 | + */ |
|
204 | + public function addScript($handle, array $dependencies = array()) |
|
205 | + { |
|
206 | + if ($this->assets->has($handle)) { |
|
207 | + return $this->assets->get($handle); |
|
208 | + } |
|
209 | + return parent::addJavascript( |
|
210 | + $handle, |
|
211 | + $this->registry->getJsUrl( |
|
212 | + $this->domain->assetNamespace(), |
|
213 | + $handle |
|
214 | + ), |
|
215 | + $this->addDefaultBlockScriptDependencies($dependencies) |
|
216 | + ) |
|
217 | + ->setRequiresTranslation(); |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * @param $handle |
|
223 | + * @param array $dependencies |
|
224 | + * @since $VID:$ |
|
225 | + * @return StylesheetAsset |
|
226 | + * @throws InvalidDataTypeException |
|
227 | + * @throws InvalidEntityException |
|
228 | + * @throws DuplicateCollectionIdentifierException |
|
229 | + */ |
|
230 | + public function addStyle($handle, array $dependencies = array()) |
|
231 | + { |
|
232 | + if ($this->assets->has($handle)) { |
|
233 | + return $this->assets->get($handle); |
|
234 | + } |
|
235 | + return parent::addStylesheet( |
|
236 | + $handle, |
|
237 | + $this->registry->getCssUrl( |
|
238 | + $this->domain->assetNamespace(), |
|
239 | + $handle |
|
240 | + ), |
|
241 | + $dependencies |
|
242 | + ); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @param array $dependencies |
|
248 | + * @return array |
|
249 | + */ |
|
250 | + protected function addDefaultBlockScriptDependencies(array $dependencies) |
|
251 | + { |
|
252 | + $dependencies += array( |
|
253 | + CoreAssetManager::JS_HANDLE_EE_DATA_STORES, |
|
254 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | + 'wp-i18n', // Provides localization functions |
|
256 | + 'wp-element', // Provides React.Component |
|
257 | + 'wp-components' // Provides many prebuilt components and controls |
|
258 | + ); |
|
259 | + return $dependencies; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * @param string $handle |
|
265 | + * @since $VID:$ |
|
266 | + * @return mixed|null |
|
267 | + */ |
|
268 | + public function getAsset($handle) |
|
269 | + { |
|
270 | + if ($this->assets->has($handle)) { |
|
271 | + return $this->assets->get($handle); |
|
272 | + } |
|
273 | + return null; |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * @return JavascriptAsset|null |
|
279 | + */ |
|
280 | + public function getEditorScript() |
|
281 | + { |
|
282 | + return $this->getAsset($this->editor_script_handle); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @return StylesheetAsset|null |
|
288 | + */ |
|
289 | + public function getEditorStyle() |
|
290 | + { |
|
291 | + return $this->getAsset($this->editor_style_handle); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @return JavascriptAsset|null |
|
297 | + */ |
|
298 | + public function getScript() |
|
299 | + { |
|
300 | + return $this->getAsset($this->script_handle); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * @return StylesheetAsset|null |
|
306 | + */ |
|
307 | + public function getStyle() |
|
308 | + { |
|
309 | + return $this->getAsset($this->style_handle); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * @return void |
|
315 | + */ |
|
316 | + public function enqueueAssets() |
|
317 | + { |
|
318 | + $assets = array( |
|
319 | + $this->getEditorScript(), |
|
320 | + $this->getEditorStyle(), |
|
321 | + $this->getScript(), |
|
322 | + $this->getStyle(), |
|
323 | + ); |
|
324 | + foreach ($assets as $asset) { |
|
325 | + if ($asset instanceof BrowserAsset && $asset->isRegistered()) { |
|
326 | + $asset->enqueueAsset(); |
|
327 | + } |
|
328 | + } |
|
329 | + } |
|
330 | 330 | |
331 | 331 | } |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function setEditorScriptHandle($editor_script_handle) |
59 | 59 | { |
60 | - if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
61 | - $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
60 | + if (strpos($editor_script_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
61 | + $editor_script_handle = BlockInterface::NAME_SPACE.'-'.$editor_script_handle; |
|
62 | 62 | } |
63 | 63 | $this->editor_script_handle = $editor_script_handle; |
64 | 64 | } |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function setEditorStyleHandle($editor_style_handle) |
80 | 80 | { |
81 | - if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
82 | - $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
81 | + if (strpos($editor_style_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
82 | + $editor_style_handle = BlockInterface::NAME_SPACE.'-'.$editor_style_handle; |
|
83 | 83 | } |
84 | 84 | $this->editor_style_handle = $editor_style_handle; |
85 | 85 | } |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function setScriptHandle($script_handle) |
101 | 101 | { |
102 | - if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
103 | - $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
102 | + if (strpos($script_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
103 | + $script_handle = BlockInterface::NAME_SPACE.'-'.$script_handle; |
|
104 | 104 | } |
105 | 105 | $this->script_handle = $script_handle; |
106 | 106 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function setStyleHandle($style_handle) |
122 | 122 | { |
123 | - if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
124 | - $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
123 | + if (strpos($style_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
124 | + $style_handle = BlockInterface::NAME_SPACE.'-'.$style_handle; |
|
125 | 125 | } |
126 | 126 | $this->style_handle = $style_handle; |
127 | 127 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function addEditorScript($handle, array $dependencies = array()) |
154 | 154 | { |
155 | - if($this->assets->has($handle)){ |
|
155 | + if ($this->assets->has($handle)) { |
|
156 | 156 | return $this->assets->get($handle); |
157 | 157 | } |
158 | 158 | return parent::addJavascript( |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | { |
252 | 252 | $dependencies += array( |
253 | 253 | CoreAssetManager::JS_HANDLE_EE_DATA_STORES, |
254 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | - 'wp-i18n', // Provides localization functions |
|
256 | - 'wp-element', // Provides React.Component |
|
254 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | + 'wp-i18n', // Provides localization functions |
|
256 | + 'wp-element', // Provides React.Component |
|
257 | 257 | 'wp-components' // Provides many prebuilt components and controls |
258 | 258 | ); |
259 | 259 | return $dependencies; |
@@ -19,470 +19,470 @@ |
||
19 | 19 | class Collection extends SplObjectStorage implements CollectionInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * a unique string for identifying this collection |
|
24 | - * |
|
25 | - * @type string $collection_identifier |
|
26 | - */ |
|
27 | - protected $collection_identifier; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
32 | - * this should be set from within the child class constructor |
|
33 | - * |
|
34 | - * @type string $interface |
|
35 | - */ |
|
36 | - protected $collection_interface; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Collection constructor |
|
41 | - * |
|
42 | - * @param string $collection_interface |
|
43 | - * @throws InvalidInterfaceException |
|
44 | - */ |
|
45 | - public function __construct($collection_interface) |
|
46 | - { |
|
47 | - $this->setCollectionInterface($collection_interface); |
|
48 | - $this->setCollectionIdentifier(); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function collectionIdentifier() |
|
56 | - { |
|
57 | - return $this->collection_identifier; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
63 | - * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
64 | - * |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - protected function setCollectionIdentifier() |
|
68 | - { |
|
69 | - // hash a few collection details |
|
70 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
71 | - // grab a few characters from the start, middle, and end of the hash |
|
72 | - $id = array(); |
|
73 | - for ($x = 0; $x < 19; $x += 9) { |
|
74 | - $id[] = substr($identifier, $x, 3); |
|
75 | - } |
|
76 | - $identifier = basename(str_replace('\\', '/', get_class($this))); |
|
77 | - $identifier .= '-' . strtoupper(implode('-', $id)); |
|
78 | - $this->collection_identifier = $identifier; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * setCollectionInterface |
|
84 | - * |
|
85 | - * @param string $collection_interface |
|
86 | - * @throws InvalidInterfaceException |
|
87 | - */ |
|
88 | - protected function setCollectionInterface($collection_interface) |
|
89 | - { |
|
90 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
91 | - throw new InvalidInterfaceException($collection_interface); |
|
92 | - } |
|
93 | - $this->collection_interface = $collection_interface; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * add |
|
99 | - * attaches an object to the Collection |
|
100 | - * and sets any supplied data associated with the current iterator entry |
|
101 | - * by calling EE_Object_Collection::set_identifier() |
|
102 | - * |
|
103 | - * @param $object |
|
104 | - * @param mixed $identifier |
|
105 | - * @return bool |
|
106 | - * @throws InvalidEntityException |
|
107 | - * @throws DuplicateCollectionIdentifierException |
|
108 | - */ |
|
109 | - public function add($object, $identifier = null) |
|
110 | - { |
|
111 | - if (! $object instanceof $this->collection_interface) { |
|
112 | - throw new InvalidEntityException($object, $this->collection_interface); |
|
113 | - } |
|
114 | - if ($this->contains($object)) { |
|
115 | - throw new DuplicateCollectionIdentifierException($identifier); |
|
116 | - } |
|
117 | - $this->attach($object); |
|
118 | - $this->setIdentifier($object, $identifier); |
|
119 | - return $this->contains($object); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * setIdentifier |
|
125 | - * Sets the data associated with an object in the Collection |
|
126 | - * if no $identifier is supplied, then the spl_object_hash() is used |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param $object |
|
130 | - * @param mixed $identifier |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function setIdentifier($object, $identifier = null) |
|
134 | - { |
|
135 | - $identifier = ! empty($identifier) |
|
136 | - ? $identifier |
|
137 | - : spl_object_hash($object); |
|
138 | - $this->rewind(); |
|
139 | - while ($this->valid()) { |
|
140 | - if ($object === $this->current()) { |
|
141 | - $this->setInfo($identifier); |
|
142 | - $this->rewind(); |
|
143 | - return true; |
|
144 | - } |
|
145 | - $this->next(); |
|
146 | - } |
|
147 | - return false; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * get |
|
153 | - * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
154 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
155 | - * |
|
156 | - * @access public |
|
157 | - * @param mixed $identifier |
|
158 | - * @return mixed |
|
159 | - */ |
|
160 | - public function get($identifier) |
|
161 | - { |
|
162 | - $this->rewind(); |
|
163 | - while ($this->valid()) { |
|
164 | - if ($identifier === $this->getInfo()) { |
|
165 | - $object = $this->current(); |
|
166 | - $this->rewind(); |
|
167 | - return $object; |
|
168 | - } |
|
169 | - $this->next(); |
|
170 | - } |
|
171 | - return null; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * has |
|
177 | - * returns TRUE or FALSE |
|
178 | - * depending on whether the object is within the Collection |
|
179 | - * based on the supplied $identifier |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * @param mixed $identifier |
|
183 | - * @return bool |
|
184 | - */ |
|
185 | - public function has($identifier) |
|
186 | - { |
|
187 | - $this->rewind(); |
|
188 | - while ($this->valid()) { |
|
189 | - if ($identifier === $this->getInfo()) { |
|
190 | - $this->rewind(); |
|
191 | - return true; |
|
192 | - } |
|
193 | - $this->next(); |
|
194 | - } |
|
195 | - return false; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * hasObject |
|
201 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
202 | - * |
|
203 | - * @access public |
|
204 | - * @param $object |
|
205 | - * @return bool |
|
206 | - */ |
|
207 | - public function hasObject($object) |
|
208 | - { |
|
209 | - return $this->contains($object); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * hasObjects |
|
215 | - * returns true if there are objects within the Collection, and false if it is empty |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @return bool |
|
219 | - */ |
|
220 | - public function hasObjects() |
|
221 | - { |
|
222 | - return $this->count() !== 0; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * isEmpty |
|
228 | - * returns true if there are no objects within the Collection, and false if there are |
|
229 | - * |
|
230 | - * @access public |
|
231 | - * @return bool |
|
232 | - */ |
|
233 | - public function isEmpty() |
|
234 | - { |
|
235 | - return $this->count() === 0; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * remove |
|
241 | - * detaches an object from the Collection |
|
242 | - * |
|
243 | - * @access public |
|
244 | - * @param $object |
|
245 | - * @return bool |
|
246 | - */ |
|
247 | - public function remove($object) |
|
248 | - { |
|
249 | - $this->detach($object); |
|
250 | - return true; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * setCurrent |
|
256 | - * advances pointer to the object whose identifier matches that which was provided |
|
257 | - * |
|
258 | - * @access public |
|
259 | - * @param mixed $identifier |
|
260 | - * @return boolean |
|
261 | - */ |
|
262 | - public function setCurrent($identifier) |
|
263 | - { |
|
264 | - $this->rewind(); |
|
265 | - while ($this->valid()) { |
|
266 | - if ($identifier === $this->getInfo()) { |
|
267 | - return true; |
|
268 | - } |
|
269 | - $this->next(); |
|
270 | - } |
|
271 | - return false; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * setCurrentUsingObject |
|
277 | - * advances pointer to the provided object |
|
278 | - * |
|
279 | - * @access public |
|
280 | - * @param $object |
|
281 | - * @return boolean |
|
282 | - */ |
|
283 | - public function setCurrentUsingObject($object) |
|
284 | - { |
|
285 | - $this->rewind(); |
|
286 | - while ($this->valid()) { |
|
287 | - if ($this->current() === $object) { |
|
288 | - return true; |
|
289 | - } |
|
290 | - $this->next(); |
|
291 | - } |
|
292 | - return false; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns the object occupying the index before the current object, |
|
298 | - * unless this is already the first object, in which case it just returns the first object |
|
299 | - * |
|
300 | - * @return mixed |
|
301 | - */ |
|
302 | - public function previous() |
|
303 | - { |
|
304 | - $index = $this->indexOf($this->current()); |
|
305 | - if ($index === 0) { |
|
306 | - return $this->current(); |
|
307 | - } |
|
308 | - $index--; |
|
309 | - return $this->objectAtIndex($index); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Returns the index of a given object, or false if not found |
|
315 | - * |
|
316 | - * @see http://stackoverflow.com/a/8736013 |
|
317 | - * @param $object |
|
318 | - * @return boolean|int|string |
|
319 | - */ |
|
320 | - public function indexOf($object) |
|
321 | - { |
|
322 | - if (! $this->contains($object)) { |
|
323 | - return false; |
|
324 | - } |
|
325 | - foreach ($this as $index => $obj) { |
|
326 | - if ($obj === $object) { |
|
327 | - return $index; |
|
328 | - } |
|
329 | - } |
|
330 | - return false; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Returns the object at the given index |
|
336 | - * |
|
337 | - * @see http://stackoverflow.com/a/8736013 |
|
338 | - * @param int $index |
|
339 | - * @return mixed |
|
340 | - */ |
|
341 | - public function objectAtIndex($index) |
|
342 | - { |
|
343 | - $iterator = new LimitIterator($this, $index, 1); |
|
344 | - $iterator->rewind(); |
|
345 | - return $iterator->current(); |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * Returns the sequence of objects as specified by the offset and length |
|
351 | - * |
|
352 | - * @see http://stackoverflow.com/a/8736013 |
|
353 | - * @param int $offset |
|
354 | - * @param int $length |
|
355 | - * @return array |
|
356 | - */ |
|
357 | - public function slice($offset, $length) |
|
358 | - { |
|
359 | - $slice = array(); |
|
360 | - $iterator = new LimitIterator($this, $offset, $length); |
|
361 | - foreach ($iterator as $object) { |
|
362 | - $slice[] = $object; |
|
363 | - } |
|
364 | - return $slice; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Inserts an object at a certain point |
|
370 | - * |
|
371 | - * @see http://stackoverflow.com/a/8736013 |
|
372 | - * @param mixed $object A single object |
|
373 | - * @param int $index |
|
374 | - * @param mixed $identifier |
|
375 | - * @return bool |
|
376 | - * @throws DuplicateCollectionIdentifierException |
|
377 | - * @throws InvalidEntityException |
|
378 | - */ |
|
379 | - public function insertObjectAt($object, $index, $identifier = null) |
|
380 | - { |
|
381 | - // check to ensure that objects don't already exist in the collection |
|
382 | - if ($this->has($identifier)) { |
|
383 | - throw new DuplicateCollectionIdentifierException($identifier); |
|
384 | - } |
|
385 | - // detach any objects at or past this index |
|
386 | - $remaining_objects = array(); |
|
387 | - if ($index < $this->count()) { |
|
388 | - $remaining_objects = $this->slice($index, $this->count() - $index); |
|
389 | - foreach ($remaining_objects as $key => $remaining_object) { |
|
390 | - // we need to grab the identifiers for each object and use them as keys |
|
391 | - $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
392 | - // and then remove the object from the current tracking array |
|
393 | - unset($remaining_objects[ $key ]); |
|
394 | - // and then remove it from the Collection |
|
395 | - $this->detach($remaining_object); |
|
396 | - } |
|
397 | - } |
|
398 | - // add the new object we're splicing in |
|
399 | - $this->add($object, $identifier); |
|
400 | - // attach the objects we previously detached |
|
401 | - foreach ($remaining_objects as $key => $remaining_object) { |
|
402 | - $this->add($remaining_object, $key); |
|
403 | - } |
|
404 | - return $this->contains($object); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Inserts an object (or an array of objects) at a certain point |
|
410 | - * |
|
411 | - * @see http://stackoverflow.com/a/8736013 |
|
412 | - * @param mixed $objects A single object or an array of objects |
|
413 | - * @param int $index |
|
414 | - */ |
|
415 | - public function insertAt($objects, $index) |
|
416 | - { |
|
417 | - if (! is_array($objects)) { |
|
418 | - $objects = array($objects); |
|
419 | - } |
|
420 | - // check to ensure that objects don't already exist in the collection |
|
421 | - foreach ($objects as $key => $object) { |
|
422 | - if ($this->contains($object)) { |
|
423 | - unset($objects[ $key ]); |
|
424 | - } |
|
425 | - } |
|
426 | - // do we have any objects left? |
|
427 | - if (! $objects) { |
|
428 | - return; |
|
429 | - } |
|
430 | - // detach any objects at or past this index |
|
431 | - $remaining = array(); |
|
432 | - if ($index < $this->count()) { |
|
433 | - $remaining = $this->slice($index, $this->count() - $index); |
|
434 | - foreach ($remaining as $object) { |
|
435 | - $this->detach($object); |
|
436 | - } |
|
437 | - } |
|
438 | - // add the new objects we're splicing in |
|
439 | - foreach ($objects as $object) { |
|
440 | - $this->attach($object); |
|
441 | - } |
|
442 | - // attach the objects we previously detached |
|
443 | - foreach ($remaining as $object) { |
|
444 | - $this->attach($object); |
|
445 | - } |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * Removes the object at the given index |
|
451 | - * |
|
452 | - * @see http://stackoverflow.com/a/8736013 |
|
453 | - * @param int $index |
|
454 | - */ |
|
455 | - public function removeAt($index) |
|
456 | - { |
|
457 | - $this->detach($this->objectAtIndex($index)); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * detaches ALL objects from the Collection |
|
463 | - */ |
|
464 | - public function detachAll() |
|
465 | - { |
|
466 | - $this->rewind(); |
|
467 | - while ($this->valid()) { |
|
468 | - $object = $this->current(); |
|
469 | - $this->next(); |
|
470 | - $this->detach($object); |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * unsets and detaches ALL objects from the Collection |
|
477 | - */ |
|
478 | - public function trashAndDetachAll() |
|
479 | - { |
|
480 | - $this->rewind(); |
|
481 | - while ($this->valid()) { |
|
482 | - $object = $this->current(); |
|
483 | - $this->next(); |
|
484 | - $this->detach($object); |
|
485 | - unset($object); |
|
486 | - } |
|
487 | - } |
|
22 | + /** |
|
23 | + * a unique string for identifying this collection |
|
24 | + * |
|
25 | + * @type string $collection_identifier |
|
26 | + */ |
|
27 | + protected $collection_identifier; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
32 | + * this should be set from within the child class constructor |
|
33 | + * |
|
34 | + * @type string $interface |
|
35 | + */ |
|
36 | + protected $collection_interface; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Collection constructor |
|
41 | + * |
|
42 | + * @param string $collection_interface |
|
43 | + * @throws InvalidInterfaceException |
|
44 | + */ |
|
45 | + public function __construct($collection_interface) |
|
46 | + { |
|
47 | + $this->setCollectionInterface($collection_interface); |
|
48 | + $this->setCollectionIdentifier(); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function collectionIdentifier() |
|
56 | + { |
|
57 | + return $this->collection_identifier; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
63 | + * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
64 | + * |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + protected function setCollectionIdentifier() |
|
68 | + { |
|
69 | + // hash a few collection details |
|
70 | + $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
71 | + // grab a few characters from the start, middle, and end of the hash |
|
72 | + $id = array(); |
|
73 | + for ($x = 0; $x < 19; $x += 9) { |
|
74 | + $id[] = substr($identifier, $x, 3); |
|
75 | + } |
|
76 | + $identifier = basename(str_replace('\\', '/', get_class($this))); |
|
77 | + $identifier .= '-' . strtoupper(implode('-', $id)); |
|
78 | + $this->collection_identifier = $identifier; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * setCollectionInterface |
|
84 | + * |
|
85 | + * @param string $collection_interface |
|
86 | + * @throws InvalidInterfaceException |
|
87 | + */ |
|
88 | + protected function setCollectionInterface($collection_interface) |
|
89 | + { |
|
90 | + if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
91 | + throw new InvalidInterfaceException($collection_interface); |
|
92 | + } |
|
93 | + $this->collection_interface = $collection_interface; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * add |
|
99 | + * attaches an object to the Collection |
|
100 | + * and sets any supplied data associated with the current iterator entry |
|
101 | + * by calling EE_Object_Collection::set_identifier() |
|
102 | + * |
|
103 | + * @param $object |
|
104 | + * @param mixed $identifier |
|
105 | + * @return bool |
|
106 | + * @throws InvalidEntityException |
|
107 | + * @throws DuplicateCollectionIdentifierException |
|
108 | + */ |
|
109 | + public function add($object, $identifier = null) |
|
110 | + { |
|
111 | + if (! $object instanceof $this->collection_interface) { |
|
112 | + throw new InvalidEntityException($object, $this->collection_interface); |
|
113 | + } |
|
114 | + if ($this->contains($object)) { |
|
115 | + throw new DuplicateCollectionIdentifierException($identifier); |
|
116 | + } |
|
117 | + $this->attach($object); |
|
118 | + $this->setIdentifier($object, $identifier); |
|
119 | + return $this->contains($object); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * setIdentifier |
|
125 | + * Sets the data associated with an object in the Collection |
|
126 | + * if no $identifier is supplied, then the spl_object_hash() is used |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param $object |
|
130 | + * @param mixed $identifier |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function setIdentifier($object, $identifier = null) |
|
134 | + { |
|
135 | + $identifier = ! empty($identifier) |
|
136 | + ? $identifier |
|
137 | + : spl_object_hash($object); |
|
138 | + $this->rewind(); |
|
139 | + while ($this->valid()) { |
|
140 | + if ($object === $this->current()) { |
|
141 | + $this->setInfo($identifier); |
|
142 | + $this->rewind(); |
|
143 | + return true; |
|
144 | + } |
|
145 | + $this->next(); |
|
146 | + } |
|
147 | + return false; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * get |
|
153 | + * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
154 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
155 | + * |
|
156 | + * @access public |
|
157 | + * @param mixed $identifier |
|
158 | + * @return mixed |
|
159 | + */ |
|
160 | + public function get($identifier) |
|
161 | + { |
|
162 | + $this->rewind(); |
|
163 | + while ($this->valid()) { |
|
164 | + if ($identifier === $this->getInfo()) { |
|
165 | + $object = $this->current(); |
|
166 | + $this->rewind(); |
|
167 | + return $object; |
|
168 | + } |
|
169 | + $this->next(); |
|
170 | + } |
|
171 | + return null; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * has |
|
177 | + * returns TRUE or FALSE |
|
178 | + * depending on whether the object is within the Collection |
|
179 | + * based on the supplied $identifier |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * @param mixed $identifier |
|
183 | + * @return bool |
|
184 | + */ |
|
185 | + public function has($identifier) |
|
186 | + { |
|
187 | + $this->rewind(); |
|
188 | + while ($this->valid()) { |
|
189 | + if ($identifier === $this->getInfo()) { |
|
190 | + $this->rewind(); |
|
191 | + return true; |
|
192 | + } |
|
193 | + $this->next(); |
|
194 | + } |
|
195 | + return false; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * hasObject |
|
201 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
202 | + * |
|
203 | + * @access public |
|
204 | + * @param $object |
|
205 | + * @return bool |
|
206 | + */ |
|
207 | + public function hasObject($object) |
|
208 | + { |
|
209 | + return $this->contains($object); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * hasObjects |
|
215 | + * returns true if there are objects within the Collection, and false if it is empty |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @return bool |
|
219 | + */ |
|
220 | + public function hasObjects() |
|
221 | + { |
|
222 | + return $this->count() !== 0; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * isEmpty |
|
228 | + * returns true if there are no objects within the Collection, and false if there are |
|
229 | + * |
|
230 | + * @access public |
|
231 | + * @return bool |
|
232 | + */ |
|
233 | + public function isEmpty() |
|
234 | + { |
|
235 | + return $this->count() === 0; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * remove |
|
241 | + * detaches an object from the Collection |
|
242 | + * |
|
243 | + * @access public |
|
244 | + * @param $object |
|
245 | + * @return bool |
|
246 | + */ |
|
247 | + public function remove($object) |
|
248 | + { |
|
249 | + $this->detach($object); |
|
250 | + return true; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * setCurrent |
|
256 | + * advances pointer to the object whose identifier matches that which was provided |
|
257 | + * |
|
258 | + * @access public |
|
259 | + * @param mixed $identifier |
|
260 | + * @return boolean |
|
261 | + */ |
|
262 | + public function setCurrent($identifier) |
|
263 | + { |
|
264 | + $this->rewind(); |
|
265 | + while ($this->valid()) { |
|
266 | + if ($identifier === $this->getInfo()) { |
|
267 | + return true; |
|
268 | + } |
|
269 | + $this->next(); |
|
270 | + } |
|
271 | + return false; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * setCurrentUsingObject |
|
277 | + * advances pointer to the provided object |
|
278 | + * |
|
279 | + * @access public |
|
280 | + * @param $object |
|
281 | + * @return boolean |
|
282 | + */ |
|
283 | + public function setCurrentUsingObject($object) |
|
284 | + { |
|
285 | + $this->rewind(); |
|
286 | + while ($this->valid()) { |
|
287 | + if ($this->current() === $object) { |
|
288 | + return true; |
|
289 | + } |
|
290 | + $this->next(); |
|
291 | + } |
|
292 | + return false; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns the object occupying the index before the current object, |
|
298 | + * unless this is already the first object, in which case it just returns the first object |
|
299 | + * |
|
300 | + * @return mixed |
|
301 | + */ |
|
302 | + public function previous() |
|
303 | + { |
|
304 | + $index = $this->indexOf($this->current()); |
|
305 | + if ($index === 0) { |
|
306 | + return $this->current(); |
|
307 | + } |
|
308 | + $index--; |
|
309 | + return $this->objectAtIndex($index); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Returns the index of a given object, or false if not found |
|
315 | + * |
|
316 | + * @see http://stackoverflow.com/a/8736013 |
|
317 | + * @param $object |
|
318 | + * @return boolean|int|string |
|
319 | + */ |
|
320 | + public function indexOf($object) |
|
321 | + { |
|
322 | + if (! $this->contains($object)) { |
|
323 | + return false; |
|
324 | + } |
|
325 | + foreach ($this as $index => $obj) { |
|
326 | + if ($obj === $object) { |
|
327 | + return $index; |
|
328 | + } |
|
329 | + } |
|
330 | + return false; |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Returns the object at the given index |
|
336 | + * |
|
337 | + * @see http://stackoverflow.com/a/8736013 |
|
338 | + * @param int $index |
|
339 | + * @return mixed |
|
340 | + */ |
|
341 | + public function objectAtIndex($index) |
|
342 | + { |
|
343 | + $iterator = new LimitIterator($this, $index, 1); |
|
344 | + $iterator->rewind(); |
|
345 | + return $iterator->current(); |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * Returns the sequence of objects as specified by the offset and length |
|
351 | + * |
|
352 | + * @see http://stackoverflow.com/a/8736013 |
|
353 | + * @param int $offset |
|
354 | + * @param int $length |
|
355 | + * @return array |
|
356 | + */ |
|
357 | + public function slice($offset, $length) |
|
358 | + { |
|
359 | + $slice = array(); |
|
360 | + $iterator = new LimitIterator($this, $offset, $length); |
|
361 | + foreach ($iterator as $object) { |
|
362 | + $slice[] = $object; |
|
363 | + } |
|
364 | + return $slice; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Inserts an object at a certain point |
|
370 | + * |
|
371 | + * @see http://stackoverflow.com/a/8736013 |
|
372 | + * @param mixed $object A single object |
|
373 | + * @param int $index |
|
374 | + * @param mixed $identifier |
|
375 | + * @return bool |
|
376 | + * @throws DuplicateCollectionIdentifierException |
|
377 | + * @throws InvalidEntityException |
|
378 | + */ |
|
379 | + public function insertObjectAt($object, $index, $identifier = null) |
|
380 | + { |
|
381 | + // check to ensure that objects don't already exist in the collection |
|
382 | + if ($this->has($identifier)) { |
|
383 | + throw new DuplicateCollectionIdentifierException($identifier); |
|
384 | + } |
|
385 | + // detach any objects at or past this index |
|
386 | + $remaining_objects = array(); |
|
387 | + if ($index < $this->count()) { |
|
388 | + $remaining_objects = $this->slice($index, $this->count() - $index); |
|
389 | + foreach ($remaining_objects as $key => $remaining_object) { |
|
390 | + // we need to grab the identifiers for each object and use them as keys |
|
391 | + $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
392 | + // and then remove the object from the current tracking array |
|
393 | + unset($remaining_objects[ $key ]); |
|
394 | + // and then remove it from the Collection |
|
395 | + $this->detach($remaining_object); |
|
396 | + } |
|
397 | + } |
|
398 | + // add the new object we're splicing in |
|
399 | + $this->add($object, $identifier); |
|
400 | + // attach the objects we previously detached |
|
401 | + foreach ($remaining_objects as $key => $remaining_object) { |
|
402 | + $this->add($remaining_object, $key); |
|
403 | + } |
|
404 | + return $this->contains($object); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Inserts an object (or an array of objects) at a certain point |
|
410 | + * |
|
411 | + * @see http://stackoverflow.com/a/8736013 |
|
412 | + * @param mixed $objects A single object or an array of objects |
|
413 | + * @param int $index |
|
414 | + */ |
|
415 | + public function insertAt($objects, $index) |
|
416 | + { |
|
417 | + if (! is_array($objects)) { |
|
418 | + $objects = array($objects); |
|
419 | + } |
|
420 | + // check to ensure that objects don't already exist in the collection |
|
421 | + foreach ($objects as $key => $object) { |
|
422 | + if ($this->contains($object)) { |
|
423 | + unset($objects[ $key ]); |
|
424 | + } |
|
425 | + } |
|
426 | + // do we have any objects left? |
|
427 | + if (! $objects) { |
|
428 | + return; |
|
429 | + } |
|
430 | + // detach any objects at or past this index |
|
431 | + $remaining = array(); |
|
432 | + if ($index < $this->count()) { |
|
433 | + $remaining = $this->slice($index, $this->count() - $index); |
|
434 | + foreach ($remaining as $object) { |
|
435 | + $this->detach($object); |
|
436 | + } |
|
437 | + } |
|
438 | + // add the new objects we're splicing in |
|
439 | + foreach ($objects as $object) { |
|
440 | + $this->attach($object); |
|
441 | + } |
|
442 | + // attach the objects we previously detached |
|
443 | + foreach ($remaining as $object) { |
|
444 | + $this->attach($object); |
|
445 | + } |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * Removes the object at the given index |
|
451 | + * |
|
452 | + * @see http://stackoverflow.com/a/8736013 |
|
453 | + * @param int $index |
|
454 | + */ |
|
455 | + public function removeAt($index) |
|
456 | + { |
|
457 | + $this->detach($this->objectAtIndex($index)); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * detaches ALL objects from the Collection |
|
463 | + */ |
|
464 | + public function detachAll() |
|
465 | + { |
|
466 | + $this->rewind(); |
|
467 | + while ($this->valid()) { |
|
468 | + $object = $this->current(); |
|
469 | + $this->next(); |
|
470 | + $this->detach($object); |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * unsets and detaches ALL objects from the Collection |
|
477 | + */ |
|
478 | + public function trashAndDetachAll() |
|
479 | + { |
|
480 | + $this->rewind(); |
|
481 | + while ($this->valid()) { |
|
482 | + $object = $this->current(); |
|
483 | + $this->next(); |
|
484 | + $this->detach($object); |
|
485 | + unset($object); |
|
486 | + } |
|
487 | + } |
|
488 | 488 | } |