@@ -61,7 +61,7 @@ |
||
61 | 61 | { |
62 | 62 | $custom_post_types = $this->custom_post_types->getDefinitions(); |
63 | 63 | foreach ($custom_post_types as $custom_post_type => $CPT) { |
64 | - $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
64 | + $this->wp_post_types[$custom_post_type] = $this->registerCustomPostType( |
|
65 | 65 | $custom_post_type, |
66 | 66 | $CPT['singular_name'], |
67 | 67 | $CPT['plural_name'], |
@@ -18,240 +18,240 @@ |
||
18 | 18 | class RegisterCustomPostTypes |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var CustomPostTypeDefinitions $custom_post_types |
|
23 | - */ |
|
24 | - public $custom_post_types; |
|
21 | + /** |
|
22 | + * @var CustomPostTypeDefinitions $custom_post_types |
|
23 | + */ |
|
24 | + public $custom_post_types; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var WP_Post_Type[] $wp_post_types |
|
28 | - */ |
|
29 | - public $wp_post_types = array(); |
|
26 | + /** |
|
27 | + * @var WP_Post_Type[] $wp_post_types |
|
28 | + */ |
|
29 | + public $wp_post_types = array(); |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * RegisterCustomPostTypes constructor. |
|
34 | - * |
|
35 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
36 | - */ |
|
37 | - public function __construct(CustomPostTypeDefinitions $custom_post_types) |
|
38 | - { |
|
39 | - $this->custom_post_types = $custom_post_types; |
|
40 | - } |
|
32 | + /** |
|
33 | + * RegisterCustomPostTypes constructor. |
|
34 | + * |
|
35 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
36 | + */ |
|
37 | + public function __construct(CustomPostTypeDefinitions $custom_post_types) |
|
38 | + { |
|
39 | + $this->custom_post_types = $custom_post_types; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @return WP_Post_Type[] |
|
45 | - */ |
|
46 | - public function getRegisteredCustomPostTypes() |
|
47 | - { |
|
48 | - return $this->wp_post_types; |
|
49 | - } |
|
43 | + /** |
|
44 | + * @return WP_Post_Type[] |
|
45 | + */ |
|
46 | + public function getRegisteredCustomPostTypes() |
|
47 | + { |
|
48 | + return $this->wp_post_types; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @return void |
|
54 | - * @throws DomainException |
|
55 | - */ |
|
56 | - public function registerCustomPostTypes() |
|
57 | - { |
|
58 | - $custom_post_types = $this->custom_post_types->getDefinitions(); |
|
59 | - foreach ($custom_post_types as $custom_post_type => $CPT) { |
|
60 | - $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
61 | - $custom_post_type, |
|
62 | - $CPT['singular_name'], |
|
63 | - $CPT['plural_name'], |
|
64 | - $CPT['singular_slug'], |
|
65 | - $CPT['plural_slug'], |
|
66 | - $CPT['args'] |
|
67 | - ); |
|
68 | - } |
|
69 | - } |
|
52 | + /** |
|
53 | + * @return void |
|
54 | + * @throws DomainException |
|
55 | + */ |
|
56 | + public function registerCustomPostTypes() |
|
57 | + { |
|
58 | + $custom_post_types = $this->custom_post_types->getDefinitions(); |
|
59 | + foreach ($custom_post_types as $custom_post_type => $CPT) { |
|
60 | + $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
61 | + $custom_post_type, |
|
62 | + $CPT['singular_name'], |
|
63 | + $CPT['plural_name'], |
|
64 | + $CPT['singular_slug'], |
|
65 | + $CPT['plural_slug'], |
|
66 | + $CPT['args'] |
|
67 | + ); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Registers a new custom post type. Sets default settings given only the following params. |
|
74 | - * Returns the registered post type object, or an error object. |
|
75 | - * |
|
76 | - * @param string $post_type the actual post type name |
|
77 | - * IMPORTANT: |
|
78 | - * this must match what the slug is for admin pages related to this CPT |
|
79 | - * Also any models must use this slug as well |
|
80 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
81 | - * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
82 | - * @param string $singular_slug |
|
83 | - * @param string $plural_slug |
|
84 | - * @param array $override_arguments exactly like $args as described in |
|
85 | - * http://codex.wordpress.org/Function_Reference/register_post_type |
|
86 | - * @return WP_Post_Type|WP_Error |
|
87 | - * @throws DomainException |
|
88 | - */ |
|
89 | - public function registerCustomPostType( |
|
90 | - $post_type, |
|
91 | - $singular_name, |
|
92 | - $plural_name, |
|
93 | - $singular_slug = '', |
|
94 | - $plural_slug = '', |
|
95 | - array $override_arguments = array() |
|
96 | - ) { |
|
97 | - $wp_post_type = register_post_type( |
|
98 | - $post_type, |
|
99 | - $this->prepareArguments( |
|
100 | - $post_type, |
|
101 | - $singular_name, |
|
102 | - $plural_name, |
|
103 | - $singular_slug, |
|
104 | - $plural_slug, |
|
105 | - $override_arguments |
|
106 | - ) |
|
107 | - ); |
|
108 | - if ($wp_post_type instanceof WP_Error) { |
|
109 | - throw new DomainException($wp_post_type->get_error_message()); |
|
110 | - } |
|
111 | - return $wp_post_type; |
|
112 | - } |
|
72 | + /** |
|
73 | + * Registers a new custom post type. Sets default settings given only the following params. |
|
74 | + * Returns the registered post type object, or an error object. |
|
75 | + * |
|
76 | + * @param string $post_type the actual post type name |
|
77 | + * IMPORTANT: |
|
78 | + * this must match what the slug is for admin pages related to this CPT |
|
79 | + * Also any models must use this slug as well |
|
80 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
81 | + * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
82 | + * @param string $singular_slug |
|
83 | + * @param string $plural_slug |
|
84 | + * @param array $override_arguments exactly like $args as described in |
|
85 | + * http://codex.wordpress.org/Function_Reference/register_post_type |
|
86 | + * @return WP_Post_Type|WP_Error |
|
87 | + * @throws DomainException |
|
88 | + */ |
|
89 | + public function registerCustomPostType( |
|
90 | + $post_type, |
|
91 | + $singular_name, |
|
92 | + $plural_name, |
|
93 | + $singular_slug = '', |
|
94 | + $plural_slug = '', |
|
95 | + array $override_arguments = array() |
|
96 | + ) { |
|
97 | + $wp_post_type = register_post_type( |
|
98 | + $post_type, |
|
99 | + $this->prepareArguments( |
|
100 | + $post_type, |
|
101 | + $singular_name, |
|
102 | + $plural_name, |
|
103 | + $singular_slug, |
|
104 | + $plural_slug, |
|
105 | + $override_arguments |
|
106 | + ) |
|
107 | + ); |
|
108 | + if ($wp_post_type instanceof WP_Error) { |
|
109 | + throw new DomainException($wp_post_type->get_error_message()); |
|
110 | + } |
|
111 | + return $wp_post_type; |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | - /** |
|
116 | - * @param string $post_type the actual post type name |
|
117 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
118 | - * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
119 | - * @param string $singular_slug |
|
120 | - * @param string $plural_slug |
|
121 | - * @param array $override_arguments The default values set in this function will be overridden |
|
122 | - * by whatever you set in $override_arguments |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - protected function prepareArguments( |
|
126 | - $post_type, |
|
127 | - $singular_name, |
|
128 | - $plural_name, |
|
129 | - $singular_slug, |
|
130 | - $plural_slug, |
|
131 | - array $override_arguments = array() |
|
132 | - ) { |
|
133 | - // verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
134 | - $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
135 | - $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
136 | - $labels = $this->getLabels( |
|
137 | - $singular_name, |
|
138 | - $plural_name, |
|
139 | - $singular_slug, |
|
140 | - $plural_slug |
|
141 | - ); |
|
142 | - // note the page_templates arg in the supports index is something specific to EE. |
|
143 | - // WordPress doesn't actually have that in their register_post_type api. |
|
144 | - $arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug); |
|
145 | - if ($override_arguments) { |
|
146 | - if (isset($override_arguments['labels'])) { |
|
147 | - $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
148 | - } |
|
149 | - $arguments = array_merge($arguments, $override_arguments); |
|
150 | - $arguments['labels'] = $labels; |
|
151 | - } |
|
152 | - return $arguments; |
|
153 | - } |
|
115 | + /** |
|
116 | + * @param string $post_type the actual post type name |
|
117 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
118 | + * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
119 | + * @param string $singular_slug |
|
120 | + * @param string $plural_slug |
|
121 | + * @param array $override_arguments The default values set in this function will be overridden |
|
122 | + * by whatever you set in $override_arguments |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + protected function prepareArguments( |
|
126 | + $post_type, |
|
127 | + $singular_name, |
|
128 | + $plural_name, |
|
129 | + $singular_slug, |
|
130 | + $plural_slug, |
|
131 | + array $override_arguments = array() |
|
132 | + ) { |
|
133 | + // verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
134 | + $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
135 | + $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
136 | + $labels = $this->getLabels( |
|
137 | + $singular_name, |
|
138 | + $plural_name, |
|
139 | + $singular_slug, |
|
140 | + $plural_slug |
|
141 | + ); |
|
142 | + // note the page_templates arg in the supports index is something specific to EE. |
|
143 | + // WordPress doesn't actually have that in their register_post_type api. |
|
144 | + $arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug); |
|
145 | + if ($override_arguments) { |
|
146 | + if (isset($override_arguments['labels'])) { |
|
147 | + $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
148 | + } |
|
149 | + $arguments = array_merge($arguments, $override_arguments); |
|
150 | + $arguments['labels'] = $labels; |
|
151 | + } |
|
152 | + return $arguments; |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * @param string $singular_name |
|
158 | - * @param string $plural_name |
|
159 | - * @param string $singular_slug |
|
160 | - * @param string $plural_slug |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug) |
|
164 | - { |
|
165 | - return array( |
|
166 | - 'name' => $plural_name, |
|
167 | - 'singular_name' => $singular_name, |
|
168 | - 'singular_slug' => $singular_slug, |
|
169 | - 'plural_slug' => $plural_slug, |
|
170 | - 'add_new' => sprintf( |
|
171 | - esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
172 | - $singular_name |
|
173 | - ), |
|
174 | - 'add_new_item' => sprintf( |
|
175 | - esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
176 | - $singular_name |
|
177 | - ), |
|
178 | - 'edit_item' => sprintf( |
|
179 | - esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
180 | - $singular_name |
|
181 | - ), |
|
182 | - 'new_item' => sprintf( |
|
183 | - esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
184 | - $singular_name |
|
185 | - ), |
|
186 | - 'all_items' => sprintf( |
|
187 | - esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
188 | - $plural_name |
|
189 | - ), |
|
190 | - 'view_item' => sprintf( |
|
191 | - esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
192 | - $singular_name |
|
193 | - ), |
|
194 | - 'search_items' => sprintf( |
|
195 | - esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
196 | - $plural_name |
|
197 | - ), |
|
198 | - 'not_found' => sprintf( |
|
199 | - esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
200 | - $plural_name |
|
201 | - ), |
|
202 | - 'not_found_in_trash' => sprintf( |
|
203 | - esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
204 | - $plural_name |
|
205 | - ), |
|
206 | - 'parent_item_colon' => '', |
|
207 | - 'menu_name' => $plural_name, |
|
208 | - ); |
|
209 | - } |
|
156 | + /** |
|
157 | + * @param string $singular_name |
|
158 | + * @param string $plural_name |
|
159 | + * @param string $singular_slug |
|
160 | + * @param string $plural_slug |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug) |
|
164 | + { |
|
165 | + return array( |
|
166 | + 'name' => $plural_name, |
|
167 | + 'singular_name' => $singular_name, |
|
168 | + 'singular_slug' => $singular_slug, |
|
169 | + 'plural_slug' => $plural_slug, |
|
170 | + 'add_new' => sprintf( |
|
171 | + esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
172 | + $singular_name |
|
173 | + ), |
|
174 | + 'add_new_item' => sprintf( |
|
175 | + esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
176 | + $singular_name |
|
177 | + ), |
|
178 | + 'edit_item' => sprintf( |
|
179 | + esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
180 | + $singular_name |
|
181 | + ), |
|
182 | + 'new_item' => sprintf( |
|
183 | + esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
184 | + $singular_name |
|
185 | + ), |
|
186 | + 'all_items' => sprintf( |
|
187 | + esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
188 | + $plural_name |
|
189 | + ), |
|
190 | + 'view_item' => sprintf( |
|
191 | + esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
192 | + $singular_name |
|
193 | + ), |
|
194 | + 'search_items' => sprintf( |
|
195 | + esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
196 | + $plural_name |
|
197 | + ), |
|
198 | + 'not_found' => sprintf( |
|
199 | + esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
200 | + $plural_name |
|
201 | + ), |
|
202 | + 'not_found_in_trash' => sprintf( |
|
203 | + esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
204 | + $plural_name |
|
205 | + ), |
|
206 | + 'parent_item_colon' => '', |
|
207 | + 'menu_name' => $plural_name, |
|
208 | + ); |
|
209 | + } |
|
210 | 210 | |
211 | 211 | |
212 | - /** |
|
213 | - * @param array $labels |
|
214 | - * @param string $post_type |
|
215 | - * @param string $plural_slug |
|
216 | - * @return array |
|
217 | - */ |
|
218 | - private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
219 | - { |
|
220 | - return array( |
|
221 | - 'labels' => $labels, |
|
222 | - 'public' => true, |
|
223 | - 'publicly_queryable' => true, |
|
224 | - 'show_ui' => false, |
|
225 | - 'show_ee_ui' => true, |
|
226 | - 'show_in_menu' => false, |
|
227 | - 'show_in_nav_menus' => false, |
|
228 | - 'query_var' => true, |
|
229 | - 'rewrite' => apply_filters( |
|
230 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
231 | - // legacy filter applied for now, |
|
232 | - // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
233 | - apply_filters( |
|
234 | - 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
235 | - array('slug' => $plural_slug), |
|
236 | - $post_type |
|
237 | - ), |
|
238 | - $post_type, |
|
239 | - $plural_slug |
|
240 | - ), |
|
241 | - 'capability_type' => 'post', |
|
242 | - 'map_meta_cap' => true, |
|
243 | - 'has_archive' => true, |
|
244 | - 'hierarchical' => false, |
|
245 | - 'menu_position' => null, |
|
246 | - 'supports' => array( |
|
247 | - 'title', |
|
248 | - 'editor', |
|
249 | - 'author', |
|
250 | - 'thumbnail', |
|
251 | - 'excerpt', |
|
252 | - 'custom-fields', |
|
253 | - 'comments', |
|
254 | - ), |
|
255 | - ); |
|
256 | - } |
|
212 | + /** |
|
213 | + * @param array $labels |
|
214 | + * @param string $post_type |
|
215 | + * @param string $plural_slug |
|
216 | + * @return array |
|
217 | + */ |
|
218 | + private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
219 | + { |
|
220 | + return array( |
|
221 | + 'labels' => $labels, |
|
222 | + 'public' => true, |
|
223 | + 'publicly_queryable' => true, |
|
224 | + 'show_ui' => false, |
|
225 | + 'show_ee_ui' => true, |
|
226 | + 'show_in_menu' => false, |
|
227 | + 'show_in_nav_menus' => false, |
|
228 | + 'query_var' => true, |
|
229 | + 'rewrite' => apply_filters( |
|
230 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
231 | + // legacy filter applied for now, |
|
232 | + // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
233 | + apply_filters( |
|
234 | + 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
235 | + array('slug' => $plural_slug), |
|
236 | + $post_type |
|
237 | + ), |
|
238 | + $post_type, |
|
239 | + $plural_slug |
|
240 | + ), |
|
241 | + 'capability_type' => 'post', |
|
242 | + 'map_meta_cap' => true, |
|
243 | + 'has_archive' => true, |
|
244 | + 'hierarchical' => false, |
|
245 | + 'menu_position' => null, |
|
246 | + 'supports' => array( |
|
247 | + 'title', |
|
248 | + 'editor', |
|
249 | + 'author', |
|
250 | + 'thumbnail', |
|
251 | + 'excerpt', |
|
252 | + 'custom-fields', |
|
253 | + 'comments', |
|
254 | + ), |
|
255 | + ); |
|
256 | + } |
|
257 | 257 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @access public |
158 | 158 | * @param mixed $identifier |
159 | - * @return mixed |
|
159 | + * @return boolean |
|
160 | 160 | */ |
161 | 161 | public function get($identifier) |
162 | 162 | { |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * advances pointer to the provided object |
279 | 279 | * |
280 | 280 | * @access public |
281 | - * @param $object |
|
281 | + * @param \EventEspresso\core\libraries\form_sections\form_handlers\SequentialStepForm $object |
|
282 | 282 | * @return boolean |
283 | 283 | */ |
284 | 284 | public function setCurrentUsingObject($object) |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @see http://stackoverflow.com/a/8736013 |
318 | 318 | * @param $object |
319 | - * @return boolean|int|string |
|
319 | + * @return integer |
|
320 | 320 | */ |
321 | 321 | public function indexOf($object) |
322 | 322 | { |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | protected function setCollectionIdentifier() |
69 | 69 | { |
70 | 70 | // hash a few collection details |
71 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
71 | + $identifier = md5(spl_object_hash($this).$this->collection_interface.time()); |
|
72 | 72 | // grab a few characters from the start, middle, and end of the hash |
73 | 73 | $id = array(); |
74 | 74 | for ($x = 0; $x < 19; $x += 9) { |
75 | 75 | $id[] = substr($identifier, $x, 3); |
76 | 76 | } |
77 | 77 | $identifier = basename(str_replace('\\', '/', get_class($this))); |
78 | - $identifier .= '-' . strtoupper(implode('-', $id)); |
|
78 | + $identifier .= '-'.strtoupper(implode('-', $id)); |
|
79 | 79 | $this->collection_identifier = $identifier; |
80 | 80 | } |
81 | 81 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | protected function setCollectionInterface($collection_interface) |
91 | 91 | { |
92 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
92 | + if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
93 | 93 | throw new InvalidInterfaceException($collection_interface); |
94 | 94 | } |
95 | 95 | $this->collection_interface = $collection_interface; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function add($object, $identifier = null) |
113 | 113 | { |
114 | - if (! $object instanceof $this->collection_interface) { |
|
114 | + if ( ! $object instanceof $this->collection_interface) { |
|
115 | 115 | throw new InvalidEntityException($object, $this->collection_interface); |
116 | 116 | } |
117 | 117 | if ($this->contains($object)) { |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public function indexOf($object) |
324 | 324 | { |
325 | - if (! $this->contains($object)) { |
|
325 | + if ( ! $this->contains($object)) { |
|
326 | 326 | return false; |
327 | 327 | } |
328 | 328 | foreach ($this as $index => $obj) { |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | $remaining_objects = $this->slice($index, $this->count() - $index); |
392 | 392 | foreach ($remaining_objects as $key => $remaining_object) { |
393 | 393 | // we need to grab the identifiers for each object and use them as keys |
394 | - $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
394 | + $remaining_objects[$remaining_object->getInfo()] = $remaining_object; |
|
395 | 395 | // and then remove the object from the current tracking array |
396 | - unset($remaining_objects[ $key ]); |
|
396 | + unset($remaining_objects[$key]); |
|
397 | 397 | // and then remove it from the Collection |
398 | 398 | $this->detach($remaining_object); |
399 | 399 | } |
@@ -417,17 +417,17 @@ discard block |
||
417 | 417 | */ |
418 | 418 | public function insertAt($objects, $index) |
419 | 419 | { |
420 | - if (! is_array($objects)) { |
|
420 | + if ( ! is_array($objects)) { |
|
421 | 421 | $objects = array($objects); |
422 | 422 | } |
423 | 423 | // check to ensure that objects don't already exist in the collection |
424 | 424 | foreach ($objects as $key => $object) { |
425 | 425 | if ($this->contains($object)) { |
426 | - unset($objects[ $key ]); |
|
426 | + unset($objects[$key]); |
|
427 | 427 | } |
428 | 428 | } |
429 | 429 | // do we have any objects left? |
430 | - if (! $objects) { |
|
430 | + if ( ! $objects) { |
|
431 | 431 | return; |
432 | 432 | } |
433 | 433 | // detach any objects at or past this index |
@@ -19,470 +19,470 @@ |
||
19 | 19 | class Collection extends SplObjectStorage implements CollectionInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * a unique string for identifying this collection |
|
24 | - * |
|
25 | - * @type string $collection_identifier |
|
26 | - */ |
|
27 | - protected $collection_identifier; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
32 | - * this should be set from within the child class constructor |
|
33 | - * |
|
34 | - * @type string $interface |
|
35 | - */ |
|
36 | - protected $collection_interface; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Collection constructor |
|
41 | - * |
|
42 | - * @param string $collection_interface |
|
43 | - * @throws InvalidInterfaceException |
|
44 | - */ |
|
45 | - public function __construct($collection_interface) |
|
46 | - { |
|
47 | - $this->setCollectionInterface($collection_interface); |
|
48 | - $this->setCollectionIdentifier(); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function collectionIdentifier() |
|
56 | - { |
|
57 | - return $this->collection_identifier; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
63 | - * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
64 | - * |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - protected function setCollectionIdentifier() |
|
68 | - { |
|
69 | - // hash a few collection details |
|
70 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
71 | - // grab a few characters from the start, middle, and end of the hash |
|
72 | - $id = array(); |
|
73 | - for ($x = 0; $x < 19; $x += 9) { |
|
74 | - $id[] = substr($identifier, $x, 3); |
|
75 | - } |
|
76 | - $identifier = basename(str_replace('\\', '/', get_class($this))); |
|
77 | - $identifier .= '-' . strtoupper(implode('-', $id)); |
|
78 | - $this->collection_identifier = $identifier; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * setCollectionInterface |
|
84 | - * |
|
85 | - * @param string $collection_interface |
|
86 | - * @throws InvalidInterfaceException |
|
87 | - */ |
|
88 | - protected function setCollectionInterface($collection_interface) |
|
89 | - { |
|
90 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
91 | - throw new InvalidInterfaceException($collection_interface); |
|
92 | - } |
|
93 | - $this->collection_interface = $collection_interface; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * add |
|
99 | - * attaches an object to the Collection |
|
100 | - * and sets any supplied data associated with the current iterator entry |
|
101 | - * by calling EE_Object_Collection::set_identifier() |
|
102 | - * |
|
103 | - * @param $object |
|
104 | - * @param mixed $identifier |
|
105 | - * @return bool |
|
106 | - * @throws InvalidEntityException |
|
107 | - * @throws DuplicateCollectionIdentifierException |
|
108 | - */ |
|
109 | - public function add($object, $identifier = null) |
|
110 | - { |
|
111 | - if (! $object instanceof $this->collection_interface) { |
|
112 | - throw new InvalidEntityException($object, $this->collection_interface); |
|
113 | - } |
|
114 | - if ($this->contains($object)) { |
|
115 | - throw new DuplicateCollectionIdentifierException($identifier); |
|
116 | - } |
|
117 | - $this->attach($object); |
|
118 | - $this->setIdentifier($object, $identifier); |
|
119 | - return $this->contains($object); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * setIdentifier |
|
125 | - * Sets the data associated with an object in the Collection |
|
126 | - * if no $identifier is supplied, then the spl_object_hash() is used |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param $object |
|
130 | - * @param mixed $identifier |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function setIdentifier($object, $identifier = null) |
|
134 | - { |
|
135 | - $identifier = ! empty($identifier) |
|
136 | - ? $identifier |
|
137 | - : spl_object_hash($object); |
|
138 | - $this->rewind(); |
|
139 | - while ($this->valid()) { |
|
140 | - if ($object === $this->current()) { |
|
141 | - $this->setInfo($identifier); |
|
142 | - $this->rewind(); |
|
143 | - return true; |
|
144 | - } |
|
145 | - $this->next(); |
|
146 | - } |
|
147 | - return false; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * get |
|
153 | - * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
154 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
155 | - * |
|
156 | - * @access public |
|
157 | - * @param mixed $identifier |
|
158 | - * @return mixed |
|
159 | - */ |
|
160 | - public function get($identifier) |
|
161 | - { |
|
162 | - $this->rewind(); |
|
163 | - while ($this->valid()) { |
|
164 | - if ($identifier === $this->getInfo()) { |
|
165 | - $object = $this->current(); |
|
166 | - $this->rewind(); |
|
167 | - return $object; |
|
168 | - } |
|
169 | - $this->next(); |
|
170 | - } |
|
171 | - return null; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * has |
|
177 | - * returns TRUE or FALSE |
|
178 | - * depending on whether the object is within the Collection |
|
179 | - * based on the supplied $identifier |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * @param mixed $identifier |
|
183 | - * @return bool |
|
184 | - */ |
|
185 | - public function has($identifier) |
|
186 | - { |
|
187 | - $this->rewind(); |
|
188 | - while ($this->valid()) { |
|
189 | - if ($identifier === $this->getInfo()) { |
|
190 | - $this->rewind(); |
|
191 | - return true; |
|
192 | - } |
|
193 | - $this->next(); |
|
194 | - } |
|
195 | - return false; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * hasObject |
|
201 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
202 | - * |
|
203 | - * @access public |
|
204 | - * @param $object |
|
205 | - * @return bool |
|
206 | - */ |
|
207 | - public function hasObject($object) |
|
208 | - { |
|
209 | - return $this->contains($object); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * hasObjects |
|
215 | - * returns true if there are objects within the Collection, and false if it is empty |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @return bool |
|
219 | - */ |
|
220 | - public function hasObjects() |
|
221 | - { |
|
222 | - return $this->count() !== 0; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * isEmpty |
|
228 | - * returns true if there are no objects within the Collection, and false if there are |
|
229 | - * |
|
230 | - * @access public |
|
231 | - * @return bool |
|
232 | - */ |
|
233 | - public function isEmpty() |
|
234 | - { |
|
235 | - return $this->count() === 0; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * remove |
|
241 | - * detaches an object from the Collection |
|
242 | - * |
|
243 | - * @access public |
|
244 | - * @param $object |
|
245 | - * @return bool |
|
246 | - */ |
|
247 | - public function remove($object) |
|
248 | - { |
|
249 | - $this->detach($object); |
|
250 | - return true; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * setCurrent |
|
256 | - * advances pointer to the object whose identifier matches that which was provided |
|
257 | - * |
|
258 | - * @access public |
|
259 | - * @param mixed $identifier |
|
260 | - * @return boolean |
|
261 | - */ |
|
262 | - public function setCurrent($identifier) |
|
263 | - { |
|
264 | - $this->rewind(); |
|
265 | - while ($this->valid()) { |
|
266 | - if ($identifier === $this->getInfo()) { |
|
267 | - return true; |
|
268 | - } |
|
269 | - $this->next(); |
|
270 | - } |
|
271 | - return false; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * setCurrentUsingObject |
|
277 | - * advances pointer to the provided object |
|
278 | - * |
|
279 | - * @access public |
|
280 | - * @param $object |
|
281 | - * @return boolean |
|
282 | - */ |
|
283 | - public function setCurrentUsingObject($object) |
|
284 | - { |
|
285 | - $this->rewind(); |
|
286 | - while ($this->valid()) { |
|
287 | - if ($this->current() === $object) { |
|
288 | - return true; |
|
289 | - } |
|
290 | - $this->next(); |
|
291 | - } |
|
292 | - return false; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns the object occupying the index before the current object, |
|
298 | - * unless this is already the first object, in which case it just returns the first object |
|
299 | - * |
|
300 | - * @return mixed |
|
301 | - */ |
|
302 | - public function previous() |
|
303 | - { |
|
304 | - $index = $this->indexOf($this->current()); |
|
305 | - if ($index === 0) { |
|
306 | - return $this->current(); |
|
307 | - } |
|
308 | - $index--; |
|
309 | - return $this->objectAtIndex($index); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Returns the index of a given object, or false if not found |
|
315 | - * |
|
316 | - * @see http://stackoverflow.com/a/8736013 |
|
317 | - * @param $object |
|
318 | - * @return boolean|int|string |
|
319 | - */ |
|
320 | - public function indexOf($object) |
|
321 | - { |
|
322 | - if (! $this->contains($object)) { |
|
323 | - return false; |
|
324 | - } |
|
325 | - foreach ($this as $index => $obj) { |
|
326 | - if ($obj === $object) { |
|
327 | - return $index; |
|
328 | - } |
|
329 | - } |
|
330 | - return false; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Returns the object at the given index |
|
336 | - * |
|
337 | - * @see http://stackoverflow.com/a/8736013 |
|
338 | - * @param int $index |
|
339 | - * @return mixed |
|
340 | - */ |
|
341 | - public function objectAtIndex($index) |
|
342 | - { |
|
343 | - $iterator = new LimitIterator($this, $index, 1); |
|
344 | - $iterator->rewind(); |
|
345 | - return $iterator->current(); |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * Returns the sequence of objects as specified by the offset and length |
|
351 | - * |
|
352 | - * @see http://stackoverflow.com/a/8736013 |
|
353 | - * @param int $offset |
|
354 | - * @param int $length |
|
355 | - * @return array |
|
356 | - */ |
|
357 | - public function slice($offset, $length) |
|
358 | - { |
|
359 | - $slice = array(); |
|
360 | - $iterator = new LimitIterator($this, $offset, $length); |
|
361 | - foreach ($iterator as $object) { |
|
362 | - $slice[] = $object; |
|
363 | - } |
|
364 | - return $slice; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Inserts an object at a certain point |
|
370 | - * |
|
371 | - * @see http://stackoverflow.com/a/8736013 |
|
372 | - * @param mixed $object A single object |
|
373 | - * @param int $index |
|
374 | - * @param mixed $identifier |
|
375 | - * @return bool |
|
376 | - * @throws DuplicateCollectionIdentifierException |
|
377 | - * @throws InvalidEntityException |
|
378 | - */ |
|
379 | - public function insertObjectAt($object, $index, $identifier = null) |
|
380 | - { |
|
381 | - // check to ensure that objects don't already exist in the collection |
|
382 | - if ($this->has($identifier)) { |
|
383 | - throw new DuplicateCollectionIdentifierException($identifier); |
|
384 | - } |
|
385 | - // detach any objects at or past this index |
|
386 | - $remaining_objects = array(); |
|
387 | - if ($index < $this->count()) { |
|
388 | - $remaining_objects = $this->slice($index, $this->count() - $index); |
|
389 | - foreach ($remaining_objects as $key => $remaining_object) { |
|
390 | - // we need to grab the identifiers for each object and use them as keys |
|
391 | - $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
392 | - // and then remove the object from the current tracking array |
|
393 | - unset($remaining_objects[ $key ]); |
|
394 | - // and then remove it from the Collection |
|
395 | - $this->detach($remaining_object); |
|
396 | - } |
|
397 | - } |
|
398 | - // add the new object we're splicing in |
|
399 | - $this->add($object, $identifier); |
|
400 | - // attach the objects we previously detached |
|
401 | - foreach ($remaining_objects as $key => $remaining_object) { |
|
402 | - $this->add($remaining_object, $key); |
|
403 | - } |
|
404 | - return $this->contains($object); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Inserts an object (or an array of objects) at a certain point |
|
410 | - * |
|
411 | - * @see http://stackoverflow.com/a/8736013 |
|
412 | - * @param mixed $objects A single object or an array of objects |
|
413 | - * @param int $index |
|
414 | - */ |
|
415 | - public function insertAt($objects, $index) |
|
416 | - { |
|
417 | - if (! is_array($objects)) { |
|
418 | - $objects = array($objects); |
|
419 | - } |
|
420 | - // check to ensure that objects don't already exist in the collection |
|
421 | - foreach ($objects as $key => $object) { |
|
422 | - if ($this->contains($object)) { |
|
423 | - unset($objects[ $key ]); |
|
424 | - } |
|
425 | - } |
|
426 | - // do we have any objects left? |
|
427 | - if (! $objects) { |
|
428 | - return; |
|
429 | - } |
|
430 | - // detach any objects at or past this index |
|
431 | - $remaining = array(); |
|
432 | - if ($index < $this->count()) { |
|
433 | - $remaining = $this->slice($index, $this->count() - $index); |
|
434 | - foreach ($remaining as $object) { |
|
435 | - $this->detach($object); |
|
436 | - } |
|
437 | - } |
|
438 | - // add the new objects we're splicing in |
|
439 | - foreach ($objects as $object) { |
|
440 | - $this->attach($object); |
|
441 | - } |
|
442 | - // attach the objects we previously detached |
|
443 | - foreach ($remaining as $object) { |
|
444 | - $this->attach($object); |
|
445 | - } |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * Removes the object at the given index |
|
451 | - * |
|
452 | - * @see http://stackoverflow.com/a/8736013 |
|
453 | - * @param int $index |
|
454 | - */ |
|
455 | - public function removeAt($index) |
|
456 | - { |
|
457 | - $this->detach($this->objectAtIndex($index)); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * detaches ALL objects from the Collection |
|
463 | - */ |
|
464 | - public function detachAll() |
|
465 | - { |
|
466 | - $this->rewind(); |
|
467 | - while ($this->valid()) { |
|
468 | - $object = $this->current(); |
|
469 | - $this->next(); |
|
470 | - $this->detach($object); |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * unsets and detaches ALL objects from the Collection |
|
477 | - */ |
|
478 | - public function trashAndDetachAll() |
|
479 | - { |
|
480 | - $this->rewind(); |
|
481 | - while ($this->valid()) { |
|
482 | - $object = $this->current(); |
|
483 | - $this->next(); |
|
484 | - $this->detach($object); |
|
485 | - unset($object); |
|
486 | - } |
|
487 | - } |
|
22 | + /** |
|
23 | + * a unique string for identifying this collection |
|
24 | + * |
|
25 | + * @type string $collection_identifier |
|
26 | + */ |
|
27 | + protected $collection_identifier; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
32 | + * this should be set from within the child class constructor |
|
33 | + * |
|
34 | + * @type string $interface |
|
35 | + */ |
|
36 | + protected $collection_interface; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Collection constructor |
|
41 | + * |
|
42 | + * @param string $collection_interface |
|
43 | + * @throws InvalidInterfaceException |
|
44 | + */ |
|
45 | + public function __construct($collection_interface) |
|
46 | + { |
|
47 | + $this->setCollectionInterface($collection_interface); |
|
48 | + $this->setCollectionIdentifier(); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function collectionIdentifier() |
|
56 | + { |
|
57 | + return $this->collection_identifier; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
63 | + * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
64 | + * |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + protected function setCollectionIdentifier() |
|
68 | + { |
|
69 | + // hash a few collection details |
|
70 | + $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
71 | + // grab a few characters from the start, middle, and end of the hash |
|
72 | + $id = array(); |
|
73 | + for ($x = 0; $x < 19; $x += 9) { |
|
74 | + $id[] = substr($identifier, $x, 3); |
|
75 | + } |
|
76 | + $identifier = basename(str_replace('\\', '/', get_class($this))); |
|
77 | + $identifier .= '-' . strtoupper(implode('-', $id)); |
|
78 | + $this->collection_identifier = $identifier; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * setCollectionInterface |
|
84 | + * |
|
85 | + * @param string $collection_interface |
|
86 | + * @throws InvalidInterfaceException |
|
87 | + */ |
|
88 | + protected function setCollectionInterface($collection_interface) |
|
89 | + { |
|
90 | + if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
91 | + throw new InvalidInterfaceException($collection_interface); |
|
92 | + } |
|
93 | + $this->collection_interface = $collection_interface; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * add |
|
99 | + * attaches an object to the Collection |
|
100 | + * and sets any supplied data associated with the current iterator entry |
|
101 | + * by calling EE_Object_Collection::set_identifier() |
|
102 | + * |
|
103 | + * @param $object |
|
104 | + * @param mixed $identifier |
|
105 | + * @return bool |
|
106 | + * @throws InvalidEntityException |
|
107 | + * @throws DuplicateCollectionIdentifierException |
|
108 | + */ |
|
109 | + public function add($object, $identifier = null) |
|
110 | + { |
|
111 | + if (! $object instanceof $this->collection_interface) { |
|
112 | + throw new InvalidEntityException($object, $this->collection_interface); |
|
113 | + } |
|
114 | + if ($this->contains($object)) { |
|
115 | + throw new DuplicateCollectionIdentifierException($identifier); |
|
116 | + } |
|
117 | + $this->attach($object); |
|
118 | + $this->setIdentifier($object, $identifier); |
|
119 | + return $this->contains($object); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * setIdentifier |
|
125 | + * Sets the data associated with an object in the Collection |
|
126 | + * if no $identifier is supplied, then the spl_object_hash() is used |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param $object |
|
130 | + * @param mixed $identifier |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function setIdentifier($object, $identifier = null) |
|
134 | + { |
|
135 | + $identifier = ! empty($identifier) |
|
136 | + ? $identifier |
|
137 | + : spl_object_hash($object); |
|
138 | + $this->rewind(); |
|
139 | + while ($this->valid()) { |
|
140 | + if ($object === $this->current()) { |
|
141 | + $this->setInfo($identifier); |
|
142 | + $this->rewind(); |
|
143 | + return true; |
|
144 | + } |
|
145 | + $this->next(); |
|
146 | + } |
|
147 | + return false; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * get |
|
153 | + * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
154 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
155 | + * |
|
156 | + * @access public |
|
157 | + * @param mixed $identifier |
|
158 | + * @return mixed |
|
159 | + */ |
|
160 | + public function get($identifier) |
|
161 | + { |
|
162 | + $this->rewind(); |
|
163 | + while ($this->valid()) { |
|
164 | + if ($identifier === $this->getInfo()) { |
|
165 | + $object = $this->current(); |
|
166 | + $this->rewind(); |
|
167 | + return $object; |
|
168 | + } |
|
169 | + $this->next(); |
|
170 | + } |
|
171 | + return null; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * has |
|
177 | + * returns TRUE or FALSE |
|
178 | + * depending on whether the object is within the Collection |
|
179 | + * based on the supplied $identifier |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * @param mixed $identifier |
|
183 | + * @return bool |
|
184 | + */ |
|
185 | + public function has($identifier) |
|
186 | + { |
|
187 | + $this->rewind(); |
|
188 | + while ($this->valid()) { |
|
189 | + if ($identifier === $this->getInfo()) { |
|
190 | + $this->rewind(); |
|
191 | + return true; |
|
192 | + } |
|
193 | + $this->next(); |
|
194 | + } |
|
195 | + return false; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * hasObject |
|
201 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
202 | + * |
|
203 | + * @access public |
|
204 | + * @param $object |
|
205 | + * @return bool |
|
206 | + */ |
|
207 | + public function hasObject($object) |
|
208 | + { |
|
209 | + return $this->contains($object); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * hasObjects |
|
215 | + * returns true if there are objects within the Collection, and false if it is empty |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @return bool |
|
219 | + */ |
|
220 | + public function hasObjects() |
|
221 | + { |
|
222 | + return $this->count() !== 0; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * isEmpty |
|
228 | + * returns true if there are no objects within the Collection, and false if there are |
|
229 | + * |
|
230 | + * @access public |
|
231 | + * @return bool |
|
232 | + */ |
|
233 | + public function isEmpty() |
|
234 | + { |
|
235 | + return $this->count() === 0; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * remove |
|
241 | + * detaches an object from the Collection |
|
242 | + * |
|
243 | + * @access public |
|
244 | + * @param $object |
|
245 | + * @return bool |
|
246 | + */ |
|
247 | + public function remove($object) |
|
248 | + { |
|
249 | + $this->detach($object); |
|
250 | + return true; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * setCurrent |
|
256 | + * advances pointer to the object whose identifier matches that which was provided |
|
257 | + * |
|
258 | + * @access public |
|
259 | + * @param mixed $identifier |
|
260 | + * @return boolean |
|
261 | + */ |
|
262 | + public function setCurrent($identifier) |
|
263 | + { |
|
264 | + $this->rewind(); |
|
265 | + while ($this->valid()) { |
|
266 | + if ($identifier === $this->getInfo()) { |
|
267 | + return true; |
|
268 | + } |
|
269 | + $this->next(); |
|
270 | + } |
|
271 | + return false; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * setCurrentUsingObject |
|
277 | + * advances pointer to the provided object |
|
278 | + * |
|
279 | + * @access public |
|
280 | + * @param $object |
|
281 | + * @return boolean |
|
282 | + */ |
|
283 | + public function setCurrentUsingObject($object) |
|
284 | + { |
|
285 | + $this->rewind(); |
|
286 | + while ($this->valid()) { |
|
287 | + if ($this->current() === $object) { |
|
288 | + return true; |
|
289 | + } |
|
290 | + $this->next(); |
|
291 | + } |
|
292 | + return false; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns the object occupying the index before the current object, |
|
298 | + * unless this is already the first object, in which case it just returns the first object |
|
299 | + * |
|
300 | + * @return mixed |
|
301 | + */ |
|
302 | + public function previous() |
|
303 | + { |
|
304 | + $index = $this->indexOf($this->current()); |
|
305 | + if ($index === 0) { |
|
306 | + return $this->current(); |
|
307 | + } |
|
308 | + $index--; |
|
309 | + return $this->objectAtIndex($index); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Returns the index of a given object, or false if not found |
|
315 | + * |
|
316 | + * @see http://stackoverflow.com/a/8736013 |
|
317 | + * @param $object |
|
318 | + * @return boolean|int|string |
|
319 | + */ |
|
320 | + public function indexOf($object) |
|
321 | + { |
|
322 | + if (! $this->contains($object)) { |
|
323 | + return false; |
|
324 | + } |
|
325 | + foreach ($this as $index => $obj) { |
|
326 | + if ($obj === $object) { |
|
327 | + return $index; |
|
328 | + } |
|
329 | + } |
|
330 | + return false; |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Returns the object at the given index |
|
336 | + * |
|
337 | + * @see http://stackoverflow.com/a/8736013 |
|
338 | + * @param int $index |
|
339 | + * @return mixed |
|
340 | + */ |
|
341 | + public function objectAtIndex($index) |
|
342 | + { |
|
343 | + $iterator = new LimitIterator($this, $index, 1); |
|
344 | + $iterator->rewind(); |
|
345 | + return $iterator->current(); |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * Returns the sequence of objects as specified by the offset and length |
|
351 | + * |
|
352 | + * @see http://stackoverflow.com/a/8736013 |
|
353 | + * @param int $offset |
|
354 | + * @param int $length |
|
355 | + * @return array |
|
356 | + */ |
|
357 | + public function slice($offset, $length) |
|
358 | + { |
|
359 | + $slice = array(); |
|
360 | + $iterator = new LimitIterator($this, $offset, $length); |
|
361 | + foreach ($iterator as $object) { |
|
362 | + $slice[] = $object; |
|
363 | + } |
|
364 | + return $slice; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Inserts an object at a certain point |
|
370 | + * |
|
371 | + * @see http://stackoverflow.com/a/8736013 |
|
372 | + * @param mixed $object A single object |
|
373 | + * @param int $index |
|
374 | + * @param mixed $identifier |
|
375 | + * @return bool |
|
376 | + * @throws DuplicateCollectionIdentifierException |
|
377 | + * @throws InvalidEntityException |
|
378 | + */ |
|
379 | + public function insertObjectAt($object, $index, $identifier = null) |
|
380 | + { |
|
381 | + // check to ensure that objects don't already exist in the collection |
|
382 | + if ($this->has($identifier)) { |
|
383 | + throw new DuplicateCollectionIdentifierException($identifier); |
|
384 | + } |
|
385 | + // detach any objects at or past this index |
|
386 | + $remaining_objects = array(); |
|
387 | + if ($index < $this->count()) { |
|
388 | + $remaining_objects = $this->slice($index, $this->count() - $index); |
|
389 | + foreach ($remaining_objects as $key => $remaining_object) { |
|
390 | + // we need to grab the identifiers for each object and use them as keys |
|
391 | + $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
392 | + // and then remove the object from the current tracking array |
|
393 | + unset($remaining_objects[ $key ]); |
|
394 | + // and then remove it from the Collection |
|
395 | + $this->detach($remaining_object); |
|
396 | + } |
|
397 | + } |
|
398 | + // add the new object we're splicing in |
|
399 | + $this->add($object, $identifier); |
|
400 | + // attach the objects we previously detached |
|
401 | + foreach ($remaining_objects as $key => $remaining_object) { |
|
402 | + $this->add($remaining_object, $key); |
|
403 | + } |
|
404 | + return $this->contains($object); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Inserts an object (or an array of objects) at a certain point |
|
410 | + * |
|
411 | + * @see http://stackoverflow.com/a/8736013 |
|
412 | + * @param mixed $objects A single object or an array of objects |
|
413 | + * @param int $index |
|
414 | + */ |
|
415 | + public function insertAt($objects, $index) |
|
416 | + { |
|
417 | + if (! is_array($objects)) { |
|
418 | + $objects = array($objects); |
|
419 | + } |
|
420 | + // check to ensure that objects don't already exist in the collection |
|
421 | + foreach ($objects as $key => $object) { |
|
422 | + if ($this->contains($object)) { |
|
423 | + unset($objects[ $key ]); |
|
424 | + } |
|
425 | + } |
|
426 | + // do we have any objects left? |
|
427 | + if (! $objects) { |
|
428 | + return; |
|
429 | + } |
|
430 | + // detach any objects at or past this index |
|
431 | + $remaining = array(); |
|
432 | + if ($index < $this->count()) { |
|
433 | + $remaining = $this->slice($index, $this->count() - $index); |
|
434 | + foreach ($remaining as $object) { |
|
435 | + $this->detach($object); |
|
436 | + } |
|
437 | + } |
|
438 | + // add the new objects we're splicing in |
|
439 | + foreach ($objects as $object) { |
|
440 | + $this->attach($object); |
|
441 | + } |
|
442 | + // attach the objects we previously detached |
|
443 | + foreach ($remaining as $object) { |
|
444 | + $this->attach($object); |
|
445 | + } |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * Removes the object at the given index |
|
451 | + * |
|
452 | + * @see http://stackoverflow.com/a/8736013 |
|
453 | + * @param int $index |
|
454 | + */ |
|
455 | + public function removeAt($index) |
|
456 | + { |
|
457 | + $this->detach($this->objectAtIndex($index)); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * detaches ALL objects from the Collection |
|
463 | + */ |
|
464 | + public function detachAll() |
|
465 | + { |
|
466 | + $this->rewind(); |
|
467 | + while ($this->valid()) { |
|
468 | + $object = $this->current(); |
|
469 | + $this->next(); |
|
470 | + $this->detach($object); |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * unsets and detaches ALL objects from the Collection |
|
477 | + */ |
|
478 | + public function trashAndDetachAll() |
|
479 | + { |
|
480 | + $this->rewind(); |
|
481 | + while ($this->valid()) { |
|
482 | + $object = $this->current(); |
|
483 | + $this->next(); |
|
484 | + $this->detach($object); |
|
485 | + unset($object); |
|
486 | + } |
|
487 | + } |
|
488 | 488 | } |
@@ -16,26 +16,26 @@ |
||
16 | 16 | class InvalidCollectionIdentifierException extends OutOfBoundsException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidCollectionIdentifierException constructor. |
|
21 | - * |
|
22 | - * @param $identifier |
|
23 | - * @param string $message |
|
24 | - * @param int $code |
|
25 | - * @param Exception|null $previous |
|
26 | - */ |
|
27 | - public function __construct($identifier, $message = '', $code = 0, Exception $previous = null) |
|
28 | - { |
|
29 | - if (empty($message)) { |
|
30 | - $message = sprintf( |
|
31 | - __( |
|
32 | - 'The supplied identifier "%1$s" does not exist within this collection. |
|
19 | + /** |
|
20 | + * InvalidCollectionIdentifierException constructor. |
|
21 | + * |
|
22 | + * @param $identifier |
|
23 | + * @param string $message |
|
24 | + * @param int $code |
|
25 | + * @param Exception|null $previous |
|
26 | + */ |
|
27 | + public function __construct($identifier, $message = '', $code = 0, Exception $previous = null) |
|
28 | + { |
|
29 | + if (empty($message)) { |
|
30 | + $message = sprintf( |
|
31 | + __( |
|
32 | + 'The supplied identifier "%1$s" does not exist within this collection. |
|
33 | 33 | You may need to delay adding this asset until the required dependency has been added.', |
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - $identifier |
|
37 | - ); |
|
38 | - } |
|
39 | - parent::__construct($message, $code, $previous); |
|
40 | - } |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + $identifier |
|
37 | + ); |
|
38 | + } |
|
39 | + parent::__construct($message, $code, $previous); |
|
40 | + } |
|
41 | 41 | } |
@@ -16,25 +16,25 @@ |
||
16 | 16 | class DuplicateCollectionIdentifierException extends OutOfRangeException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * DuplicateCollectionIdentifierException constructor. |
|
21 | - * |
|
22 | - * @param $identifier |
|
23 | - * @param string $message |
|
24 | - * @param int $code |
|
25 | - * @param Exception|null $previous |
|
26 | - */ |
|
27 | - public function __construct($identifier, $message = '', $code = 0, Exception $previous = null) |
|
28 | - { |
|
29 | - if (empty($message)) { |
|
30 | - $message = sprintf( |
|
31 | - __( |
|
32 | - 'The supplied identifier "%1$s" already exists within this collection.', |
|
33 | - 'event_espresso' |
|
34 | - ), |
|
35 | - $identifier |
|
36 | - ); |
|
37 | - } |
|
38 | - parent::__construct($message, $code, $previous); |
|
39 | - } |
|
19 | + /** |
|
20 | + * DuplicateCollectionIdentifierException constructor. |
|
21 | + * |
|
22 | + * @param $identifier |
|
23 | + * @param string $message |
|
24 | + * @param int $code |
|
25 | + * @param Exception|null $previous |
|
26 | + */ |
|
27 | + public function __construct($identifier, $message = '', $code = 0, Exception $previous = null) |
|
28 | + { |
|
29 | + if (empty($message)) { |
|
30 | + $message = sprintf( |
|
31 | + __( |
|
32 | + 'The supplied identifier "%1$s" already exists within this collection.', |
|
33 | + 'event_espresso' |
|
34 | + ), |
|
35 | + $identifier |
|
36 | + ); |
|
37 | + } |
|
38 | + parent::__construct($message, $code, $previous); |
|
39 | + } |
|
40 | 40 | } |
@@ -21,86 +21,86 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * AssetCollection constructor |
|
26 | - * |
|
27 | - * @throws InvalidInterfaceException |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | - } |
|
24 | + /** |
|
25 | + * AssetCollection constructor |
|
26 | + * |
|
27 | + * @throws InvalidInterfaceException |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * @return StylesheetAsset[] |
|
37 | - * @since $VID:$ |
|
38 | - */ |
|
39 | - public function getStylesheetAssets() |
|
40 | - { |
|
41 | - return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | - } |
|
35 | + /** |
|
36 | + * @return StylesheetAsset[] |
|
37 | + * @since $VID:$ |
|
38 | + */ |
|
39 | + public function getStylesheetAssets() |
|
40 | + { |
|
41 | + return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @return JavascriptAsset[] |
|
47 | - * @since $VID:$ |
|
48 | - */ |
|
49 | - public function getJavascriptAssets() |
|
50 | - { |
|
51 | - return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | - } |
|
45 | + /** |
|
46 | + * @return JavascriptAsset[] |
|
47 | + * @since $VID:$ |
|
48 | + */ |
|
49 | + public function getJavascriptAssets() |
|
50 | + { |
|
51 | + return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @return ManifestFile[] |
|
57 | - * @since $VID:$ |
|
58 | - */ |
|
59 | - public function getManifestFiles() |
|
60 | - { |
|
61 | - return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | - } |
|
55 | + /** |
|
56 | + * @return ManifestFile[] |
|
57 | + * @since $VID:$ |
|
58 | + */ |
|
59 | + public function getManifestFiles() |
|
60 | + { |
|
61 | + return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @param $type |
|
67 | - * @return array |
|
68 | - * @since $VID:$ |
|
69 | - */ |
|
70 | - protected function getAssetsOfType($type) |
|
71 | - { |
|
72 | - $files = array(); |
|
73 | - $this->rewind(); |
|
74 | - while ($this->valid()) { |
|
75 | - /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
|
76 | - $asset = $this->current(); |
|
77 | - if ($asset->type() === $type) { |
|
78 | - $files[ $asset->handle() ] = $asset; |
|
79 | - } |
|
80 | - $this->next(); |
|
81 | - } |
|
82 | - $this->rewind(); |
|
83 | - return $files; |
|
84 | - } |
|
65 | + /** |
|
66 | + * @param $type |
|
67 | + * @return array |
|
68 | + * @since $VID:$ |
|
69 | + */ |
|
70 | + protected function getAssetsOfType($type) |
|
71 | + { |
|
72 | + $files = array(); |
|
73 | + $this->rewind(); |
|
74 | + while ($this->valid()) { |
|
75 | + /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
|
76 | + $asset = $this->current(); |
|
77 | + if ($asset->type() === $type) { |
|
78 | + $files[ $asset->handle() ] = $asset; |
|
79 | + } |
|
80 | + $this->next(); |
|
81 | + } |
|
82 | + $this->rewind(); |
|
83 | + return $files; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * @return JavascriptAsset[] |
|
89 | - * @since $VID:$ |
|
90 | - */ |
|
91 | - public function getJavascriptAssetsWithData() |
|
92 | - { |
|
93 | - $files = array(); |
|
94 | - $this->rewind(); |
|
95 | - while ($this->valid()) { |
|
96 | - /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
|
97 | - $asset = $this->current(); |
|
98 | - if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) { |
|
99 | - $files[ $asset->handle() ] = $asset; |
|
100 | - } |
|
101 | - $this->next(); |
|
102 | - } |
|
103 | - $this->rewind(); |
|
104 | - return $files; |
|
105 | - } |
|
87 | + /** |
|
88 | + * @return JavascriptAsset[] |
|
89 | + * @since $VID:$ |
|
90 | + */ |
|
91 | + public function getJavascriptAssetsWithData() |
|
92 | + { |
|
93 | + $files = array(); |
|
94 | + $this->rewind(); |
|
95 | + while ($this->valid()) { |
|
96 | + /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
|
97 | + $asset = $this->current(); |
|
98 | + if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) { |
|
99 | + $files[ $asset->handle() ] = $asset; |
|
100 | + } |
|
101 | + $this->next(); |
|
102 | + } |
|
103 | + $this->rewind(); |
|
104 | + return $files; |
|
105 | + } |
|
106 | 106 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
76 | 76 | $asset = $this->current(); |
77 | 77 | if ($asset->type() === $type) { |
78 | - $files[ $asset->handle() ] = $asset; |
|
78 | + $files[$asset->handle()] = $asset; |
|
79 | 79 | } |
80 | 80 | $this->next(); |
81 | 81 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
97 | 97 | $asset = $this->current(); |
98 | 98 | if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) { |
99 | - $files[ $asset->handle() ] = $asset; |
|
99 | + $files[$asset->handle()] = $asset; |
|
100 | 100 | } |
101 | 101 | $this->next(); |
102 | 102 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $this->removeAlreadyRegisteredDataForScriptHandles(); |
146 | 146 | wp_add_inline_script( |
147 | 147 | 'eejs-core', |
148 | - 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
148 | + 'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)), |
|
149 | 149 | 'before' |
150 | 150 | ); |
151 | 151 | $scripts = $this->assets->getJavascriptAssetsWithData(); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | public function addData($key, $value) |
175 | 175 | { |
176 | 176 | if ($this->verifyDataNotExisting($key)) { |
177 | - $this->jsdata[ $key ] = $value; |
|
177 | + $this->jsdata[$key] = $value; |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function pushData($key, $value) |
197 | 197 | { |
198 | - if (isset($this->jsdata[ $key ]) |
|
199 | - && ! is_array($this->jsdata[ $key ]) |
|
198 | + if (isset($this->jsdata[$key]) |
|
199 | + && ! is_array($this->jsdata[$key]) |
|
200 | 200 | ) { |
201 | 201 | throw new InvalidArgumentException( |
202 | 202 | sprintf( |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | ) |
211 | 211 | ); |
212 | 212 | } |
213 | - $this->jsdata[ $key ][] = $value; |
|
213 | + $this->jsdata[$key][] = $value; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | |
@@ -224,11 +224,11 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public function addTemplate($template_reference, $template_content) |
226 | 226 | { |
227 | - if (! isset($this->jsdata['templates'])) { |
|
227 | + if ( ! isset($this->jsdata['templates'])) { |
|
228 | 228 | $this->jsdata['templates'] = array(); |
229 | 229 | } |
230 | 230 | //no overrides allowed. |
231 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
231 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
232 | 232 | throw new InvalidArgumentException( |
233 | 233 | sprintf( |
234 | 234 | __( |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | ) |
240 | 240 | ); |
241 | 241 | } |
242 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
242 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function getTemplate($template_reference) |
253 | 253 | { |
254 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
255 | - ? $this->jsdata['templates'][ $template_reference ] |
|
254 | + return isset($this->jsdata['templates'][$template_reference]) |
|
255 | + ? $this->jsdata['templates'][$template_reference] |
|
256 | 256 | : ''; |
257 | 257 | } |
258 | 258 | |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function getData($key) |
267 | 267 | { |
268 | - return isset($this->jsdata[ $key ]) |
|
269 | - ? $this->jsdata[ $key ] |
|
268 | + return isset($this->jsdata[$key]) |
|
269 | + ? $this->jsdata[$key] |
|
270 | 270 | : false; |
271 | 271 | } |
272 | 272 | |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | */ |
282 | 282 | protected function verifyDataNotExisting($key) |
283 | 283 | { |
284 | - if (isset($this->jsdata[ $key ])) { |
|
285 | - if (is_array($this->jsdata[ $key ])) { |
|
284 | + if (isset($this->jsdata[$key])) { |
|
285 | + if (is_array($this->jsdata[$key])) { |
|
286 | 286 | throw new InvalidArgumentException( |
287 | 287 | sprintf( |
288 | 288 | __( |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | public function getAssetUrl($namespace, $chunk_name, $asset_type) |
326 | 326 | { |
327 | 327 | $url = isset( |
328 | - $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ], |
|
329 | - $this->manifest_data[ $namespace ]['url_base'] |
|
328 | + $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
329 | + $this->manifest_data[$namespace]['url_base'] |
|
330 | 330 | ) |
331 | - ? $this->manifest_data[ $namespace ]['url_base'] |
|
332 | - . $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ] |
|
331 | + ? $this->manifest_data[$namespace]['url_base'] |
|
332 | + . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
333 | 333 | : $chunk_name; |
334 | 334 | return apply_filters( |
335 | 335 | 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | $this->registerManifestFile( |
380 | 380 | $manifest_file->assetNamespace(), |
381 | 381 | $manifest_file->urlBase(), |
382 | - $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
382 | + $manifest_file->filepath().Registry::FILE_NAME_BUILD_MANIFEST |
|
383 | 383 | ); |
384 | 384 | } |
385 | 385 | } |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | */ |
398 | 398 | public function registerManifestFile($namespace, $url_base, $manifest_file) |
399 | 399 | { |
400 | - if (isset($this->manifest_data[ $namespace ])) { |
|
400 | + if (isset($this->manifest_data[$namespace])) { |
|
401 | 401 | throw new InvalidArgumentException( |
402 | 402 | sprintf( |
403 | 403 | esc_html__( |
@@ -428,9 +428,9 @@ discard block |
||
428 | 428 | } |
429 | 429 | return; |
430 | 430 | } |
431 | - $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
432 | - if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
433 | - $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
431 | + $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
432 | + if ( ! isset($this->manifest_data[$namespace]['url_base'])) { |
|
433 | + $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | */ |
446 | 446 | private function decodeManifestFile($manifest_file) |
447 | 447 | { |
448 | - if (! file_exists($manifest_file)) { |
|
448 | + if ( ! file_exists($manifest_file)) { |
|
449 | 449 | throw new InvalidFilePathException($manifest_file); |
450 | 450 | } |
451 | 451 | return json_decode(file_get_contents($manifest_file), true); |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | */ |
460 | 460 | private function addRegisteredScriptHandlesWithData($script_handle) |
461 | 461 | { |
462 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
462 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | |
@@ -485,23 +485,23 @@ discard block |
||
485 | 485 | */ |
486 | 486 | private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
487 | 487 | { |
488 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
488 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
489 | 489 | global $wp_scripts; |
490 | 490 | $unset_handle = false; |
491 | 491 | if ($wp_scripts->get_data($script_handle, 'data')) { |
492 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
492 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
493 | 493 | $unset_handle = true; |
494 | 494 | } |
495 | 495 | //deal with inline_scripts |
496 | 496 | if ($wp_scripts->get_data($script_handle, 'before')) { |
497 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
497 | + unset($wp_scripts->registered[$script_handle]->extra['before']); |
|
498 | 498 | $unset_handle = true; |
499 | 499 | } |
500 | 500 | if ($wp_scripts->get_data($script_handle, 'after')) { |
501 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
501 | + unset($wp_scripts->registered[$script_handle]->extra['after']); |
|
502 | 502 | } |
503 | 503 | if ($unset_handle) { |
504 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
504 | + unset($this->script_handles_with_data[$script_handle]); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | } |
@@ -23,560 +23,560 @@ |
||
23 | 23 | class Registry |
24 | 24 | { |
25 | 25 | |
26 | - const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var AssetCollection $assets |
|
30 | - */ |
|
31 | - protected $assets; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var I18nRegistry |
|
35 | - */ |
|
36 | - private $i18n_registry; |
|
37 | - |
|
38 | - /** |
|
39 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $jsdata = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
47 | - * page source. |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - private $script_handles_with_data = array(); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Holds the manifest data obtained from registered manifest files. |
|
56 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
57 | - * Shape of this array is: |
|
58 | - * array( |
|
59 | - * 'some_namespace_slug' => array( |
|
60 | - * 'some_chunk_name' => array( |
|
61 | - * 'js' => 'filename.js' |
|
62 | - * 'css' => 'filename.js' |
|
63 | - * ), |
|
64 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
65 | - * ) |
|
66 | - * ) |
|
67 | - * |
|
68 | - * @var array |
|
69 | - */ |
|
70 | - private $manifest_data = array(); |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Registry constructor. |
|
75 | - * Hooking into WP actions for script registry. |
|
76 | - * |
|
77 | - * @param AssetCollection $assets |
|
78 | - * @param I18nRegistry $i18n_registry |
|
79 | - */ |
|
80 | - public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
81 | - { |
|
82 | - $this->assets = $assets; |
|
83 | - $this->i18n_registry = $i18n_registry; |
|
84 | - add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
85 | - add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
86 | - add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
87 | - add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
88 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
89 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
90 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
91 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
97 | - * translation handling. |
|
98 | - * |
|
99 | - * @return I18nRegistry |
|
100 | - */ |
|
101 | - public function getI18nRegistry() |
|
102 | - { |
|
103 | - return $this->i18n_registry; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Callback for the wp_enqueue_scripts actions used to register assets. |
|
109 | - * |
|
110 | - * @since $VID:$ |
|
111 | - * @throws Exception |
|
112 | - */ |
|
113 | - public function registerScriptsAndStyles() |
|
114 | - { |
|
115 | - try { |
|
116 | - $this->registerScripts($this->assets->getJavascriptAssets()); |
|
117 | - $this->registerStyles($this->assets->getStylesheetAssets()); |
|
118 | - } catch (Exception $exception) { |
|
119 | - new ExceptionStackTraceDisplay($exception); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * Registers JS assets with WP core |
|
126 | - * |
|
127 | - * @since $VID:$ |
|
128 | - * @param JavascriptAsset[] $scripts |
|
129 | - * @throws AssetRegistrationException |
|
130 | - * @throws InvalidDataTypeException |
|
131 | - */ |
|
132 | - public function registerScripts(array $scripts) |
|
133 | - { |
|
134 | - foreach ($scripts as $script) { |
|
135 | - // skip to next script if this has already been done |
|
136 | - if ($script->isRegistered()) { |
|
137 | - continue; |
|
138 | - } |
|
139 | - do_action( |
|
140 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
141 | - $script |
|
142 | - ); |
|
143 | - $registered = wp_register_script( |
|
144 | - $script->handle(), |
|
145 | - $script->source(), |
|
146 | - $script->dependencies(), |
|
147 | - $script->version(), |
|
148 | - $script->loadInFooter() |
|
149 | - ); |
|
150 | - if (defined('EE_DEBUG') && EE_DEBUG && ! $registered) { |
|
151 | - throw new AssetRegistrationException($script->handle()); |
|
152 | - } |
|
153 | - $script->setRegistered($registered); |
|
154 | - if ($script->requiresTranslation()) { |
|
155 | - $this->registerTranslation($script->handle()); |
|
156 | - } |
|
157 | - do_action( |
|
158 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
159 | - $script |
|
160 | - ); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Registers CSS assets with WP core |
|
167 | - * |
|
168 | - * @since $VID:$ |
|
169 | - * @param StylesheetAsset[] $styles |
|
170 | - * @throws InvalidDataTypeException |
|
171 | - */ |
|
172 | - public function registerStyles(array $styles) |
|
173 | - { |
|
174 | - foreach ($styles as $style) { |
|
175 | - // skip to next style if this has already been done |
|
176 | - if ($style->isRegistered()) { |
|
177 | - continue; |
|
178 | - } |
|
179 | - do_action( |
|
180 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
181 | - $style |
|
182 | - ); |
|
183 | - wp_enqueue_style( |
|
184 | - $style->handle(), |
|
185 | - $style->source(), |
|
186 | - $style->dependencies(), |
|
187 | - $style->version(), |
|
188 | - $style->media() |
|
189 | - ); |
|
190 | - $style->setRegistered(); |
|
191 | - do_action( |
|
192 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
193 | - $style |
|
194 | - ); |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Call back for the script print in frontend and backend. |
|
201 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
202 | - * |
|
203 | - * @since 4.9.31.rc.015 |
|
204 | - */ |
|
205 | - public function enqueueData() |
|
206 | - { |
|
207 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
208 | - wp_add_inline_script( |
|
209 | - 'eejs-core', |
|
210 | - 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
211 | - 'before' |
|
212 | - ); |
|
213 | - $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
214 | - foreach ($scripts as $script) { |
|
215 | - $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
216 | - if ($script->hasLocalizationCallback()) { |
|
217 | - $localize = $script->localizationCallback(); |
|
218 | - $localize(); |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * Used to add data to eejs.data object. |
|
226 | - * Note: Overriding existing data is not allowed. |
|
227 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
228 | - * If the data you add is something like this: |
|
229 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
230 | - * It will be exposed in the page source as: |
|
231 | - * eejs.data.my_plugin_data.foo == gar |
|
232 | - * |
|
233 | - * @param string $key Key used to access your data |
|
234 | - * @param string|array $value Value to attach to key |
|
235 | - * @throws InvalidArgumentException |
|
236 | - */ |
|
237 | - public function addData($key, $value) |
|
238 | - { |
|
239 | - if ($this->verifyDataNotExisting($key)) { |
|
240 | - $this->jsdata[ $key ] = $value; |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
247 | - * elements in an array. |
|
248 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
249 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
250 | - * object like this, eejs.data.test = [ my_data, |
|
251 | - * ] |
|
252 | - * If there has already been a scalar value attached to the data object given key, then |
|
253 | - * this will throw an exception. |
|
254 | - * |
|
255 | - * @param string $key Key to attach data to. |
|
256 | - * @param string|array $value Value being registered. |
|
257 | - * @throws InvalidArgumentException |
|
258 | - */ |
|
259 | - public function pushData($key, $value) |
|
260 | - { |
|
261 | - if (isset($this->jsdata[ $key ]) |
|
262 | - && ! is_array($this->jsdata[ $key ]) |
|
263 | - ) { |
|
264 | - throw new InvalidArgumentException( |
|
265 | - sprintf( |
|
266 | - __( |
|
267 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
26 | + const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var AssetCollection $assets |
|
30 | + */ |
|
31 | + protected $assets; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var I18nRegistry |
|
35 | + */ |
|
36 | + private $i18n_registry; |
|
37 | + |
|
38 | + /** |
|
39 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $jsdata = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
47 | + * page source. |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + private $script_handles_with_data = array(); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Holds the manifest data obtained from registered manifest files. |
|
56 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
57 | + * Shape of this array is: |
|
58 | + * array( |
|
59 | + * 'some_namespace_slug' => array( |
|
60 | + * 'some_chunk_name' => array( |
|
61 | + * 'js' => 'filename.js' |
|
62 | + * 'css' => 'filename.js' |
|
63 | + * ), |
|
64 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
65 | + * ) |
|
66 | + * ) |
|
67 | + * |
|
68 | + * @var array |
|
69 | + */ |
|
70 | + private $manifest_data = array(); |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Registry constructor. |
|
75 | + * Hooking into WP actions for script registry. |
|
76 | + * |
|
77 | + * @param AssetCollection $assets |
|
78 | + * @param I18nRegistry $i18n_registry |
|
79 | + */ |
|
80 | + public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
81 | + { |
|
82 | + $this->assets = $assets; |
|
83 | + $this->i18n_registry = $i18n_registry; |
|
84 | + add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
85 | + add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
86 | + add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
87 | + add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
88 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
89 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
90 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
91 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
97 | + * translation handling. |
|
98 | + * |
|
99 | + * @return I18nRegistry |
|
100 | + */ |
|
101 | + public function getI18nRegistry() |
|
102 | + { |
|
103 | + return $this->i18n_registry; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Callback for the wp_enqueue_scripts actions used to register assets. |
|
109 | + * |
|
110 | + * @since $VID:$ |
|
111 | + * @throws Exception |
|
112 | + */ |
|
113 | + public function registerScriptsAndStyles() |
|
114 | + { |
|
115 | + try { |
|
116 | + $this->registerScripts($this->assets->getJavascriptAssets()); |
|
117 | + $this->registerStyles($this->assets->getStylesheetAssets()); |
|
118 | + } catch (Exception $exception) { |
|
119 | + new ExceptionStackTraceDisplay($exception); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * Registers JS assets with WP core |
|
126 | + * |
|
127 | + * @since $VID:$ |
|
128 | + * @param JavascriptAsset[] $scripts |
|
129 | + * @throws AssetRegistrationException |
|
130 | + * @throws InvalidDataTypeException |
|
131 | + */ |
|
132 | + public function registerScripts(array $scripts) |
|
133 | + { |
|
134 | + foreach ($scripts as $script) { |
|
135 | + // skip to next script if this has already been done |
|
136 | + if ($script->isRegistered()) { |
|
137 | + continue; |
|
138 | + } |
|
139 | + do_action( |
|
140 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
141 | + $script |
|
142 | + ); |
|
143 | + $registered = wp_register_script( |
|
144 | + $script->handle(), |
|
145 | + $script->source(), |
|
146 | + $script->dependencies(), |
|
147 | + $script->version(), |
|
148 | + $script->loadInFooter() |
|
149 | + ); |
|
150 | + if (defined('EE_DEBUG') && EE_DEBUG && ! $registered) { |
|
151 | + throw new AssetRegistrationException($script->handle()); |
|
152 | + } |
|
153 | + $script->setRegistered($registered); |
|
154 | + if ($script->requiresTranslation()) { |
|
155 | + $this->registerTranslation($script->handle()); |
|
156 | + } |
|
157 | + do_action( |
|
158 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
159 | + $script |
|
160 | + ); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Registers CSS assets with WP core |
|
167 | + * |
|
168 | + * @since $VID:$ |
|
169 | + * @param StylesheetAsset[] $styles |
|
170 | + * @throws InvalidDataTypeException |
|
171 | + */ |
|
172 | + public function registerStyles(array $styles) |
|
173 | + { |
|
174 | + foreach ($styles as $style) { |
|
175 | + // skip to next style if this has already been done |
|
176 | + if ($style->isRegistered()) { |
|
177 | + continue; |
|
178 | + } |
|
179 | + do_action( |
|
180 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
181 | + $style |
|
182 | + ); |
|
183 | + wp_enqueue_style( |
|
184 | + $style->handle(), |
|
185 | + $style->source(), |
|
186 | + $style->dependencies(), |
|
187 | + $style->version(), |
|
188 | + $style->media() |
|
189 | + ); |
|
190 | + $style->setRegistered(); |
|
191 | + do_action( |
|
192 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
193 | + $style |
|
194 | + ); |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Call back for the script print in frontend and backend. |
|
201 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
202 | + * |
|
203 | + * @since 4.9.31.rc.015 |
|
204 | + */ |
|
205 | + public function enqueueData() |
|
206 | + { |
|
207 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
208 | + wp_add_inline_script( |
|
209 | + 'eejs-core', |
|
210 | + 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
211 | + 'before' |
|
212 | + ); |
|
213 | + $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
214 | + foreach ($scripts as $script) { |
|
215 | + $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
216 | + if ($script->hasLocalizationCallback()) { |
|
217 | + $localize = $script->localizationCallback(); |
|
218 | + $localize(); |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * Used to add data to eejs.data object. |
|
226 | + * Note: Overriding existing data is not allowed. |
|
227 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
228 | + * If the data you add is something like this: |
|
229 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
230 | + * It will be exposed in the page source as: |
|
231 | + * eejs.data.my_plugin_data.foo == gar |
|
232 | + * |
|
233 | + * @param string $key Key used to access your data |
|
234 | + * @param string|array $value Value to attach to key |
|
235 | + * @throws InvalidArgumentException |
|
236 | + */ |
|
237 | + public function addData($key, $value) |
|
238 | + { |
|
239 | + if ($this->verifyDataNotExisting($key)) { |
|
240 | + $this->jsdata[ $key ] = $value; |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
247 | + * elements in an array. |
|
248 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
249 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
250 | + * object like this, eejs.data.test = [ my_data, |
|
251 | + * ] |
|
252 | + * If there has already been a scalar value attached to the data object given key, then |
|
253 | + * this will throw an exception. |
|
254 | + * |
|
255 | + * @param string $key Key to attach data to. |
|
256 | + * @param string|array $value Value being registered. |
|
257 | + * @throws InvalidArgumentException |
|
258 | + */ |
|
259 | + public function pushData($key, $value) |
|
260 | + { |
|
261 | + if (isset($this->jsdata[ $key ]) |
|
262 | + && ! is_array($this->jsdata[ $key ]) |
|
263 | + ) { |
|
264 | + throw new InvalidArgumentException( |
|
265 | + sprintf( |
|
266 | + __( |
|
267 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
268 | 268 | push values to this data element when it is an array.', |
269 | - 'event_espresso' |
|
270 | - ), |
|
271 | - $key, |
|
272 | - __METHOD__ |
|
273 | - ) |
|
274 | - ); |
|
275 | - } |
|
276 | - $this->jsdata[ $key ][] = $value; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Used to set content used by javascript for a template. |
|
282 | - * Note: Overrides of existing registered templates are not allowed. |
|
283 | - * |
|
284 | - * @param string $template_reference |
|
285 | - * @param string $template_content |
|
286 | - * @throws InvalidArgumentException |
|
287 | - */ |
|
288 | - public function addTemplate($template_reference, $template_content) |
|
289 | - { |
|
290 | - if (! isset($this->jsdata['templates'])) { |
|
291 | - $this->jsdata['templates'] = array(); |
|
292 | - } |
|
293 | - //no overrides allowed. |
|
294 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
295 | - throw new InvalidArgumentException( |
|
296 | - sprintf( |
|
297 | - __( |
|
298 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
299 | - 'event_espresso' |
|
300 | - ), |
|
301 | - $template_reference |
|
302 | - ) |
|
303 | - ); |
|
304 | - } |
|
305 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Retrieve the template content already registered for the given reference. |
|
311 | - * |
|
312 | - * @param string $template_reference |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - public function getTemplate($template_reference) |
|
316 | - { |
|
317 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
318 | - ? $this->jsdata['templates'][ $template_reference ] |
|
319 | - : ''; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * Retrieve registered data. |
|
325 | - * |
|
326 | - * @param string $key Name of key to attach data to. |
|
327 | - * @return mixed If there is no for the given key, then false is returned. |
|
328 | - */ |
|
329 | - public function getData($key) |
|
330 | - { |
|
331 | - return isset($this->jsdata[ $key ]) |
|
332 | - ? $this->jsdata[ $key ] |
|
333 | - : false; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Verifies whether the given data exists already on the jsdata array. |
|
339 | - * Overriding data is not allowed. |
|
340 | - * |
|
341 | - * @param string $key Index for data. |
|
342 | - * @return bool If valid then return true. |
|
343 | - * @throws InvalidArgumentException if data already exists. |
|
344 | - */ |
|
345 | - protected function verifyDataNotExisting($key) |
|
346 | - { |
|
347 | - if (isset($this->jsdata[ $key ])) { |
|
348 | - if (is_array($this->jsdata[ $key ])) { |
|
349 | - throw new InvalidArgumentException( |
|
350 | - sprintf( |
|
351 | - __( |
|
352 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
269 | + 'event_espresso' |
|
270 | + ), |
|
271 | + $key, |
|
272 | + __METHOD__ |
|
273 | + ) |
|
274 | + ); |
|
275 | + } |
|
276 | + $this->jsdata[ $key ][] = $value; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Used to set content used by javascript for a template. |
|
282 | + * Note: Overrides of existing registered templates are not allowed. |
|
283 | + * |
|
284 | + * @param string $template_reference |
|
285 | + * @param string $template_content |
|
286 | + * @throws InvalidArgumentException |
|
287 | + */ |
|
288 | + public function addTemplate($template_reference, $template_content) |
|
289 | + { |
|
290 | + if (! isset($this->jsdata['templates'])) { |
|
291 | + $this->jsdata['templates'] = array(); |
|
292 | + } |
|
293 | + //no overrides allowed. |
|
294 | + if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
295 | + throw new InvalidArgumentException( |
|
296 | + sprintf( |
|
297 | + __( |
|
298 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
299 | + 'event_espresso' |
|
300 | + ), |
|
301 | + $template_reference |
|
302 | + ) |
|
303 | + ); |
|
304 | + } |
|
305 | + $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Retrieve the template content already registered for the given reference. |
|
311 | + * |
|
312 | + * @param string $template_reference |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + public function getTemplate($template_reference) |
|
316 | + { |
|
317 | + return isset($this->jsdata['templates'][ $template_reference ]) |
|
318 | + ? $this->jsdata['templates'][ $template_reference ] |
|
319 | + : ''; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * Retrieve registered data. |
|
325 | + * |
|
326 | + * @param string $key Name of key to attach data to. |
|
327 | + * @return mixed If there is no for the given key, then false is returned. |
|
328 | + */ |
|
329 | + public function getData($key) |
|
330 | + { |
|
331 | + return isset($this->jsdata[ $key ]) |
|
332 | + ? $this->jsdata[ $key ] |
|
333 | + : false; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Verifies whether the given data exists already on the jsdata array. |
|
339 | + * Overriding data is not allowed. |
|
340 | + * |
|
341 | + * @param string $key Index for data. |
|
342 | + * @return bool If valid then return true. |
|
343 | + * @throws InvalidArgumentException if data already exists. |
|
344 | + */ |
|
345 | + protected function verifyDataNotExisting($key) |
|
346 | + { |
|
347 | + if (isset($this->jsdata[ $key ])) { |
|
348 | + if (is_array($this->jsdata[ $key ])) { |
|
349 | + throw new InvalidArgumentException( |
|
350 | + sprintf( |
|
351 | + __( |
|
352 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
353 | 353 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
354 | 354 | %2$s method to push your value to the array.', |
355 | - 'event_espresso' |
|
356 | - ), |
|
357 | - $key, |
|
358 | - 'pushData()' |
|
359 | - ) |
|
360 | - ); |
|
361 | - } |
|
362 | - throw new InvalidArgumentException( |
|
363 | - sprintf( |
|
364 | - __( |
|
365 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
355 | + 'event_espresso' |
|
356 | + ), |
|
357 | + $key, |
|
358 | + 'pushData()' |
|
359 | + ) |
|
360 | + ); |
|
361 | + } |
|
362 | + throw new InvalidArgumentException( |
|
363 | + sprintf( |
|
364 | + __( |
|
365 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
366 | 366 | allowed. Consider attaching your value to a different key', |
367 | - 'event_espresso' |
|
368 | - ), |
|
369 | - $key |
|
370 | - ) |
|
371 | - ); |
|
372 | - } |
|
373 | - return true; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Get the actual asset path for asset manifests. |
|
379 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
380 | - * |
|
381 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
382 | - * asset file location. |
|
383 | - * @param string $chunk_name |
|
384 | - * @param string $asset_type |
|
385 | - * @return string |
|
386 | - * @since 4.9.59.p |
|
387 | - */ |
|
388 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
389 | - { |
|
390 | - $url = isset( |
|
391 | - $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ], |
|
392 | - $this->manifest_data[ $namespace ]['url_base'] |
|
393 | - ) |
|
394 | - ? $this->manifest_data[ $namespace ]['url_base'] |
|
395 | - . $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ] |
|
396 | - : $chunk_name; |
|
397 | - return apply_filters( |
|
398 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
399 | - $url, |
|
400 | - $namespace, |
|
401 | - $chunk_name, |
|
402 | - $asset_type |
|
403 | - ); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Return the url to a js file for the given namespace and chunk name. |
|
409 | - * |
|
410 | - * @param string $namespace |
|
411 | - * @param string $chunk_name |
|
412 | - * @return string |
|
413 | - */ |
|
414 | - public function getJsUrl($namespace, $chunk_name) |
|
415 | - { |
|
416 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * Return the url to a css file for the given namespace and chunk name. |
|
422 | - * |
|
423 | - * @param string $namespace |
|
424 | - * @param string $chunk_name |
|
425 | - * @return string |
|
426 | - */ |
|
427 | - public function getCssUrl($namespace, $chunk_name) |
|
428 | - { |
|
429 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * @since $VID:$ |
|
435 | - * @throws InvalidArgumentException |
|
436 | - * @throws InvalidFilePathException |
|
437 | - */ |
|
438 | - public function registerManifestFiles() |
|
439 | - { |
|
440 | - $manifest_files = $this->assets->getManifestFiles(); |
|
441 | - foreach ($manifest_files as $manifest_file) { |
|
442 | - $this->registerManifestFile( |
|
443 | - $manifest_file->assetNamespace(), |
|
444 | - $manifest_file->urlBase(), |
|
445 | - $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
446 | - ); |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
453 | - * |
|
454 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
455 | - * @param string $url_base The url base for the manifest file location. |
|
456 | - * @param string $manifest_file The absolute path to the manifest file. |
|
457 | - * @throws InvalidArgumentException |
|
458 | - * @throws InvalidFilePathException |
|
459 | - * @since 4.9.59.p |
|
460 | - */ |
|
461 | - public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
462 | - { |
|
463 | - if (isset($this->manifest_data[ $namespace ])) { |
|
464 | - throw new InvalidArgumentException( |
|
465 | - sprintf( |
|
466 | - esc_html__( |
|
467 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
468 | - 'event_espresso' |
|
469 | - ), |
|
470 | - $namespace |
|
471 | - ) |
|
472 | - ); |
|
473 | - } |
|
474 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
475 | - if (is_admin()) { |
|
476 | - EE_Error::add_error( |
|
477 | - sprintf( |
|
478 | - esc_html__( |
|
479 | - 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
480 | - 'event_espresso' |
|
481 | - ), |
|
482 | - 'Event Espresso', |
|
483 | - $url_base, |
|
484 | - 'plugins_url', |
|
485 | - 'WP_PLUGIN_URL' |
|
486 | - ), |
|
487 | - __FILE__, |
|
488 | - __FUNCTION__, |
|
489 | - __LINE__ |
|
490 | - ); |
|
491 | - } |
|
492 | - return; |
|
493 | - } |
|
494 | - $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
495 | - if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
496 | - $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
497 | - } |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * Decodes json from the provided manifest file. |
|
503 | - * |
|
504 | - * @since 4.9.59.p |
|
505 | - * @param string $manifest_file Path to manifest file. |
|
506 | - * @return array |
|
507 | - * @throws InvalidFilePathException |
|
508 | - */ |
|
509 | - private function decodeManifestFile($manifest_file) |
|
510 | - { |
|
511 | - if (! file_exists($manifest_file)) { |
|
512 | - throw new InvalidFilePathException($manifest_file); |
|
513 | - } |
|
514 | - return json_decode(file_get_contents($manifest_file), true); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * This is used to set registered script handles that have data. |
|
520 | - * |
|
521 | - * @param string $script_handle |
|
522 | - */ |
|
523 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
524 | - { |
|
525 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /**i |
|
367 | + 'event_espresso' |
|
368 | + ), |
|
369 | + $key |
|
370 | + ) |
|
371 | + ); |
|
372 | + } |
|
373 | + return true; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Get the actual asset path for asset manifests. |
|
379 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
380 | + * |
|
381 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
382 | + * asset file location. |
|
383 | + * @param string $chunk_name |
|
384 | + * @param string $asset_type |
|
385 | + * @return string |
|
386 | + * @since 4.9.59.p |
|
387 | + */ |
|
388 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
389 | + { |
|
390 | + $url = isset( |
|
391 | + $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ], |
|
392 | + $this->manifest_data[ $namespace ]['url_base'] |
|
393 | + ) |
|
394 | + ? $this->manifest_data[ $namespace ]['url_base'] |
|
395 | + . $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ] |
|
396 | + : $chunk_name; |
|
397 | + return apply_filters( |
|
398 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
399 | + $url, |
|
400 | + $namespace, |
|
401 | + $chunk_name, |
|
402 | + $asset_type |
|
403 | + ); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Return the url to a js file for the given namespace and chunk name. |
|
409 | + * |
|
410 | + * @param string $namespace |
|
411 | + * @param string $chunk_name |
|
412 | + * @return string |
|
413 | + */ |
|
414 | + public function getJsUrl($namespace, $chunk_name) |
|
415 | + { |
|
416 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * Return the url to a css file for the given namespace and chunk name. |
|
422 | + * |
|
423 | + * @param string $namespace |
|
424 | + * @param string $chunk_name |
|
425 | + * @return string |
|
426 | + */ |
|
427 | + public function getCssUrl($namespace, $chunk_name) |
|
428 | + { |
|
429 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * @since $VID:$ |
|
435 | + * @throws InvalidArgumentException |
|
436 | + * @throws InvalidFilePathException |
|
437 | + */ |
|
438 | + public function registerManifestFiles() |
|
439 | + { |
|
440 | + $manifest_files = $this->assets->getManifestFiles(); |
|
441 | + foreach ($manifest_files as $manifest_file) { |
|
442 | + $this->registerManifestFile( |
|
443 | + $manifest_file->assetNamespace(), |
|
444 | + $manifest_file->urlBase(), |
|
445 | + $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
446 | + ); |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
453 | + * |
|
454 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
455 | + * @param string $url_base The url base for the manifest file location. |
|
456 | + * @param string $manifest_file The absolute path to the manifest file. |
|
457 | + * @throws InvalidArgumentException |
|
458 | + * @throws InvalidFilePathException |
|
459 | + * @since 4.9.59.p |
|
460 | + */ |
|
461 | + public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
462 | + { |
|
463 | + if (isset($this->manifest_data[ $namespace ])) { |
|
464 | + throw new InvalidArgumentException( |
|
465 | + sprintf( |
|
466 | + esc_html__( |
|
467 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
468 | + 'event_espresso' |
|
469 | + ), |
|
470 | + $namespace |
|
471 | + ) |
|
472 | + ); |
|
473 | + } |
|
474 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
475 | + if (is_admin()) { |
|
476 | + EE_Error::add_error( |
|
477 | + sprintf( |
|
478 | + esc_html__( |
|
479 | + 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
480 | + 'event_espresso' |
|
481 | + ), |
|
482 | + 'Event Espresso', |
|
483 | + $url_base, |
|
484 | + 'plugins_url', |
|
485 | + 'WP_PLUGIN_URL' |
|
486 | + ), |
|
487 | + __FILE__, |
|
488 | + __FUNCTION__, |
|
489 | + __LINE__ |
|
490 | + ); |
|
491 | + } |
|
492 | + return; |
|
493 | + } |
|
494 | + $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
495 | + if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
496 | + $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
497 | + } |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * Decodes json from the provided manifest file. |
|
503 | + * |
|
504 | + * @since 4.9.59.p |
|
505 | + * @param string $manifest_file Path to manifest file. |
|
506 | + * @return array |
|
507 | + * @throws InvalidFilePathException |
|
508 | + */ |
|
509 | + private function decodeManifestFile($manifest_file) |
|
510 | + { |
|
511 | + if (! file_exists($manifest_file)) { |
|
512 | + throw new InvalidFilePathException($manifest_file); |
|
513 | + } |
|
514 | + return json_decode(file_get_contents($manifest_file), true); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * This is used to set registered script handles that have data. |
|
520 | + * |
|
521 | + * @param string $script_handle |
|
522 | + */ |
|
523 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
524 | + { |
|
525 | + $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /**i |
|
530 | 530 | * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
531 | 531 | * Dependency stored in WP_Scripts if its set. |
532 | 532 | */ |
533 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
534 | - { |
|
535 | - if (empty($this->script_handles_with_data)) { |
|
536 | - return; |
|
537 | - } |
|
538 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
539 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
540 | - } |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
546 | - * |
|
547 | - * @param string $script_handle |
|
548 | - */ |
|
549 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
550 | - { |
|
551 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
552 | - global $wp_scripts; |
|
553 | - $unset_handle = false; |
|
554 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
555 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
556 | - $unset_handle = true; |
|
557 | - } |
|
558 | - //deal with inline_scripts |
|
559 | - if ($wp_scripts->get_data($script_handle, 'before')) { |
|
560 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
561 | - $unset_handle = true; |
|
562 | - } |
|
563 | - if ($wp_scripts->get_data($script_handle, 'after')) { |
|
564 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
565 | - } |
|
566 | - if ($unset_handle) { |
|
567 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
568 | - } |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * register translations for a registered script |
|
575 | - * |
|
576 | - * @param string $handle |
|
577 | - */ |
|
578 | - public function registerTranslation($handle) |
|
579 | - { |
|
580 | - $this->i18n_registry->registerScriptI18n($handle); |
|
581 | - } |
|
533 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
534 | + { |
|
535 | + if (empty($this->script_handles_with_data)) { |
|
536 | + return; |
|
537 | + } |
|
538 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
539 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
540 | + } |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
546 | + * |
|
547 | + * @param string $script_handle |
|
548 | + */ |
|
549 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
550 | + { |
|
551 | + if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
552 | + global $wp_scripts; |
|
553 | + $unset_handle = false; |
|
554 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
555 | + unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
556 | + $unset_handle = true; |
|
557 | + } |
|
558 | + //deal with inline_scripts |
|
559 | + if ($wp_scripts->get_data($script_handle, 'before')) { |
|
560 | + unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
561 | + $unset_handle = true; |
|
562 | + } |
|
563 | + if ($wp_scripts->get_data($script_handle, 'after')) { |
|
564 | + unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
565 | + } |
|
566 | + if ($unset_handle) { |
|
567 | + unset($this->script_handles_with_data[ $script_handle ]); |
|
568 | + } |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * register translations for a registered script |
|
575 | + * |
|
576 | + * @param string $handle |
|
577 | + */ |
|
578 | + public function registerTranslation($handle) |
|
579 | + { |
|
580 | + $this->i18n_registry->registerScriptI18n($handle); |
|
581 | + } |
|
582 | 582 | } |
@@ -16,28 +16,28 @@ |
||
16 | 16 | class InvalidIdentifierException extends InvalidArgumentException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidIdentifierException constructor. |
|
21 | - * |
|
22 | - * @param string $actual the identifier that was supplied |
|
23 | - * @param string $expected example of an acceptable identifier |
|
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 identifier "%1$s" is invalid. A value like "%2$s" was expected.', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - $actual, |
|
37 | - $expected |
|
38 | - ); |
|
39 | - } |
|
40 | - parent::__construct($message, $code, $previous); |
|
41 | - } |
|
19 | + /** |
|
20 | + * InvalidIdentifierException constructor. |
|
21 | + * |
|
22 | + * @param string $actual the identifier that was supplied |
|
23 | + * @param string $expected example of an acceptable identifier |
|
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 identifier "%1$s" is invalid. A value like "%2$s" was expected.', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + $actual, |
|
37 | + $expected |
|
38 | + ); |
|
39 | + } |
|
40 | + parent::__construct($message, $code, $previous); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | // Location: core/exceptions/InvalidIdentifierException.php |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | //js.api |
176 | 176 | $this->addJavascript( |
177 | 177 | CoreAssetManager::JS_HANDLE_EE_JS_API, |
178 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
178 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
179 | 179 | array( |
180 | 180 | CoreAssetManager::JS_HANDLE_UNDERSCORE, |
181 | 181 | CoreAssetManager::JS_HANDLE_EE_JS_CORE |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | |
188 | 188 | $this->addJavascript( |
189 | 189 | CoreAssetManager::JS_HANDLE_EE_CORE, |
190 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
190 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
191 | 191 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
192 | 192 | ) |
193 | 193 | ->setLocalizationCallback( |
194 | - function () { |
|
194 | + function() { |
|
195 | 195 | wp_localize_script( |
196 | 196 | CoreAssetManager::JS_HANDLE_EE_CORE, |
197 | 197 | CoreAssetManager::JS_HANDLE_EE_I18N, |
@@ -213,16 +213,16 @@ discard block |
||
213 | 213 | if ($this->template_config->enable_default_style && ! is_admin()) { |
214 | 214 | $this->addStylesheet( |
215 | 215 | CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
216 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
216 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
217 | 217 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
218 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
218 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
219 | 219 | array('dashicons') |
220 | 220 | ); |
221 | 221 | //Load custom style sheet if available |
222 | 222 | if ($this->template_config->custom_style_sheet !== null) { |
223 | 223 | $this->addStylesheet( |
224 | 224 | CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
225 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
225 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
226 | 226 | array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
227 | 227 | ); |
228 | 228 | } |
@@ -242,14 +242,14 @@ discard block |
||
242 | 242 | { |
243 | 243 | $this->addJavascript( |
244 | 244 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
245 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
245 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
246 | 246 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
247 | 247 | ) |
248 | 248 | ->setVersion('1.15.0'); |
249 | 249 | |
250 | 250 | $this->addJavascript( |
251 | 251 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
252 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
252 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
253 | 253 | array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
254 | 254 | ) |
255 | 255 | ->setVersion('1.15.0'); |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | // @link http://josscrowcroft.github.io/accounting.js/ |
271 | 271 | $this->addJavascript( |
272 | 272 | CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
273 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
273 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
274 | 274 | array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
275 | 275 | ) |
276 | 276 | ->setVersion('0.3.2'); |
@@ -278,11 +278,11 @@ discard block |
||
278 | 278 | $currency_config = $this->currency_config; |
279 | 279 | $this->addJavascript( |
280 | 280 | CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
281 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
281 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
282 | 282 | array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
283 | 283 | ) |
284 | 284 | ->setLocalizationCallback( |
285 | - function () use ($currency_config) { |
|
285 | + function() use ($currency_config) { |
|
286 | 286 | wp_localize_script( |
287 | 287 | CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
288 | 288 | 'EE_ACCOUNTING_CFG', |
@@ -28,337 +28,337 @@ |
||
28 | 28 | class CoreAssetManager extends AssetManager |
29 | 29 | { |
30 | 30 | |
31 | - // WordPress core / Third party JS asset handles |
|
32 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
33 | - |
|
34 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
35 | - |
|
36 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
37 | - |
|
38 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
39 | - |
|
40 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
41 | - |
|
42 | - // EE JS assets handles |
|
43 | - const JS_HANDLE_EE_MANIFEST = 'ee-manifest'; |
|
44 | - |
|
45 | - const JS_HANDLE_EE_JS_CORE = 'eejs-core'; |
|
46 | - |
|
47 | - const JS_HANDLE_EE_VENDOR_REACT = 'ee-vendor-react'; |
|
48 | - |
|
49 | - const JS_HANDLE_EE_JS_API = 'eejs-api'; |
|
50 | - |
|
51 | - const JS_HANDLE_EE_CORE = 'espresso_core'; |
|
52 | - |
|
53 | - const JS_HANDLE_EE_I18N = 'eei18n'; |
|
54 | - |
|
55 | - const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting'; |
|
56 | - |
|
57 | - const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
58 | - |
|
59 | - // EE CSS assets handles |
|
60 | - const CSS_HANDLE_EE_DEFAULT = 'espresso_default'; |
|
61 | - |
|
62 | - const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css'; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var EE_Currency_Config $currency_config |
|
66 | - */ |
|
67 | - protected $currency_config; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var EE_Template_Config $template_config |
|
71 | - */ |
|
72 | - protected $template_config; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * CoreAssetRegister constructor. |
|
77 | - * |
|
78 | - * @param AssetCollection $assets |
|
79 | - * @param EE_Currency_Config $currency_config |
|
80 | - * @param EE_Template_Config $template_config |
|
81 | - * @param DomainInterface $domain |
|
82 | - * @param Registry $registry |
|
83 | - */ |
|
84 | - public function __construct( |
|
85 | - AssetCollection $assets, |
|
86 | - EE_Currency_Config $currency_config, |
|
87 | - EE_Template_Config $template_config, |
|
88 | - DomainInterface $domain, |
|
89 | - Registry $registry |
|
90 | - ) { |
|
91 | - $this->currency_config = $currency_config; |
|
92 | - $this->template_config = $template_config; |
|
93 | - parent::__construct($domain, $assets, $registry); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @since $VID:$ |
|
99 | - * @throws DuplicateCollectionIdentifierException |
|
100 | - * @throws InvalidArgumentException |
|
101 | - * @throws InvalidDataTypeException |
|
102 | - * @throws InvalidEntityException |
|
103 | - */ |
|
104 | - public function addAssets() |
|
105 | - { |
|
106 | - $this->addJavascriptFiles(); |
|
107 | - $this->addStylesheetFiles(); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @since $VID:$ |
|
113 | - * @throws DuplicateCollectionIdentifierException |
|
114 | - * @throws InvalidArgumentException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws InvalidEntityException |
|
117 | - */ |
|
118 | - public function addJavascriptFiles() |
|
119 | - { |
|
120 | - $this->loadCoreJs(); |
|
121 | - $this->loadJqueryValidate(); |
|
122 | - $this->loadAccountingJs(); |
|
123 | - add_action( |
|
124 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
125 | - array($this, 'loadQtipJs') |
|
126 | - ); |
|
127 | - $this->registerAdminAssets(); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @since $VID:$ |
|
133 | - * @throws DuplicateCollectionIdentifierException |
|
134 | - * @throws InvalidDataTypeException |
|
135 | - * @throws InvalidEntityException |
|
136 | - */ |
|
137 | - public function addStylesheetFiles() |
|
138 | - { |
|
139 | - $this->loadCoreCss(); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * core default javascript |
|
145 | - * |
|
146 | - * @since $VID:$ |
|
147 | - * @throws DuplicateCollectionIdentifierException |
|
148 | - * @throws InvalidArgumentException |
|
149 | - * @throws InvalidDataTypeException |
|
150 | - * @throws InvalidEntityException |
|
151 | - */ |
|
152 | - private function loadCoreJs() |
|
153 | - { |
|
154 | - $this->addJavascript( |
|
155 | - CoreAssetManager::JS_HANDLE_EE_MANIFEST, |
|
156 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
157 | - ); |
|
158 | - |
|
159 | - $this->addJavascript( |
|
160 | - CoreAssetManager::JS_HANDLE_EE_JS_CORE, |
|
161 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
162 | - array(CoreAssetManager::JS_HANDLE_EE_MANIFEST) |
|
163 | - ) |
|
164 | - ->setRequiresTranslation() |
|
165 | - ->setHasLocalizedData(); |
|
166 | - |
|
167 | - $this->addJavascript( |
|
168 | - CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
169 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'), |
|
170 | - array(CoreAssetManager::JS_HANDLE_EE_JS_CORE) |
|
171 | - ); |
|
172 | - |
|
173 | - global $wp_version; |
|
174 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
175 | - //js.api |
|
176 | - $this->addJavascript( |
|
177 | - CoreAssetManager::JS_HANDLE_EE_JS_API, |
|
178 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
179 | - array( |
|
180 | - CoreAssetManager::JS_HANDLE_UNDERSCORE, |
|
181 | - CoreAssetManager::JS_HANDLE_EE_JS_CORE |
|
182 | - ) |
|
183 | - ); |
|
184 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
185 | - $this->registry->addData( |
|
186 | - 'paths', |
|
187 | - array( |
|
188 | - 'rest_route' => rest_url('ee/v4.8.36/'), |
|
189 | - 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
190 | - 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName() |
|
191 | - ) |
|
192 | - ); |
|
193 | - } |
|
194 | - |
|
195 | - $this->addJavascript( |
|
196 | - CoreAssetManager::JS_HANDLE_EE_CORE, |
|
197 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
198 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
199 | - ) |
|
200 | - ->setLocalizationCallback( |
|
201 | - function () { |
|
202 | - wp_localize_script( |
|
203 | - CoreAssetManager::JS_HANDLE_EE_CORE, |
|
204 | - CoreAssetManager::JS_HANDLE_EE_I18N, |
|
205 | - EE_Registry::$i18n_js_strings |
|
206 | - ); |
|
207 | - } |
|
208 | - ); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @since $VID:$ |
|
214 | - * @throws DuplicateCollectionIdentifierException |
|
215 | - * @throws InvalidDataTypeException |
|
216 | - * @throws InvalidEntityException |
|
217 | - */ |
|
218 | - private function loadCoreCss() |
|
219 | - { |
|
220 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
221 | - $this->addStylesheet( |
|
222 | - CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
|
223 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
224 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
225 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
226 | - array('dashicons') |
|
227 | - ); |
|
228 | - //Load custom style sheet if available |
|
229 | - if ($this->template_config->custom_style_sheet !== null) { |
|
230 | - $this->addStylesheet( |
|
231 | - CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
|
232 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
233 | - array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
|
234 | - ); |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * jQuery Validate for form validation |
|
242 | - * |
|
243 | - * @since $VID:$ |
|
244 | - * @throws DuplicateCollectionIdentifierException |
|
245 | - * @throws InvalidDataTypeException |
|
246 | - * @throws InvalidEntityException |
|
247 | - */ |
|
248 | - private function loadJqueryValidate() |
|
249 | - { |
|
250 | - $this->addJavascript( |
|
251 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
252 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
253 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
254 | - ) |
|
255 | - ->setVersion('1.15.0'); |
|
256 | - |
|
257 | - $this->addJavascript( |
|
258 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
259 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
260 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
261 | - ) |
|
262 | - ->setVersion('1.15.0'); |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * accounting.js for performing client-side calculations |
|
268 | - * |
|
269 | - * @since $VID:$ |
|
270 | - * @throws DuplicateCollectionIdentifierException |
|
271 | - * @throws InvalidDataTypeException |
|
272 | - * @throws InvalidEntityException |
|
273 | - */ |
|
274 | - private function loadAccountingJs() |
|
275 | - { |
|
276 | - //accounting.js library |
|
277 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
278 | - $this->addJavascript( |
|
279 | - CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
280 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
281 | - array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
282 | - ) |
|
283 | - ->setVersion('0.3.2'); |
|
284 | - |
|
285 | - $currency_config = $this->currency_config; |
|
286 | - $this->addJavascript( |
|
287 | - CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
288 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
289 | - array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
290 | - ) |
|
291 | - ->setLocalizationCallback( |
|
292 | - function () use ($currency_config) { |
|
293 | - wp_localize_script( |
|
294 | - CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
295 | - 'EE_ACCOUNTING_CFG', |
|
296 | - array( |
|
297 | - 'currency' => array( |
|
298 | - 'symbol' => $currency_config->sign, |
|
299 | - 'format' => array( |
|
300 | - 'pos' => $currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
301 | - 'neg' => $currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
302 | - 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s', |
|
303 | - ), |
|
304 | - 'decimal' => $currency_config->dec_mrk, |
|
305 | - 'thousand' => $currency_config->thsnds, |
|
306 | - 'precision' => $currency_config->dec_plc, |
|
307 | - ), |
|
308 | - 'number' => array( |
|
309 | - 'precision' => $currency_config->dec_plc, |
|
310 | - 'thousand' => $currency_config->thsnds, |
|
311 | - 'decimal' => $currency_config->dec_mrk, |
|
312 | - ), |
|
313 | - ) |
|
314 | - ); |
|
315 | - } |
|
316 | - ) |
|
317 | - ->setVersion(); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * registers assets for cleaning your ears |
|
323 | - * |
|
324 | - * @param JavascriptAsset $script |
|
325 | - */ |
|
326 | - public function loadQtipJs(JavascriptAsset $script) |
|
327 | - { |
|
328 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
329 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
330 | - if ( |
|
331 | - $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE |
|
332 | - && apply_filters('FHEE_load_qtip', false) |
|
333 | - ) { |
|
334 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
335 | - } |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * assets that are used in the WordPress admin |
|
341 | - * |
|
342 | - * @since $VID:$ |
|
343 | - * @throws DuplicateCollectionIdentifierException |
|
344 | - * @throws InvalidDataTypeException |
|
345 | - * @throws InvalidEntityException |
|
346 | - */ |
|
347 | - private function registerAdminAssets() |
|
348 | - { |
|
349 | - $this->addJavascript( |
|
350 | - CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
351 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
352 | - array( |
|
353 | - CoreAssetManager::JS_HANDLE_JQUERY, |
|
354 | - CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
355 | - ) |
|
356 | - ) |
|
357 | - ->setRequiresTranslation(); |
|
358 | - |
|
359 | - $this->addStylesheet( |
|
360 | - CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
361 | - $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
362 | - ); |
|
363 | - } |
|
31 | + // WordPress core / Third party JS asset handles |
|
32 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
33 | + |
|
34 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
35 | + |
|
36 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
37 | + |
|
38 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
39 | + |
|
40 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
41 | + |
|
42 | + // EE JS assets handles |
|
43 | + const JS_HANDLE_EE_MANIFEST = 'ee-manifest'; |
|
44 | + |
|
45 | + const JS_HANDLE_EE_JS_CORE = 'eejs-core'; |
|
46 | + |
|
47 | + const JS_HANDLE_EE_VENDOR_REACT = 'ee-vendor-react'; |
|
48 | + |
|
49 | + const JS_HANDLE_EE_JS_API = 'eejs-api'; |
|
50 | + |
|
51 | + const JS_HANDLE_EE_CORE = 'espresso_core'; |
|
52 | + |
|
53 | + const JS_HANDLE_EE_I18N = 'eei18n'; |
|
54 | + |
|
55 | + const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting'; |
|
56 | + |
|
57 | + const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
58 | + |
|
59 | + // EE CSS assets handles |
|
60 | + const CSS_HANDLE_EE_DEFAULT = 'espresso_default'; |
|
61 | + |
|
62 | + const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css'; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var EE_Currency_Config $currency_config |
|
66 | + */ |
|
67 | + protected $currency_config; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var EE_Template_Config $template_config |
|
71 | + */ |
|
72 | + protected $template_config; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * CoreAssetRegister constructor. |
|
77 | + * |
|
78 | + * @param AssetCollection $assets |
|
79 | + * @param EE_Currency_Config $currency_config |
|
80 | + * @param EE_Template_Config $template_config |
|
81 | + * @param DomainInterface $domain |
|
82 | + * @param Registry $registry |
|
83 | + */ |
|
84 | + public function __construct( |
|
85 | + AssetCollection $assets, |
|
86 | + EE_Currency_Config $currency_config, |
|
87 | + EE_Template_Config $template_config, |
|
88 | + DomainInterface $domain, |
|
89 | + Registry $registry |
|
90 | + ) { |
|
91 | + $this->currency_config = $currency_config; |
|
92 | + $this->template_config = $template_config; |
|
93 | + parent::__construct($domain, $assets, $registry); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @since $VID:$ |
|
99 | + * @throws DuplicateCollectionIdentifierException |
|
100 | + * @throws InvalidArgumentException |
|
101 | + * @throws InvalidDataTypeException |
|
102 | + * @throws InvalidEntityException |
|
103 | + */ |
|
104 | + public function addAssets() |
|
105 | + { |
|
106 | + $this->addJavascriptFiles(); |
|
107 | + $this->addStylesheetFiles(); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @since $VID:$ |
|
113 | + * @throws DuplicateCollectionIdentifierException |
|
114 | + * @throws InvalidArgumentException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws InvalidEntityException |
|
117 | + */ |
|
118 | + public function addJavascriptFiles() |
|
119 | + { |
|
120 | + $this->loadCoreJs(); |
|
121 | + $this->loadJqueryValidate(); |
|
122 | + $this->loadAccountingJs(); |
|
123 | + add_action( |
|
124 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
125 | + array($this, 'loadQtipJs') |
|
126 | + ); |
|
127 | + $this->registerAdminAssets(); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @since $VID:$ |
|
133 | + * @throws DuplicateCollectionIdentifierException |
|
134 | + * @throws InvalidDataTypeException |
|
135 | + * @throws InvalidEntityException |
|
136 | + */ |
|
137 | + public function addStylesheetFiles() |
|
138 | + { |
|
139 | + $this->loadCoreCss(); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * core default javascript |
|
145 | + * |
|
146 | + * @since $VID:$ |
|
147 | + * @throws DuplicateCollectionIdentifierException |
|
148 | + * @throws InvalidArgumentException |
|
149 | + * @throws InvalidDataTypeException |
|
150 | + * @throws InvalidEntityException |
|
151 | + */ |
|
152 | + private function loadCoreJs() |
|
153 | + { |
|
154 | + $this->addJavascript( |
|
155 | + CoreAssetManager::JS_HANDLE_EE_MANIFEST, |
|
156 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
157 | + ); |
|
158 | + |
|
159 | + $this->addJavascript( |
|
160 | + CoreAssetManager::JS_HANDLE_EE_JS_CORE, |
|
161 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
162 | + array(CoreAssetManager::JS_HANDLE_EE_MANIFEST) |
|
163 | + ) |
|
164 | + ->setRequiresTranslation() |
|
165 | + ->setHasLocalizedData(); |
|
166 | + |
|
167 | + $this->addJavascript( |
|
168 | + CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
169 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'), |
|
170 | + array(CoreAssetManager::JS_HANDLE_EE_JS_CORE) |
|
171 | + ); |
|
172 | + |
|
173 | + global $wp_version; |
|
174 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
175 | + //js.api |
|
176 | + $this->addJavascript( |
|
177 | + CoreAssetManager::JS_HANDLE_EE_JS_API, |
|
178 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
179 | + array( |
|
180 | + CoreAssetManager::JS_HANDLE_UNDERSCORE, |
|
181 | + CoreAssetManager::JS_HANDLE_EE_JS_CORE |
|
182 | + ) |
|
183 | + ); |
|
184 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
185 | + $this->registry->addData( |
|
186 | + 'paths', |
|
187 | + array( |
|
188 | + 'rest_route' => rest_url('ee/v4.8.36/'), |
|
189 | + 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
190 | + 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName() |
|
191 | + ) |
|
192 | + ); |
|
193 | + } |
|
194 | + |
|
195 | + $this->addJavascript( |
|
196 | + CoreAssetManager::JS_HANDLE_EE_CORE, |
|
197 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
198 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
199 | + ) |
|
200 | + ->setLocalizationCallback( |
|
201 | + function () { |
|
202 | + wp_localize_script( |
|
203 | + CoreAssetManager::JS_HANDLE_EE_CORE, |
|
204 | + CoreAssetManager::JS_HANDLE_EE_I18N, |
|
205 | + EE_Registry::$i18n_js_strings |
|
206 | + ); |
|
207 | + } |
|
208 | + ); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @since $VID:$ |
|
214 | + * @throws DuplicateCollectionIdentifierException |
|
215 | + * @throws InvalidDataTypeException |
|
216 | + * @throws InvalidEntityException |
|
217 | + */ |
|
218 | + private function loadCoreCss() |
|
219 | + { |
|
220 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
221 | + $this->addStylesheet( |
|
222 | + CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
|
223 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
224 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
225 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
226 | + array('dashicons') |
|
227 | + ); |
|
228 | + //Load custom style sheet if available |
|
229 | + if ($this->template_config->custom_style_sheet !== null) { |
|
230 | + $this->addStylesheet( |
|
231 | + CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
|
232 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
233 | + array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
|
234 | + ); |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * jQuery Validate for form validation |
|
242 | + * |
|
243 | + * @since $VID:$ |
|
244 | + * @throws DuplicateCollectionIdentifierException |
|
245 | + * @throws InvalidDataTypeException |
|
246 | + * @throws InvalidEntityException |
|
247 | + */ |
|
248 | + private function loadJqueryValidate() |
|
249 | + { |
|
250 | + $this->addJavascript( |
|
251 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
252 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
253 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
254 | + ) |
|
255 | + ->setVersion('1.15.0'); |
|
256 | + |
|
257 | + $this->addJavascript( |
|
258 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
259 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
260 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
261 | + ) |
|
262 | + ->setVersion('1.15.0'); |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * accounting.js for performing client-side calculations |
|
268 | + * |
|
269 | + * @since $VID:$ |
|
270 | + * @throws DuplicateCollectionIdentifierException |
|
271 | + * @throws InvalidDataTypeException |
|
272 | + * @throws InvalidEntityException |
|
273 | + */ |
|
274 | + private function loadAccountingJs() |
|
275 | + { |
|
276 | + //accounting.js library |
|
277 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
278 | + $this->addJavascript( |
|
279 | + CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
280 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
281 | + array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
282 | + ) |
|
283 | + ->setVersion('0.3.2'); |
|
284 | + |
|
285 | + $currency_config = $this->currency_config; |
|
286 | + $this->addJavascript( |
|
287 | + CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
288 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
289 | + array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
290 | + ) |
|
291 | + ->setLocalizationCallback( |
|
292 | + function () use ($currency_config) { |
|
293 | + wp_localize_script( |
|
294 | + CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
295 | + 'EE_ACCOUNTING_CFG', |
|
296 | + array( |
|
297 | + 'currency' => array( |
|
298 | + 'symbol' => $currency_config->sign, |
|
299 | + 'format' => array( |
|
300 | + 'pos' => $currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
301 | + 'neg' => $currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
302 | + 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s', |
|
303 | + ), |
|
304 | + 'decimal' => $currency_config->dec_mrk, |
|
305 | + 'thousand' => $currency_config->thsnds, |
|
306 | + 'precision' => $currency_config->dec_plc, |
|
307 | + ), |
|
308 | + 'number' => array( |
|
309 | + 'precision' => $currency_config->dec_plc, |
|
310 | + 'thousand' => $currency_config->thsnds, |
|
311 | + 'decimal' => $currency_config->dec_mrk, |
|
312 | + ), |
|
313 | + ) |
|
314 | + ); |
|
315 | + } |
|
316 | + ) |
|
317 | + ->setVersion(); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * registers assets for cleaning your ears |
|
323 | + * |
|
324 | + * @param JavascriptAsset $script |
|
325 | + */ |
|
326 | + public function loadQtipJs(JavascriptAsset $script) |
|
327 | + { |
|
328 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
329 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
330 | + if ( |
|
331 | + $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE |
|
332 | + && apply_filters('FHEE_load_qtip', false) |
|
333 | + ) { |
|
334 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
335 | + } |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * assets that are used in the WordPress admin |
|
341 | + * |
|
342 | + * @since $VID:$ |
|
343 | + * @throws DuplicateCollectionIdentifierException |
|
344 | + * @throws InvalidDataTypeException |
|
345 | + * @throws InvalidEntityException |
|
346 | + */ |
|
347 | + private function registerAdminAssets() |
|
348 | + { |
|
349 | + $this->addJavascript( |
|
350 | + CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
351 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
352 | + array( |
|
353 | + CoreAssetManager::JS_HANDLE_JQUERY, |
|
354 | + CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
355 | + ) |
|
356 | + ) |
|
357 | + ->setRequiresTranslation(); |
|
358 | + |
|
359 | + $this->addStylesheet( |
|
360 | + CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
361 | + $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
362 | + ); |
|
363 | + } |
|
364 | 364 | } |
@@ -16,26 +16,26 @@ |
||
16 | 16 | class ManifestFile extends Asset |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Asset constructor. |
|
21 | - * |
|
22 | - * @param DomainInterface $domain |
|
23 | - * @throws InvalidDataTypeException |
|
24 | - */ |
|
25 | - public function __construct(DomainInterface $domain) |
|
26 | - { |
|
27 | - parent::__construct(Asset::TYPE_MANIFEST, $domain->assetNamespace(), $domain); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - public function urlBase() |
|
32 | - { |
|
33 | - return $this->domain->distributionAssetsUrl(); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - public function filepath() |
|
38 | - { |
|
39 | - return $this->domain->distributionAssetsPath(); |
|
40 | - } |
|
19 | + /** |
|
20 | + * Asset constructor. |
|
21 | + * |
|
22 | + * @param DomainInterface $domain |
|
23 | + * @throws InvalidDataTypeException |
|
24 | + */ |
|
25 | + public function __construct(DomainInterface $domain) |
|
26 | + { |
|
27 | + parent::__construct(Asset::TYPE_MANIFEST, $domain->assetNamespace(), $domain); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + public function urlBase() |
|
32 | + { |
|
33 | + return $this->domain->distributionAssetsUrl(); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + public function filepath() |
|
38 | + { |
|
39 | + return $this->domain->distributionAssetsPath(); |
|
40 | + } |
|
41 | 41 | } |