@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | ) { |
88 | 88 | try { |
89 | 89 | $this->collection_details = $collection_details; |
90 | - if (! $collection instanceof CollectionInterface) { |
|
90 | + if ( ! $collection instanceof CollectionInterface) { |
|
91 | 91 | $collection = new Collection($this->collection_details->getCollectionInterface()); |
92 | 92 | } |
93 | 93 | $this->collection = $collection; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | protected function loadAllFromFilepaths() |
121 | 121 | { |
122 | - if (! $this->file_locator instanceof FileLocator) { |
|
122 | + if ( ! $this->file_locator instanceof FileLocator) { |
|
123 | 123 | $this->file_locator = new FileLocator(); |
124 | 124 | } |
125 | 125 | $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | */ |
153 | 153 | protected function loadClassFromFilepath($filepath) |
154 | 154 | { |
155 | - if (! is_string($filepath)) { |
|
155 | + if ( ! is_string($filepath)) { |
|
156 | 156 | throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
157 | 157 | } |
158 | - if (! is_readable($filepath)) { |
|
158 | + if ( ! is_readable($filepath)) { |
|
159 | 159 | throw new InvalidFilePathException($filepath); |
160 | 160 | } |
161 | 161 | require_once $filepath; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $file_name = basename($filepath); |
164 | 164 | // now remove any file extensions |
165 | 165 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
166 | - if (! class_exists($class_name)) { |
|
166 | + if ( ! class_exists($class_name)) { |
|
167 | 167 | throw new InvalidClassException($class_name); |
168 | 168 | } |
169 | 169 | $entity = $this->entity_factory instanceof FactoryInterface |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | // objects added to the collection based on entity callback, so the entity itself decides |
238 | 238 | case CollectionDetails::ID_CALLBACK_METHOD: |
239 | 239 | $identifier_callback = $this->collection_details->identifierCallback(); |
240 | - if (! method_exists($entity, $identifier_callback)) { |
|
240 | + if ( ! method_exists($entity, $identifier_callback)) { |
|
241 | 241 | throw new InvalidEntityException( |
242 | 242 | $entity, |
243 | 243 | $this->collection_details->getCollectionInterface(), |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | */ |
304 | 304 | protected function loadClassFromFQCN($FQCN) |
305 | 305 | { |
306 | - if (! is_string($FQCN)) { |
|
306 | + if ( ! is_string($FQCN)) { |
|
307 | 307 | throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
308 | 308 | } |
309 | - if (! class_exists($FQCN)) { |
|
309 | + if ( ! class_exists($FQCN)) { |
|
310 | 310 | throw new InvalidClassException($FQCN); |
311 | 311 | } |
312 | 312 | do_action( |
@@ -28,295 +28,295 @@ |
||
28 | 28 | */ |
29 | 29 | class CollectionLoader |
30 | 30 | { |
31 | - /** |
|
32 | - * possible return value when adding entities to a collection. |
|
33 | - * denotes that the entity was NOT ADDED to the collection |
|
34 | - */ |
|
35 | - const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
31 | + /** |
|
32 | + * possible return value when adding entities to a collection. |
|
33 | + * denotes that the entity was NOT ADDED to the collection |
|
34 | + */ |
|
35 | + const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * possible return value when adding entities to a collection. |
|
39 | - * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
40 | - */ |
|
41 | - const ENTITY_ADDED = 'entity-added-to-collection'; |
|
37 | + /** |
|
38 | + * possible return value when adding entities to a collection. |
|
39 | + * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
40 | + */ |
|
41 | + const ENTITY_ADDED = 'entity-added-to-collection'; |
|
42 | 42 | |
43 | - /** |
|
44 | - * possible return value when adding entities to a collection. |
|
45 | - * denotes that the entity was ALREADY ADDED to the collection, |
|
46 | - * and therefore could not be added again. |
|
47 | - */ |
|
48 | - const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
43 | + /** |
|
44 | + * possible return value when adding entities to a collection. |
|
45 | + * denotes that the entity was ALREADY ADDED to the collection, |
|
46 | + * and therefore could not be added again. |
|
47 | + */ |
|
48 | + const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @var CollectionDetailsInterface $collection_details |
|
53 | - */ |
|
54 | - protected $collection_details; |
|
51 | + /** |
|
52 | + * @var CollectionDetailsInterface $collection_details |
|
53 | + */ |
|
54 | + protected $collection_details; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @var CollectionInterface $collection |
|
58 | - */ |
|
59 | - protected $collection; |
|
56 | + /** |
|
57 | + * @var CollectionInterface $collection |
|
58 | + */ |
|
59 | + protected $collection; |
|
60 | 60 | |
61 | - /** |
|
62 | - * @var FactoryInterface $entity_factory |
|
63 | - */ |
|
64 | - protected $entity_factory; |
|
61 | + /** |
|
62 | + * @var FactoryInterface $entity_factory |
|
63 | + */ |
|
64 | + protected $entity_factory; |
|
65 | 65 | |
66 | - /** |
|
67 | - * @var FileLocator $file_locator |
|
68 | - */ |
|
69 | - protected $file_locator; |
|
66 | + /** |
|
67 | + * @var FileLocator $file_locator |
|
68 | + */ |
|
69 | + protected $file_locator; |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * CollectionLoader constructor. |
|
74 | - * |
|
75 | - * @param CollectionDetailsInterface $collection_details |
|
76 | - * @param CollectionInterface $collection |
|
77 | - * @param LocatorInterface $file_locator |
|
78 | - * @param FactoryInterface|null $entity_factory |
|
79 | - * @throws CollectionLoaderException |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - CollectionDetailsInterface $collection_details, |
|
83 | - CollectionInterface $collection = null, |
|
84 | - LocatorInterface $file_locator = null, |
|
85 | - FactoryInterface $entity_factory = null |
|
86 | - ) { |
|
87 | - try { |
|
88 | - $this->collection_details = $collection_details; |
|
89 | - if (! $collection instanceof CollectionInterface) { |
|
90 | - $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
91 | - } |
|
92 | - $this->collection = $collection; |
|
93 | - $this->file_locator = $file_locator; |
|
94 | - $this->entity_factory = $entity_factory; |
|
95 | - $this->loadAllFromFilepaths(); |
|
96 | - $this->loadFromFQCNs(); |
|
97 | - } catch (Exception $exception) { |
|
98 | - throw new CollectionLoaderException($exception); |
|
99 | - } |
|
100 | - } |
|
72 | + /** |
|
73 | + * CollectionLoader constructor. |
|
74 | + * |
|
75 | + * @param CollectionDetailsInterface $collection_details |
|
76 | + * @param CollectionInterface $collection |
|
77 | + * @param LocatorInterface $file_locator |
|
78 | + * @param FactoryInterface|null $entity_factory |
|
79 | + * @throws CollectionLoaderException |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + CollectionDetailsInterface $collection_details, |
|
83 | + CollectionInterface $collection = null, |
|
84 | + LocatorInterface $file_locator = null, |
|
85 | + FactoryInterface $entity_factory = null |
|
86 | + ) { |
|
87 | + try { |
|
88 | + $this->collection_details = $collection_details; |
|
89 | + if (! $collection instanceof CollectionInterface) { |
|
90 | + $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
91 | + } |
|
92 | + $this->collection = $collection; |
|
93 | + $this->file_locator = $file_locator; |
|
94 | + $this->entity_factory = $entity_factory; |
|
95 | + $this->loadAllFromFilepaths(); |
|
96 | + $this->loadFromFQCNs(); |
|
97 | + } catch (Exception $exception) { |
|
98 | + throw new CollectionLoaderException($exception); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * @return CollectionInterface |
|
105 | - */ |
|
106 | - public function getCollection() |
|
107 | - { |
|
108 | - return $this->collection; |
|
109 | - } |
|
103 | + /** |
|
104 | + * @return CollectionInterface |
|
105 | + */ |
|
106 | + public function getCollection() |
|
107 | + { |
|
108 | + return $this->collection; |
|
109 | + } |
|
110 | 110 | |
111 | 111 | |
112 | - /** |
|
113 | - * @throws InvalidClassException |
|
114 | - * @throws InvalidFilePathException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws InvalidEntityException |
|
117 | - * @throws DuplicateCollectionIdentifierException |
|
118 | - */ |
|
119 | - protected function loadAllFromFilepaths() |
|
120 | - { |
|
121 | - if (! $this->file_locator instanceof FileLocator) { |
|
122 | - $this->file_locator = new FileLocator(); |
|
123 | - } |
|
124 | - $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
125 | - // find all of the files that match the file mask in the specified folder |
|
126 | - $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
127 | - // filter the results |
|
128 | - $filepaths = (array) apply_filters( |
|
129 | - 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
130 | - $this->file_locator->getFilePaths(), |
|
131 | - $this->collection_details->collectionName(), |
|
132 | - $this->collection_details |
|
133 | - ); |
|
134 | - if (empty($filepaths)) { |
|
135 | - return; |
|
136 | - } |
|
137 | - foreach ($filepaths as $filepath) { |
|
138 | - $this->loadClassFromFilepath($filepath); |
|
139 | - } |
|
140 | - } |
|
112 | + /** |
|
113 | + * @throws InvalidClassException |
|
114 | + * @throws InvalidFilePathException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws InvalidEntityException |
|
117 | + * @throws DuplicateCollectionIdentifierException |
|
118 | + */ |
|
119 | + protected function loadAllFromFilepaths() |
|
120 | + { |
|
121 | + if (! $this->file_locator instanceof FileLocator) { |
|
122 | + $this->file_locator = new FileLocator(); |
|
123 | + } |
|
124 | + $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
125 | + // find all of the files that match the file mask in the specified folder |
|
126 | + $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
127 | + // filter the results |
|
128 | + $filepaths = (array) apply_filters( |
|
129 | + 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
130 | + $this->file_locator->getFilePaths(), |
|
131 | + $this->collection_details->collectionName(), |
|
132 | + $this->collection_details |
|
133 | + ); |
|
134 | + if (empty($filepaths)) { |
|
135 | + return; |
|
136 | + } |
|
137 | + foreach ($filepaths as $filepath) { |
|
138 | + $this->loadClassFromFilepath($filepath); |
|
139 | + } |
|
140 | + } |
|
141 | 141 | |
142 | 142 | |
143 | - /** |
|
144 | - * @param string $filepath |
|
145 | - * @return string |
|
146 | - * @throws InvalidEntityException |
|
147 | - * @throws InvalidDataTypeException |
|
148 | - * @throws InvalidFilePathException |
|
149 | - * @throws InvalidClassException |
|
150 | - * @throws DuplicateCollectionIdentifierException |
|
151 | - */ |
|
152 | - protected function loadClassFromFilepath($filepath) |
|
153 | - { |
|
154 | - if (! is_string($filepath)) { |
|
155 | - throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
156 | - } |
|
157 | - if (! is_readable($filepath)) { |
|
158 | - throw new InvalidFilePathException($filepath); |
|
159 | - } |
|
160 | - require_once $filepath; |
|
161 | - // extract filename from path |
|
162 | - $file_name = basename($filepath); |
|
163 | - // now remove any file extensions |
|
164 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
165 | - if (! class_exists($class_name)) { |
|
166 | - throw new InvalidClassException($class_name); |
|
167 | - } |
|
168 | - $entity = $this->entity_factory instanceof FactoryInterface |
|
169 | - ? call_user_func(array($this->entity_factory, 'create'), $class_name) |
|
170 | - : new $class_name(); |
|
171 | - return $this->addEntityToCollection($entity, $file_name); |
|
172 | - } |
|
143 | + /** |
|
144 | + * @param string $filepath |
|
145 | + * @return string |
|
146 | + * @throws InvalidEntityException |
|
147 | + * @throws InvalidDataTypeException |
|
148 | + * @throws InvalidFilePathException |
|
149 | + * @throws InvalidClassException |
|
150 | + * @throws DuplicateCollectionIdentifierException |
|
151 | + */ |
|
152 | + protected function loadClassFromFilepath($filepath) |
|
153 | + { |
|
154 | + if (! is_string($filepath)) { |
|
155 | + throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
156 | + } |
|
157 | + if (! is_readable($filepath)) { |
|
158 | + throw new InvalidFilePathException($filepath); |
|
159 | + } |
|
160 | + require_once $filepath; |
|
161 | + // extract filename from path |
|
162 | + $file_name = basename($filepath); |
|
163 | + // now remove any file extensions |
|
164 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
165 | + if (! class_exists($class_name)) { |
|
166 | + throw new InvalidClassException($class_name); |
|
167 | + } |
|
168 | + $entity = $this->entity_factory instanceof FactoryInterface |
|
169 | + ? call_user_func(array($this->entity_factory, 'create'), $class_name) |
|
170 | + : new $class_name(); |
|
171 | + return $this->addEntityToCollection($entity, $file_name); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * @param $entity |
|
177 | - * @param mixed $identifier |
|
178 | - * @return string |
|
179 | - * @throws InvalidEntityException |
|
180 | - * @throws DuplicateCollectionIdentifierException |
|
181 | - */ |
|
182 | - protected function addEntityToCollection($entity, $identifier) |
|
183 | - { |
|
184 | - do_action( |
|
185 | - 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
186 | - $entity, |
|
187 | - $this->collection_details->collectionName(), |
|
188 | - $this->collection_details |
|
189 | - ); |
|
190 | - $identifier = $this->setIdentifier($entity, $identifier); |
|
191 | - if ($this->collection->has($identifier)) { |
|
192 | - do_action( |
|
193 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
194 | - $this, |
|
195 | - $this->collection_details->collectionName(), |
|
196 | - $this->collection_details |
|
197 | - ); |
|
198 | - return CollectionLoader::ENTITY_EXISTS; |
|
199 | - } |
|
200 | - if ($this->collection->add($entity, $identifier)) { |
|
201 | - do_action( |
|
202 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
203 | - $this, |
|
204 | - $this->collection_details->collectionName(), |
|
205 | - $this->collection_details |
|
206 | - ); |
|
207 | - return CollectionLoader::ENTITY_ADDED; |
|
208 | - } |
|
209 | - do_action( |
|
210 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
211 | - $this, |
|
212 | - $this->collection_details->collectionName(), |
|
213 | - $this->collection_details |
|
214 | - ); |
|
215 | - return CollectionLoader::ENTITY_NOT_ADDED; |
|
216 | - } |
|
175 | + /** |
|
176 | + * @param $entity |
|
177 | + * @param mixed $identifier |
|
178 | + * @return string |
|
179 | + * @throws InvalidEntityException |
|
180 | + * @throws DuplicateCollectionIdentifierException |
|
181 | + */ |
|
182 | + protected function addEntityToCollection($entity, $identifier) |
|
183 | + { |
|
184 | + do_action( |
|
185 | + 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
186 | + $entity, |
|
187 | + $this->collection_details->collectionName(), |
|
188 | + $this->collection_details |
|
189 | + ); |
|
190 | + $identifier = $this->setIdentifier($entity, $identifier); |
|
191 | + if ($this->collection->has($identifier)) { |
|
192 | + do_action( |
|
193 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
194 | + $this, |
|
195 | + $this->collection_details->collectionName(), |
|
196 | + $this->collection_details |
|
197 | + ); |
|
198 | + return CollectionLoader::ENTITY_EXISTS; |
|
199 | + } |
|
200 | + if ($this->collection->add($entity, $identifier)) { |
|
201 | + do_action( |
|
202 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
203 | + $this, |
|
204 | + $this->collection_details->collectionName(), |
|
205 | + $this->collection_details |
|
206 | + ); |
|
207 | + return CollectionLoader::ENTITY_ADDED; |
|
208 | + } |
|
209 | + do_action( |
|
210 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
211 | + $this, |
|
212 | + $this->collection_details->collectionName(), |
|
213 | + $this->collection_details |
|
214 | + ); |
|
215 | + return CollectionLoader::ENTITY_NOT_ADDED; |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | - /** |
|
220 | - * @param $entity |
|
221 | - * @param mixed $identifier |
|
222 | - * @return string |
|
223 | - * @throws InvalidEntityException |
|
224 | - */ |
|
225 | - protected function setIdentifier($entity, $identifier) |
|
226 | - { |
|
227 | - switch ($this->collection_details->identifierType()) { |
|
228 | - // every unique object gets added to the collection, but not duplicates of the exact same object |
|
229 | - case CollectionDetails::ID_OBJECT_HASH: |
|
230 | - $identifier = spl_object_hash($entity); |
|
231 | - break; |
|
232 | - // only one entity per class can be added to collection, like a singleton |
|
233 | - case CollectionDetails::ID_CLASS_NAME: |
|
234 | - $identifier = get_class($entity); |
|
235 | - break; |
|
236 | - // objects added to the collection based on entity callback, so the entity itself decides |
|
237 | - case CollectionDetails::ID_CALLBACK_METHOD: |
|
238 | - $identifier_callback = $this->collection_details->identifierCallback(); |
|
239 | - if (! method_exists($entity, $identifier_callback)) { |
|
240 | - throw new InvalidEntityException( |
|
241 | - $entity, |
|
242 | - $this->collection_details->getCollectionInterface(), |
|
243 | - sprintf( |
|
244 | - esc_html__( |
|
245 | - 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
219 | + /** |
|
220 | + * @param $entity |
|
221 | + * @param mixed $identifier |
|
222 | + * @return string |
|
223 | + * @throws InvalidEntityException |
|
224 | + */ |
|
225 | + protected function setIdentifier($entity, $identifier) |
|
226 | + { |
|
227 | + switch ($this->collection_details->identifierType()) { |
|
228 | + // every unique object gets added to the collection, but not duplicates of the exact same object |
|
229 | + case CollectionDetails::ID_OBJECT_HASH: |
|
230 | + $identifier = spl_object_hash($entity); |
|
231 | + break; |
|
232 | + // only one entity per class can be added to collection, like a singleton |
|
233 | + case CollectionDetails::ID_CLASS_NAME: |
|
234 | + $identifier = get_class($entity); |
|
235 | + break; |
|
236 | + // objects added to the collection based on entity callback, so the entity itself decides |
|
237 | + case CollectionDetails::ID_CALLBACK_METHOD: |
|
238 | + $identifier_callback = $this->collection_details->identifierCallback(); |
|
239 | + if (! method_exists($entity, $identifier_callback)) { |
|
240 | + throw new InvalidEntityException( |
|
241 | + $entity, |
|
242 | + $this->collection_details->getCollectionInterface(), |
|
243 | + sprintf( |
|
244 | + esc_html__( |
|
245 | + 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
246 | 246 | of "%2$s", but does not contain this method.', |
247 | - 'event_espresso' |
|
248 | - ), |
|
249 | - $identifier_callback, |
|
250 | - get_class($entity) |
|
251 | - ) |
|
252 | - ); |
|
253 | - } |
|
254 | - $identifier = $entity->{$identifier_callback}(); |
|
255 | - break; |
|
256 | - } |
|
257 | - return apply_filters( |
|
258 | - 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
259 | - $identifier, |
|
260 | - $this->collection_details->collectionName(), |
|
261 | - $this->collection_details |
|
262 | - ); |
|
263 | - } |
|
247 | + 'event_espresso' |
|
248 | + ), |
|
249 | + $identifier_callback, |
|
250 | + get_class($entity) |
|
251 | + ) |
|
252 | + ); |
|
253 | + } |
|
254 | + $identifier = $entity->{$identifier_callback}(); |
|
255 | + break; |
|
256 | + } |
|
257 | + return apply_filters( |
|
258 | + 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
259 | + $identifier, |
|
260 | + $this->collection_details->collectionName(), |
|
261 | + $this->collection_details |
|
262 | + ); |
|
263 | + } |
|
264 | 264 | |
265 | 265 | |
266 | - /** |
|
267 | - * @throws ReflectionException |
|
268 | - * @throws InvalidArgumentException |
|
269 | - * @throws InvalidInterfaceException |
|
270 | - * @throws EE_Error |
|
271 | - * @throws InvalidClassException |
|
272 | - * @throws InvalidDataTypeException |
|
273 | - * @throws InvalidEntityException |
|
274 | - * @throws DuplicateCollectionIdentifierException |
|
275 | - */ |
|
276 | - protected function loadFromFQCNs() |
|
277 | - { |
|
278 | - $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
279 | - $FQCNs = (array) apply_filters( |
|
280 | - 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
281 | - $FQCNs, |
|
282 | - $this->collection_details->collectionName(), |
|
283 | - $this->collection_details |
|
284 | - ); |
|
285 | - foreach ($FQCNs as $FQCN) { |
|
286 | - $this->loadClassFromFQCN($FQCN); |
|
287 | - } |
|
288 | - } |
|
266 | + /** |
|
267 | + * @throws ReflectionException |
|
268 | + * @throws InvalidArgumentException |
|
269 | + * @throws InvalidInterfaceException |
|
270 | + * @throws EE_Error |
|
271 | + * @throws InvalidClassException |
|
272 | + * @throws InvalidDataTypeException |
|
273 | + * @throws InvalidEntityException |
|
274 | + * @throws DuplicateCollectionIdentifierException |
|
275 | + */ |
|
276 | + protected function loadFromFQCNs() |
|
277 | + { |
|
278 | + $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
279 | + $FQCNs = (array) apply_filters( |
|
280 | + 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
281 | + $FQCNs, |
|
282 | + $this->collection_details->collectionName(), |
|
283 | + $this->collection_details |
|
284 | + ); |
|
285 | + foreach ($FQCNs as $FQCN) { |
|
286 | + $this->loadClassFromFQCN($FQCN); |
|
287 | + } |
|
288 | + } |
|
289 | 289 | |
290 | 290 | |
291 | - /** |
|
292 | - * @param string $FQCN Fully Qualified Class Name |
|
293 | - * @return string |
|
294 | - * @throws InvalidArgumentException |
|
295 | - * @throws InvalidInterfaceException |
|
296 | - * @throws ReflectionException |
|
297 | - * @throws EE_Error |
|
298 | - * @throws InvalidEntityException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws InvalidClassException |
|
301 | - * @throws DuplicateCollectionIdentifierException |
|
302 | - */ |
|
303 | - protected function loadClassFromFQCN($FQCN) |
|
304 | - { |
|
305 | - if (! is_string($FQCN)) { |
|
306 | - throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
307 | - } |
|
308 | - if (! class_exists($FQCN)) { |
|
309 | - throw new InvalidClassException($FQCN); |
|
310 | - } |
|
311 | - do_action( |
|
312 | - 'FHEE__CollectionLoader__loadClassFromFQCN__beforeLoading', |
|
313 | - $FQCN, |
|
314 | - $this->collection_details->collectionName(), |
|
315 | - $this->collection_details |
|
316 | - ); |
|
317 | - $entity = $this->entity_factory instanceof FactoryInterface |
|
318 | - ? call_user_func(array($this->entity_factory, 'create'), $FQCN) |
|
319 | - : EE_Registry::instance()->create($FQCN); |
|
320 | - return $this->addEntityToCollection($entity, $FQCN); |
|
321 | - } |
|
291 | + /** |
|
292 | + * @param string $FQCN Fully Qualified Class Name |
|
293 | + * @return string |
|
294 | + * @throws InvalidArgumentException |
|
295 | + * @throws InvalidInterfaceException |
|
296 | + * @throws ReflectionException |
|
297 | + * @throws EE_Error |
|
298 | + * @throws InvalidEntityException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws InvalidClassException |
|
301 | + * @throws DuplicateCollectionIdentifierException |
|
302 | + */ |
|
303 | + protected function loadClassFromFQCN($FQCN) |
|
304 | + { |
|
305 | + if (! is_string($FQCN)) { |
|
306 | + throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
307 | + } |
|
308 | + if (! class_exists($FQCN)) { |
|
309 | + throw new InvalidClassException($FQCN); |
|
310 | + } |
|
311 | + do_action( |
|
312 | + 'FHEE__CollectionLoader__loadClassFromFQCN__beforeLoading', |
|
313 | + $FQCN, |
|
314 | + $this->collection_details->collectionName(), |
|
315 | + $this->collection_details |
|
316 | + ); |
|
317 | + $entity = $this->entity_factory instanceof FactoryInterface |
|
318 | + ? call_user_func(array($this->entity_factory, 'create'), $FQCN) |
|
319 | + : EE_Registry::instance()->create($FQCN); |
|
320 | + return $this->addEntityToCollection($entity, $FQCN); |
|
321 | + } |
|
322 | 322 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | // If not, then attempt to deal with any errors, |
101 | 101 | // otherwise, try to hobble along without the session |
102 | - if (! $this->handleSessionSaveHandlerErrors()) { |
|
102 | + if ( ! $this->handleSessionSaveHandlerErrors()) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | // there is no record of a fatal error while trying to start the session |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | ), |
250 | 250 | '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">', |
251 | 251 | '</a>', |
252 | - '<a href="' . $retry_session_url . '">' |
|
252 | + '<a href="'.$retry_session_url.'">' |
|
253 | 253 | ), |
254 | 254 | __FILE__, |
255 | 255 | __FUNCTION__, |
@@ -27,237 +27,237 @@ |
||
27 | 27 | */ |
28 | 28 | class SessionStartHandler |
29 | 29 | { |
30 | - const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status'; |
|
31 | - const REQUEST_PARAM_RETRY_SESSION = 'ee_retry_session'; |
|
32 | - const SESSION_SAVE_HANDLER_STATUS_FAILED = 'session_save_handler_failed'; |
|
33 | - const SESSION_SAVE_HANDLER_STATUS_SUCCESS = 'session_save_handler_success'; |
|
34 | - const SESSION_SAVE_HANDLER_STATUS_UNKNOWN = 'session_save_handler_untested'; |
|
30 | + const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status'; |
|
31 | + const REQUEST_PARAM_RETRY_SESSION = 'ee_retry_session'; |
|
32 | + const SESSION_SAVE_HANDLER_STATUS_FAILED = 'session_save_handler_failed'; |
|
33 | + const SESSION_SAVE_HANDLER_STATUS_SUCCESS = 'session_save_handler_success'; |
|
34 | + const SESSION_SAVE_HANDLER_STATUS_UNKNOWN = 'session_save_handler_untested'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var RequestInterface $request |
|
38 | - */ |
|
39 | - protected $request; |
|
36 | + /** |
|
37 | + * @var RequestInterface $request |
|
38 | + */ |
|
39 | + protected $request; |
|
40 | 40 | |
41 | - /** |
|
42 | - * StartSession constructor. |
|
43 | - * |
|
44 | - * @param RequestInterface $request |
|
45 | - */ |
|
46 | - public function __construct(RequestInterface $request) |
|
47 | - { |
|
48 | - $this->request = $request; |
|
49 | - } |
|
41 | + /** |
|
42 | + * StartSession constructor. |
|
43 | + * |
|
44 | + * @param RequestInterface $request |
|
45 | + */ |
|
46 | + public function __construct(RequestInterface $request) |
|
47 | + { |
|
48 | + $this->request = $request; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Check if a custom session save handler is in play |
|
53 | - * and attempt to start the PHP session |
|
54 | - * |
|
55 | - * @since 4.9.68.p |
|
56 | - */ |
|
57 | - public function startSession() |
|
58 | - { |
|
59 | - // check that session has started |
|
60 | - if (session_id() === '') { |
|
61 | - // starts a new session if one doesn't already exist, or re-initiates an existing one |
|
62 | - if ($this->hasKnownCustomSessionSaveHandler()) { |
|
63 | - $this->checkCustomSessionSaveHandler(); |
|
64 | - } else { |
|
65 | - session_start(); |
|
66 | - session_write_close(); |
|
67 | - } |
|
68 | - } |
|
69 | - } |
|
51 | + /** |
|
52 | + * Check if a custom session save handler is in play |
|
53 | + * and attempt to start the PHP session |
|
54 | + * |
|
55 | + * @since 4.9.68.p |
|
56 | + */ |
|
57 | + public function startSession() |
|
58 | + { |
|
59 | + // check that session has started |
|
60 | + if (session_id() === '') { |
|
61 | + // starts a new session if one doesn't already exist, or re-initiates an existing one |
|
62 | + if ($this->hasKnownCustomSessionSaveHandler()) { |
|
63 | + $this->checkCustomSessionSaveHandler(); |
|
64 | + } else { |
|
65 | + session_start(); |
|
66 | + session_write_close(); |
|
67 | + } |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler |
|
73 | - * |
|
74 | - * @since 4.9.68.p |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - private function hasKnownCustomSessionSaveHandler() |
|
78 | - { |
|
79 | - return in_array( |
|
80 | - ini_get('session.save_handler'), |
|
81 | - array( |
|
82 | - 'user', |
|
83 | - ), |
|
84 | - true |
|
85 | - ); |
|
86 | - } |
|
71 | + /** |
|
72 | + * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler |
|
73 | + * |
|
74 | + * @since 4.9.68.p |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + private function hasKnownCustomSessionSaveHandler() |
|
78 | + { |
|
79 | + return in_array( |
|
80 | + ini_get('session.save_handler'), |
|
81 | + array( |
|
82 | + 'user', |
|
83 | + ), |
|
84 | + true |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Attempt to start the PHP session when a custom Session Save Handler is known to be set. |
|
90 | - * |
|
91 | - * @since 4.9.68.p |
|
92 | - */ |
|
93 | - private function checkCustomSessionSaveHandler() |
|
94 | - { |
|
95 | - // If we've already successfully tested the session save handler |
|
96 | - // on a previous request then just start the session |
|
97 | - if ($this->sessionSaveHandlerIsValid()) { |
|
98 | - session_start(); |
|
99 | - session_write_close(); |
|
100 | - return; |
|
101 | - } |
|
102 | - // If not, then attempt to deal with any errors, |
|
103 | - // otherwise, try to hobble along without the session |
|
104 | - if (! $this->handleSessionSaveHandlerErrors()) { |
|
105 | - return; |
|
106 | - } |
|
107 | - // there is no record of a fatal error while trying to start the session |
|
108 | - // so let's see if there's a custom session save handler. Proceed with caution |
|
109 | - $this->initializeSessionSaveHandlerStatus(); |
|
110 | - // hold your breath, the custom session save handler might cause a fatal here... |
|
111 | - session_start(); |
|
112 | - session_write_close(); |
|
113 | - // phew! we made it! the custom session handler is a-ok |
|
114 | - $this->setSessionSaveHandlerStatusToValid(); |
|
115 | - } |
|
88 | + /** |
|
89 | + * Attempt to start the PHP session when a custom Session Save Handler is known to be set. |
|
90 | + * |
|
91 | + * @since 4.9.68.p |
|
92 | + */ |
|
93 | + private function checkCustomSessionSaveHandler() |
|
94 | + { |
|
95 | + // If we've already successfully tested the session save handler |
|
96 | + // on a previous request then just start the session |
|
97 | + if ($this->sessionSaveHandlerIsValid()) { |
|
98 | + session_start(); |
|
99 | + session_write_close(); |
|
100 | + return; |
|
101 | + } |
|
102 | + // If not, then attempt to deal with any errors, |
|
103 | + // otherwise, try to hobble along without the session |
|
104 | + if (! $this->handleSessionSaveHandlerErrors()) { |
|
105 | + return; |
|
106 | + } |
|
107 | + // there is no record of a fatal error while trying to start the session |
|
108 | + // so let's see if there's a custom session save handler. Proceed with caution |
|
109 | + $this->initializeSessionSaveHandlerStatus(); |
|
110 | + // hold your breath, the custom session save handler might cause a fatal here... |
|
111 | + session_start(); |
|
112 | + session_write_close(); |
|
113 | + // phew! we made it! the custom session handler is a-ok |
|
114 | + $this->setSessionSaveHandlerStatusToValid(); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * retrieves the value for the 'ee_session_save_handler_status' WP option. |
|
120 | - * default value = 'session_save_handler_untested' |
|
121 | - * |
|
122 | - * @since 4.9.68.p |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - private function getSessionSaveHandlerStatus() |
|
126 | - { |
|
127 | - return get_option( |
|
128 | - SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
129 | - SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN |
|
130 | - ); |
|
131 | - } |
|
118 | + /** |
|
119 | + * retrieves the value for the 'ee_session_save_handler_status' WP option. |
|
120 | + * default value = 'session_save_handler_untested' |
|
121 | + * |
|
122 | + * @since 4.9.68.p |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + private function getSessionSaveHandlerStatus() |
|
126 | + { |
|
127 | + return get_option( |
|
128 | + SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
129 | + SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN |
|
130 | + ); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed' |
|
135 | - * which can then be upgraded is everything works correctly |
|
136 | - * |
|
137 | - * @since 4.9.68.p |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - private function initializeSessionSaveHandlerStatus() |
|
141 | - { |
|
142 | - return update_option( |
|
143 | - SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
144 | - SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED |
|
145 | - ); |
|
146 | - } |
|
133 | + /** |
|
134 | + * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed' |
|
135 | + * which can then be upgraded is everything works correctly |
|
136 | + * |
|
137 | + * @since 4.9.68.p |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + private function initializeSessionSaveHandlerStatus() |
|
141 | + { |
|
142 | + return update_option( |
|
143 | + SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
144 | + SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED |
|
145 | + ); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success' |
|
150 | - * |
|
151 | - * @since 4.9.68.p |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - private function setSessionSaveHandlerStatusToValid() |
|
155 | - { |
|
156 | - return update_option( |
|
157 | - SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
158 | - SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS |
|
159 | - ); |
|
160 | - } |
|
148 | + /** |
|
149 | + * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success' |
|
150 | + * |
|
151 | + * @since 4.9.68.p |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + private function setSessionSaveHandlerStatusToValid() |
|
155 | + { |
|
156 | + return update_option( |
|
157 | + SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
158 | + SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS |
|
159 | + ); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested' |
|
164 | - * |
|
165 | - * @since 4.9.68.p |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - private function resetSessionSaveHandlerStatus() |
|
169 | - { |
|
170 | - return update_option( |
|
171 | - SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
172 | - SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN |
|
173 | - ); |
|
174 | - } |
|
162 | + /** |
|
163 | + * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested' |
|
164 | + * |
|
165 | + * @since 4.9.68.p |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + private function resetSessionSaveHandlerStatus() |
|
169 | + { |
|
170 | + return update_option( |
|
171 | + SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
172 | + SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN |
|
173 | + ); |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Returns `true` if the 'ee_session_save_handler_status' WP option value |
|
178 | - * is equal to 'session_save_handler_success' |
|
179 | - * |
|
180 | - * @since 4.9.68.p |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - private function sessionSaveHandlerIsValid() |
|
184 | - { |
|
185 | - return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS; |
|
186 | - } |
|
176 | + /** |
|
177 | + * Returns `true` if the 'ee_session_save_handler_status' WP option value |
|
178 | + * is equal to 'session_save_handler_success' |
|
179 | + * |
|
180 | + * @since 4.9.68.p |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + private function sessionSaveHandlerIsValid() |
|
184 | + { |
|
185 | + return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS; |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Returns `true` if the 'ee_session_save_handler_status' WP option value |
|
190 | - * is equal to 'session_save_handler_failed' |
|
191 | - * |
|
192 | - * @since 4.9.68.p |
|
193 | - * @return bool |
|
194 | - */ |
|
195 | - private function sessionSaveHandlerFailed() |
|
196 | - { |
|
197 | - return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED; |
|
198 | - } |
|
188 | + /** |
|
189 | + * Returns `true` if the 'ee_session_save_handler_status' WP option value |
|
190 | + * is equal to 'session_save_handler_failed' |
|
191 | + * |
|
192 | + * @since 4.9.68.p |
|
193 | + * @return bool |
|
194 | + */ |
|
195 | + private function sessionSaveHandlerFailed() |
|
196 | + { |
|
197 | + return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED; |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * Returns `true` if no errors were detected with the session save handler, |
|
202 | - * otherwise attempts to work notify the appropriate authorities |
|
203 | - * with a suggestion for how to fix the issue, and returns `false`. |
|
204 | - * |
|
205 | - * |
|
206 | - * @since 4.9.68.p |
|
207 | - * @return bool |
|
208 | - */ |
|
209 | - private function handleSessionSaveHandlerErrors() |
|
210 | - { |
|
211 | - // Check if we had a fatal error last time while trying to start the session |
|
212 | - if ($this->sessionSaveHandlerFailed()) { |
|
213 | - // apparently, last time we tried using the custom session save handler there was a fatal |
|
214 | - if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) { |
|
215 | - $this->resetSessionSaveHandlerStatus(); |
|
216 | - // remove "ee_retry_session", otherwise if the problem still isn't fixed, |
|
217 | - // we'll just keep getting the fatal error over and over. |
|
218 | - // Better to remove it and redirect, and try on the next request |
|
219 | - EEH_URL::safeRedirectAndExit( |
|
220 | - remove_query_arg( |
|
221 | - array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION), |
|
222 | - EEH_URL::current_url() |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - // so the session is broken, don't try it again, |
|
227 | - // just show a message to users that can fix it |
|
228 | - $this->displaySessionSaveHandlerErrorNotice(); |
|
229 | - return false; |
|
230 | - } |
|
231 | - return true; |
|
232 | - } |
|
200 | + /** |
|
201 | + * Returns `true` if no errors were detected with the session save handler, |
|
202 | + * otherwise attempts to work notify the appropriate authorities |
|
203 | + * with a suggestion for how to fix the issue, and returns `false`. |
|
204 | + * |
|
205 | + * |
|
206 | + * @since 4.9.68.p |
|
207 | + * @return bool |
|
208 | + */ |
|
209 | + private function handleSessionSaveHandlerErrors() |
|
210 | + { |
|
211 | + // Check if we had a fatal error last time while trying to start the session |
|
212 | + if ($this->sessionSaveHandlerFailed()) { |
|
213 | + // apparently, last time we tried using the custom session save handler there was a fatal |
|
214 | + if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) { |
|
215 | + $this->resetSessionSaveHandlerStatus(); |
|
216 | + // remove "ee_retry_session", otherwise if the problem still isn't fixed, |
|
217 | + // we'll just keep getting the fatal error over and over. |
|
218 | + // Better to remove it and redirect, and try on the next request |
|
219 | + EEH_URL::safeRedirectAndExit( |
|
220 | + remove_query_arg( |
|
221 | + array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION), |
|
222 | + EEH_URL::current_url() |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + // so the session is broken, don't try it again, |
|
227 | + // just show a message to users that can fix it |
|
228 | + $this->displaySessionSaveHandlerErrorNotice(); |
|
229 | + return false; |
|
230 | + } |
|
231 | + return true; |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * Generates an EE_Error notice regarding the current session woes |
|
236 | - * but only if the current user is an admin with permission to 'install_plugins'. |
|
237 | - * |
|
238 | - * @since 4.9.68.p |
|
239 | - */ |
|
240 | - private function displaySessionSaveHandlerErrorNotice() |
|
241 | - { |
|
242 | - if (current_user_can('install_plugins')) { |
|
243 | - $retry_session_url = add_query_arg( |
|
244 | - array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true), |
|
245 | - EEH_URL::current_url() |
|
246 | - ); |
|
247 | - EE_Error::add_error( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">', |
|
254 | - '</a>', |
|
255 | - '<a href="' . $retry_session_url . '">' |
|
256 | - ), |
|
257 | - __FILE__, |
|
258 | - __FUNCTION__, |
|
259 | - __LINE__ |
|
260 | - ); |
|
261 | - } |
|
262 | - } |
|
234 | + /** |
|
235 | + * Generates an EE_Error notice regarding the current session woes |
|
236 | + * but only if the current user is an admin with permission to 'install_plugins'. |
|
237 | + * |
|
238 | + * @since 4.9.68.p |
|
239 | + */ |
|
240 | + private function displaySessionSaveHandlerErrorNotice() |
|
241 | + { |
|
242 | + if (current_user_can('install_plugins')) { |
|
243 | + $retry_session_url = add_query_arg( |
|
244 | + array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true), |
|
245 | + EEH_URL::current_url() |
|
246 | + ); |
|
247 | + EE_Error::add_error( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">', |
|
254 | + '</a>', |
|
255 | + '<a href="' . $retry_session_url . '">' |
|
256 | + ), |
|
257 | + __FILE__, |
|
258 | + __FUNCTION__, |
|
259 | + __LINE__ |
|
260 | + ); |
|
261 | + } |
|
262 | + } |
|
263 | 263 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct($alias, $fqcn) |
36 | 36 | { |
37 | - if (! is_subclass_of($fqcn, $alias)) { |
|
37 | + if ( ! is_subclass_of($fqcn, $alias)) { |
|
38 | 38 | throw new InvalidAliasException($fqcn, $alias); |
39 | 39 | } |
40 | 40 | $this->alias = $alias; |
@@ -16,46 +16,46 @@ |
||
16 | 16 | */ |
17 | 17 | class ClassAlias |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string $alias an interface or base class representing what object |
|
21 | - * can be utilized by another object and/or function |
|
22 | - */ |
|
23 | - private $alias; |
|
19 | + /** |
|
20 | + * @var string $alias an interface or base class representing what object |
|
21 | + * can be utilized by another object and/or function |
|
22 | + */ |
|
23 | + private $alias; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var string $fqcn the actual class that should be substituted for the alias above |
|
27 | - */ |
|
28 | - private $fqcn; |
|
25 | + /** |
|
26 | + * @var string $fqcn the actual class that should be substituted for the alias above |
|
27 | + */ |
|
28 | + private $fqcn; |
|
29 | 29 | |
30 | - /** |
|
31 | - * ClassAlias constructor. |
|
32 | - * |
|
33 | - * @param string $alias Interface specified by implementing class |
|
34 | - * @param string $fqcn Concrete class that satisfies interface |
|
35 | - * @throws InvalidAliasException |
|
36 | - */ |
|
37 | - public function __construct($alias, $fqcn) |
|
38 | - { |
|
39 | - if (! is_subclass_of($fqcn, $alias)) { |
|
40 | - throw new InvalidAliasException($fqcn, $alias); |
|
41 | - } |
|
42 | - $this->alias = $alias; |
|
43 | - $this->fqcn = $fqcn; |
|
44 | - } |
|
30 | + /** |
|
31 | + * ClassAlias constructor. |
|
32 | + * |
|
33 | + * @param string $alias Interface specified by implementing class |
|
34 | + * @param string $fqcn Concrete class that satisfies interface |
|
35 | + * @throws InvalidAliasException |
|
36 | + */ |
|
37 | + public function __construct($alias, $fqcn) |
|
38 | + { |
|
39 | + if (! is_subclass_of($fqcn, $alias)) { |
|
40 | + throw new InvalidAliasException($fqcn, $alias); |
|
41 | + } |
|
42 | + $this->alias = $alias; |
|
43 | + $this->fqcn = $fqcn; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function alias() |
|
50 | - { |
|
51 | - return $this->alias; |
|
52 | - } |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function alias() |
|
50 | + { |
|
51 | + return $this->alias; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function fqcn() |
|
58 | - { |
|
59 | - return $this->fqcn; |
|
60 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function fqcn() |
|
58 | + { |
|
59 | + return $this->fqcn; |
|
60 | + } |
|
61 | 61 | } |
@@ -18,41 +18,41 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class FactoryWithDependencyResolver implements FactoryInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @var DependencyResolverInterface $dependency_resolver |
|
23 | - */ |
|
24 | - private $dependency_resolver; |
|
21 | + /** |
|
22 | + * @var DependencyResolverInterface $dependency_resolver |
|
23 | + */ |
|
24 | + private $dependency_resolver; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var LoaderInterface $loader |
|
28 | - */ |
|
29 | - private $loader; |
|
26 | + /** |
|
27 | + * @var LoaderInterface $loader |
|
28 | + */ |
|
29 | + private $loader; |
|
30 | 30 | |
31 | - /** |
|
32 | - * FactoryWithDependencyResolver constructor. |
|
33 | - * |
|
34 | - * @param DependencyResolverInterface $dependency_resolver |
|
35 | - * @param LoaderInterface $loader |
|
36 | - */ |
|
37 | - public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader) |
|
38 | - { |
|
39 | - $this->dependency_resolver = $dependency_resolver; |
|
40 | - $this->loader = $loader; |
|
41 | - } |
|
31 | + /** |
|
32 | + * FactoryWithDependencyResolver constructor. |
|
33 | + * |
|
34 | + * @param DependencyResolverInterface $dependency_resolver |
|
35 | + * @param LoaderInterface $loader |
|
36 | + */ |
|
37 | + public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader) |
|
38 | + { |
|
39 | + $this->dependency_resolver = $dependency_resolver; |
|
40 | + $this->loader = $loader; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return DependencyResolverInterface |
|
45 | - */ |
|
46 | - public function dependencyResolver() |
|
47 | - { |
|
48 | - return $this->dependency_resolver; |
|
49 | - } |
|
43 | + /** |
|
44 | + * @return DependencyResolverInterface |
|
45 | + */ |
|
46 | + public function dependencyResolver() |
|
47 | + { |
|
48 | + return $this->dependency_resolver; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return LoaderInterface |
|
53 | - */ |
|
54 | - public function loader() |
|
55 | - { |
|
56 | - return $this->loader; |
|
57 | - } |
|
51 | + /** |
|
52 | + * @return LoaderInterface |
|
53 | + */ |
|
54 | + public function loader() |
|
55 | + { |
|
56 | + return $this->loader; |
|
57 | + } |
|
58 | 58 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | public function isMatchingRoute() |
24 | 24 | { |
25 | 25 | foreach ($this->specifications as $specification) { |
26 | - if (! $specification->isMatchingRoute()) { |
|
26 | + if ( ! $specification->isMatchingRoute()) { |
|
27 | 27 | return false; |
28 | 28 | } |
29 | 29 | } |
@@ -13,19 +13,19 @@ |
||
13 | 13 | */ |
14 | 14 | class MatchAllRouteSpecifications extends MultiRouteSpecification |
15 | 15 | { |
16 | - /** |
|
17 | - * returns true if current request matches specification |
|
18 | - * |
|
19 | - * @since 4.9.71.p |
|
20 | - * @return boolean |
|
21 | - */ |
|
22 | - public function isMatchingRoute() |
|
23 | - { |
|
24 | - foreach ($this->specifications as $specification) { |
|
25 | - if (! $specification->isMatchingRoute()) { |
|
26 | - return false; |
|
27 | - } |
|
28 | - } |
|
29 | - return true; |
|
30 | - } |
|
16 | + /** |
|
17 | + * returns true if current request matches specification |
|
18 | + * |
|
19 | + * @since 4.9.71.p |
|
20 | + * @return boolean |
|
21 | + */ |
|
22 | + public function isMatchingRoute() |
|
23 | + { |
|
24 | + foreach ($this->specifications as $specification) { |
|
25 | + if (! $specification->isMatchingRoute()) { |
|
26 | + return false; |
|
27 | + } |
|
28 | + } |
|
29 | + return true; |
|
30 | + } |
|
31 | 31 | } |
@@ -115,7 +115,7 @@ |
||
115 | 115 | { |
116 | 116 | /** @var RouteMatchSpecificationInterface $specification */ |
117 | 117 | $specification = $this->specifications->get($routeMatchSpecificationFqcn); |
118 | - if (! $specification instanceof $routeMatchSpecificationFqcn) { |
|
118 | + if ( ! $specification instanceof $routeMatchSpecificationFqcn) { |
|
119 | 119 | throw new InvalidClassException($routeMatchSpecificationFqcn); |
120 | 120 | } |
121 | 121 | return $specification->isMatchingRoute(); |
@@ -25,122 +25,122 @@ |
||
25 | 25 | */ |
26 | 26 | class RouteMatchSpecificationManager |
27 | 27 | { |
28 | - /** |
|
29 | - * @var CollectionInterface[]|RouteMatchSpecificationInterface[] $specifications |
|
30 | - */ |
|
31 | - private $specifications; |
|
28 | + /** |
|
29 | + * @var CollectionInterface[]|RouteMatchSpecificationInterface[] $specifications |
|
30 | + */ |
|
31 | + private $specifications; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var RouteMatchSpecificationFactory $specifications_factory |
|
35 | - */ |
|
36 | - private $specifications_factory; |
|
33 | + /** |
|
34 | + * @var RouteMatchSpecificationFactory $specifications_factory |
|
35 | + */ |
|
36 | + private $specifications_factory; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * RouteMatchSpecificationManager constructor. |
|
41 | - * |
|
42 | - * @param RouteMatchSpecificationCollection $specifications |
|
43 | - * @param RouteMatchSpecificationFactory $specifications_factory |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - RouteMatchSpecificationCollection $specifications, |
|
47 | - RouteMatchSpecificationFactory $specifications_factory |
|
48 | - ) { |
|
49 | - $this->specifications = $specifications; |
|
50 | - $this->specifications_factory = $specifications_factory; |
|
51 | - add_action('AHEE__EE_System__loadRouteMatchSpecifications', array($this, 'initialize')); |
|
52 | - } |
|
39 | + /** |
|
40 | + * RouteMatchSpecificationManager constructor. |
|
41 | + * |
|
42 | + * @param RouteMatchSpecificationCollection $specifications |
|
43 | + * @param RouteMatchSpecificationFactory $specifications_factory |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + RouteMatchSpecificationCollection $specifications, |
|
47 | + RouteMatchSpecificationFactory $specifications_factory |
|
48 | + ) { |
|
49 | + $this->specifications = $specifications; |
|
50 | + $this->specifications_factory = $specifications_factory; |
|
51 | + add_action('AHEE__EE_System__loadRouteMatchSpecifications', array($this, 'initialize')); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Perform any early setup required for block editors to functions |
|
57 | - * |
|
58 | - * @return void |
|
59 | - * @throws CollectionLoaderException |
|
60 | - * @throws CollectionDetailsException |
|
61 | - */ |
|
62 | - public function initialize() |
|
63 | - { |
|
64 | - $this->populateSpecificationCollection(); |
|
65 | - } |
|
55 | + /** |
|
56 | + * Perform any early setup required for block editors to functions |
|
57 | + * |
|
58 | + * @return void |
|
59 | + * @throws CollectionLoaderException |
|
60 | + * @throws CollectionDetailsException |
|
61 | + */ |
|
62 | + public function initialize() |
|
63 | + { |
|
64 | + $this->populateSpecificationCollection(); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * @return CollectionInterface|RouteMatchSpecificationInterface[] |
|
70 | - * @throws CollectionLoaderException |
|
71 | - * @throws CollectionDetailsException |
|
72 | - * @since 4.9.71.p |
|
73 | - */ |
|
74 | - private function populateSpecificationCollection() |
|
75 | - { |
|
76 | - $loader = new CollectionLoader( |
|
77 | - new CollectionDetails( |
|
78 | - // collection name |
|
79 | - RouteMatchSpecificationCollection::COLLECTION_NAME, |
|
80 | - // collection interface |
|
81 | - 'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface', |
|
82 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
83 | - apply_filters( |
|
84 | - 'FHEE__EventEspresso_core_services_route_match_RouteMatchSpecificationManager__populateSpecificationCollection__collection_FQCNs', |
|
85 | - array( |
|
86 | - 'EventEspresso\core\domain\entities\route_match\specifications\admin', |
|
87 | - 'EventEspresso\core\domain\entities\route_match\specifications\frontend', |
|
88 | - ) |
|
89 | - ), |
|
90 | - // filepaths to classes to add |
|
91 | - array(), |
|
92 | - // file mask to use if parsing folder for files to add |
|
93 | - '', |
|
94 | - // what to use as identifier for collection entities |
|
95 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
96 | - CollectionDetails::ID_CLASS_NAME |
|
97 | - ), |
|
98 | - $this->specifications, |
|
99 | - null, |
|
100 | - $this->specifications_factory |
|
101 | - ); |
|
102 | - return $loader->getCollection(); |
|
103 | - } |
|
68 | + /** |
|
69 | + * @return CollectionInterface|RouteMatchSpecificationInterface[] |
|
70 | + * @throws CollectionLoaderException |
|
71 | + * @throws CollectionDetailsException |
|
72 | + * @since 4.9.71.p |
|
73 | + */ |
|
74 | + private function populateSpecificationCollection() |
|
75 | + { |
|
76 | + $loader = new CollectionLoader( |
|
77 | + new CollectionDetails( |
|
78 | + // collection name |
|
79 | + RouteMatchSpecificationCollection::COLLECTION_NAME, |
|
80 | + // collection interface |
|
81 | + 'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface', |
|
82 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
83 | + apply_filters( |
|
84 | + 'FHEE__EventEspresso_core_services_route_match_RouteMatchSpecificationManager__populateSpecificationCollection__collection_FQCNs', |
|
85 | + array( |
|
86 | + 'EventEspresso\core\domain\entities\route_match\specifications\admin', |
|
87 | + 'EventEspresso\core\domain\entities\route_match\specifications\frontend', |
|
88 | + ) |
|
89 | + ), |
|
90 | + // filepaths to classes to add |
|
91 | + array(), |
|
92 | + // file mask to use if parsing folder for files to add |
|
93 | + '', |
|
94 | + // what to use as identifier for collection entities |
|
95 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
96 | + CollectionDetails::ID_CLASS_NAME |
|
97 | + ), |
|
98 | + $this->specifications, |
|
99 | + null, |
|
100 | + $this->specifications_factory |
|
101 | + ); |
|
102 | + return $loader->getCollection(); |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * Given the FQCN for a RouteMatchSpecification, will return true if the current request matches |
|
108 | - * |
|
109 | - * @param string $routeMatchSpecificationFqcn fully qualified class name |
|
110 | - * @return bool |
|
111 | - * @throws InvalidClassException |
|
112 | - * @since 4.9.71.p |
|
113 | - */ |
|
114 | - public function routeMatchesCurrentRequest($routeMatchSpecificationFqcn) |
|
115 | - { |
|
116 | - /** @var RouteMatchSpecificationInterface $specification */ |
|
117 | - $specification = $this->specifications->get($routeMatchSpecificationFqcn); |
|
118 | - if (! $specification instanceof $routeMatchSpecificationFqcn) { |
|
119 | - throw new InvalidClassException($routeMatchSpecificationFqcn); |
|
120 | - } |
|
121 | - return $specification->isMatchingRoute(); |
|
122 | - } |
|
106 | + /** |
|
107 | + * Given the FQCN for a RouteMatchSpecification, will return true if the current request matches |
|
108 | + * |
|
109 | + * @param string $routeMatchSpecificationFqcn fully qualified class name |
|
110 | + * @return bool |
|
111 | + * @throws InvalidClassException |
|
112 | + * @since 4.9.71.p |
|
113 | + */ |
|
114 | + public function routeMatchesCurrentRequest($routeMatchSpecificationFqcn) |
|
115 | + { |
|
116 | + /** @var RouteMatchSpecificationInterface $specification */ |
|
117 | + $specification = $this->specifications->get($routeMatchSpecificationFqcn); |
|
118 | + if (! $specification instanceof $routeMatchSpecificationFqcn) { |
|
119 | + throw new InvalidClassException($routeMatchSpecificationFqcn); |
|
120 | + } |
|
121 | + return $specification->isMatchingRoute(); |
|
122 | + } |
|
123 | 123 | |
124 | 124 | |
125 | - /** |
|
126 | - * Handy method for development that returns |
|
127 | - * a list of existing RouteMatchSpecification classes |
|
128 | - * matching the current request that can be used to identify it. |
|
129 | - * If no matches are returned (or nothing acceptable) |
|
130 | - * then create a new one that better matches your requirements. |
|
131 | - * |
|
132 | - * @return array |
|
133 | - * @since 4.9.71.p |
|
134 | - */ |
|
135 | - public function findRouteMatchSpecificationsMatchingCurrentRequest() |
|
136 | - { |
|
137 | - $matches = array(); |
|
138 | - foreach ($this->specifications as $specification) { |
|
139 | - /** @var RouteMatchSpecificationInterface $specification */ |
|
140 | - if ($specification->isMatchingRoute()) { |
|
141 | - $matches[] = get_class($specification); |
|
142 | - } |
|
143 | - } |
|
144 | - return $matches; |
|
145 | - } |
|
125 | + /** |
|
126 | + * Handy method for development that returns |
|
127 | + * a list of existing RouteMatchSpecification classes |
|
128 | + * matching the current request that can be used to identify it. |
|
129 | + * If no matches are returned (or nothing acceptable) |
|
130 | + * then create a new one that better matches your requirements. |
|
131 | + * |
|
132 | + * @return array |
|
133 | + * @since 4.9.71.p |
|
134 | + */ |
|
135 | + public function findRouteMatchSpecificationsMatchingCurrentRequest() |
|
136 | + { |
|
137 | + $matches = array(); |
|
138 | + foreach ($this->specifications as $specification) { |
|
139 | + /** @var RouteMatchSpecificationInterface $specification */ |
|
140 | + if ($specification->isMatchingRoute()) { |
|
141 | + $matches[] = get_class($specification); |
|
142 | + } |
|
143 | + } |
|
144 | + return $matches; |
|
145 | + } |
|
146 | 146 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | foreach ($this->blocks as $block) { |
146 | 146 | $block->initialize(); |
147 | 147 | $this->trackAssetManagersForBlocks($block); |
148 | - if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
148 | + if ( ! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
149 | 149 | $this->block_asset_manager_collection->add($block->assetManager()); |
150 | 150 | $block->assetManager()->setAssetHandles(); |
151 | 151 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $supported_routes = $block->supportedRoutes(); |
168 | 168 | foreach ($supported_routes as $supported_route) { |
169 | 169 | if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
170 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
170 | + $this->block_asset_managers[$block->blockType()] = $block->assetManager()->assetNamespace(); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function matchesRoute(BlockInterface $block) |
185 | 185 | { |
186 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
186 | + if (isset($this->block_asset_managers[$block->blockType()])) { |
|
187 | 187 | return true; |
188 | 188 | } |
189 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
189 | + unset($this->block_asset_managers[$block->blockType()]); |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
@@ -202,12 +202,12 @@ discard block |
||
202 | 202 | try { |
203 | 203 | // cycle thru block loader folders |
204 | 204 | foreach ($this->blocks as $block) { |
205 | - if (! $this->matchesRoute($block)) { |
|
205 | + if ( ! $this->matchesRoute($block)) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | 208 | // perform any setup required for the block |
209 | 209 | $block_type = $block->registerBlock(); |
210 | - if (! $block_type instanceof WP_Block_Type) { |
|
210 | + if ( ! $block_type instanceof WP_Block_Type) { |
|
211 | 211 | throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
212 | 212 | } |
213 | 213 | do_action( |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $assets = array_flip($this->block_asset_managers); |
227 | 227 | foreach ($this->block_asset_manager_collection as $asset_manager) { |
228 | 228 | // if there are no longer any blocks that require these assets, |
229 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
229 | + if ( ! isset($assets[$asset_manager->assetNamespace()])) { |
|
230 | 230 | // then unset asset enqueueing and bail |
231 | 231 | remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
232 | 232 | remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
@@ -31,223 +31,223 @@ |
||
31 | 31 | */ |
32 | 32 | class BlockRegistrationManager extends BlockManager |
33 | 33 | { |
34 | - /** |
|
35 | - * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
36 | - */ |
|
37 | - protected $block_asset_manager_collection; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var RouteMatchSpecificationManager $route_manager |
|
41 | - */ |
|
42 | - protected $route_manager; |
|
43 | - |
|
44 | - /** |
|
45 | - * array for tracking asset managers required by blocks for the current route |
|
46 | - * |
|
47 | - * @var array $block_asset_managers |
|
48 | - */ |
|
49 | - protected $block_asset_managers = array(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * BlockRegistrationManager constructor. |
|
54 | - * |
|
55 | - * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
56 | - * @param BlockCollection $blocks |
|
57 | - * @param RouteMatchSpecificationManager $route_manager |
|
58 | - * @param RequestInterface $request |
|
59 | - */ |
|
60 | - public function __construct( |
|
61 | - BlockAssetManagerCollection $block_asset_manager_collection, |
|
62 | - BlockCollection $blocks, |
|
63 | - RouteMatchSpecificationManager $route_manager, |
|
64 | - RequestInterface $request |
|
65 | - ) { |
|
66 | - $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
67 | - $this->route_manager = $route_manager; |
|
68 | - parent::__construct($blocks, $request); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Returns the name of a hookpoint to be used to call initialize() |
|
74 | - * |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function initHook() |
|
78 | - { |
|
79 | - return 'AHEE__EE_System__initialize'; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Perform any early setup required for block editors to functions |
|
85 | - * |
|
86 | - * @return void |
|
87 | - * @throws Exception |
|
88 | - */ |
|
89 | - public function initialize() |
|
90 | - { |
|
91 | - $this->initializeBlocks(); |
|
92 | - add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
93 | - add_action('wp_loaded', array($this, 'unloadAssets')); |
|
94 | - add_filter('block_categories_all', array($this, 'addEspressoBlockCategories')); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @param array $categories |
|
100 | - * @since 4.9.71.p |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function addEspressoBlockCategories(array $categories) |
|
104 | - { |
|
105 | - return array_merge( |
|
106 | - $categories, |
|
107 | - array( |
|
108 | - array( |
|
109 | - 'slug' => 'event-espresso', |
|
110 | - 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
111 | - ), |
|
112 | - ) |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @return CollectionInterface|BlockInterface[] |
|
119 | - * @throws CollectionLoaderException |
|
120 | - * @throws CollectionDetailsException |
|
121 | - */ |
|
122 | - protected function populateBlockCollection() |
|
123 | - { |
|
124 | - $loader = new CollectionLoader( |
|
125 | - new CollectionDetails( |
|
126 | - // collection name |
|
127 | - 'editor_blocks', |
|
128 | - // collection interface |
|
129 | - 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
130 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
131 | - apply_filters( |
|
132 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
133 | - array('EventEspresso\core\domain\entities\editor\blocks') |
|
134 | - ), |
|
135 | - // filepaths to classes to add |
|
136 | - array(), |
|
137 | - // file mask to use if parsing folder for files to add |
|
138 | - '', |
|
139 | - // what to use as identifier for collection entities |
|
140 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
141 | - CollectionDetails::ID_CLASS_NAME |
|
142 | - ), |
|
143 | - $this->blocks |
|
144 | - ); |
|
145 | - return $loader->getCollection(); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * populates the BlockCollection and calls initialize() on all installed blocks |
|
151 | - * |
|
152 | - * @return void |
|
153 | - * @throws Exception |
|
154 | - */ |
|
155 | - public function initializeBlocks() |
|
156 | - { |
|
157 | - try { |
|
158 | - $this->populateBlockCollection(); |
|
159 | - // cycle thru block loaders and initialize each loader |
|
160 | - foreach ($this->blocks as $block) { |
|
161 | - $block->initialize(); |
|
162 | - $this->trackAssetManagersForBlocks($block); |
|
163 | - if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
164 | - $this->block_asset_manager_collection->add($block->assetManager()); |
|
165 | - $block->assetManager()->setAssetHandles(); |
|
166 | - } |
|
167 | - } |
|
168 | - } catch (Exception $exception) { |
|
169 | - new ExceptionStackTraceDisplay($exception); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * track blocks with routes that match the current request |
|
176 | - * |
|
177 | - * @param BlockInterface $block |
|
178 | - * @throws InvalidClassException |
|
179 | - */ |
|
180 | - private function trackAssetManagersForBlocks(BlockInterface $block) |
|
181 | - { |
|
182 | - $supported_routes = $block->supportedRoutes(); |
|
183 | - foreach ($supported_routes as $supported_route) { |
|
184 | - if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
185 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
186 | - } |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * returns true if the block should be registered for the current request |
|
193 | - * else removes block from block_routes array and returns false |
|
194 | - * |
|
195 | - * @param BlockInterface $block |
|
196 | - * @return boolean |
|
197 | - * @throws InvalidClassException |
|
198 | - */ |
|
199 | - public function matchesRoute(BlockInterface $block) |
|
200 | - { |
|
201 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
202 | - return true; |
|
203 | - } |
|
204 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
205 | - return false; |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * calls registerBlock() and load assets for all installed blocks |
|
211 | - * |
|
212 | - * @return void |
|
213 | - * @throws Exception |
|
214 | - */ |
|
215 | - public function registerBlocks() |
|
216 | - { |
|
217 | - try { |
|
218 | - // cycle thru block loader folders |
|
219 | - foreach ($this->blocks as $block) { |
|
220 | - if (! $this->matchesRoute($block)) { |
|
221 | - continue; |
|
222 | - } |
|
223 | - // perform any setup required for the block |
|
224 | - $block_type = $block->registerBlock(); |
|
225 | - if (! $block_type instanceof WP_Block_Type) { |
|
226 | - throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
227 | - } |
|
228 | - do_action( |
|
229 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
230 | - $block, |
|
231 | - $block_type |
|
232 | - ); |
|
233 | - } |
|
234 | - } catch (Exception $exception) { |
|
235 | - new ExceptionStackTraceDisplay($exception); |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - public function unloadAssets() |
|
240 | - { |
|
241 | - $assets = array_flip($this->block_asset_managers); |
|
242 | - foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
243 | - // if there are no longer any blocks that require these assets, |
|
244 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
245 | - // then unset asset enqueueing and bail |
|
246 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
247 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
248 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
249 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
34 | + /** |
|
35 | + * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
36 | + */ |
|
37 | + protected $block_asset_manager_collection; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var RouteMatchSpecificationManager $route_manager |
|
41 | + */ |
|
42 | + protected $route_manager; |
|
43 | + |
|
44 | + /** |
|
45 | + * array for tracking asset managers required by blocks for the current route |
|
46 | + * |
|
47 | + * @var array $block_asset_managers |
|
48 | + */ |
|
49 | + protected $block_asset_managers = array(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * BlockRegistrationManager constructor. |
|
54 | + * |
|
55 | + * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
56 | + * @param BlockCollection $blocks |
|
57 | + * @param RouteMatchSpecificationManager $route_manager |
|
58 | + * @param RequestInterface $request |
|
59 | + */ |
|
60 | + public function __construct( |
|
61 | + BlockAssetManagerCollection $block_asset_manager_collection, |
|
62 | + BlockCollection $blocks, |
|
63 | + RouteMatchSpecificationManager $route_manager, |
|
64 | + RequestInterface $request |
|
65 | + ) { |
|
66 | + $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
67 | + $this->route_manager = $route_manager; |
|
68 | + parent::__construct($blocks, $request); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Returns the name of a hookpoint to be used to call initialize() |
|
74 | + * |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function initHook() |
|
78 | + { |
|
79 | + return 'AHEE__EE_System__initialize'; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Perform any early setup required for block editors to functions |
|
85 | + * |
|
86 | + * @return void |
|
87 | + * @throws Exception |
|
88 | + */ |
|
89 | + public function initialize() |
|
90 | + { |
|
91 | + $this->initializeBlocks(); |
|
92 | + add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
93 | + add_action('wp_loaded', array($this, 'unloadAssets')); |
|
94 | + add_filter('block_categories_all', array($this, 'addEspressoBlockCategories')); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @param array $categories |
|
100 | + * @since 4.9.71.p |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function addEspressoBlockCategories(array $categories) |
|
104 | + { |
|
105 | + return array_merge( |
|
106 | + $categories, |
|
107 | + array( |
|
108 | + array( |
|
109 | + 'slug' => 'event-espresso', |
|
110 | + 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
111 | + ), |
|
112 | + ) |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @return CollectionInterface|BlockInterface[] |
|
119 | + * @throws CollectionLoaderException |
|
120 | + * @throws CollectionDetailsException |
|
121 | + */ |
|
122 | + protected function populateBlockCollection() |
|
123 | + { |
|
124 | + $loader = new CollectionLoader( |
|
125 | + new CollectionDetails( |
|
126 | + // collection name |
|
127 | + 'editor_blocks', |
|
128 | + // collection interface |
|
129 | + 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
130 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
131 | + apply_filters( |
|
132 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
133 | + array('EventEspresso\core\domain\entities\editor\blocks') |
|
134 | + ), |
|
135 | + // filepaths to classes to add |
|
136 | + array(), |
|
137 | + // file mask to use if parsing folder for files to add |
|
138 | + '', |
|
139 | + // what to use as identifier for collection entities |
|
140 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
141 | + CollectionDetails::ID_CLASS_NAME |
|
142 | + ), |
|
143 | + $this->blocks |
|
144 | + ); |
|
145 | + return $loader->getCollection(); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * populates the BlockCollection and calls initialize() on all installed blocks |
|
151 | + * |
|
152 | + * @return void |
|
153 | + * @throws Exception |
|
154 | + */ |
|
155 | + public function initializeBlocks() |
|
156 | + { |
|
157 | + try { |
|
158 | + $this->populateBlockCollection(); |
|
159 | + // cycle thru block loaders and initialize each loader |
|
160 | + foreach ($this->blocks as $block) { |
|
161 | + $block->initialize(); |
|
162 | + $this->trackAssetManagersForBlocks($block); |
|
163 | + if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
164 | + $this->block_asset_manager_collection->add($block->assetManager()); |
|
165 | + $block->assetManager()->setAssetHandles(); |
|
166 | + } |
|
167 | + } |
|
168 | + } catch (Exception $exception) { |
|
169 | + new ExceptionStackTraceDisplay($exception); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * track blocks with routes that match the current request |
|
176 | + * |
|
177 | + * @param BlockInterface $block |
|
178 | + * @throws InvalidClassException |
|
179 | + */ |
|
180 | + private function trackAssetManagersForBlocks(BlockInterface $block) |
|
181 | + { |
|
182 | + $supported_routes = $block->supportedRoutes(); |
|
183 | + foreach ($supported_routes as $supported_route) { |
|
184 | + if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
185 | + $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
186 | + } |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * returns true if the block should be registered for the current request |
|
193 | + * else removes block from block_routes array and returns false |
|
194 | + * |
|
195 | + * @param BlockInterface $block |
|
196 | + * @return boolean |
|
197 | + * @throws InvalidClassException |
|
198 | + */ |
|
199 | + public function matchesRoute(BlockInterface $block) |
|
200 | + { |
|
201 | + if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
202 | + return true; |
|
203 | + } |
|
204 | + unset($this->block_asset_managers[ $block->blockType() ]); |
|
205 | + return false; |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * calls registerBlock() and load assets for all installed blocks |
|
211 | + * |
|
212 | + * @return void |
|
213 | + * @throws Exception |
|
214 | + */ |
|
215 | + public function registerBlocks() |
|
216 | + { |
|
217 | + try { |
|
218 | + // cycle thru block loader folders |
|
219 | + foreach ($this->blocks as $block) { |
|
220 | + if (! $this->matchesRoute($block)) { |
|
221 | + continue; |
|
222 | + } |
|
223 | + // perform any setup required for the block |
|
224 | + $block_type = $block->registerBlock(); |
|
225 | + if (! $block_type instanceof WP_Block_Type) { |
|
226 | + throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
227 | + } |
|
228 | + do_action( |
|
229 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
230 | + $block, |
|
231 | + $block_type |
|
232 | + ); |
|
233 | + } |
|
234 | + } catch (Exception $exception) { |
|
235 | + new ExceptionStackTraceDisplay($exception); |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + public function unloadAssets() |
|
240 | + { |
|
241 | + $assets = array_flip($this->block_asset_managers); |
|
242 | + foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
243 | + // if there are no longer any blocks that require these assets, |
|
244 | + if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
245 | + // then unset asset enqueueing and bail |
|
246 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
247 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
248 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
249 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | 253 | } |
@@ -16,131 +16,131 @@ |
||
16 | 16 | */ |
17 | 17 | class Config |
18 | 18 | { |
19 | - /** |
|
20 | - * @var EE_Network_Config |
|
21 | - */ |
|
22 | - private $network_config; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @var EE_Config |
|
27 | - */ |
|
28 | - private $ee_config; |
|
29 | - |
|
30 | - |
|
31 | - public function __construct(EE_Network_Config $network_config, EE_Config $ee_config) |
|
32 | - { |
|
33 | - $this->network_config = $network_config; |
|
34 | - $this->ee_config = $ee_config; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Get the site license key for the site. |
|
40 | - */ |
|
41 | - public function siteLicenseKey() |
|
42 | - { |
|
43 | - return $this->network_config->core->site_license_key; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - public function i18nDomain() |
|
48 | - { |
|
49 | - return 'event_espresso'; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - public function checkPeriod() |
|
54 | - { |
|
55 | - return 24; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - public function optionKey() |
|
60 | - { |
|
61 | - return 'ee_site_license_key'; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - public function optionsPageSlug() |
|
66 | - { |
|
67 | - return 'espresso_general_settings'; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - public function hostServerUrl() |
|
72 | - { |
|
73 | - return defined('PUE_UPDATES_ENDPOINT') |
|
74 | - ? PUE_UPDATES_ENDPOINT |
|
75 | - : 'https://eventespresso.com'; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - public function pluginSlug() |
|
80 | - { |
|
81 | - // Note: PUE uses a simple preg_match to determine what type is currently installed based on version number. |
|
82 | - // So it's important that you use a key for the version type that is unique and not found in another key. |
|
83 | - // For example: |
|
84 | - // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
85 | - // $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug'; |
|
86 | - // The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr ) |
|
87 | - // so doing something like: |
|
88 | - // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
89 | - // $plugin_slug['prerelease']['b'] = 'some-pre-release-slug'; |
|
90 | - // ..WOULD work! |
|
91 | - return array( |
|
92 | - 'free' => array('decaf' => 'event-espresso-core-decaf'), |
|
93 | - 'premium' => array('p' => 'event-espresso-core-reg'), |
|
94 | - 'prerelease' => array('beta' => 'event-espresso-core-pr'), |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Return whether the site is opted in for UXIP or not. |
|
101 | - * |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function isOptedInForUxip() |
|
105 | - { |
|
106 | - return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Return whether the site has been notified about UXIP or not. |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - public function hasNotifiedForUxip() |
|
116 | - { |
|
117 | - return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Set the site opted in for UXIP. |
|
123 | - */ |
|
124 | - public function setHasOptedInForUxip() |
|
125 | - { |
|
126 | - $this->ee_config->core->ee_ueip_optin = true; |
|
127 | - $this->ee_config->update_espresso_config(false, false); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Set the site opted out for UXIP |
|
133 | - */ |
|
134 | - public function setHasOptedOutForUxip() |
|
135 | - { |
|
136 | - $this->ee_config->core->ee_ueip_optin = false; |
|
137 | - $this->ee_config->update_espresso_config(false, false); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - public function setHasNotifiedAboutUxip() |
|
142 | - { |
|
143 | - $this->ee_config->core->ee_ueip_has_notified = true; |
|
144 | - $this->ee_config->update_espresso_config(false, false); |
|
145 | - } |
|
19 | + /** |
|
20 | + * @var EE_Network_Config |
|
21 | + */ |
|
22 | + private $network_config; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @var EE_Config |
|
27 | + */ |
|
28 | + private $ee_config; |
|
29 | + |
|
30 | + |
|
31 | + public function __construct(EE_Network_Config $network_config, EE_Config $ee_config) |
|
32 | + { |
|
33 | + $this->network_config = $network_config; |
|
34 | + $this->ee_config = $ee_config; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Get the site license key for the site. |
|
40 | + */ |
|
41 | + public function siteLicenseKey() |
|
42 | + { |
|
43 | + return $this->network_config->core->site_license_key; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + public function i18nDomain() |
|
48 | + { |
|
49 | + return 'event_espresso'; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + public function checkPeriod() |
|
54 | + { |
|
55 | + return 24; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + public function optionKey() |
|
60 | + { |
|
61 | + return 'ee_site_license_key'; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + public function optionsPageSlug() |
|
66 | + { |
|
67 | + return 'espresso_general_settings'; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + public function hostServerUrl() |
|
72 | + { |
|
73 | + return defined('PUE_UPDATES_ENDPOINT') |
|
74 | + ? PUE_UPDATES_ENDPOINT |
|
75 | + : 'https://eventespresso.com'; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + public function pluginSlug() |
|
80 | + { |
|
81 | + // Note: PUE uses a simple preg_match to determine what type is currently installed based on version number. |
|
82 | + // So it's important that you use a key for the version type that is unique and not found in another key. |
|
83 | + // For example: |
|
84 | + // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
85 | + // $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug'; |
|
86 | + // The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr ) |
|
87 | + // so doing something like: |
|
88 | + // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
89 | + // $plugin_slug['prerelease']['b'] = 'some-pre-release-slug'; |
|
90 | + // ..WOULD work! |
|
91 | + return array( |
|
92 | + 'free' => array('decaf' => 'event-espresso-core-decaf'), |
|
93 | + 'premium' => array('p' => 'event-espresso-core-reg'), |
|
94 | + 'prerelease' => array('beta' => 'event-espresso-core-pr'), |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Return whether the site is opted in for UXIP or not. |
|
101 | + * |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function isOptedInForUxip() |
|
105 | + { |
|
106 | + return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Return whether the site has been notified about UXIP or not. |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + public function hasNotifiedForUxip() |
|
116 | + { |
|
117 | + return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Set the site opted in for UXIP. |
|
123 | + */ |
|
124 | + public function setHasOptedInForUxip() |
|
125 | + { |
|
126 | + $this->ee_config->core->ee_ueip_optin = true; |
|
127 | + $this->ee_config->update_espresso_config(false, false); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Set the site opted out for UXIP |
|
133 | + */ |
|
134 | + public function setHasOptedOutForUxip() |
|
135 | + { |
|
136 | + $this->ee_config->core->ee_ueip_optin = false; |
|
137 | + $this->ee_config->update_espresso_config(false, false); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + public function setHasNotifiedAboutUxip() |
|
142 | + { |
|
143 | + $this->ee_config->core->ee_ueip_has_notified = true; |
|
144 | + $this->ee_config->update_espresso_config(false, false); |
|
145 | + } |
|
146 | 146 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function addAlias(ClassAlias $alias) |
99 | 99 | { |
100 | - $this->aliases[ $alias->alias() ] = $alias; |
|
100 | + $this->aliases[$alias->alias()] = $alias; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function resolveAlias($param_fqcn) |
108 | 108 | { |
109 | - return isset($this->aliases[ $param_fqcn ]) |
|
110 | - ? $this->aliases[ $param_fqcn ]->fqcn() |
|
109 | + return isset($this->aliases[$param_fqcn]) |
|
110 | + ? $this->aliases[$param_fqcn]->fqcn() |
|
111 | 111 | : $this->classCache()->getFqnForAlias($param_fqcn); |
112 | 112 | } |
113 | 113 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $this->resolveDependenciesForClass($param_class); |
171 | 171 | } |
172 | 172 | $param_class = $this->resolveAlias($param_class); |
173 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
173 | + $dependencies[$param_class] = EE_Dependency_Map::load_from_cache; |
|
174 | 174 | } |
175 | 175 | $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
176 | 176 | } |
@@ -22,155 +22,155 @@ |
||
22 | 22 | */ |
23 | 23 | abstract class DependencyResolver implements DependencyResolverInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * @var Mirror $mirror |
|
27 | - */ |
|
28 | - private $mirror; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var ClassInterfaceCache $class_cache |
|
32 | - */ |
|
33 | - private $class_cache; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var EE_Dependency_Map $dependency_map |
|
37 | - */ |
|
38 | - private $dependency_map; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var ClassAlias[] $aliases |
|
42 | - */ |
|
43 | - protected $aliases = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array $namespace_roots |
|
47 | - */ |
|
48 | - protected $namespace_roots = array(); |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * RouteMatchSpecificationDependencyResolver constructor. |
|
53 | - * |
|
54 | - * @param Mirror $mirror |
|
55 | - * @param ClassInterfaceCache $class_cache |
|
56 | - * @param EE_Dependency_Map $dependency_map |
|
57 | - */ |
|
58 | - public function __construct( |
|
59 | - Mirror $mirror, |
|
60 | - ClassInterfaceCache $class_cache, |
|
61 | - EE_Dependency_Map $dependency_map |
|
62 | - ) { |
|
63 | - $this->mirror = $mirror; |
|
64 | - $this->class_cache = $class_cache; |
|
65 | - $this->dependency_map = $dependency_map; |
|
66 | - $this->initialize(); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @return Mirror |
|
71 | - */ |
|
72 | - public function mirror() |
|
73 | - { |
|
74 | - return $this->mirror; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * @return ClassInterfaceCache |
|
79 | - */ |
|
80 | - public function classCache() |
|
81 | - { |
|
82 | - return $this->class_cache; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @return EE_Dependency_Map |
|
87 | - */ |
|
88 | - public function dependencyMap() |
|
89 | - { |
|
90 | - return $this->dependency_map; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param ClassAlias $alias |
|
95 | - * @throws InvalidAliasException |
|
96 | - */ |
|
97 | - public function addAlias(ClassAlias $alias) |
|
98 | - { |
|
99 | - $this->aliases[ $alias->alias() ] = $alias; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function resolveAlias($param_fqcn) |
|
107 | - { |
|
108 | - return isset($this->aliases[ $param_fqcn ]) |
|
109 | - ? $this->aliases[ $param_fqcn ]->fqcn() |
|
110 | - : $this->classCache()->getFqnForAlias($param_fqcn); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Primarily used to indicate the namespace root for composite objects |
|
115 | - * so that dependencies requiring the same DependencyResolver can be acquired |
|
116 | - * for example: |
|
117 | - * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
118 | - * may all implement Vendor\path\to\Interface, |
|
119 | - * but Vendor\path\to\class\C could be a composite object |
|
120 | - * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
121 | - * and needs both of those dependencies resolved, which would therefore require |
|
122 | - * the use of the same DependencyResolver. |
|
123 | - * |
|
124 | - * By specifying a namespace root of "Vendor\path\to\", |
|
125 | - * then all classes that are descendants of that namespace |
|
126 | - * will use DependencyResolver to acquire the classes they need |
|
127 | - * |
|
128 | - * @param string $namespace_root Partial namespace used for detecting other classes |
|
129 | - * that should employ this same DependencyResolver |
|
130 | - */ |
|
131 | - public function addNamespaceRoot($namespace_root) |
|
132 | - { |
|
133 | - $this->namespace_roots[] = $namespace_root; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Returns true if the parameter FQCN belongs to one of |
|
138 | - * the namespaces that utilizes this DependencyResolver |
|
139 | - * |
|
140 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
141 | - * @return boolean |
|
142 | - * @since 4.9.71.p |
|
143 | - */ |
|
144 | - public function dependencyRecursionExists($param_fqcn) |
|
145 | - { |
|
146 | - foreach ($this->namespace_roots as $namespace_root) { |
|
147 | - if (strpos($param_fqcn, $namespace_root) !== false) { |
|
148 | - return true; |
|
149 | - } |
|
150 | - } |
|
151 | - return false; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param string $fqcn Fully Qualified Class Name |
|
157 | - * @throws InvalidDataTypeException |
|
158 | - * @throws ReflectionException |
|
159 | - * @since 4.9.71.p |
|
160 | - */ |
|
161 | - public function resolveDependenciesForClass($fqcn) |
|
162 | - { |
|
163 | - $dependencies = array(); |
|
164 | - $params = $this->mirror()->getParameters($fqcn); |
|
165 | - foreach ($params as $index => $param) { |
|
166 | - // is this a dependency for a specific class ? |
|
167 | - $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
168 | - if ($this->dependencyRecursionExists($param_class)) { |
|
169 | - $this->resolveDependenciesForClass($param_class); |
|
170 | - } |
|
171 | - $param_class = $this->resolveAlias($param_class); |
|
172 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
173 | - } |
|
174 | - $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
175 | - } |
|
25 | + /** |
|
26 | + * @var Mirror $mirror |
|
27 | + */ |
|
28 | + private $mirror; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var ClassInterfaceCache $class_cache |
|
32 | + */ |
|
33 | + private $class_cache; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var EE_Dependency_Map $dependency_map |
|
37 | + */ |
|
38 | + private $dependency_map; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var ClassAlias[] $aliases |
|
42 | + */ |
|
43 | + protected $aliases = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array $namespace_roots |
|
47 | + */ |
|
48 | + protected $namespace_roots = array(); |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * RouteMatchSpecificationDependencyResolver constructor. |
|
53 | + * |
|
54 | + * @param Mirror $mirror |
|
55 | + * @param ClassInterfaceCache $class_cache |
|
56 | + * @param EE_Dependency_Map $dependency_map |
|
57 | + */ |
|
58 | + public function __construct( |
|
59 | + Mirror $mirror, |
|
60 | + ClassInterfaceCache $class_cache, |
|
61 | + EE_Dependency_Map $dependency_map |
|
62 | + ) { |
|
63 | + $this->mirror = $mirror; |
|
64 | + $this->class_cache = $class_cache; |
|
65 | + $this->dependency_map = $dependency_map; |
|
66 | + $this->initialize(); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @return Mirror |
|
71 | + */ |
|
72 | + public function mirror() |
|
73 | + { |
|
74 | + return $this->mirror; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * @return ClassInterfaceCache |
|
79 | + */ |
|
80 | + public function classCache() |
|
81 | + { |
|
82 | + return $this->class_cache; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @return EE_Dependency_Map |
|
87 | + */ |
|
88 | + public function dependencyMap() |
|
89 | + { |
|
90 | + return $this->dependency_map; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param ClassAlias $alias |
|
95 | + * @throws InvalidAliasException |
|
96 | + */ |
|
97 | + public function addAlias(ClassAlias $alias) |
|
98 | + { |
|
99 | + $this->aliases[ $alias->alias() ] = $alias; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function resolveAlias($param_fqcn) |
|
107 | + { |
|
108 | + return isset($this->aliases[ $param_fqcn ]) |
|
109 | + ? $this->aliases[ $param_fqcn ]->fqcn() |
|
110 | + : $this->classCache()->getFqnForAlias($param_fqcn); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Primarily used to indicate the namespace root for composite objects |
|
115 | + * so that dependencies requiring the same DependencyResolver can be acquired |
|
116 | + * for example: |
|
117 | + * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
118 | + * may all implement Vendor\path\to\Interface, |
|
119 | + * but Vendor\path\to\class\C could be a composite object |
|
120 | + * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
121 | + * and needs both of those dependencies resolved, which would therefore require |
|
122 | + * the use of the same DependencyResolver. |
|
123 | + * |
|
124 | + * By specifying a namespace root of "Vendor\path\to\", |
|
125 | + * then all classes that are descendants of that namespace |
|
126 | + * will use DependencyResolver to acquire the classes they need |
|
127 | + * |
|
128 | + * @param string $namespace_root Partial namespace used for detecting other classes |
|
129 | + * that should employ this same DependencyResolver |
|
130 | + */ |
|
131 | + public function addNamespaceRoot($namespace_root) |
|
132 | + { |
|
133 | + $this->namespace_roots[] = $namespace_root; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Returns true if the parameter FQCN belongs to one of |
|
138 | + * the namespaces that utilizes this DependencyResolver |
|
139 | + * |
|
140 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
141 | + * @return boolean |
|
142 | + * @since 4.9.71.p |
|
143 | + */ |
|
144 | + public function dependencyRecursionExists($param_fqcn) |
|
145 | + { |
|
146 | + foreach ($this->namespace_roots as $namespace_root) { |
|
147 | + if (strpos($param_fqcn, $namespace_root) !== false) { |
|
148 | + return true; |
|
149 | + } |
|
150 | + } |
|
151 | + return false; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param string $fqcn Fully Qualified Class Name |
|
157 | + * @throws InvalidDataTypeException |
|
158 | + * @throws ReflectionException |
|
159 | + * @since 4.9.71.p |
|
160 | + */ |
|
161 | + public function resolveDependenciesForClass($fqcn) |
|
162 | + { |
|
163 | + $dependencies = array(); |
|
164 | + $params = $this->mirror()->getParameters($fqcn); |
|
165 | + foreach ($params as $index => $param) { |
|
166 | + // is this a dependency for a specific class ? |
|
167 | + $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
168 | + if ($this->dependencyRecursionExists($param_class)) { |
|
169 | + $this->resolveDependenciesForClass($param_class); |
|
170 | + } |
|
171 | + $param_class = $this->resolveAlias($param_class); |
|
172 | + $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
173 | + } |
|
174 | + $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
175 | + } |
|
176 | 176 | } |