@@ -10,21 +10,21 @@ |
||
10 | 10 | * @subpackage Axolotl |
11 | 11 | */ |
12 | 12 | class GuardedPropertyException extends RuntimeException { |
13 | - /** |
|
14 | - * Property that threw. |
|
15 | - * |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - public $property; |
|
13 | + /** |
|
14 | + * Property that threw. |
|
15 | + * |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + public $property; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Construct a GuardedPropertyException. |
|
22 | - * |
|
23 | - * @param string $property Property that was guarded. |
|
24 | - */ |
|
25 | - public function __construct( $property ) { |
|
26 | - parent::__construct(); |
|
20 | + /** |
|
21 | + * Construct a GuardedPropertyException. |
|
22 | + * |
|
23 | + * @param string $property Property that was guarded. |
|
24 | + */ |
|
25 | + public function __construct( $property ) { |
|
26 | + parent::__construct(); |
|
27 | 27 | |
28 | - $this->property = $property; |
|
29 | - } |
|
28 | + $this->property = $property; |
|
29 | + } |
|
30 | 30 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * |
23 | 23 | * @param string $property Property that was guarded. |
24 | 24 | */ |
25 | - public function __construct( $property ) { |
|
25 | + public function __construct($property) { |
|
26 | 26 | parent::__construct(); |
27 | 27 | |
28 | 28 | $this->property = $property; |
@@ -12,272 +12,272 @@ |
||
12 | 12 | * @subpackage Register |
13 | 13 | */ |
14 | 14 | class Register implements RegisterContract { |
15 | - /** |
|
16 | - * Minification string for enqueued assets. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - private $min = '.min'; |
|
15 | + /** |
|
16 | + * Minification string for enqueued assets. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + private $min = '.min'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Url to the plugin directory. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $url; |
|
22 | + /** |
|
23 | + * Url to the plugin directory. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $url; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Script/plugin version. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $version; |
|
29 | + /** |
|
30 | + * Script/plugin version. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $version; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Array of script definition arrays. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - private $scripts = array(); |
|
36 | + /** |
|
37 | + * Array of script definition arrays. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + private $scripts = array(); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Array of style definition arrays. |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - private $styles = array(); |
|
43 | + /** |
|
44 | + * Array of style definition arrays. |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + private $styles = array(); |
|
49 | 49 | |
50 | - /** |
|
51 | - * Instantiates a new instance of the Register class. |
|
52 | - * |
|
53 | - * The URL param should be relative to the plugin directory. The URL |
|
54 | - * form should always end with a '/'. All asset location definitions |
|
55 | - * should not begin with a slash and should be relative to the plugin's |
|
56 | - * root directory. The URL provided by default from the Application |
|
57 | - * class is compatible. |
|
58 | - * |
|
59 | - * @param string $url |
|
60 | - * @param string $version |
|
61 | - */ |
|
62 | - public function __construct( $url, $version = null ) { |
|
63 | - $this->url = $url; |
|
64 | - $this->version = $version ?: null; // Empty string should remain null. |
|
65 | - } |
|
50 | + /** |
|
51 | + * Instantiates a new instance of the Register class. |
|
52 | + * |
|
53 | + * The URL param should be relative to the plugin directory. The URL |
|
54 | + * form should always end with a '/'. All asset location definitions |
|
55 | + * should not begin with a slash and should be relative to the plugin's |
|
56 | + * root directory. The URL provided by default from the Application |
|
57 | + * class is compatible. |
|
58 | + * |
|
59 | + * @param string $url |
|
60 | + * @param string $version |
|
61 | + */ |
|
62 | + public function __construct( $url, $version = null ) { |
|
63 | + $this->url = $url; |
|
64 | + $this->version = $version ?: null; // Empty string should remain null. |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * {@inheritdoc} |
|
69 | - * |
|
70 | - * @param bool $debug |
|
71 | - */ |
|
72 | - public function set_debug( $debug ) { |
|
73 | - if ( $debug ) { |
|
74 | - $this->min = ''; |
|
75 | - } else { |
|
76 | - $this->min = '.min'; |
|
77 | - } |
|
78 | - } |
|
67 | + /** |
|
68 | + * {@inheritdoc} |
|
69 | + * |
|
70 | + * @param bool $debug |
|
71 | + */ |
|
72 | + public function set_debug( $debug ) { |
|
73 | + if ( $debug ) { |
|
74 | + $this->min = ''; |
|
75 | + } else { |
|
76 | + $this->min = '.min'; |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * {@inheritdoc} |
|
82 | - * |
|
83 | - * @param array $script |
|
84 | - */ |
|
85 | - public function register_script( $script ) { |
|
86 | - $this->scripts[] = $script; |
|
87 | - } |
|
80 | + /** |
|
81 | + * {@inheritdoc} |
|
82 | + * |
|
83 | + * @param array $script |
|
84 | + */ |
|
85 | + public function register_script( $script ) { |
|
86 | + $this->scripts[] = $script; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * {@inheritdoc} |
|
91 | - * |
|
92 | - * @param array $style |
|
93 | - */ |
|
94 | - public function register_style( $style ) { |
|
95 | - $this->styles[] = $style; |
|
96 | - } |
|
89 | + /** |
|
90 | + * {@inheritdoc} |
|
91 | + * |
|
92 | + * @param array $style |
|
93 | + */ |
|
94 | + public function register_style( $style ) { |
|
95 | + $this->styles[] = $style; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * {@inheritDoc} |
|
100 | - */ |
|
101 | - public function enqueue_web_scripts() { |
|
102 | - foreach ( $this->scripts as $script ) { |
|
103 | - if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) { |
|
104 | - $this->enqueue_script( $script ); |
|
105 | - } |
|
106 | - } |
|
107 | - } |
|
98 | + /** |
|
99 | + * {@inheritDoc} |
|
100 | + */ |
|
101 | + public function enqueue_web_scripts() { |
|
102 | + foreach ( $this->scripts as $script ) { |
|
103 | + if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) { |
|
104 | + $this->enqueue_script( $script ); |
|
105 | + } |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * {@inheritDoc} |
|
111 | - */ |
|
112 | - public function enqueue_web_styles() { |
|
113 | - foreach ( $this->styles as $style ) { |
|
114 | - if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) { |
|
115 | - $this->enqueue_style( $style ); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
109 | + /** |
|
110 | + * {@inheritDoc} |
|
111 | + */ |
|
112 | + public function enqueue_web_styles() { |
|
113 | + foreach ( $this->styles as $style ) { |
|
114 | + if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) { |
|
115 | + $this->enqueue_style( $style ); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * {@inheritDoc} |
|
122 | - * |
|
123 | - * @param string $hook Passes a string representing the current page. |
|
124 | - */ |
|
125 | - public function enqueue_admin_scripts( $hook ) { |
|
126 | - foreach ( $this->scripts as $script ) { |
|
127 | - if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) { |
|
128 | - $this->enqueue_script( $script, $hook ); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
120 | + /** |
|
121 | + * {@inheritDoc} |
|
122 | + * |
|
123 | + * @param string $hook Passes a string representing the current page. |
|
124 | + */ |
|
125 | + public function enqueue_admin_scripts( $hook ) { |
|
126 | + foreach ( $this->scripts as $script ) { |
|
127 | + if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) { |
|
128 | + $this->enqueue_script( $script, $hook ); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * {@inheritDoc} |
|
135 | - * |
|
136 | - * @param string $hook Passes a string representing the current page. |
|
137 | - */ |
|
138 | - public function enqueue_admin_styles( $hook ) { |
|
139 | - foreach ( $this->styles as $style ) { |
|
140 | - if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) { |
|
141 | - $this->enqueue_style( $style, $hook ); |
|
142 | - } |
|
143 | - } |
|
144 | - } |
|
133 | + /** |
|
134 | + * {@inheritDoc} |
|
135 | + * |
|
136 | + * @param string $hook Passes a string representing the current page. |
|
137 | + */ |
|
138 | + public function enqueue_admin_styles( $hook ) { |
|
139 | + foreach ( $this->styles as $style ) { |
|
140 | + if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) { |
|
141 | + $this->enqueue_style( $style, $hook ); |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * {@inheritDoc} |
|
148 | - */ |
|
149 | - public function register_blocks() { |
|
150 | - $blocks = array(); |
|
146 | + /** |
|
147 | + * {@inheritDoc} |
|
148 | + */ |
|
149 | + public function register_blocks() { |
|
150 | + $blocks = array(); |
|
151 | 151 | |
152 | - foreach ( $this->styles as $style ) { |
|
153 | - if ( in_array( $style['type'], array( 'block' ) ) ) { |
|
154 | - wp_register_style( |
|
155 | - $style['handle'], |
|
156 | - $this->url . $style['src'] . $this->min . '.css', |
|
157 | - isset( $style['deps'] ) ? $style['deps'] : array(), |
|
158 | - $this->version, |
|
159 | - isset( $style['media'] ) ? $style['media'] : 'all' |
|
160 | - ); |
|
152 | + foreach ( $this->styles as $style ) { |
|
153 | + if ( in_array( $style['type'], array( 'block' ) ) ) { |
|
154 | + wp_register_style( |
|
155 | + $style['handle'], |
|
156 | + $this->url . $style['src'] . $this->min . '.css', |
|
157 | + isset( $style['deps'] ) ? $style['deps'] : array(), |
|
158 | + $this->version, |
|
159 | + isset( $style['media'] ) ? $style['media'] : 'all' |
|
160 | + ); |
|
161 | 161 | |
162 | - if ( ! isset( $blocks[ $style['block'] ] ) ) { |
|
163 | - $blocks[ $style['block'] ] = array(); |
|
164 | - } |
|
162 | + if ( ! isset( $blocks[ $style['block'] ] ) ) { |
|
163 | + $blocks[ $style['block'] ] = array(); |
|
164 | + } |
|
165 | 165 | |
166 | - $blocks[ $style['block'] ]['editor_style'] = $style['handle']; |
|
167 | - } |
|
168 | - } |
|
166 | + $blocks[ $style['block'] ]['editor_style'] = $style['handle']; |
|
167 | + } |
|
168 | + } |
|
169 | 169 | |
170 | - foreach ( $this->scripts as $script ) { |
|
171 | - if ( in_array( $script['type'], array( 'block' ) ) ) { |
|
172 | - wp_register_script( |
|
173 | - $script['handle'], |
|
174 | - $this->url . $script['src'] . $this->min . '.js', |
|
175 | - isset( $script['deps'] ) ? $script['deps'] : array(), |
|
176 | - $this->version, |
|
177 | - isset( $script['footer'] ) ? $script['footer'] : false |
|
178 | - ); |
|
170 | + foreach ( $this->scripts as $script ) { |
|
171 | + if ( in_array( $script['type'], array( 'block' ) ) ) { |
|
172 | + wp_register_script( |
|
173 | + $script['handle'], |
|
174 | + $this->url . $script['src'] . $this->min . '.js', |
|
175 | + isset( $script['deps'] ) ? $script['deps'] : array(), |
|
176 | + $this->version, |
|
177 | + isset( $script['footer'] ) ? $script['footer'] : false |
|
178 | + ); |
|
179 | 179 | |
180 | - $this->localize_script( $script ); |
|
180 | + $this->localize_script( $script ); |
|
181 | 181 | |
182 | - if ( ! isset( $blocks[ $script['block'] ] ) ) { |
|
183 | - $blocks[ $script['block'] ] = array(); |
|
184 | - } |
|
182 | + if ( ! isset( $blocks[ $script['block'] ] ) ) { |
|
183 | + $blocks[ $script['block'] ] = array(); |
|
184 | + } |
|
185 | 185 | |
186 | - $blocks[ $script['block'] ]['editor_script'] = $script['handle']; |
|
187 | - } |
|
188 | - } |
|
186 | + $blocks[ $script['block'] ]['editor_script'] = $script['handle']; |
|
187 | + } |
|
188 | + } |
|
189 | 189 | |
190 | - foreach ( $blocks as $slug => $opts ) { |
|
191 | - register_block_type( $slug, $opts ); |
|
192 | - } |
|
193 | - } |
|
190 | + foreach ( $blocks as $slug => $opts ) { |
|
191 | + register_block_type( $slug, $opts ); |
|
192 | + } |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * {@inheritDoc} |
|
197 | - * |
|
198 | - * @return array[] |
|
199 | - */ |
|
200 | - public function action_hooks() { |
|
201 | - return array( |
|
202 | - array( |
|
203 | - 'hook' => 'wp_enqueue_scripts', |
|
204 | - 'method' => 'enqueue_web_scripts', |
|
205 | - ), |
|
206 | - array( |
|
207 | - 'hook' => 'wp_enqueue_scripts', |
|
208 | - 'method' => 'enqueue_web_styles', |
|
209 | - ), |
|
210 | - array( |
|
211 | - 'hook' => 'admin_enqueue_scripts', |
|
212 | - 'method' => 'enqueue_admin_scripts', |
|
213 | - ), |
|
214 | - array( |
|
215 | - 'hook' => 'admin_enqueue_scripts', |
|
216 | - 'method' => 'enqueue_admin_styles', |
|
217 | - ), |
|
218 | - array( |
|
219 | - 'hook' => 'init', |
|
220 | - 'method' => 'register_blocks', |
|
221 | - ), |
|
222 | - ); |
|
223 | - } |
|
195 | + /** |
|
196 | + * {@inheritDoc} |
|
197 | + * |
|
198 | + * @return array[] |
|
199 | + */ |
|
200 | + public function action_hooks() { |
|
201 | + return array( |
|
202 | + array( |
|
203 | + 'hook' => 'wp_enqueue_scripts', |
|
204 | + 'method' => 'enqueue_web_scripts', |
|
205 | + ), |
|
206 | + array( |
|
207 | + 'hook' => 'wp_enqueue_scripts', |
|
208 | + 'method' => 'enqueue_web_styles', |
|
209 | + ), |
|
210 | + array( |
|
211 | + 'hook' => 'admin_enqueue_scripts', |
|
212 | + 'method' => 'enqueue_admin_scripts', |
|
213 | + ), |
|
214 | + array( |
|
215 | + 'hook' => 'admin_enqueue_scripts', |
|
216 | + 'method' => 'enqueue_admin_styles', |
|
217 | + ), |
|
218 | + array( |
|
219 | + 'hook' => 'init', |
|
220 | + 'method' => 'register_blocks', |
|
221 | + ), |
|
222 | + ); |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * Enqueues an individual script if the style's condition is met. |
|
227 | - * |
|
228 | - * @param array $script The script attachment callback. |
|
229 | - * @param string $hook The location hook. Only passed on admin side. |
|
230 | - */ |
|
231 | - protected function enqueue_script( $script, $hook = null ) { |
|
232 | - if ( $script['condition']( $hook ) ) { |
|
233 | - wp_enqueue_script( |
|
234 | - $script['handle'], |
|
235 | - $this->url . $script['src'] . $this->min . '.js', |
|
236 | - isset( $script['deps'] ) ? $script['deps'] : array(), |
|
237 | - $this->version, |
|
238 | - isset( $script['footer'] ) ? $script['footer'] : false |
|
239 | - ); |
|
225 | + /** |
|
226 | + * Enqueues an individual script if the style's condition is met. |
|
227 | + * |
|
228 | + * @param array $script The script attachment callback. |
|
229 | + * @param string $hook The location hook. Only passed on admin side. |
|
230 | + */ |
|
231 | + protected function enqueue_script( $script, $hook = null ) { |
|
232 | + if ( $script['condition']( $hook ) ) { |
|
233 | + wp_enqueue_script( |
|
234 | + $script['handle'], |
|
235 | + $this->url . $script['src'] . $this->min . '.js', |
|
236 | + isset( $script['deps'] ) ? $script['deps'] : array(), |
|
237 | + $this->version, |
|
238 | + isset( $script['footer'] ) ? $script['footer'] : false |
|
239 | + ); |
|
240 | 240 | |
241 | - $this->localize_script( $script ); |
|
242 | - } |
|
243 | - } |
|
241 | + $this->localize_script( $script ); |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * Enqueues an individual stylesheet if the style's condition is met. |
|
247 | - * |
|
248 | - * @param array $style The style attachment callback. |
|
249 | - * @param string $hook The location hook. |
|
250 | - */ |
|
251 | - protected function enqueue_style( $style, $hook = null ) { |
|
252 | - if ( $style['condition']( $hook ) ) { |
|
253 | - wp_enqueue_style( |
|
254 | - $style['handle'], |
|
255 | - $this->url . $style['src'] . $this->min . '.css', |
|
256 | - isset( $style['deps'] ) ? $style['deps'] : array(), |
|
257 | - $this->version, |
|
258 | - isset( $style['media'] ) ? $style['media'] : 'all' |
|
259 | - ); |
|
260 | - } |
|
261 | - } |
|
245 | + /** |
|
246 | + * Enqueues an individual stylesheet if the style's condition is met. |
|
247 | + * |
|
248 | + * @param array $style The style attachment callback. |
|
249 | + * @param string $hook The location hook. |
|
250 | + */ |
|
251 | + protected function enqueue_style( $style, $hook = null ) { |
|
252 | + if ( $style['condition']( $hook ) ) { |
|
253 | + wp_enqueue_style( |
|
254 | + $style['handle'], |
|
255 | + $this->url . $style['src'] . $this->min . '.css', |
|
256 | + isset( $style['deps'] ) ? $style['deps'] : array(), |
|
257 | + $this->version, |
|
258 | + isset( $style['media'] ) ? $style['media'] : 'all' |
|
259 | + ); |
|
260 | + } |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * Registers the localization of the provided script. |
|
265 | - * |
|
266 | - * @param array $script Script defintion. |
|
267 | - */ |
|
268 | - protected function localize_script( $script ) { |
|
269 | - if ( ! isset( $script['localize'] ) ) { |
|
270 | - return; |
|
271 | - } |
|
263 | + /** |
|
264 | + * Registers the localization of the provided script. |
|
265 | + * |
|
266 | + * @param array $script Script defintion. |
|
267 | + */ |
|
268 | + protected function localize_script( $script ) { |
|
269 | + if ( ! isset( $script['localize'] ) ) { |
|
270 | + return; |
|
271 | + } |
|
272 | 272 | |
273 | - if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables |
|
274 | - $script['localize'] = call_user_func( $script['localize'] ); |
|
275 | - } |
|
273 | + if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables |
|
274 | + $script['localize'] = call_user_func( $script['localize'] ); |
|
275 | + } |
|
276 | 276 | |
277 | - wp_localize_script( |
|
278 | - $script['handle'], |
|
279 | - $script['localize']['name'], |
|
280 | - $script['localize']['data'] |
|
281 | - ); |
|
282 | - } |
|
277 | + wp_localize_script( |
|
278 | + $script['handle'], |
|
279 | + $script['localize']['name'], |
|
280 | + $script['localize']['data'] |
|
281 | + ); |
|
282 | + } |
|
283 | 283 | } |