@@ -70,44 +70,44 @@ |
||
70 | 70 | class LoaderFactory |
71 | 71 | { |
72 | 72 | |
73 | - /** |
|
74 | - * @var LoaderInterface $loader ; |
|
75 | - */ |
|
76 | - private static $loader; |
|
73 | + /** |
|
74 | + * @var LoaderInterface $loader ; |
|
75 | + */ |
|
76 | + private static $loader; |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
81 | - * BootstrapDependencyInjectionContainer::buildLoader() |
|
82 | - * otherwise can be left null |
|
83 | - * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
84 | - * @param ObjectIdentifier|null $object_identifier |
|
85 | - * @return LoaderInterface |
|
86 | - * @throws InvalidArgumentException |
|
87 | - * @throws InvalidDataTypeException |
|
88 | - * @throws InvalidInterfaceException |
|
89 | - */ |
|
90 | - public static function getLoader( |
|
91 | - $generator = null, |
|
92 | - ClassInterfaceCache $class_cache = null, |
|
93 | - ObjectIdentifier $object_identifier = null |
|
94 | - ) { |
|
95 | - if (! LoaderFactory::$loader instanceof LoaderInterface |
|
96 | - && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
97 | - && $class_cache instanceof ClassInterfaceCache |
|
98 | - && $object_identifier instanceof ObjectIdentifier |
|
99 | - ) { |
|
100 | - $core_loader = new CoreLoader($generator); |
|
101 | - LoaderFactory::$loader = new Loader( |
|
102 | - $core_loader, |
|
103 | - new CachingLoader( |
|
104 | - $core_loader, |
|
105 | - new LooseCollection(''), |
|
106 | - $object_identifier |
|
107 | - ), |
|
108 | - $class_cache |
|
109 | - ); |
|
110 | - } |
|
111 | - return LoaderFactory::$loader; |
|
112 | - } |
|
79 | + /** |
|
80 | + * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
81 | + * BootstrapDependencyInjectionContainer::buildLoader() |
|
82 | + * otherwise can be left null |
|
83 | + * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
84 | + * @param ObjectIdentifier|null $object_identifier |
|
85 | + * @return LoaderInterface |
|
86 | + * @throws InvalidArgumentException |
|
87 | + * @throws InvalidDataTypeException |
|
88 | + * @throws InvalidInterfaceException |
|
89 | + */ |
|
90 | + public static function getLoader( |
|
91 | + $generator = null, |
|
92 | + ClassInterfaceCache $class_cache = null, |
|
93 | + ObjectIdentifier $object_identifier = null |
|
94 | + ) { |
|
95 | + if (! LoaderFactory::$loader instanceof LoaderInterface |
|
96 | + && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
97 | + && $class_cache instanceof ClassInterfaceCache |
|
98 | + && $object_identifier instanceof ObjectIdentifier |
|
99 | + ) { |
|
100 | + $core_loader = new CoreLoader($generator); |
|
101 | + LoaderFactory::$loader = new Loader( |
|
102 | + $core_loader, |
|
103 | + new CachingLoader( |
|
104 | + $core_loader, |
|
105 | + new LooseCollection(''), |
|
106 | + $object_identifier |
|
107 | + ), |
|
108 | + $class_cache |
|
109 | + ); |
|
110 | + } |
|
111 | + return LoaderFactory::$loader; |
|
112 | + } |
|
113 | 113 | } |
@@ -92,7 +92,7 @@ |
||
92 | 92 | ClassInterfaceCache $class_cache = null, |
93 | 93 | ObjectIdentifier $object_identifier = null |
94 | 94 | ) { |
95 | - if (! LoaderFactory::$loader instanceof LoaderInterface |
|
95 | + if ( ! LoaderFactory::$loader instanceof LoaderInterface |
|
96 | 96 | && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
97 | 97 | && $class_cache instanceof ClassInterfaceCache |
98 | 98 | && $object_identifier instanceof ObjectIdentifier |
@@ -163,7 +163,7 @@ |
||
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @param $entity |
166 | - * @param mixed $identifier |
|
166 | + * @param string $identifier |
|
167 | 167 | * @return string |
168 | 168 | * @throws InvalidEntityException |
169 | 169 | */ |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | LocatorInterface $file_locator = null |
85 | 85 | ) { |
86 | 86 | $this->collection_details = $collection_details; |
87 | - if (! $collection instanceof CollectionInterface) { |
|
87 | + if ( ! $collection instanceof CollectionInterface) { |
|
88 | 88 | $collection = new Collection($this->collection_details->getCollectionInterface()); |
89 | 89 | } |
90 | 90 | $this->collection = $collection; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function loadAllFromFilepaths() |
113 | 113 | { |
114 | - if (! $this->file_locator instanceof FileLocator) { |
|
114 | + if ( ! $this->file_locator instanceof FileLocator) { |
|
115 | 115 | $this->file_locator = new FileLocator(); |
116 | 116 | } |
117 | 117 | $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function loadClassFromFilepath($filepath) |
145 | 145 | { |
146 | - if (! is_string($filepath)) { |
|
146 | + if ( ! is_string($filepath)) { |
|
147 | 147 | throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
148 | 148 | } |
149 | - if (! is_readable($filepath)) { |
|
149 | + if ( ! is_readable($filepath)) { |
|
150 | 150 | throw new InvalidFilePathException($filepath); |
151 | 151 | } |
152 | 152 | require_once $filepath; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $file_name = basename($filepath); |
155 | 155 | // now remove any file extensions |
156 | 156 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
157 | - if (! class_exists($class_name)) { |
|
157 | + if ( ! class_exists($class_name)) { |
|
158 | 158 | throw new InvalidClassException($class_name); |
159 | 159 | } |
160 | 160 | return $this->addEntityToCollection(new $class_name(), $file_name); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | // objects added to the collection based on entity callback, so the entity itself decides |
225 | 225 | case CollectionDetails::ID_CALLBACK_METHOD: |
226 | 226 | $identifier_callback = $this->collection_details->identifierCallback(); |
227 | - if (! method_exists($entity, $identifier_callback)) { |
|
227 | + if ( ! method_exists($entity, $identifier_callback)) { |
|
228 | 228 | throw new InvalidEntityException( |
229 | 229 | $entity, |
230 | 230 | $this->collection_details->getCollectionInterface(), |
@@ -288,10 +288,10 @@ discard block |
||
288 | 288 | */ |
289 | 289 | protected function loadClassFromFQCN($FQCN) |
290 | 290 | { |
291 | - if (! is_string($FQCN)) { |
|
291 | + if ( ! is_string($FQCN)) { |
|
292 | 292 | throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
293 | 293 | } |
294 | - if (! class_exists($FQCN)) { |
|
294 | + if ( ! class_exists($FQCN)) { |
|
295 | 295 | throw new InvalidClassException($FQCN); |
296 | 296 | } |
297 | 297 | return $this->addEntityToCollection( |
@@ -27,276 +27,276 @@ |
||
27 | 27 | class CollectionLoader |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * possible return value when adding entities to a collection. |
|
32 | - * denotes that the entity was NOT ADDED to the collection |
|
33 | - */ |
|
34 | - const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
30 | + /** |
|
31 | + * possible return value when adding entities to a collection. |
|
32 | + * denotes that the entity was NOT ADDED to the collection |
|
33 | + */ |
|
34 | + const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * possible return value when adding entities to a collection. |
|
38 | - * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
39 | - */ |
|
40 | - const ENTITY_ADDED = 'entity-added-to-collection'; |
|
36 | + /** |
|
37 | + * possible return value when adding entities to a collection. |
|
38 | + * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
39 | + */ |
|
40 | + const ENTITY_ADDED = 'entity-added-to-collection'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * possible return value when adding entities to a collection. |
|
44 | - * denotes that the entity was ALREADY ADDED to the collection, |
|
45 | - * and therefore could not be added again. |
|
46 | - */ |
|
47 | - const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
42 | + /** |
|
43 | + * possible return value when adding entities to a collection. |
|
44 | + * denotes that the entity was ALREADY ADDED to the collection, |
|
45 | + * and therefore could not be added again. |
|
46 | + */ |
|
47 | + const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @var CollectionDetailsInterface $collection_details |
|
52 | - */ |
|
53 | - protected $collection_details; |
|
50 | + /** |
|
51 | + * @var CollectionDetailsInterface $collection_details |
|
52 | + */ |
|
53 | + protected $collection_details; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var CollectionInterface $collection |
|
57 | - */ |
|
58 | - protected $collection; |
|
55 | + /** |
|
56 | + * @var CollectionInterface $collection |
|
57 | + */ |
|
58 | + protected $collection; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var FileLocator $file_locator |
|
62 | - */ |
|
63 | - protected $file_locator; |
|
60 | + /** |
|
61 | + * @var FileLocator $file_locator |
|
62 | + */ |
|
63 | + protected $file_locator; |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * CollectionLoader constructor. |
|
68 | - * |
|
69 | - * @param CollectionDetailsInterface $collection_details |
|
70 | - * @param CollectionInterface $collection |
|
71 | - * @param LocatorInterface $file_locator |
|
72 | - * @throws ReflectionException |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws EE_Error |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws InvalidClassException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidFilePathException |
|
79 | - * @throws InvalidEntityException |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - CollectionDetailsInterface $collection_details, |
|
83 | - CollectionInterface $collection = null, |
|
84 | - LocatorInterface $file_locator = null |
|
85 | - ) { |
|
86 | - $this->collection_details = $collection_details; |
|
87 | - if (! $collection instanceof CollectionInterface) { |
|
88 | - $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
89 | - } |
|
90 | - $this->collection = $collection; |
|
91 | - $this->file_locator = $file_locator; |
|
92 | - $this->loadAllFromFilepaths(); |
|
93 | - $this->loadFromFQCNs(); |
|
94 | - } |
|
66 | + /** |
|
67 | + * CollectionLoader constructor. |
|
68 | + * |
|
69 | + * @param CollectionDetailsInterface $collection_details |
|
70 | + * @param CollectionInterface $collection |
|
71 | + * @param LocatorInterface $file_locator |
|
72 | + * @throws ReflectionException |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws EE_Error |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws InvalidClassException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidFilePathException |
|
79 | + * @throws InvalidEntityException |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + CollectionDetailsInterface $collection_details, |
|
83 | + CollectionInterface $collection = null, |
|
84 | + LocatorInterface $file_locator = null |
|
85 | + ) { |
|
86 | + $this->collection_details = $collection_details; |
|
87 | + if (! $collection instanceof CollectionInterface) { |
|
88 | + $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
89 | + } |
|
90 | + $this->collection = $collection; |
|
91 | + $this->file_locator = $file_locator; |
|
92 | + $this->loadAllFromFilepaths(); |
|
93 | + $this->loadFromFQCNs(); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * @return CollectionInterface |
|
99 | - */ |
|
100 | - public function getCollection() |
|
101 | - { |
|
102 | - return $this->collection; |
|
103 | - } |
|
97 | + /** |
|
98 | + * @return CollectionInterface |
|
99 | + */ |
|
100 | + public function getCollection() |
|
101 | + { |
|
102 | + return $this->collection; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * @throws InvalidClassException |
|
108 | - * @throws InvalidFilePathException |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidEntityException |
|
111 | - */ |
|
112 | - protected function loadAllFromFilepaths() |
|
113 | - { |
|
114 | - if (! $this->file_locator instanceof FileLocator) { |
|
115 | - $this->file_locator = new FileLocator(); |
|
116 | - } |
|
117 | - $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
118 | - // find all of the files that match the file mask in the specified folder |
|
119 | - $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
120 | - // filter the results |
|
121 | - $filepaths = (array) apply_filters( |
|
122 | - 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
123 | - $this->file_locator->getFilePaths(), |
|
124 | - $this->collection_details->collectionName(), |
|
125 | - $this->collection_details |
|
126 | - ); |
|
127 | - if (empty($filepaths)) { |
|
128 | - return; |
|
129 | - } |
|
130 | - foreach ($filepaths as $filepath) { |
|
131 | - $this->loadClassFromFilepath($filepath); |
|
132 | - } |
|
133 | - } |
|
106 | + /** |
|
107 | + * @throws InvalidClassException |
|
108 | + * @throws InvalidFilePathException |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidEntityException |
|
111 | + */ |
|
112 | + protected function loadAllFromFilepaths() |
|
113 | + { |
|
114 | + if (! $this->file_locator instanceof FileLocator) { |
|
115 | + $this->file_locator = new FileLocator(); |
|
116 | + } |
|
117 | + $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
118 | + // find all of the files that match the file mask in the specified folder |
|
119 | + $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
120 | + // filter the results |
|
121 | + $filepaths = (array) apply_filters( |
|
122 | + 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
123 | + $this->file_locator->getFilePaths(), |
|
124 | + $this->collection_details->collectionName(), |
|
125 | + $this->collection_details |
|
126 | + ); |
|
127 | + if (empty($filepaths)) { |
|
128 | + return; |
|
129 | + } |
|
130 | + foreach ($filepaths as $filepath) { |
|
131 | + $this->loadClassFromFilepath($filepath); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * @param string $filepath |
|
138 | - * @return string |
|
139 | - * @throws InvalidEntityException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidFilePathException |
|
142 | - * @throws InvalidClassException |
|
143 | - */ |
|
144 | - protected function loadClassFromFilepath($filepath) |
|
145 | - { |
|
146 | - if (! is_string($filepath)) { |
|
147 | - throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
148 | - } |
|
149 | - if (! is_readable($filepath)) { |
|
150 | - throw new InvalidFilePathException($filepath); |
|
151 | - } |
|
152 | - require_once $filepath; |
|
153 | - // extract filename from path |
|
154 | - $file_name = basename($filepath); |
|
155 | - // now remove any file extensions |
|
156 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
157 | - if (! class_exists($class_name)) { |
|
158 | - throw new InvalidClassException($class_name); |
|
159 | - } |
|
160 | - return $this->addEntityToCollection(new $class_name(), $file_name); |
|
161 | - } |
|
136 | + /** |
|
137 | + * @param string $filepath |
|
138 | + * @return string |
|
139 | + * @throws InvalidEntityException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidFilePathException |
|
142 | + * @throws InvalidClassException |
|
143 | + */ |
|
144 | + protected function loadClassFromFilepath($filepath) |
|
145 | + { |
|
146 | + if (! is_string($filepath)) { |
|
147 | + throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
148 | + } |
|
149 | + if (! is_readable($filepath)) { |
|
150 | + throw new InvalidFilePathException($filepath); |
|
151 | + } |
|
152 | + require_once $filepath; |
|
153 | + // extract filename from path |
|
154 | + $file_name = basename($filepath); |
|
155 | + // now remove any file extensions |
|
156 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
157 | + if (! class_exists($class_name)) { |
|
158 | + throw new InvalidClassException($class_name); |
|
159 | + } |
|
160 | + return $this->addEntityToCollection(new $class_name(), $file_name); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * @param $entity |
|
166 | - * @param mixed $identifier |
|
167 | - * @return string |
|
168 | - * @throws InvalidEntityException |
|
169 | - */ |
|
170 | - protected function addEntityToCollection($entity, $identifier) |
|
171 | - { |
|
172 | - do_action( |
|
173 | - 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
174 | - $entity, |
|
175 | - $this->collection_details->collectionName(), |
|
176 | - $this->collection_details |
|
177 | - ); |
|
178 | - $identifier = $this->setIdentifier($entity, $identifier); |
|
179 | - if ($this->collection->has($identifier)) { |
|
180 | - do_action( |
|
181 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
182 | - $this, |
|
183 | - $this->collection_details->collectionName(), |
|
184 | - $this->collection_details |
|
185 | - ); |
|
186 | - return CollectionLoader::ENTITY_EXISTS; |
|
187 | - } |
|
188 | - if ($this->collection->add($entity, $identifier)) { |
|
189 | - do_action( |
|
190 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
191 | - $this, |
|
192 | - $this->collection_details->collectionName(), |
|
193 | - $this->collection_details |
|
194 | - ); |
|
195 | - return CollectionLoader::ENTITY_ADDED; |
|
196 | - } |
|
197 | - do_action( |
|
198 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
199 | - $this, |
|
200 | - $this->collection_details->collectionName(), |
|
201 | - $this->collection_details |
|
202 | - ); |
|
203 | - return CollectionLoader::ENTITY_NOT_ADDED; |
|
204 | - } |
|
164 | + /** |
|
165 | + * @param $entity |
|
166 | + * @param mixed $identifier |
|
167 | + * @return string |
|
168 | + * @throws InvalidEntityException |
|
169 | + */ |
|
170 | + protected function addEntityToCollection($entity, $identifier) |
|
171 | + { |
|
172 | + do_action( |
|
173 | + 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
174 | + $entity, |
|
175 | + $this->collection_details->collectionName(), |
|
176 | + $this->collection_details |
|
177 | + ); |
|
178 | + $identifier = $this->setIdentifier($entity, $identifier); |
|
179 | + if ($this->collection->has($identifier)) { |
|
180 | + do_action( |
|
181 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
182 | + $this, |
|
183 | + $this->collection_details->collectionName(), |
|
184 | + $this->collection_details |
|
185 | + ); |
|
186 | + return CollectionLoader::ENTITY_EXISTS; |
|
187 | + } |
|
188 | + if ($this->collection->add($entity, $identifier)) { |
|
189 | + do_action( |
|
190 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
191 | + $this, |
|
192 | + $this->collection_details->collectionName(), |
|
193 | + $this->collection_details |
|
194 | + ); |
|
195 | + return CollectionLoader::ENTITY_ADDED; |
|
196 | + } |
|
197 | + do_action( |
|
198 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
199 | + $this, |
|
200 | + $this->collection_details->collectionName(), |
|
201 | + $this->collection_details |
|
202 | + ); |
|
203 | + return CollectionLoader::ENTITY_NOT_ADDED; |
|
204 | + } |
|
205 | 205 | |
206 | 206 | |
207 | - /** |
|
208 | - * @param $entity |
|
209 | - * @param mixed $identifier |
|
210 | - * @return string |
|
211 | - * @throws InvalidEntityException |
|
212 | - */ |
|
213 | - protected function setIdentifier($entity, $identifier) |
|
214 | - { |
|
215 | - switch ($this->collection_details->identifierType()) { |
|
216 | - // every unique object gets added to the collection, but not duplicates of the exact same object |
|
217 | - case CollectionDetails::ID_OBJECT_HASH: |
|
218 | - $identifier = spl_object_hash($entity); |
|
219 | - break; |
|
220 | - // only one entity per class can be added to collection, like a singleton |
|
221 | - case CollectionDetails::ID_CLASS_NAME: |
|
222 | - $identifier = get_class($entity); |
|
223 | - break; |
|
224 | - // objects added to the collection based on entity callback, so the entity itself decides |
|
225 | - case CollectionDetails::ID_CALLBACK_METHOD: |
|
226 | - $identifier_callback = $this->collection_details->identifierCallback(); |
|
227 | - if (! method_exists($entity, $identifier_callback)) { |
|
228 | - throw new InvalidEntityException( |
|
229 | - $entity, |
|
230 | - $this->collection_details->getCollectionInterface(), |
|
231 | - sprintf( |
|
232 | - __( |
|
233 | - 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
207 | + /** |
|
208 | + * @param $entity |
|
209 | + * @param mixed $identifier |
|
210 | + * @return string |
|
211 | + * @throws InvalidEntityException |
|
212 | + */ |
|
213 | + protected function setIdentifier($entity, $identifier) |
|
214 | + { |
|
215 | + switch ($this->collection_details->identifierType()) { |
|
216 | + // every unique object gets added to the collection, but not duplicates of the exact same object |
|
217 | + case CollectionDetails::ID_OBJECT_HASH: |
|
218 | + $identifier = spl_object_hash($entity); |
|
219 | + break; |
|
220 | + // only one entity per class can be added to collection, like a singleton |
|
221 | + case CollectionDetails::ID_CLASS_NAME: |
|
222 | + $identifier = get_class($entity); |
|
223 | + break; |
|
224 | + // objects added to the collection based on entity callback, so the entity itself decides |
|
225 | + case CollectionDetails::ID_CALLBACK_METHOD: |
|
226 | + $identifier_callback = $this->collection_details->identifierCallback(); |
|
227 | + if (! method_exists($entity, $identifier_callback)) { |
|
228 | + throw new InvalidEntityException( |
|
229 | + $entity, |
|
230 | + $this->collection_details->getCollectionInterface(), |
|
231 | + sprintf( |
|
232 | + __( |
|
233 | + 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
234 | 234 | of "%2$s", but does not contain this method.', |
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - $identifier_callback, |
|
238 | - get_class($entity) |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - $identifier = $entity->{$identifier_callback}(); |
|
243 | - break; |
|
244 | - } |
|
245 | - return apply_filters( |
|
246 | - 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
247 | - $identifier, |
|
248 | - $this->collection_details->collectionName(), |
|
249 | - $this->collection_details |
|
250 | - ); |
|
251 | - } |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + $identifier_callback, |
|
238 | + get_class($entity) |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + $identifier = $entity->{$identifier_callback}(); |
|
243 | + break; |
|
244 | + } |
|
245 | + return apply_filters( |
|
246 | + 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
247 | + $identifier, |
|
248 | + $this->collection_details->collectionName(), |
|
249 | + $this->collection_details |
|
250 | + ); |
|
251 | + } |
|
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * @throws ReflectionException |
|
256 | - * @throws InvalidArgumentException |
|
257 | - * @throws InvalidInterfaceException |
|
258 | - * @throws EE_Error |
|
259 | - * @throws InvalidClassException |
|
260 | - * @throws InvalidDataTypeException |
|
261 | - * @throws InvalidEntityException |
|
262 | - */ |
|
263 | - protected function loadFromFQCNs() |
|
264 | - { |
|
265 | - $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
266 | - $FQCNs = (array) apply_filters( |
|
267 | - 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
268 | - $FQCNs, |
|
269 | - $this->collection_details->collectionName(), |
|
270 | - $this->collection_details |
|
271 | - ); |
|
272 | - foreach ($FQCNs as $FQCN) { |
|
273 | - $this->loadClassFromFQCN($FQCN); |
|
274 | - } |
|
275 | - } |
|
254 | + /** |
|
255 | + * @throws ReflectionException |
|
256 | + * @throws InvalidArgumentException |
|
257 | + * @throws InvalidInterfaceException |
|
258 | + * @throws EE_Error |
|
259 | + * @throws InvalidClassException |
|
260 | + * @throws InvalidDataTypeException |
|
261 | + * @throws InvalidEntityException |
|
262 | + */ |
|
263 | + protected function loadFromFQCNs() |
|
264 | + { |
|
265 | + $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
266 | + $FQCNs = (array) apply_filters( |
|
267 | + 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
268 | + $FQCNs, |
|
269 | + $this->collection_details->collectionName(), |
|
270 | + $this->collection_details |
|
271 | + ); |
|
272 | + foreach ($FQCNs as $FQCN) { |
|
273 | + $this->loadClassFromFQCN($FQCN); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | 277 | |
278 | - /** |
|
279 | - * @param string $FQCN Fully Qualified Class Name |
|
280 | - * @return string |
|
281 | - * @throws InvalidArgumentException |
|
282 | - * @throws InvalidInterfaceException |
|
283 | - * @throws ReflectionException |
|
284 | - * @throws EE_Error |
|
285 | - * @throws InvalidEntityException |
|
286 | - * @throws InvalidDataTypeException |
|
287 | - * @throws InvalidClassException |
|
288 | - */ |
|
289 | - protected function loadClassFromFQCN($FQCN) |
|
290 | - { |
|
291 | - if (! is_string($FQCN)) { |
|
292 | - throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
293 | - } |
|
294 | - if (! class_exists($FQCN)) { |
|
295 | - throw new InvalidClassException($FQCN); |
|
296 | - } |
|
297 | - return $this->addEntityToCollection( |
|
298 | - EE_Registry::instance()->create($FQCN), |
|
299 | - $FQCN |
|
300 | - ); |
|
301 | - } |
|
278 | + /** |
|
279 | + * @param string $FQCN Fully Qualified Class Name |
|
280 | + * @return string |
|
281 | + * @throws InvalidArgumentException |
|
282 | + * @throws InvalidInterfaceException |
|
283 | + * @throws ReflectionException |
|
284 | + * @throws EE_Error |
|
285 | + * @throws InvalidEntityException |
|
286 | + * @throws InvalidDataTypeException |
|
287 | + * @throws InvalidClassException |
|
288 | + */ |
|
289 | + protected function loadClassFromFQCN($FQCN) |
|
290 | + { |
|
291 | + if (! is_string($FQCN)) { |
|
292 | + throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
293 | + } |
|
294 | + if (! class_exists($FQCN)) { |
|
295 | + throw new InvalidClassException($FQCN); |
|
296 | + } |
|
297 | + return $this->addEntityToCollection( |
|
298 | + EE_Registry::instance()->create($FQCN), |
|
299 | + $FQCN |
|
300 | + ); |
|
301 | + } |
|
302 | 302 | } |
@@ -16,30 +16,30 @@ |
||
16 | 16 | class InvalidEntityException extends InvalidArgumentException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidEntityException constructor. |
|
21 | - * |
|
22 | - * @param mixed $actual the actual object (or thing) we got |
|
23 | - * @param string $expected classname of the entity we wanted |
|
24 | - * @param string $message |
|
25 | - * @param int $code |
|
26 | - * @param Exception $previous |
|
27 | - */ |
|
28 | - public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | - { |
|
30 | - if (empty($message)) { |
|
31 | - $message = sprintf( |
|
32 | - __( |
|
33 | - 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - is_object($actual) |
|
37 | - ? get_class($actual) |
|
38 | - : gettype($actual), |
|
39 | - $expected, |
|
40 | - var_export($actual, true) |
|
41 | - ); |
|
42 | - } |
|
43 | - parent::__construct($message, $code, $previous); |
|
44 | - } |
|
19 | + /** |
|
20 | + * InvalidEntityException constructor. |
|
21 | + * |
|
22 | + * @param mixed $actual the actual object (or thing) we got |
|
23 | + * @param string $expected classname of the entity we wanted |
|
24 | + * @param string $message |
|
25 | + * @param int $code |
|
26 | + * @param Exception $previous |
|
27 | + */ |
|
28 | + public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | + { |
|
30 | + if (empty($message)) { |
|
31 | + $message = sprintf( |
|
32 | + __( |
|
33 | + 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + is_object($actual) |
|
37 | + ? get_class($actual) |
|
38 | + : gettype($actual), |
|
39 | + $expected, |
|
40 | + var_export($actual, true) |
|
41 | + ); |
|
42 | + } |
|
43 | + parent::__construct($message, $code, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -23,246 +23,246 @@ |
||
23 | 23 | abstract class EditorBlock implements EditorBlockInterface |
24 | 24 | { |
25 | 25 | |
26 | - const NS = 'event-espresso/'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var DomainInterface $domain |
|
30 | - */ |
|
31 | - protected $domain; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var LoaderInterface $loader |
|
35 | - */ |
|
36 | - protected $loader; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @var Registry |
|
41 | - */ |
|
42 | - protected $assets_registry; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string $editor_block_type |
|
46 | - */ |
|
47 | - private $editor_block_type; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var WP_Block_Type $wp_block_type |
|
51 | - */ |
|
52 | - private $wp_block_type; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $supported_post_types |
|
56 | - */ |
|
57 | - private $supported_post_types; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var array $attributes |
|
61 | - */ |
|
62 | - private $attributes; |
|
63 | - |
|
64 | - /** |
|
65 | - * If set to true, then the block will render its content client side |
|
66 | - * If false, then the block will render its content server side using the renderBlock() method |
|
67 | - * |
|
68 | - * @var bool $dynamic |
|
69 | - */ |
|
70 | - private $dynamic = false; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * EditorBlockLoader constructor. |
|
75 | - * |
|
76 | - * @param DomainInterface $domain |
|
77 | - * @param LoaderInterface $loader |
|
78 | - * @param Registry $assets_registry |
|
79 | - */ |
|
80 | - public function __construct( |
|
81 | - DomainInterface $domain, |
|
82 | - LoaderInterface $loader, |
|
83 | - Registry $assets_registry |
|
84 | - ) { |
|
85 | - $this->domain = $domain; |
|
86 | - $this->loader = $loader; |
|
87 | - $this->assets_registry = $assets_registry; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function editorBlockType() |
|
95 | - { |
|
96 | - return $this->editor_block_type; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function namespacedEditorBlockType() |
|
104 | - { |
|
105 | - return EditorBlock::NS . $this->editor_block_type; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param string $editor_block_type |
|
111 | - */ |
|
112 | - protected function setEditorBlockType($editor_block_type) |
|
113 | - { |
|
114 | - $this->editor_block_type = $editor_block_type; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @param WP_Block_Type $wp_block_type |
|
120 | - */ |
|
121 | - protected function setWpBlockType($wp_block_type) |
|
122 | - { |
|
123 | - $this->wp_block_type = $wp_block_type; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param array $supported_post_types |
|
129 | - */ |
|
130 | - protected function setSupportedPostTypes(array $supported_post_types) |
|
131 | - { |
|
132 | - $this->supported_post_types = $supported_post_types; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function attributes() |
|
140 | - { |
|
141 | - return $this->attributes; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param array $attributes |
|
147 | - */ |
|
148 | - public function setAttributes(array $attributes) |
|
149 | - { |
|
150 | - $this->attributes = $attributes; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function isDynamic() |
|
158 | - { |
|
159 | - return $this->dynamic; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param bool $dynamic |
|
165 | - */ |
|
166 | - public function setDynamic($dynamic = true) |
|
167 | - { |
|
168 | - $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Registers the Editor Block with WP core; |
|
174 | - * Returns the registered block type on success, or false on failure. |
|
175 | - * |
|
176 | - * @return WP_Block_Type|false |
|
177 | - */ |
|
178 | - public function registerBlock() |
|
179 | - { |
|
180 | - $context ='core'; |
|
181 | - // todo add route detection (ie inject route) and change context based on route |
|
182 | - $args = array( |
|
183 | - 'attributes' => $this->attributes(), |
|
184 | - 'editor_script' => "ee-{$context}-blocks", |
|
185 | - 'editor_style' => "ee-{$context}-blocks", |
|
186 | - 'script' => "ee-{$context}-blocks", |
|
187 | - 'style' => "ee-{$context}-blocks", |
|
188 | - ); |
|
189 | - if (! $this->isDynamic()) { |
|
190 | - $args['render_callback'] = $this->renderBlock(); |
|
191 | - } |
|
192 | - $wp_block_type = register_block_type( |
|
193 | - new WP_Block_Type( |
|
194 | - $this->namespacedEditorBlockType(), |
|
195 | - $args |
|
196 | - ) |
|
197 | - ); |
|
198 | - $this->setWpBlockType($wp_block_type); |
|
199 | - return $wp_block_type; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
205 | - */ |
|
206 | - public function unRegisterBlock() |
|
207 | - { |
|
208 | - return unregister_block_type($this->namespacedEditorBlockType()); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * returns true if the block type applies for the supplied post type |
|
214 | - * and should be added to that post type's editor |
|
215 | - * |
|
216 | - * @param string $post_type |
|
217 | - * @return boolean |
|
218 | - */ |
|
219 | - public function appliesToPostType($post_type) |
|
220 | - { |
|
221 | - return in_array($post_type, $this->supported_post_types, true); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - public function getEditorContainer() |
|
229 | - { |
|
230 | - return array( |
|
231 | - $this->namespacedEditorBlockType(), |
|
232 | - array() |
|
233 | - ); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function registerScripts() |
|
241 | - { |
|
242 | - // wp_register_script( |
|
243 | - // 'core-blocks', |
|
244 | - // $this->domain->distributionAssetsUrl() . 'ee-core-blocks.dist.js', |
|
245 | - // array( |
|
246 | - // 'wp-blocks', // Provides useful functions and components for extending the editor |
|
247 | - // 'wp-i18n', // Provides localization functions |
|
248 | - // 'wp-element', // Provides React.Component |
|
249 | - // 'wp-components' // Provides many prebuilt components and controls |
|
250 | - // ), |
|
251 | - // filemtime($this->domain->distributionAssetsPath() . 'ee-core-blocks.dist.js') |
|
252 | - // ); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - public function registerStyles() |
|
260 | - { |
|
261 | - // wp_register_style( |
|
262 | - // 'ee-block-styles', |
|
263 | - // $this->domain->distributionAssetsUrl() . 'style.css', |
|
264 | - // array(), |
|
265 | - // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
266 | - // ); |
|
267 | - } |
|
26 | + const NS = 'event-espresso/'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var DomainInterface $domain |
|
30 | + */ |
|
31 | + protected $domain; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var LoaderInterface $loader |
|
35 | + */ |
|
36 | + protected $loader; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @var Registry |
|
41 | + */ |
|
42 | + protected $assets_registry; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string $editor_block_type |
|
46 | + */ |
|
47 | + private $editor_block_type; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var WP_Block_Type $wp_block_type |
|
51 | + */ |
|
52 | + private $wp_block_type; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $supported_post_types |
|
56 | + */ |
|
57 | + private $supported_post_types; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var array $attributes |
|
61 | + */ |
|
62 | + private $attributes; |
|
63 | + |
|
64 | + /** |
|
65 | + * If set to true, then the block will render its content client side |
|
66 | + * If false, then the block will render its content server side using the renderBlock() method |
|
67 | + * |
|
68 | + * @var bool $dynamic |
|
69 | + */ |
|
70 | + private $dynamic = false; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * EditorBlockLoader constructor. |
|
75 | + * |
|
76 | + * @param DomainInterface $domain |
|
77 | + * @param LoaderInterface $loader |
|
78 | + * @param Registry $assets_registry |
|
79 | + */ |
|
80 | + public function __construct( |
|
81 | + DomainInterface $domain, |
|
82 | + LoaderInterface $loader, |
|
83 | + Registry $assets_registry |
|
84 | + ) { |
|
85 | + $this->domain = $domain; |
|
86 | + $this->loader = $loader; |
|
87 | + $this->assets_registry = $assets_registry; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function editorBlockType() |
|
95 | + { |
|
96 | + return $this->editor_block_type; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function namespacedEditorBlockType() |
|
104 | + { |
|
105 | + return EditorBlock::NS . $this->editor_block_type; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param string $editor_block_type |
|
111 | + */ |
|
112 | + protected function setEditorBlockType($editor_block_type) |
|
113 | + { |
|
114 | + $this->editor_block_type = $editor_block_type; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @param WP_Block_Type $wp_block_type |
|
120 | + */ |
|
121 | + protected function setWpBlockType($wp_block_type) |
|
122 | + { |
|
123 | + $this->wp_block_type = $wp_block_type; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param array $supported_post_types |
|
129 | + */ |
|
130 | + protected function setSupportedPostTypes(array $supported_post_types) |
|
131 | + { |
|
132 | + $this->supported_post_types = $supported_post_types; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function attributes() |
|
140 | + { |
|
141 | + return $this->attributes; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param array $attributes |
|
147 | + */ |
|
148 | + public function setAttributes(array $attributes) |
|
149 | + { |
|
150 | + $this->attributes = $attributes; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function isDynamic() |
|
158 | + { |
|
159 | + return $this->dynamic; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param bool $dynamic |
|
165 | + */ |
|
166 | + public function setDynamic($dynamic = true) |
|
167 | + { |
|
168 | + $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Registers the Editor Block with WP core; |
|
174 | + * Returns the registered block type on success, or false on failure. |
|
175 | + * |
|
176 | + * @return WP_Block_Type|false |
|
177 | + */ |
|
178 | + public function registerBlock() |
|
179 | + { |
|
180 | + $context ='core'; |
|
181 | + // todo add route detection (ie inject route) and change context based on route |
|
182 | + $args = array( |
|
183 | + 'attributes' => $this->attributes(), |
|
184 | + 'editor_script' => "ee-{$context}-blocks", |
|
185 | + 'editor_style' => "ee-{$context}-blocks", |
|
186 | + 'script' => "ee-{$context}-blocks", |
|
187 | + 'style' => "ee-{$context}-blocks", |
|
188 | + ); |
|
189 | + if (! $this->isDynamic()) { |
|
190 | + $args['render_callback'] = $this->renderBlock(); |
|
191 | + } |
|
192 | + $wp_block_type = register_block_type( |
|
193 | + new WP_Block_Type( |
|
194 | + $this->namespacedEditorBlockType(), |
|
195 | + $args |
|
196 | + ) |
|
197 | + ); |
|
198 | + $this->setWpBlockType($wp_block_type); |
|
199 | + return $wp_block_type; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
205 | + */ |
|
206 | + public function unRegisterBlock() |
|
207 | + { |
|
208 | + return unregister_block_type($this->namespacedEditorBlockType()); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * returns true if the block type applies for the supplied post type |
|
214 | + * and should be added to that post type's editor |
|
215 | + * |
|
216 | + * @param string $post_type |
|
217 | + * @return boolean |
|
218 | + */ |
|
219 | + public function appliesToPostType($post_type) |
|
220 | + { |
|
221 | + return in_array($post_type, $this->supported_post_types, true); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + public function getEditorContainer() |
|
229 | + { |
|
230 | + return array( |
|
231 | + $this->namespacedEditorBlockType(), |
|
232 | + array() |
|
233 | + ); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function registerScripts() |
|
241 | + { |
|
242 | + // wp_register_script( |
|
243 | + // 'core-blocks', |
|
244 | + // $this->domain->distributionAssetsUrl() . 'ee-core-blocks.dist.js', |
|
245 | + // array( |
|
246 | + // 'wp-blocks', // Provides useful functions and components for extending the editor |
|
247 | + // 'wp-i18n', // Provides localization functions |
|
248 | + // 'wp-element', // Provides React.Component |
|
249 | + // 'wp-components' // Provides many prebuilt components and controls |
|
250 | + // ), |
|
251 | + // filemtime($this->domain->distributionAssetsPath() . 'ee-core-blocks.dist.js') |
|
252 | + // ); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + public function registerStyles() |
|
260 | + { |
|
261 | + // wp_register_style( |
|
262 | + // 'ee-block-styles', |
|
263 | + // $this->domain->distributionAssetsUrl() . 'style.css', |
|
264 | + // array(), |
|
265 | + // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
266 | + // ); |
|
267 | + } |
|
268 | 268 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function namespacedEditorBlockType() |
104 | 104 | { |
105 | - return EditorBlock::NS . $this->editor_block_type; |
|
105 | + return EditorBlock::NS.$this->editor_block_type; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function registerBlock() |
179 | 179 | { |
180 | - $context ='core'; |
|
180 | + $context = 'core'; |
|
181 | 181 | // todo add route detection (ie inject route) and change context based on route |
182 | - $args = array( |
|
182 | + $args = array( |
|
183 | 183 | 'attributes' => $this->attributes(), |
184 | 184 | 'editor_script' => "ee-{$context}-blocks", |
185 | 185 | 'editor_style' => "ee-{$context}-blocks", |
186 | 186 | 'script' => "ee-{$context}-blocks", |
187 | 187 | 'style' => "ee-{$context}-blocks", |
188 | 188 | ); |
189 | - if (! $this->isDynamic()) { |
|
189 | + if ( ! $this->isDynamic()) { |
|
190 | 190 | $args['render_callback'] = $this->renderBlock(); |
191 | 191 | } |
192 | 192 | $wp_block_type = register_block_type( |
@@ -20,94 +20,94 @@ |
||
20 | 20 | abstract class EditorBlockManager |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var CollectionInterface|EditorBlockInterface[] $blocks |
|
25 | - */ |
|
26 | - protected $blocks; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var RequestInterface $request |
|
30 | - */ |
|
31 | - protected $request; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var DomainInterface $domain |
|
35 | - */ |
|
36 | - protected $domain; |
|
37 | - |
|
38 | - /** |
|
39 | - * the post type that the current request applies to |
|
40 | - * |
|
41 | - * @var string $request_post_type |
|
42 | - */ |
|
43 | - protected $request_post_type; |
|
44 | - |
|
45 | - /** |
|
46 | - * value of the 'page' $_GET param |
|
47 | - * |
|
48 | - * @var string $page |
|
49 | - */ |
|
50 | - protected $page; |
|
51 | - |
|
52 | - /** |
|
53 | - * value of the 'action' $_GET param |
|
54 | - * |
|
55 | - * @var string $action |
|
56 | - */ |
|
57 | - protected $action; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @var Registry |
|
62 | - */ |
|
63 | - protected $assets_registry; |
|
64 | - |
|
65 | - /** |
|
66 | - * EditorBlockManager constructor. |
|
67 | - * |
|
68 | - * @param EditorBlockCollection $blocks |
|
69 | - * @param RequestInterface $request |
|
70 | - * @param DomainInterface $domain |
|
71 | - * @param Registry $assets_registry |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - EditorBlockCollection $blocks, |
|
75 | - RequestInterface $request, |
|
76 | - DomainInterface $domain, |
|
77 | - Registry $assets_registry |
|
78 | - ) { |
|
79 | - $this->blocks = $blocks; |
|
80 | - $this->request = $request; |
|
81 | - $this->domain = $domain; |
|
82 | - $this->assets_registry = $assets_registry; |
|
83 | - $this->request_post_type = $this->request->getRequestParam('post_type', ''); |
|
84 | - $this->page = $this->request->getRequestParam('page', ''); |
|
85 | - $this->action = $this->request->getRequestParam('action', ''); |
|
86 | - add_action($this->init_hook(), array($this, 'initialize')); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns the name of a hookpoint to be used to call initialize() |
|
92 | - * |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - abstract public function initHook(); |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Perform any early setup required for block editors to functions |
|
100 | - * |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - abstract public function initialize(); |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function currentRequestPostType() |
|
110 | - { |
|
111 | - return $this->request_post_type; |
|
112 | - } |
|
23 | + /** |
|
24 | + * @var CollectionInterface|EditorBlockInterface[] $blocks |
|
25 | + */ |
|
26 | + protected $blocks; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var RequestInterface $request |
|
30 | + */ |
|
31 | + protected $request; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var DomainInterface $domain |
|
35 | + */ |
|
36 | + protected $domain; |
|
37 | + |
|
38 | + /** |
|
39 | + * the post type that the current request applies to |
|
40 | + * |
|
41 | + * @var string $request_post_type |
|
42 | + */ |
|
43 | + protected $request_post_type; |
|
44 | + |
|
45 | + /** |
|
46 | + * value of the 'page' $_GET param |
|
47 | + * |
|
48 | + * @var string $page |
|
49 | + */ |
|
50 | + protected $page; |
|
51 | + |
|
52 | + /** |
|
53 | + * value of the 'action' $_GET param |
|
54 | + * |
|
55 | + * @var string $action |
|
56 | + */ |
|
57 | + protected $action; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @var Registry |
|
62 | + */ |
|
63 | + protected $assets_registry; |
|
64 | + |
|
65 | + /** |
|
66 | + * EditorBlockManager constructor. |
|
67 | + * |
|
68 | + * @param EditorBlockCollection $blocks |
|
69 | + * @param RequestInterface $request |
|
70 | + * @param DomainInterface $domain |
|
71 | + * @param Registry $assets_registry |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + EditorBlockCollection $blocks, |
|
75 | + RequestInterface $request, |
|
76 | + DomainInterface $domain, |
|
77 | + Registry $assets_registry |
|
78 | + ) { |
|
79 | + $this->blocks = $blocks; |
|
80 | + $this->request = $request; |
|
81 | + $this->domain = $domain; |
|
82 | + $this->assets_registry = $assets_registry; |
|
83 | + $this->request_post_type = $this->request->getRequestParam('post_type', ''); |
|
84 | + $this->page = $this->request->getRequestParam('page', ''); |
|
85 | + $this->action = $this->request->getRequestParam('action', ''); |
|
86 | + add_action($this->init_hook(), array($this, 'initialize')); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns the name of a hookpoint to be used to call initialize() |
|
92 | + * |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + abstract public function initHook(); |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Perform any early setup required for block editors to functions |
|
100 | + * |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + abstract public function initialize(); |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function currentRequestPostType() |
|
110 | + { |
|
111 | + return $this->request_post_type; |
|
112 | + } |
|
113 | 113 | } |
@@ -10,294 +10,294 @@ |
||
10 | 10 | */ |
11 | 11 | trait MessagesAdmin |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | - * a string. |
|
16 | - */ |
|
17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | - { |
|
19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | - * a string. |
|
25 | - */ |
|
26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | - { |
|
28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | - * a string. |
|
35 | - */ |
|
36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Directs to message settings page |
|
44 | - */ |
|
45 | - public function amOnMessageSettingsPage() |
|
46 | - { |
|
47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | - { |
|
53 | - $this->actor()->dragAndDrop( |
|
54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | - * @param string $message_type_slug |
|
63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | - */ |
|
65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | - { |
|
67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | - * |
|
75 | - * @param int $expected_occurence_count |
|
76 | - * @param string $text_to_check_for |
|
77 | - * @param string $field |
|
78 | - * @param string $message_type_label |
|
79 | - * @param string $message_status |
|
80 | - * @param string $messenger |
|
81 | - * @param string $context |
|
82 | - */ |
|
83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | - $expected_occurence_count, |
|
85 | - $text_to_check_for, |
|
86 | - $field, |
|
87 | - $message_type_label, |
|
88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | - $messenger = 'Email', |
|
90 | - $context = 'Event Admin' |
|
91 | - ) { |
|
92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | - $field, |
|
94 | - $message_type_label, |
|
95 | - $message_status, |
|
96 | - $messenger, |
|
97 | - $context, |
|
98 | - $text_to_check_for, |
|
99 | - 0 |
|
100 | - )); |
|
101 | - $actual_count = count($elements); |
|
102 | - $this->actor()->assertEquals( |
|
103 | - $expected_occurence_count, |
|
104 | - $actual_count, |
|
105 | - sprintf( |
|
106 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | - $expected_occurence_count, |
|
108 | - $text_to_check_for, |
|
109 | - $field, |
|
110 | - $actual_count |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | - * default (global) message template list table. |
|
119 | - * Also takes care of verifying the template was created. |
|
120 | - * @param string $message_type_label |
|
121 | - * @param string $messenger_label |
|
122 | - */ |
|
123 | - public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | - { |
|
125 | - $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | - $this->actor()->click( |
|
127 | - MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | - $message_type_label, |
|
129 | - $messenger_label |
|
130 | - ) |
|
131 | - ); |
|
132 | - $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This switches the context of the current messages template to the given reference. |
|
138 | - * @param string $context_reference This should be the visible label for the option. |
|
139 | - */ |
|
140 | - public function switchContextTo($context_reference) |
|
141 | - { |
|
142 | - $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | - $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | - * toggling. |
|
151 | - * |
|
152 | - * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | - * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | - * (false) |
|
155 | - */ |
|
156 | - public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | - { |
|
158 | - $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
159 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
160 | - if ($expected_state_is_active) { |
|
161 | - $this->actor()->waitForText("The template for $context_string is currently active."); |
|
162 | - } else { |
|
163 | - $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Triggers saving the message template. |
|
170 | - * @param bool $and_close Use to indicate to click the Save and Close button. |
|
171 | - */ |
|
172 | - public function saveMessageTemplate($and_close = false) |
|
173 | - { |
|
174 | - $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
175 | - if ($and_close) { |
|
176 | - $this->actor()->click('Save and Close'); |
|
177 | - } else { |
|
178 | - $this->actor()->click('Save'); |
|
179 | - } |
|
180 | - $this->actor()->waitForText('successfully updated'); |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * This takes care of clicking the View Message icon for the given parameters. |
|
186 | - * Assumes you are already viewing the messages activity list table. |
|
187 | - * @param $message_type_label |
|
188 | - * @param $message_status |
|
189 | - * @param string $messenger |
|
190 | - * @param string $context |
|
191 | - * @param int $number_in_set |
|
192 | - */ |
|
193 | - public function viewMessageInMessagesListTableFor( |
|
194 | - $message_type_label, |
|
195 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
196 | - $messenger = 'Email', |
|
197 | - $context = 'Event Admin', |
|
198 | - $number_in_set = 1 |
|
199 | - ) { |
|
200 | - $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
201 | - $message_type_label, |
|
202 | - $message_status, |
|
203 | - $messenger, |
|
204 | - $context, |
|
205 | - $number_in_set |
|
206 | - )); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
212 | - * Assumes you are already viewing the messages activity list table. |
|
213 | - * @param $message_type_label |
|
214 | - * @param $message_status |
|
215 | - * @param string $messenger |
|
216 | - * @param string $context |
|
217 | - * @param int $number_in_set |
|
218 | - */ |
|
219 | - public function deleteMessageInMessagesListTableFor( |
|
220 | - $message_type_label, |
|
221 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
222 | - $messenger = 'Email', |
|
223 | - $context = 'Event Admin', |
|
224 | - $number_in_set = 1 |
|
225 | - ) { |
|
226 | - $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
227 | - $message_type_label, |
|
228 | - $message_status, |
|
229 | - $messenger, |
|
230 | - $context, |
|
231 | - $number_in_set |
|
232 | - ); |
|
233 | - $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
234 | - 'to', |
|
235 | - $message_type_label, |
|
236 | - $message_status, |
|
237 | - $messenger, |
|
238 | - $context, |
|
239 | - '', |
|
240 | - $number_in_set |
|
241 | - ); |
|
242 | - $this->actor()->scrollTo($cell_selector, 0, -30); |
|
243 | - $this->actor()->moveMouseOver( |
|
244 | - $cell_selector, |
|
245 | - 5, |
|
246 | - 5 |
|
247 | - ); |
|
248 | - $this->actor()->waitForElementVisible( |
|
249 | - $delete_action_selector |
|
250 | - ); |
|
251 | - $this->actor()->click( |
|
252 | - $delete_action_selector |
|
253 | - ); |
|
254 | - $this->actor()->waitForText('successfully deleted', 20); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
260 | - * list table, this will take care of validating the given text is in that window. |
|
261 | - * @param string $text_to_view |
|
262 | - */ |
|
263 | - public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
264 | - { |
|
265 | - $this->actor()->wait(2); |
|
266 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
267 | - $this->actor()->switchToIframe('message-view-window'); |
|
268 | - $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
269 | - $this->actor()->switchToIframe(); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * This returns the value for the link at the given selector in the message modal. |
|
275 | - * @param string $selector (any selector string accepted by WebDriver) |
|
276 | - */ |
|
277 | - public function observeLinkAtSelectorInMessageModal($selector) |
|
278 | - { |
|
279 | - $this->actor()->wait(2); |
|
280 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
281 | - $this->actor()->switchToIframe('message-view-window'); |
|
282 | - $link = $this->actor()->observeLinkUrlAt($selector); |
|
283 | - $this->actor()->switchToIframe(); |
|
284 | - return $link; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
290 | - * list table, this will take care of validating the given text is NOT that window. |
|
291 | - * @param string $text_to_view |
|
292 | - */ |
|
293 | - public function dontSeeTextInViewMessageModal($text_to_view) |
|
294 | - { |
|
295 | - $this->seeTextInViewMessageModal($text_to_view, true); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - public function dismissMessageModal() |
|
300 | - { |
|
301 | - $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
302 | - } |
|
13 | + /** |
|
14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | + * a string. |
|
16 | + */ |
|
17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | + { |
|
19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | + * a string. |
|
25 | + */ |
|
26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | + { |
|
28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | + * a string. |
|
35 | + */ |
|
36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Directs to message settings page |
|
44 | + */ |
|
45 | + public function amOnMessageSettingsPage() |
|
46 | + { |
|
47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | + { |
|
53 | + $this->actor()->dragAndDrop( |
|
54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | + * @param string $message_type_slug |
|
63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | + */ |
|
65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | + { |
|
67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | + * |
|
75 | + * @param int $expected_occurence_count |
|
76 | + * @param string $text_to_check_for |
|
77 | + * @param string $field |
|
78 | + * @param string $message_type_label |
|
79 | + * @param string $message_status |
|
80 | + * @param string $messenger |
|
81 | + * @param string $context |
|
82 | + */ |
|
83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | + $expected_occurence_count, |
|
85 | + $text_to_check_for, |
|
86 | + $field, |
|
87 | + $message_type_label, |
|
88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | + $messenger = 'Email', |
|
90 | + $context = 'Event Admin' |
|
91 | + ) { |
|
92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | + $field, |
|
94 | + $message_type_label, |
|
95 | + $message_status, |
|
96 | + $messenger, |
|
97 | + $context, |
|
98 | + $text_to_check_for, |
|
99 | + 0 |
|
100 | + )); |
|
101 | + $actual_count = count($elements); |
|
102 | + $this->actor()->assertEquals( |
|
103 | + $expected_occurence_count, |
|
104 | + $actual_count, |
|
105 | + sprintf( |
|
106 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | + $expected_occurence_count, |
|
108 | + $text_to_check_for, |
|
109 | + $field, |
|
110 | + $actual_count |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | + * default (global) message template list table. |
|
119 | + * Also takes care of verifying the template was created. |
|
120 | + * @param string $message_type_label |
|
121 | + * @param string $messenger_label |
|
122 | + */ |
|
123 | + public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | + { |
|
125 | + $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | + $this->actor()->click( |
|
127 | + MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | + $message_type_label, |
|
129 | + $messenger_label |
|
130 | + ) |
|
131 | + ); |
|
132 | + $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This switches the context of the current messages template to the given reference. |
|
138 | + * @param string $context_reference This should be the visible label for the option. |
|
139 | + */ |
|
140 | + public function switchContextTo($context_reference) |
|
141 | + { |
|
142 | + $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | + $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | + * toggling. |
|
151 | + * |
|
152 | + * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | + * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | + * (false) |
|
155 | + */ |
|
156 | + public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | + { |
|
158 | + $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
159 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
160 | + if ($expected_state_is_active) { |
|
161 | + $this->actor()->waitForText("The template for $context_string is currently active."); |
|
162 | + } else { |
|
163 | + $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Triggers saving the message template. |
|
170 | + * @param bool $and_close Use to indicate to click the Save and Close button. |
|
171 | + */ |
|
172 | + public function saveMessageTemplate($and_close = false) |
|
173 | + { |
|
174 | + $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
175 | + if ($and_close) { |
|
176 | + $this->actor()->click('Save and Close'); |
|
177 | + } else { |
|
178 | + $this->actor()->click('Save'); |
|
179 | + } |
|
180 | + $this->actor()->waitForText('successfully updated'); |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * This takes care of clicking the View Message icon for the given parameters. |
|
186 | + * Assumes you are already viewing the messages activity list table. |
|
187 | + * @param $message_type_label |
|
188 | + * @param $message_status |
|
189 | + * @param string $messenger |
|
190 | + * @param string $context |
|
191 | + * @param int $number_in_set |
|
192 | + */ |
|
193 | + public function viewMessageInMessagesListTableFor( |
|
194 | + $message_type_label, |
|
195 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
196 | + $messenger = 'Email', |
|
197 | + $context = 'Event Admin', |
|
198 | + $number_in_set = 1 |
|
199 | + ) { |
|
200 | + $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
201 | + $message_type_label, |
|
202 | + $message_status, |
|
203 | + $messenger, |
|
204 | + $context, |
|
205 | + $number_in_set |
|
206 | + )); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
212 | + * Assumes you are already viewing the messages activity list table. |
|
213 | + * @param $message_type_label |
|
214 | + * @param $message_status |
|
215 | + * @param string $messenger |
|
216 | + * @param string $context |
|
217 | + * @param int $number_in_set |
|
218 | + */ |
|
219 | + public function deleteMessageInMessagesListTableFor( |
|
220 | + $message_type_label, |
|
221 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
222 | + $messenger = 'Email', |
|
223 | + $context = 'Event Admin', |
|
224 | + $number_in_set = 1 |
|
225 | + ) { |
|
226 | + $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
227 | + $message_type_label, |
|
228 | + $message_status, |
|
229 | + $messenger, |
|
230 | + $context, |
|
231 | + $number_in_set |
|
232 | + ); |
|
233 | + $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
234 | + 'to', |
|
235 | + $message_type_label, |
|
236 | + $message_status, |
|
237 | + $messenger, |
|
238 | + $context, |
|
239 | + '', |
|
240 | + $number_in_set |
|
241 | + ); |
|
242 | + $this->actor()->scrollTo($cell_selector, 0, -30); |
|
243 | + $this->actor()->moveMouseOver( |
|
244 | + $cell_selector, |
|
245 | + 5, |
|
246 | + 5 |
|
247 | + ); |
|
248 | + $this->actor()->waitForElementVisible( |
|
249 | + $delete_action_selector |
|
250 | + ); |
|
251 | + $this->actor()->click( |
|
252 | + $delete_action_selector |
|
253 | + ); |
|
254 | + $this->actor()->waitForText('successfully deleted', 20); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
260 | + * list table, this will take care of validating the given text is in that window. |
|
261 | + * @param string $text_to_view |
|
262 | + */ |
|
263 | + public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
264 | + { |
|
265 | + $this->actor()->wait(2); |
|
266 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
267 | + $this->actor()->switchToIframe('message-view-window'); |
|
268 | + $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
269 | + $this->actor()->switchToIframe(); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * This returns the value for the link at the given selector in the message modal. |
|
275 | + * @param string $selector (any selector string accepted by WebDriver) |
|
276 | + */ |
|
277 | + public function observeLinkAtSelectorInMessageModal($selector) |
|
278 | + { |
|
279 | + $this->actor()->wait(2); |
|
280 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
281 | + $this->actor()->switchToIframe('message-view-window'); |
|
282 | + $link = $this->actor()->observeLinkUrlAt($selector); |
|
283 | + $this->actor()->switchToIframe(); |
|
284 | + return $link; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
290 | + * list table, this will take care of validating the given text is NOT that window. |
|
291 | + * @param string $text_to_view |
|
292 | + */ |
|
293 | + public function dontSeeTextInViewMessageModal($text_to_view) |
|
294 | + { |
|
295 | + $this->seeTextInViewMessageModal($text_to_view, true); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + public function dismissMessageModal() |
|
300 | + { |
|
301 | + $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
302 | + } |
|
303 | 303 | } |
@@ -7,16 +7,16 @@ discard block |
||
7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
9 | 9 | if (! defined('DS')) { |
10 | - define('DS', '/'); |
|
10 | + define('DS', '/'); |
|
11 | 11 | } |
12 | 12 | if (! defined('PS')) { |
13 | - define('PS', PATH_SEPARATOR); |
|
13 | + define('PS', PATH_SEPARATOR); |
|
14 | 14 | } |
15 | 15 | if (! defined('SP')) { |
16 | - define('SP', ' '); |
|
16 | + define('SP', ' '); |
|
17 | 17 | } |
18 | 18 | if (! defined('EENL')) { |
19 | - define('EENL', "\n"); |
|
19 | + define('EENL', "\n"); |
|
20 | 20 | } |
21 | 21 | // define the plugin directory and URL |
22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
@@ -70,16 +70,16 @@ discard block |
||
70 | 70 | define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
71 | 71 | // check for DOMPDF fonts in uploads |
72 | 72 | if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
74 | 74 | } |
75 | 75 | // ajax constants |
76 | 76 | define( |
77 | - 'EE_FRONT_AJAX', |
|
78 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) |
|
77 | + 'EE_FRONT_AJAX', |
|
78 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) |
|
79 | 79 | ); |
80 | 80 | define( |
81 | - 'EE_ADMIN_AJAX', |
|
82 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) |
|
81 | + 'EE_ADMIN_AJAX', |
|
82 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) |
|
83 | 83 | ); |
84 | 84 | // just a handy constant occasionally needed for finding values representing infinity in the DB |
85 | 85 | // you're better to use this than its straight value (currently -1) in case you ever |
@@ -89,5 +89,5 @@ discard block |
||
89 | 89 | define('EE_DEBUG', false); |
90 | 90 | // for older WP versions |
91 | 91 | if (! defined('MONTH_IN_SECONDS')) { |
92 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
92 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
93 | 93 | } |
@@ -6,71 +6,71 @@ discard block |
||
6 | 6 | define('EE_MIN_PHP_VER_RECOMMENDED', '5.6.32'); |
7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
9 | -if (! defined('DS')) { |
|
9 | +if ( ! defined('DS')) { |
|
10 | 10 | define('DS', '/'); |
11 | 11 | } |
12 | -if (! defined('PS')) { |
|
12 | +if ( ! defined('PS')) { |
|
13 | 13 | define('PS', PATH_SEPARATOR); |
14 | 14 | } |
15 | -if (! defined('SP')) { |
|
15 | +if ( ! defined('SP')) { |
|
16 | 16 | define('SP', ' '); |
17 | 17 | } |
18 | -if (! defined('EENL')) { |
|
18 | +if ( ! defined('EENL')) { |
|
19 | 19 | define('EENL', "\n"); |
20 | 20 | } |
21 | 21 | // define the plugin directory and URL |
22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
23 | -define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE) . DS); |
|
23 | +define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE).DS); |
|
24 | 24 | define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
25 | 25 | // main root folder paths |
26 | -define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
27 | -define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
28 | -define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
29 | -define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
30 | -define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
31 | -define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
32 | -define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
33 | -define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
26 | +define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages'.DS); |
|
27 | +define('EE_CORE', EE_PLUGIN_DIR_PATH.'core'.DS); |
|
28 | +define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules'.DS); |
|
29 | +define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public'.DS); |
|
30 | +define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes'.DS); |
|
31 | +define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets'.DS); |
|
32 | +define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods'.DS); |
|
33 | +define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated'.DS); |
|
34 | 34 | // core system paths |
35 | -define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
36 | -define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
37 | -define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
38 | -define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
39 | -define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
40 | -define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
41 | -define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
42 | -define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
43 | -define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
44 | -define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
45 | -define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
46 | -define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
35 | +define('EE_ADMIN', EE_CORE.'admin'.DS); |
|
36 | +define('EE_CPTS', EE_CORE.'CPTs'.DS); |
|
37 | +define('EE_CLASSES', EE_CORE.'db_classes'.DS); |
|
38 | +define('EE_INTERFACES', EE_CORE.'interfaces'.DS); |
|
39 | +define('EE_BUSINESS', EE_CORE.'business'.DS); |
|
40 | +define('EE_MODELS', EE_CORE.'db_models'.DS); |
|
41 | +define('EE_HELPERS', EE_CORE.'helpers'.DS); |
|
42 | +define('EE_LIBRARIES', EE_CORE.'libraries'.DS); |
|
43 | +define('EE_TEMPLATES', EE_CORE.'templates'.DS); |
|
44 | +define('EE_THIRD_PARTY', EE_CORE.'third_party_libs'.DS); |
|
45 | +define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets'.DS); |
|
46 | +define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections'.DS); |
|
47 | 47 | // gateways |
48 | -define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
49 | -define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
48 | +define('EE_GATEWAYS', EE_MODULES.'gateways'.DS); |
|
49 | +define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules'.DS.'gateways'.DS); |
|
50 | 50 | // asset URL paths |
51 | -define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
52 | -define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
53 | -define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
54 | -define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
55 | -define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
56 | -define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
51 | +define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core'.DS.'templates'.DS); |
|
52 | +define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets'.DS); |
|
53 | +define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images'.DS); |
|
54 | +define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core'.DS.'third_party_libs'.DS); |
|
55 | +define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/'); |
|
56 | +define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/'); |
|
57 | 57 | // define upload paths |
58 | 58 | $uploads = wp_upload_dir(); |
59 | 59 | // define the uploads directory and URL |
60 | -define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
61 | -define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
60 | +define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].DS.'espresso'.DS); |
|
61 | +define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].DS.'espresso'.DS); |
|
62 | 62 | // define the templates directory and URL |
63 | -define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
64 | -define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
63 | +define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].DS.'espresso'.DS.'templates'.DS); |
|
64 | +define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].DS.'espresso'.DS.'templates'.DS); |
|
65 | 65 | // define the gateway directory and URL |
66 | -define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
67 | -define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
66 | +define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].DS.'espresso'.DS.'gateways'.DS); |
|
67 | +define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].DS.'espresso'.DS.'gateways'.DS); |
|
68 | 68 | // languages folder/path |
69 | -define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
70 | -define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
69 | +define('EE_LANGUAGES_SAFE_LOC', '..'.DS.'uploads'.DS.'espresso'.DS.'languages'.DS); |
|
70 | +define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages'.DS); |
|
71 | 71 | // check for DOMPDF fonts in uploads |
72 | -if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
72 | +if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS)) { |
|
73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS); |
|
74 | 74 | } |
75 | 75 | // ajax constants |
76 | 76 | define( |
@@ -88,6 +88,6 @@ discard block |
||
88 | 88 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
89 | 89 | define('EE_DEBUG', false); |
90 | 90 | // for older WP versions |
91 | -if (! defined('MONTH_IN_SECONDS')) { |
|
91 | +if ( ! defined('MONTH_IN_SECONDS')) { |
|
92 | 92 | define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
93 | 93 | } |
@@ -6,22 +6,22 @@ discard block |
||
6 | 6 | */ |
7 | 7 | function espresso_load_error_handling() |
8 | 8 | { |
9 | - static $error_handling_loaded = false; |
|
10 | - if ($error_handling_loaded) { |
|
11 | - return; |
|
12 | - } |
|
13 | - // load debugging tools |
|
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | - \EEH_Debug_Tools::instance(); |
|
17 | - } |
|
18 | - // load error handling |
|
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | - } else { |
|
22 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | - } |
|
24 | - $error_handling_loaded = true; |
|
9 | + static $error_handling_loaded = false; |
|
10 | + if ($error_handling_loaded) { |
|
11 | + return; |
|
12 | + } |
|
13 | + // load debugging tools |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | + \EEH_Debug_Tools::instance(); |
|
17 | + } |
|
18 | + // load error handling |
|
19 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | + } else { |
|
22 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | + } |
|
24 | + $error_handling_loaded = true; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | */ |
36 | 36 | function espresso_load_required($classname, $full_path_to_file) |
37 | 37 | { |
38 | - if (is_readable($full_path_to_file)) { |
|
39 | - require_once $full_path_to_file; |
|
40 | - } else { |
|
41 | - throw new \EE_Error( |
|
42 | - sprintf( |
|
43 | - esc_html__( |
|
44 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | - 'event_espresso' |
|
46 | - ), |
|
47 | - $classname |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
38 | + if (is_readable($full_path_to_file)) { |
|
39 | + require_once $full_path_to_file; |
|
40 | + } else { |
|
41 | + throw new \EE_Error( |
|
42 | + sprintf( |
|
43 | + esc_html__( |
|
44 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | + 'event_espresso' |
|
46 | + ), |
|
47 | + $classname |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | |
@@ -66,39 +66,39 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | - try { |
|
71 | - espresso_load_error_handling(); |
|
72 | - espresso_load_required( |
|
73 | - 'EEH_Base', |
|
74 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
75 | - ); |
|
76 | - espresso_load_required( |
|
77 | - 'EEH_File', |
|
78 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
79 | - ); |
|
80 | - espresso_load_required( |
|
81 | - 'EEH_File', |
|
82 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
83 | - ); |
|
84 | - espresso_load_required( |
|
85 | - 'EEH_Array', |
|
86 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
87 | - ); |
|
88 | - // instantiate and configure PSR4 autoloader |
|
89 | - espresso_load_required( |
|
90 | - 'Psr4Autoloader', |
|
91 | - EE_CORE . 'Psr4Autoloader.php' |
|
92 | - ); |
|
93 | - espresso_load_required( |
|
94 | - 'EE_Psr4AutoloaderInit', |
|
95 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
96 | - ); |
|
97 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
98 | - $AutoloaderInit->initializeAutoloader(); |
|
99 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
100 | - } catch (Exception $e) { |
|
101 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
102 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
103 | - } |
|
69 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | + try { |
|
71 | + espresso_load_error_handling(); |
|
72 | + espresso_load_required( |
|
73 | + 'EEH_Base', |
|
74 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
75 | + ); |
|
76 | + espresso_load_required( |
|
77 | + 'EEH_File', |
|
78 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
79 | + ); |
|
80 | + espresso_load_required( |
|
81 | + 'EEH_File', |
|
82 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
83 | + ); |
|
84 | + espresso_load_required( |
|
85 | + 'EEH_Array', |
|
86 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
87 | + ); |
|
88 | + // instantiate and configure PSR4 autoloader |
|
89 | + espresso_load_required( |
|
90 | + 'Psr4Autoloader', |
|
91 | + EE_CORE . 'Psr4Autoloader.php' |
|
92 | + ); |
|
93 | + espresso_load_required( |
|
94 | + 'EE_Psr4AutoloaderInit', |
|
95 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
96 | + ); |
|
97 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
98 | + $AutoloaderInit->initializeAutoloader(); |
|
99 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
100 | + } catch (Exception $e) { |
|
101 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
102 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
103 | + } |
|
104 | 104 | } |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | return; |
12 | 12 | } |
13 | 13 | // load debugging tools |
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS.'EEH_Debug_Tools.helper.php'; |
|
16 | 16 | \EEH_Debug_Tools::instance(); |
17 | 17 | } |
18 | 18 | // load error handling |
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
19 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE.'EE_Error.core.php'; |
|
21 | 21 | } else { |
22 | 22 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
23 | 23 | } |
@@ -66,39 +66,39 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
69 | + require_once __DIR__.'/espresso_definitions.php'; |
|
70 | 70 | try { |
71 | 71 | espresso_load_error_handling(); |
72 | 72 | espresso_load_required( |
73 | 73 | 'EEH_Base', |
74 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
74 | + EE_CORE.'helpers'.DS.'EEH_Base.helper.php' |
|
75 | 75 | ); |
76 | 76 | espresso_load_required( |
77 | 77 | 'EEH_File', |
78 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
78 | + EE_CORE.'interfaces'.DS.'EEHI_File.interface.php' |
|
79 | 79 | ); |
80 | 80 | espresso_load_required( |
81 | 81 | 'EEH_File', |
82 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
82 | + EE_CORE.'helpers'.DS.'EEH_File.helper.php' |
|
83 | 83 | ); |
84 | 84 | espresso_load_required( |
85 | 85 | 'EEH_Array', |
86 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
86 | + EE_CORE.'helpers'.DS.'EEH_Array.helper.php' |
|
87 | 87 | ); |
88 | 88 | // instantiate and configure PSR4 autoloader |
89 | 89 | espresso_load_required( |
90 | 90 | 'Psr4Autoloader', |
91 | - EE_CORE . 'Psr4Autoloader.php' |
|
91 | + EE_CORE.'Psr4Autoloader.php' |
|
92 | 92 | ); |
93 | 93 | espresso_load_required( |
94 | 94 | 'EE_Psr4AutoloaderInit', |
95 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
95 | + EE_CORE.'EE_Psr4AutoloaderInit.core.php' |
|
96 | 96 | ); |
97 | 97 | $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
98 | 98 | $AutoloaderInit->initializeAutoloader(); |
99 | 99 | new EventEspresso\core\services\bootstrap\BootstrapCore(); |
100 | 100 | } catch (Exception $e) { |
101 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
101 | + require_once EE_CORE.'exceptions'.DS.'ExceptionStackTraceDisplay.php'; |
|
102 | 102 | new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
103 | 103 | } |
104 | 104 | } |
@@ -15,403 +15,403 @@ |
||
15 | 15 | class EE_SPCO_JSON_Response |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $_errors = ''; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $_unexpected_errors = ''; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_attention = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $_success = ''; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $_plz_select_method_of_payment = ''; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - protected $_redirect_url = ''; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - protected $_registration_time_limit = ''; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $_redirect_form = ''; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - protected $_reg_step_html = ''; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - protected $_method_of_payment = ''; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var float |
|
70 | - */ |
|
71 | - protected $_payment_amount; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var array |
|
75 | - */ |
|
76 | - protected $_return_data = array(); |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @var array |
|
81 | - */ |
|
82 | - protected $_validation_rules = array(); |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * class constructor |
|
87 | - */ |
|
88 | - public function __construct() |
|
89 | - { |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * __toString |
|
95 | - * |
|
96 | - * allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a JSON encoded string |
|
97 | - * ie: $json_response = new EE_SPCO_JSON_Response(); |
|
98 | - * echo $json_response; |
|
99 | - * |
|
100 | - * @access public |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function __toString() |
|
104 | - { |
|
105 | - $JSON_response = array(); |
|
106 | - // grab notices |
|
107 | - $notices = EE_Error::get_notices(false); |
|
108 | - $this->set_attention(isset($notices['attention']) ? $notices['attention'] : ''); |
|
109 | - $this->set_errors(isset($notices['errors']) ? $notices['errors'] : ''); |
|
110 | - $this->set_success(isset($notices['success']) ? $notices['success'] : ''); |
|
111 | - // add notices to JSON response, but only if they exist |
|
112 | - if ($this->attention()) { |
|
113 | - $JSON_response['attention'] = $this->attention(); |
|
114 | - } |
|
115 | - if ($this->errors()) { |
|
116 | - $JSON_response['errors'] = $this->errors(); |
|
117 | - } |
|
118 | - if ($this->unexpected_errors()) { |
|
119 | - $JSON_response['unexpected_errors'] = $this->unexpected_errors(); |
|
120 | - } |
|
121 | - if ($this->success()) { |
|
122 | - $JSON_response['success'] = $this->success(); |
|
123 | - } |
|
124 | - // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
|
125 | - if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
126 | - $JSON_response['success'] = null; |
|
127 | - } |
|
128 | - // set redirect_url, IF it exists |
|
129 | - if ($this->redirect_url()) { |
|
130 | - $JSON_response['redirect_url'] = $this->redirect_url(); |
|
131 | - } |
|
132 | - // set registration_time_limit, IF it exists |
|
133 | - if ($this->registration_time_limit()) { |
|
134 | - $JSON_response['registration_time_limit'] = $this->registration_time_limit(); |
|
135 | - } |
|
136 | - // set payment_amount, IF it exists |
|
137 | - if ($this->payment_amount() !== null) { |
|
138 | - $JSON_response['payment_amount'] = $this->payment_amount(); |
|
139 | - } |
|
140 | - // grab generic return data |
|
141 | - $return_data = $this->return_data(); |
|
142 | - // add billing form validation rules |
|
143 | - if ($this->validation_rules()) { |
|
144 | - $return_data['validation_rules'] = $this->validation_rules(); |
|
145 | - } |
|
146 | - // set reg_step_html, IF it exists |
|
147 | - if ($this->reg_step_html()) { |
|
148 | - $return_data['reg_step_html'] = $this->reg_step_html(); |
|
149 | - } |
|
150 | - // set method of payment, IF it exists |
|
151 | - if ($this->method_of_payment()) { |
|
152 | - $return_data['method_of_payment'] = $this->method_of_payment(); |
|
153 | - } |
|
154 | - // set "plz_select_method_of_payment" message, IF it exists |
|
155 | - if ($this->plz_select_method_of_payment()) { |
|
156 | - $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment(); |
|
157 | - } |
|
158 | - // set redirect_form, IF it exists |
|
159 | - if ($this->redirect_form()) { |
|
160 | - $return_data['redirect_form'] = $this->redirect_form(); |
|
161 | - } |
|
162 | - // and finally, add return_data array to main JSON response array, IF it contains anything |
|
163 | - // why did we add some of the above properties to the return data array? |
|
164 | - // because it is easier and cleaner in the Javascript to deal with this way |
|
165 | - if (! empty($return_data)) { |
|
166 | - $JSON_response['return_data'] = $return_data; |
|
167 | - } |
|
168 | - // filter final array |
|
169 | - $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response); |
|
170 | - // return encoded array |
|
171 | - return (string) wp_json_encode($JSON_response); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param string $attention |
|
177 | - */ |
|
178 | - public function set_attention($attention) |
|
179 | - { |
|
180 | - $this->_attention = $attention; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - public function attention() |
|
188 | - { |
|
189 | - return $this->_attention; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @param string $errors |
|
195 | - */ |
|
196 | - public function set_errors($errors) |
|
197 | - { |
|
198 | - $this->_errors = $errors; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function errors() |
|
206 | - { |
|
207 | - return $this->_errors; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function unexpected_errors() |
|
215 | - { |
|
216 | - return $this->_unexpected_errors; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string $unexpected_errors |
|
222 | - */ |
|
223 | - public function set_unexpected_errors($unexpected_errors) |
|
224 | - { |
|
225 | - $this->_unexpected_errors = $unexpected_errors; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * @param string $success |
|
231 | - */ |
|
232 | - public function set_success($success) |
|
233 | - { |
|
234 | - $this->_success = $success; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @return string |
|
240 | - */ |
|
241 | - public function success() |
|
242 | - { |
|
243 | - return $this->_success; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @param string $method_of_payment |
|
249 | - */ |
|
250 | - public function set_method_of_payment($method_of_payment) |
|
251 | - { |
|
252 | - $this->_method_of_payment = $method_of_payment; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return string |
|
258 | - */ |
|
259 | - public function method_of_payment() |
|
260 | - { |
|
261 | - return $this->_method_of_payment; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return float |
|
267 | - */ |
|
268 | - public function payment_amount() |
|
269 | - { |
|
270 | - return $this->_payment_amount; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param float $payment_amount |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - public function set_payment_amount($payment_amount) |
|
279 | - { |
|
280 | - $this->_payment_amount = (float) $payment_amount; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @param string $next_step_html |
|
286 | - */ |
|
287 | - public function set_reg_step_html($next_step_html) |
|
288 | - { |
|
289 | - $this->_reg_step_html = $next_step_html; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - public function reg_step_html() |
|
297 | - { |
|
298 | - return $this->_reg_step_html; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * @param string $redirect_form |
|
304 | - */ |
|
305 | - public function set_redirect_form($redirect_form) |
|
306 | - { |
|
307 | - $this->_redirect_form = $redirect_form; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - public function redirect_form() |
|
315 | - { |
|
316 | - return ! empty($this->_redirect_form) ? $this->_redirect_form : false; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @param string $plz_select_method_of_payment |
|
322 | - */ |
|
323 | - public function set_plz_select_method_of_payment($plz_select_method_of_payment) |
|
324 | - { |
|
325 | - $this->_plz_select_method_of_payment = $plz_select_method_of_payment; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @return string |
|
331 | - */ |
|
332 | - public function plz_select_method_of_payment() |
|
333 | - { |
|
334 | - return $this->_plz_select_method_of_payment; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @param string $redirect_url |
|
340 | - */ |
|
341 | - public function set_redirect_url($redirect_url) |
|
342 | - { |
|
343 | - $this->_redirect_url = $redirect_url; |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * @return string |
|
349 | - */ |
|
350 | - public function redirect_url() |
|
351 | - { |
|
352 | - return $this->_redirect_url; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function registration_time_limit() |
|
360 | - { |
|
361 | - return $this->_registration_time_limit; |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * @param string $registration_time_limit |
|
367 | - */ |
|
368 | - public function set_registration_time_limit($registration_time_limit) |
|
369 | - { |
|
370 | - $this->_registration_time_limit = $registration_time_limit; |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * @param array $return_data |
|
376 | - */ |
|
377 | - public function set_return_data($return_data) |
|
378 | - { |
|
379 | - $this->_return_data = array_merge($this->_return_data, $return_data); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * @return array |
|
385 | - */ |
|
386 | - public function return_data() |
|
387 | - { |
|
388 | - return $this->_return_data; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * @param array $validation_rules |
|
394 | - */ |
|
395 | - public function add_validation_rules(array $validation_rules = array()) |
|
396 | - { |
|
397 | - if (is_array($validation_rules) && ! empty($validation_rules)) { |
|
398 | - $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @return array | bool |
|
405 | - */ |
|
406 | - public function validation_rules() |
|
407 | - { |
|
408 | - return ! empty($this->_validation_rules) ? $this->_validation_rules : false; |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - public function echoAndExit() |
|
413 | - { |
|
414 | - echo $this; |
|
415 | - exit(); |
|
416 | - } |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $_errors = ''; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $_unexpected_errors = ''; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_attention = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $_success = ''; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $_plz_select_method_of_payment = ''; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + protected $_redirect_url = ''; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + protected $_registration_time_limit = ''; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $_redirect_form = ''; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + protected $_reg_step_html = ''; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + protected $_method_of_payment = ''; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var float |
|
70 | + */ |
|
71 | + protected $_payment_amount; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var array |
|
75 | + */ |
|
76 | + protected $_return_data = array(); |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @var array |
|
81 | + */ |
|
82 | + protected $_validation_rules = array(); |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * class constructor |
|
87 | + */ |
|
88 | + public function __construct() |
|
89 | + { |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * __toString |
|
95 | + * |
|
96 | + * allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a JSON encoded string |
|
97 | + * ie: $json_response = new EE_SPCO_JSON_Response(); |
|
98 | + * echo $json_response; |
|
99 | + * |
|
100 | + * @access public |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function __toString() |
|
104 | + { |
|
105 | + $JSON_response = array(); |
|
106 | + // grab notices |
|
107 | + $notices = EE_Error::get_notices(false); |
|
108 | + $this->set_attention(isset($notices['attention']) ? $notices['attention'] : ''); |
|
109 | + $this->set_errors(isset($notices['errors']) ? $notices['errors'] : ''); |
|
110 | + $this->set_success(isset($notices['success']) ? $notices['success'] : ''); |
|
111 | + // add notices to JSON response, but only if they exist |
|
112 | + if ($this->attention()) { |
|
113 | + $JSON_response['attention'] = $this->attention(); |
|
114 | + } |
|
115 | + if ($this->errors()) { |
|
116 | + $JSON_response['errors'] = $this->errors(); |
|
117 | + } |
|
118 | + if ($this->unexpected_errors()) { |
|
119 | + $JSON_response['unexpected_errors'] = $this->unexpected_errors(); |
|
120 | + } |
|
121 | + if ($this->success()) { |
|
122 | + $JSON_response['success'] = $this->success(); |
|
123 | + } |
|
124 | + // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
|
125 | + if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
126 | + $JSON_response['success'] = null; |
|
127 | + } |
|
128 | + // set redirect_url, IF it exists |
|
129 | + if ($this->redirect_url()) { |
|
130 | + $JSON_response['redirect_url'] = $this->redirect_url(); |
|
131 | + } |
|
132 | + // set registration_time_limit, IF it exists |
|
133 | + if ($this->registration_time_limit()) { |
|
134 | + $JSON_response['registration_time_limit'] = $this->registration_time_limit(); |
|
135 | + } |
|
136 | + // set payment_amount, IF it exists |
|
137 | + if ($this->payment_amount() !== null) { |
|
138 | + $JSON_response['payment_amount'] = $this->payment_amount(); |
|
139 | + } |
|
140 | + // grab generic return data |
|
141 | + $return_data = $this->return_data(); |
|
142 | + // add billing form validation rules |
|
143 | + if ($this->validation_rules()) { |
|
144 | + $return_data['validation_rules'] = $this->validation_rules(); |
|
145 | + } |
|
146 | + // set reg_step_html, IF it exists |
|
147 | + if ($this->reg_step_html()) { |
|
148 | + $return_data['reg_step_html'] = $this->reg_step_html(); |
|
149 | + } |
|
150 | + // set method of payment, IF it exists |
|
151 | + if ($this->method_of_payment()) { |
|
152 | + $return_data['method_of_payment'] = $this->method_of_payment(); |
|
153 | + } |
|
154 | + // set "plz_select_method_of_payment" message, IF it exists |
|
155 | + if ($this->plz_select_method_of_payment()) { |
|
156 | + $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment(); |
|
157 | + } |
|
158 | + // set redirect_form, IF it exists |
|
159 | + if ($this->redirect_form()) { |
|
160 | + $return_data['redirect_form'] = $this->redirect_form(); |
|
161 | + } |
|
162 | + // and finally, add return_data array to main JSON response array, IF it contains anything |
|
163 | + // why did we add some of the above properties to the return data array? |
|
164 | + // because it is easier and cleaner in the Javascript to deal with this way |
|
165 | + if (! empty($return_data)) { |
|
166 | + $JSON_response['return_data'] = $return_data; |
|
167 | + } |
|
168 | + // filter final array |
|
169 | + $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response); |
|
170 | + // return encoded array |
|
171 | + return (string) wp_json_encode($JSON_response); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param string $attention |
|
177 | + */ |
|
178 | + public function set_attention($attention) |
|
179 | + { |
|
180 | + $this->_attention = $attention; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + public function attention() |
|
188 | + { |
|
189 | + return $this->_attention; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @param string $errors |
|
195 | + */ |
|
196 | + public function set_errors($errors) |
|
197 | + { |
|
198 | + $this->_errors = $errors; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function errors() |
|
206 | + { |
|
207 | + return $this->_errors; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public function unexpected_errors() |
|
215 | + { |
|
216 | + return $this->_unexpected_errors; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $unexpected_errors |
|
222 | + */ |
|
223 | + public function set_unexpected_errors($unexpected_errors) |
|
224 | + { |
|
225 | + $this->_unexpected_errors = $unexpected_errors; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * @param string $success |
|
231 | + */ |
|
232 | + public function set_success($success) |
|
233 | + { |
|
234 | + $this->_success = $success; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @return string |
|
240 | + */ |
|
241 | + public function success() |
|
242 | + { |
|
243 | + return $this->_success; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @param string $method_of_payment |
|
249 | + */ |
|
250 | + public function set_method_of_payment($method_of_payment) |
|
251 | + { |
|
252 | + $this->_method_of_payment = $method_of_payment; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return string |
|
258 | + */ |
|
259 | + public function method_of_payment() |
|
260 | + { |
|
261 | + return $this->_method_of_payment; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return float |
|
267 | + */ |
|
268 | + public function payment_amount() |
|
269 | + { |
|
270 | + return $this->_payment_amount; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @param float $payment_amount |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + public function set_payment_amount($payment_amount) |
|
279 | + { |
|
280 | + $this->_payment_amount = (float) $payment_amount; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @param string $next_step_html |
|
286 | + */ |
|
287 | + public function set_reg_step_html($next_step_html) |
|
288 | + { |
|
289 | + $this->_reg_step_html = $next_step_html; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + public function reg_step_html() |
|
297 | + { |
|
298 | + return $this->_reg_step_html; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * @param string $redirect_form |
|
304 | + */ |
|
305 | + public function set_redirect_form($redirect_form) |
|
306 | + { |
|
307 | + $this->_redirect_form = $redirect_form; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + public function redirect_form() |
|
315 | + { |
|
316 | + return ! empty($this->_redirect_form) ? $this->_redirect_form : false; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @param string $plz_select_method_of_payment |
|
322 | + */ |
|
323 | + public function set_plz_select_method_of_payment($plz_select_method_of_payment) |
|
324 | + { |
|
325 | + $this->_plz_select_method_of_payment = $plz_select_method_of_payment; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @return string |
|
331 | + */ |
|
332 | + public function plz_select_method_of_payment() |
|
333 | + { |
|
334 | + return $this->_plz_select_method_of_payment; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @param string $redirect_url |
|
340 | + */ |
|
341 | + public function set_redirect_url($redirect_url) |
|
342 | + { |
|
343 | + $this->_redirect_url = $redirect_url; |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * @return string |
|
349 | + */ |
|
350 | + public function redirect_url() |
|
351 | + { |
|
352 | + return $this->_redirect_url; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function registration_time_limit() |
|
360 | + { |
|
361 | + return $this->_registration_time_limit; |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * @param string $registration_time_limit |
|
367 | + */ |
|
368 | + public function set_registration_time_limit($registration_time_limit) |
|
369 | + { |
|
370 | + $this->_registration_time_limit = $registration_time_limit; |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * @param array $return_data |
|
376 | + */ |
|
377 | + public function set_return_data($return_data) |
|
378 | + { |
|
379 | + $this->_return_data = array_merge($this->_return_data, $return_data); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * @return array |
|
385 | + */ |
|
386 | + public function return_data() |
|
387 | + { |
|
388 | + return $this->_return_data; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * @param array $validation_rules |
|
394 | + */ |
|
395 | + public function add_validation_rules(array $validation_rules = array()) |
|
396 | + { |
|
397 | + if (is_array($validation_rules) && ! empty($validation_rules)) { |
|
398 | + $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @return array | bool |
|
405 | + */ |
|
406 | + public function validation_rules() |
|
407 | + { |
|
408 | + return ! empty($this->_validation_rules) ? $this->_validation_rules : false; |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + public function echoAndExit() |
|
413 | + { |
|
414 | + echo $this; |
|
415 | + exit(); |
|
416 | + } |
|
417 | 417 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $JSON_response['success'] = $this->success(); |
123 | 123 | } |
124 | 124 | // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
125 | - if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
125 | + if ( ! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
126 | 126 | $JSON_response['success'] = null; |
127 | 127 | } |
128 | 128 | // set redirect_url, IF it exists |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | // and finally, add return_data array to main JSON response array, IF it contains anything |
163 | 163 | // why did we add some of the above properties to the return data array? |
164 | 164 | // because it is easier and cleaner in the Javascript to deal with this way |
165 | - if (! empty($return_data)) { |
|
165 | + if ( ! empty($return_data)) { |
|
166 | 166 | $JSON_response['return_data'] = $return_data; |
167 | 167 | } |
168 | 168 | // filter final array |