@@ -42,375 +42,375 @@ discard block |
||
42 | 42 | */ |
43 | 43 | class ClassLoader { |
44 | 44 | |
45 | - // PSR-4 |
|
46 | - private $prefixLengthsPsr4 = array(); |
|
47 | - private $prefixDirsPsr4 = array(); |
|
48 | - private $fallbackDirsPsr4 = array(); |
|
49 | - |
|
50 | - // PSR-0 |
|
51 | - private $prefixesPsr0 = array(); |
|
52 | - private $fallbackDirsPsr0 = array(); |
|
53 | - |
|
54 | - private $useIncludePath = false; |
|
55 | - private $classMap = array(); |
|
56 | - private $classMapAuthoritative = false; |
|
57 | - private $missingClasses = array(); |
|
58 | - private $apcuPrefix; |
|
59 | - |
|
60 | - public function getPrefixes() { |
|
61 | - if ( ! empty( $this->prefixesPsr0 ) ) { |
|
62 | - return call_user_func_array( 'array_merge', array_values( $this->prefixesPsr0 ) ); |
|
63 | - } |
|
64 | - |
|
65 | - return array(); |
|
66 | - } |
|
67 | - |
|
68 | - public function getPrefixesPsr4() { |
|
69 | - return $this->prefixDirsPsr4; |
|
70 | - } |
|
71 | - |
|
72 | - public function getFallbackDirs() { |
|
73 | - return $this->fallbackDirsPsr0; |
|
74 | - } |
|
75 | - |
|
76 | - public function getFallbackDirsPsr4() { |
|
77 | - return $this->fallbackDirsPsr4; |
|
78 | - } |
|
79 | - |
|
80 | - public function getClassMap() { |
|
81 | - return $this->classMap; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param array $classMap Class to filename map |
|
86 | - */ |
|
87 | - public function addClassMap( array $classMap ) { |
|
88 | - if ( $this->classMap ) { |
|
89 | - $this->classMap = array_merge( $this->classMap, $classMap ); |
|
90 | - } else { |
|
91 | - $this->classMap = $classMap; |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Registers a set of PSR-0 directories for a given prefix, either |
|
97 | - * appending or prepending to the ones previously set for this prefix. |
|
98 | - * |
|
99 | - * @param string $prefix The prefix |
|
100 | - * @param array|string $paths The PSR-0 root directories |
|
101 | - * @param bool $prepend Whether to prepend the directories |
|
102 | - */ |
|
103 | - public function add( $prefix, $paths, $prepend = false ) { |
|
104 | - if ( ! $prefix ) { |
|
105 | - if ( $prepend ) { |
|
106 | - $this->fallbackDirsPsr0 = array_merge( |
|
107 | - (array) $paths, |
|
108 | - $this->fallbackDirsPsr0 |
|
109 | - ); |
|
110 | - } else { |
|
111 | - $this->fallbackDirsPsr0 = array_merge( |
|
112 | - $this->fallbackDirsPsr0, |
|
113 | - (array) $paths |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - return; |
|
118 | - } |
|
119 | - |
|
120 | - $first = $prefix[0]; |
|
121 | - if ( ! isset( $this->prefixesPsr0[ $first ][ $prefix ] ) ) { |
|
122 | - $this->prefixesPsr0[ $first ][ $prefix ] = (array) $paths; |
|
123 | - |
|
124 | - return; |
|
125 | - } |
|
126 | - if ( $prepend ) { |
|
127 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
128 | - (array) $paths, |
|
129 | - $this->prefixesPsr0[ $first ][ $prefix ] |
|
130 | - ); |
|
131 | - } else { |
|
132 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
133 | - $this->prefixesPsr0[ $first ][ $prefix ], |
|
134 | - (array) $paths |
|
135 | - ); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Registers a set of PSR-4 directories for a given namespace, either |
|
141 | - * appending or prepending to the ones previously set for this namespace. |
|
142 | - * |
|
143 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
144 | - * @param array|string $paths The PSR-4 base directories |
|
145 | - * @param bool $prepend Whether to prepend the directories |
|
146 | - * |
|
147 | - * @throws \InvalidArgumentException |
|
148 | - */ |
|
149 | - public function addPsr4( $prefix, $paths, $prepend = false ) { |
|
150 | - if ( ! $prefix ) { |
|
151 | - // Register directories for the root namespace. |
|
152 | - if ( $prepend ) { |
|
153 | - $this->fallbackDirsPsr4 = array_merge( |
|
154 | - (array) $paths, |
|
155 | - $this->fallbackDirsPsr4 |
|
156 | - ); |
|
157 | - } else { |
|
158 | - $this->fallbackDirsPsr4 = array_merge( |
|
159 | - $this->fallbackDirsPsr4, |
|
160 | - (array) $paths |
|
161 | - ); |
|
162 | - } |
|
163 | - } elseif ( ! isset( $this->prefixDirsPsr4[ $prefix ] ) ) { |
|
164 | - // Register directories for a new namespace. |
|
165 | - $length = strlen( $prefix ); |
|
166 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
167 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
168 | - } |
|
169 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
170 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
171 | - } elseif ( $prepend ) { |
|
172 | - // Prepend directories for an already registered namespace. |
|
173 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
174 | - (array) $paths, |
|
175 | - $this->prefixDirsPsr4[ $prefix ] |
|
176 | - ); |
|
177 | - } else { |
|
178 | - // Append directories for an already registered namespace. |
|
179 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
180 | - $this->prefixDirsPsr4[ $prefix ], |
|
181 | - (array) $paths |
|
182 | - ); |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Registers a set of PSR-0 directories for a given prefix, |
|
188 | - * replacing any others previously set for this prefix. |
|
189 | - * |
|
190 | - * @param string $prefix The prefix |
|
191 | - * @param array|string $paths The PSR-0 base directories |
|
192 | - */ |
|
193 | - public function set( $prefix, $paths ) { |
|
194 | - if ( ! $prefix ) { |
|
195 | - $this->fallbackDirsPsr0 = (array) $paths; |
|
196 | - } else { |
|
197 | - $this->prefixesPsr0[ $prefix[0] ][ $prefix ] = (array) $paths; |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Registers a set of PSR-4 directories for a given namespace, |
|
203 | - * replacing any others previously set for this namespace. |
|
204 | - * |
|
205 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
206 | - * @param array|string $paths The PSR-4 base directories |
|
207 | - * |
|
208 | - * @throws \InvalidArgumentException |
|
209 | - */ |
|
210 | - public function setPsr4( $prefix, $paths ) { |
|
211 | - if ( ! $prefix ) { |
|
212 | - $this->fallbackDirsPsr4 = (array) $paths; |
|
213 | - } else { |
|
214 | - $length = strlen( $prefix ); |
|
215 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
216 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
217 | - } |
|
218 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
219 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Turns on searching the include path for class files. |
|
225 | - * |
|
226 | - * @param bool $useIncludePath |
|
227 | - */ |
|
228 | - public function setUseIncludePath( $useIncludePath ) { |
|
229 | - $this->useIncludePath = $useIncludePath; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Can be used to check if the autoloader uses the include path to check |
|
234 | - * for classes. |
|
235 | - * |
|
236 | - * @return bool |
|
237 | - */ |
|
238 | - public function getUseIncludePath() { |
|
239 | - return $this->useIncludePath; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Turns off searching the prefix and fallback directories for classes |
|
244 | - * that have not been registered with the class map. |
|
245 | - * |
|
246 | - * @param bool $classMapAuthoritative |
|
247 | - */ |
|
248 | - public function setClassMapAuthoritative( $classMapAuthoritative ) { |
|
249 | - $this->classMapAuthoritative = $classMapAuthoritative; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Should class lookup fail if not found in the current class map? |
|
254 | - * |
|
255 | - * @return bool |
|
256 | - */ |
|
257 | - public function isClassMapAuthoritative() { |
|
258 | - return $this->classMapAuthoritative; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
263 | - * |
|
264 | - * @param string|null $apcuPrefix |
|
265 | - */ |
|
266 | - public function setApcuPrefix( $apcuPrefix ) { |
|
267 | - $this->apcuPrefix = function_exists( 'apcu_fetch' ) && filter_var( ini_get( 'apc.enabled' ), FILTER_VALIDATE_BOOLEAN ) ? $apcuPrefix : null; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * The APCu prefix in use, or null if APCu caching is not enabled. |
|
272 | - * |
|
273 | - * @return string|null |
|
274 | - */ |
|
275 | - public function getApcuPrefix() { |
|
276 | - return $this->apcuPrefix; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Registers this instance as an autoloader. |
|
281 | - * |
|
282 | - * @param bool $prepend Whether to prepend the autoloader or not |
|
283 | - */ |
|
284 | - public function register( $prepend = false ) { |
|
285 | - spl_autoload_register( array( $this, 'loadClass' ), true, $prepend ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Unregisters this instance as an autoloader. |
|
290 | - */ |
|
291 | - public function unregister() { |
|
292 | - spl_autoload_unregister( array( $this, 'loadClass' ) ); |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Loads the given class or interface. |
|
297 | - * |
|
298 | - * @param string $class The name of the class |
|
299 | - * @return bool|null True if loaded, null otherwise |
|
300 | - */ |
|
301 | - public function loadClass( $class ) { |
|
302 | - if ( $file = $this->findFile( $class ) ) { |
|
303 | - includeFile( $file ); |
|
304 | - |
|
305 | - return true; |
|
306 | - } |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Finds the path to the file where the class is defined. |
|
311 | - * |
|
312 | - * @param string $class The name of the class |
|
313 | - * |
|
314 | - * @return string|false The path if found, false otherwise |
|
315 | - */ |
|
316 | - public function findFile( $class ) { |
|
317 | - // class map lookup |
|
318 | - if ( isset( $this->classMap[ $class ] ) ) { |
|
319 | - return $this->classMap[ $class ]; |
|
320 | - } |
|
321 | - if ( $this->classMapAuthoritative || isset( $this->missingClasses[ $class ] ) ) { |
|
322 | - return false; |
|
323 | - } |
|
324 | - if ( null !== $this->apcuPrefix ) { |
|
325 | - $file = apcu_fetch( $this->apcuPrefix . $class, $hit ); |
|
326 | - if ( $hit ) { |
|
327 | - return $file; |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - $file = $this->findFileWithExtension( $class, '.php' ); |
|
332 | - |
|
333 | - // Search for Hack files if we are running on HHVM |
|
334 | - if ( false === $file && defined( 'HHVM_VERSION' ) ) { |
|
335 | - $file = $this->findFileWithExtension( $class, '.hh' ); |
|
336 | - } |
|
337 | - |
|
338 | - if ( null !== $this->apcuPrefix ) { |
|
339 | - apcu_add( $this->apcuPrefix . $class, $file ); |
|
340 | - } |
|
341 | - |
|
342 | - if ( false === $file ) { |
|
343 | - // Remember that this class does not exist. |
|
344 | - $this->missingClasses[ $class ] = true; |
|
345 | - } |
|
346 | - |
|
347 | - return $file; |
|
348 | - } |
|
349 | - |
|
350 | - private function findFileWithExtension( $class, $ext ) { |
|
351 | - // PSR-4 lookup |
|
352 | - $logicalPathPsr4 = strtr( $class, '\\', DIRECTORY_SEPARATOR ) . $ext; |
|
353 | - |
|
354 | - $first = $class[0]; |
|
355 | - if ( isset( $this->prefixLengthsPsr4[ $first ] ) ) { |
|
356 | - $subPath = $class; |
|
357 | - while ( false !== $lastPos = strrpos( $subPath, '\\' ) ) { |
|
358 | - $subPath = substr( $subPath, 0, $lastPos ); |
|
359 | - $search = $subPath . '\\'; |
|
360 | - if ( isset( $this->prefixDirsPsr4[ $search ] ) ) { |
|
361 | - $pathEnd = DIRECTORY_SEPARATOR . substr( $logicalPathPsr4, $lastPos + 1 ); |
|
362 | - foreach ( $this->prefixDirsPsr4[ $search ] as $dir ) { |
|
363 | - if ( file_exists( $file = $dir . $pathEnd ) ) { |
|
364 | - return $file; |
|
365 | - } |
|
366 | - } |
|
367 | - } |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - // PSR-4 fallback dirs |
|
372 | - foreach ( $this->fallbackDirsPsr4 as $dir ) { |
|
373 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4 ) ) { |
|
374 | - return $file; |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - // PSR-0 lookup |
|
379 | - if ( false !== $pos = strrpos( $class, '\\' ) ) { |
|
380 | - // namespaced class name |
|
381 | - $logicalPathPsr0 = substr( $logicalPathPsr4, 0, $pos + 1 ) |
|
382 | - . strtr( substr( $logicalPathPsr4, $pos + 1 ), '_', DIRECTORY_SEPARATOR ); |
|
383 | - } else { |
|
384 | - // PEAR-like class name |
|
385 | - $logicalPathPsr0 = strtr( $class, '_', DIRECTORY_SEPARATOR ) . $ext; |
|
386 | - } |
|
387 | - |
|
388 | - if ( isset( $this->prefixesPsr0[ $first ] ) ) { |
|
389 | - foreach ( $this->prefixesPsr0[ $first ] as $prefix => $dirs ) { |
|
390 | - if ( 0 === strpos( $class, $prefix ) ) { |
|
391 | - foreach ( $dirs as $dir ) { |
|
392 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
393 | - return $file; |
|
394 | - } |
|
395 | - } |
|
396 | - } |
|
397 | - } |
|
398 | - } |
|
399 | - |
|
400 | - // PSR-0 fallback dirs |
|
401 | - foreach ( $this->fallbackDirsPsr0 as $dir ) { |
|
402 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
403 | - return $file; |
|
404 | - } |
|
405 | - } |
|
406 | - |
|
407 | - // PSR-0 include paths. |
|
408 | - if ( $this->useIncludePath && $file = stream_resolve_include_path( $logicalPathPsr0 ) ) { |
|
409 | - return $file; |
|
410 | - } |
|
411 | - |
|
412 | - return false; |
|
413 | - } |
|
45 | + // PSR-4 |
|
46 | + private $prefixLengthsPsr4 = array(); |
|
47 | + private $prefixDirsPsr4 = array(); |
|
48 | + private $fallbackDirsPsr4 = array(); |
|
49 | + |
|
50 | + // PSR-0 |
|
51 | + private $prefixesPsr0 = array(); |
|
52 | + private $fallbackDirsPsr0 = array(); |
|
53 | + |
|
54 | + private $useIncludePath = false; |
|
55 | + private $classMap = array(); |
|
56 | + private $classMapAuthoritative = false; |
|
57 | + private $missingClasses = array(); |
|
58 | + private $apcuPrefix; |
|
59 | + |
|
60 | + public function getPrefixes() { |
|
61 | + if ( ! empty( $this->prefixesPsr0 ) ) { |
|
62 | + return call_user_func_array( 'array_merge', array_values( $this->prefixesPsr0 ) ); |
|
63 | + } |
|
64 | + |
|
65 | + return array(); |
|
66 | + } |
|
67 | + |
|
68 | + public function getPrefixesPsr4() { |
|
69 | + return $this->prefixDirsPsr4; |
|
70 | + } |
|
71 | + |
|
72 | + public function getFallbackDirs() { |
|
73 | + return $this->fallbackDirsPsr0; |
|
74 | + } |
|
75 | + |
|
76 | + public function getFallbackDirsPsr4() { |
|
77 | + return $this->fallbackDirsPsr4; |
|
78 | + } |
|
79 | + |
|
80 | + public function getClassMap() { |
|
81 | + return $this->classMap; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param array $classMap Class to filename map |
|
86 | + */ |
|
87 | + public function addClassMap( array $classMap ) { |
|
88 | + if ( $this->classMap ) { |
|
89 | + $this->classMap = array_merge( $this->classMap, $classMap ); |
|
90 | + } else { |
|
91 | + $this->classMap = $classMap; |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Registers a set of PSR-0 directories for a given prefix, either |
|
97 | + * appending or prepending to the ones previously set for this prefix. |
|
98 | + * |
|
99 | + * @param string $prefix The prefix |
|
100 | + * @param array|string $paths The PSR-0 root directories |
|
101 | + * @param bool $prepend Whether to prepend the directories |
|
102 | + */ |
|
103 | + public function add( $prefix, $paths, $prepend = false ) { |
|
104 | + if ( ! $prefix ) { |
|
105 | + if ( $prepend ) { |
|
106 | + $this->fallbackDirsPsr0 = array_merge( |
|
107 | + (array) $paths, |
|
108 | + $this->fallbackDirsPsr0 |
|
109 | + ); |
|
110 | + } else { |
|
111 | + $this->fallbackDirsPsr0 = array_merge( |
|
112 | + $this->fallbackDirsPsr0, |
|
113 | + (array) $paths |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + return; |
|
118 | + } |
|
119 | + |
|
120 | + $first = $prefix[0]; |
|
121 | + if ( ! isset( $this->prefixesPsr0[ $first ][ $prefix ] ) ) { |
|
122 | + $this->prefixesPsr0[ $first ][ $prefix ] = (array) $paths; |
|
123 | + |
|
124 | + return; |
|
125 | + } |
|
126 | + if ( $prepend ) { |
|
127 | + $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
128 | + (array) $paths, |
|
129 | + $this->prefixesPsr0[ $first ][ $prefix ] |
|
130 | + ); |
|
131 | + } else { |
|
132 | + $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
133 | + $this->prefixesPsr0[ $first ][ $prefix ], |
|
134 | + (array) $paths |
|
135 | + ); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Registers a set of PSR-4 directories for a given namespace, either |
|
141 | + * appending or prepending to the ones previously set for this namespace. |
|
142 | + * |
|
143 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
144 | + * @param array|string $paths The PSR-4 base directories |
|
145 | + * @param bool $prepend Whether to prepend the directories |
|
146 | + * |
|
147 | + * @throws \InvalidArgumentException |
|
148 | + */ |
|
149 | + public function addPsr4( $prefix, $paths, $prepend = false ) { |
|
150 | + if ( ! $prefix ) { |
|
151 | + // Register directories for the root namespace. |
|
152 | + if ( $prepend ) { |
|
153 | + $this->fallbackDirsPsr4 = array_merge( |
|
154 | + (array) $paths, |
|
155 | + $this->fallbackDirsPsr4 |
|
156 | + ); |
|
157 | + } else { |
|
158 | + $this->fallbackDirsPsr4 = array_merge( |
|
159 | + $this->fallbackDirsPsr4, |
|
160 | + (array) $paths |
|
161 | + ); |
|
162 | + } |
|
163 | + } elseif ( ! isset( $this->prefixDirsPsr4[ $prefix ] ) ) { |
|
164 | + // Register directories for a new namespace. |
|
165 | + $length = strlen( $prefix ); |
|
166 | + if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
167 | + throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
168 | + } |
|
169 | + $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
170 | + $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
171 | + } elseif ( $prepend ) { |
|
172 | + // Prepend directories for an already registered namespace. |
|
173 | + $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
174 | + (array) $paths, |
|
175 | + $this->prefixDirsPsr4[ $prefix ] |
|
176 | + ); |
|
177 | + } else { |
|
178 | + // Append directories for an already registered namespace. |
|
179 | + $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
180 | + $this->prefixDirsPsr4[ $prefix ], |
|
181 | + (array) $paths |
|
182 | + ); |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Registers a set of PSR-0 directories for a given prefix, |
|
188 | + * replacing any others previously set for this prefix. |
|
189 | + * |
|
190 | + * @param string $prefix The prefix |
|
191 | + * @param array|string $paths The PSR-0 base directories |
|
192 | + */ |
|
193 | + public function set( $prefix, $paths ) { |
|
194 | + if ( ! $prefix ) { |
|
195 | + $this->fallbackDirsPsr0 = (array) $paths; |
|
196 | + } else { |
|
197 | + $this->prefixesPsr0[ $prefix[0] ][ $prefix ] = (array) $paths; |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Registers a set of PSR-4 directories for a given namespace, |
|
203 | + * replacing any others previously set for this namespace. |
|
204 | + * |
|
205 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
206 | + * @param array|string $paths The PSR-4 base directories |
|
207 | + * |
|
208 | + * @throws \InvalidArgumentException |
|
209 | + */ |
|
210 | + public function setPsr4( $prefix, $paths ) { |
|
211 | + if ( ! $prefix ) { |
|
212 | + $this->fallbackDirsPsr4 = (array) $paths; |
|
213 | + } else { |
|
214 | + $length = strlen( $prefix ); |
|
215 | + if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
216 | + throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
217 | + } |
|
218 | + $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
219 | + $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Turns on searching the include path for class files. |
|
225 | + * |
|
226 | + * @param bool $useIncludePath |
|
227 | + */ |
|
228 | + public function setUseIncludePath( $useIncludePath ) { |
|
229 | + $this->useIncludePath = $useIncludePath; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Can be used to check if the autoloader uses the include path to check |
|
234 | + * for classes. |
|
235 | + * |
|
236 | + * @return bool |
|
237 | + */ |
|
238 | + public function getUseIncludePath() { |
|
239 | + return $this->useIncludePath; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Turns off searching the prefix and fallback directories for classes |
|
244 | + * that have not been registered with the class map. |
|
245 | + * |
|
246 | + * @param bool $classMapAuthoritative |
|
247 | + */ |
|
248 | + public function setClassMapAuthoritative( $classMapAuthoritative ) { |
|
249 | + $this->classMapAuthoritative = $classMapAuthoritative; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Should class lookup fail if not found in the current class map? |
|
254 | + * |
|
255 | + * @return bool |
|
256 | + */ |
|
257 | + public function isClassMapAuthoritative() { |
|
258 | + return $this->classMapAuthoritative; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
263 | + * |
|
264 | + * @param string|null $apcuPrefix |
|
265 | + */ |
|
266 | + public function setApcuPrefix( $apcuPrefix ) { |
|
267 | + $this->apcuPrefix = function_exists( 'apcu_fetch' ) && filter_var( ini_get( 'apc.enabled' ), FILTER_VALIDATE_BOOLEAN ) ? $apcuPrefix : null; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * The APCu prefix in use, or null if APCu caching is not enabled. |
|
272 | + * |
|
273 | + * @return string|null |
|
274 | + */ |
|
275 | + public function getApcuPrefix() { |
|
276 | + return $this->apcuPrefix; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Registers this instance as an autoloader. |
|
281 | + * |
|
282 | + * @param bool $prepend Whether to prepend the autoloader or not |
|
283 | + */ |
|
284 | + public function register( $prepend = false ) { |
|
285 | + spl_autoload_register( array( $this, 'loadClass' ), true, $prepend ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Unregisters this instance as an autoloader. |
|
290 | + */ |
|
291 | + public function unregister() { |
|
292 | + spl_autoload_unregister( array( $this, 'loadClass' ) ); |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Loads the given class or interface. |
|
297 | + * |
|
298 | + * @param string $class The name of the class |
|
299 | + * @return bool|null True if loaded, null otherwise |
|
300 | + */ |
|
301 | + public function loadClass( $class ) { |
|
302 | + if ( $file = $this->findFile( $class ) ) { |
|
303 | + includeFile( $file ); |
|
304 | + |
|
305 | + return true; |
|
306 | + } |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Finds the path to the file where the class is defined. |
|
311 | + * |
|
312 | + * @param string $class The name of the class |
|
313 | + * |
|
314 | + * @return string|false The path if found, false otherwise |
|
315 | + */ |
|
316 | + public function findFile( $class ) { |
|
317 | + // class map lookup |
|
318 | + if ( isset( $this->classMap[ $class ] ) ) { |
|
319 | + return $this->classMap[ $class ]; |
|
320 | + } |
|
321 | + if ( $this->classMapAuthoritative || isset( $this->missingClasses[ $class ] ) ) { |
|
322 | + return false; |
|
323 | + } |
|
324 | + if ( null !== $this->apcuPrefix ) { |
|
325 | + $file = apcu_fetch( $this->apcuPrefix . $class, $hit ); |
|
326 | + if ( $hit ) { |
|
327 | + return $file; |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + $file = $this->findFileWithExtension( $class, '.php' ); |
|
332 | + |
|
333 | + // Search for Hack files if we are running on HHVM |
|
334 | + if ( false === $file && defined( 'HHVM_VERSION' ) ) { |
|
335 | + $file = $this->findFileWithExtension( $class, '.hh' ); |
|
336 | + } |
|
337 | + |
|
338 | + if ( null !== $this->apcuPrefix ) { |
|
339 | + apcu_add( $this->apcuPrefix . $class, $file ); |
|
340 | + } |
|
341 | + |
|
342 | + if ( false === $file ) { |
|
343 | + // Remember that this class does not exist. |
|
344 | + $this->missingClasses[ $class ] = true; |
|
345 | + } |
|
346 | + |
|
347 | + return $file; |
|
348 | + } |
|
349 | + |
|
350 | + private function findFileWithExtension( $class, $ext ) { |
|
351 | + // PSR-4 lookup |
|
352 | + $logicalPathPsr4 = strtr( $class, '\\', DIRECTORY_SEPARATOR ) . $ext; |
|
353 | + |
|
354 | + $first = $class[0]; |
|
355 | + if ( isset( $this->prefixLengthsPsr4[ $first ] ) ) { |
|
356 | + $subPath = $class; |
|
357 | + while ( false !== $lastPos = strrpos( $subPath, '\\' ) ) { |
|
358 | + $subPath = substr( $subPath, 0, $lastPos ); |
|
359 | + $search = $subPath . '\\'; |
|
360 | + if ( isset( $this->prefixDirsPsr4[ $search ] ) ) { |
|
361 | + $pathEnd = DIRECTORY_SEPARATOR . substr( $logicalPathPsr4, $lastPos + 1 ); |
|
362 | + foreach ( $this->prefixDirsPsr4[ $search ] as $dir ) { |
|
363 | + if ( file_exists( $file = $dir . $pathEnd ) ) { |
|
364 | + return $file; |
|
365 | + } |
|
366 | + } |
|
367 | + } |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + // PSR-4 fallback dirs |
|
372 | + foreach ( $this->fallbackDirsPsr4 as $dir ) { |
|
373 | + if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4 ) ) { |
|
374 | + return $file; |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + // PSR-0 lookup |
|
379 | + if ( false !== $pos = strrpos( $class, '\\' ) ) { |
|
380 | + // namespaced class name |
|
381 | + $logicalPathPsr0 = substr( $logicalPathPsr4, 0, $pos + 1 ) |
|
382 | + . strtr( substr( $logicalPathPsr4, $pos + 1 ), '_', DIRECTORY_SEPARATOR ); |
|
383 | + } else { |
|
384 | + // PEAR-like class name |
|
385 | + $logicalPathPsr0 = strtr( $class, '_', DIRECTORY_SEPARATOR ) . $ext; |
|
386 | + } |
|
387 | + |
|
388 | + if ( isset( $this->prefixesPsr0[ $first ] ) ) { |
|
389 | + foreach ( $this->prefixesPsr0[ $first ] as $prefix => $dirs ) { |
|
390 | + if ( 0 === strpos( $class, $prefix ) ) { |
|
391 | + foreach ( $dirs as $dir ) { |
|
392 | + if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
393 | + return $file; |
|
394 | + } |
|
395 | + } |
|
396 | + } |
|
397 | + } |
|
398 | + } |
|
399 | + |
|
400 | + // PSR-0 fallback dirs |
|
401 | + foreach ( $this->fallbackDirsPsr0 as $dir ) { |
|
402 | + if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
403 | + return $file; |
|
404 | + } |
|
405 | + } |
|
406 | + |
|
407 | + // PSR-0 include paths. |
|
408 | + if ( $this->useIncludePath && $file = stream_resolve_include_path( $logicalPathPsr0 ) ) { |
|
409 | + return $file; |
|
410 | + } |
|
411 | + |
|
412 | + return false; |
|
413 | + } |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -419,5 +419,5 @@ discard block |
||
419 | 419 | * Prevents access to $this/self from included files. |
420 | 420 | */ |
421 | 421 | function includeFile( $file ) { |
422 | - include $file; |
|
422 | + include $file; |
|
423 | 423 | } |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | private $apcuPrefix; |
59 | 59 | |
60 | 60 | public function getPrefixes() { |
61 | - if ( ! empty( $this->prefixesPsr0 ) ) { |
|
62 | - return call_user_func_array( 'array_merge', array_values( $this->prefixesPsr0 ) ); |
|
61 | + if ( ! empty($this->prefixesPsr0)) { |
|
62 | + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | return array(); |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * @param array $classMap Class to filename map |
86 | 86 | */ |
87 | - public function addClassMap( array $classMap ) { |
|
88 | - if ( $this->classMap ) { |
|
89 | - $this->classMap = array_merge( $this->classMap, $classMap ); |
|
87 | + public function addClassMap(array $classMap) { |
|
88 | + if ($this->classMap) { |
|
89 | + $this->classMap = array_merge($this->classMap, $classMap); |
|
90 | 90 | } else { |
91 | 91 | $this->classMap = $classMap; |
92 | 92 | } |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param array|string $paths The PSR-0 root directories |
101 | 101 | * @param bool $prepend Whether to prepend the directories |
102 | 102 | */ |
103 | - public function add( $prefix, $paths, $prepend = false ) { |
|
104 | - if ( ! $prefix ) { |
|
105 | - if ( $prepend ) { |
|
103 | + public function add($prefix, $paths, $prepend = false) { |
|
104 | + if ( ! $prefix) { |
|
105 | + if ($prepend) { |
|
106 | 106 | $this->fallbackDirsPsr0 = array_merge( |
107 | 107 | (array) $paths, |
108 | 108 | $this->fallbackDirsPsr0 |
@@ -118,19 +118,19 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | $first = $prefix[0]; |
121 | - if ( ! isset( $this->prefixesPsr0[ $first ][ $prefix ] ) ) { |
|
122 | - $this->prefixesPsr0[ $first ][ $prefix ] = (array) $paths; |
|
121 | + if ( ! isset($this->prefixesPsr0[$first][$prefix])) { |
|
122 | + $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
|
123 | 123 | |
124 | 124 | return; |
125 | 125 | } |
126 | - if ( $prepend ) { |
|
127 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
126 | + if ($prepend) { |
|
127 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
128 | 128 | (array) $paths, |
129 | - $this->prefixesPsr0[ $first ][ $prefix ] |
|
129 | + $this->prefixesPsr0[$first][$prefix] |
|
130 | 130 | ); |
131 | 131 | } else { |
132 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
133 | - $this->prefixesPsr0[ $first ][ $prefix ], |
|
132 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
133 | + $this->prefixesPsr0[$first][$prefix], |
|
134 | 134 | (array) $paths |
135 | 135 | ); |
136 | 136 | } |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @throws \InvalidArgumentException |
148 | 148 | */ |
149 | - public function addPsr4( $prefix, $paths, $prepend = false ) { |
|
150 | - if ( ! $prefix ) { |
|
149 | + public function addPsr4($prefix, $paths, $prepend = false) { |
|
150 | + if ( ! $prefix) { |
|
151 | 151 | // Register directories for the root namespace. |
152 | - if ( $prepend ) { |
|
152 | + if ($prepend) { |
|
153 | 153 | $this->fallbackDirsPsr4 = array_merge( |
154 | 154 | (array) $paths, |
155 | 155 | $this->fallbackDirsPsr4 |
@@ -160,24 +160,24 @@ discard block |
||
160 | 160 | (array) $paths |
161 | 161 | ); |
162 | 162 | } |
163 | - } elseif ( ! isset( $this->prefixDirsPsr4[ $prefix ] ) ) { |
|
163 | + } elseif ( ! isset($this->prefixDirsPsr4[$prefix])) { |
|
164 | 164 | // Register directories for a new namespace. |
165 | - $length = strlen( $prefix ); |
|
166 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
167 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
165 | + $length = strlen($prefix); |
|
166 | + if ('\\' !== $prefix[$length - 1]) { |
|
167 | + throw new \InvalidArgumentException('A non-empty PSR-4 prefix must end with a namespace separator.'); |
|
168 | 168 | } |
169 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
170 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
171 | - } elseif ( $prepend ) { |
|
169 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
170 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
171 | + } elseif ($prepend) { |
|
172 | 172 | // Prepend directories for an already registered namespace. |
173 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
173 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
174 | 174 | (array) $paths, |
175 | - $this->prefixDirsPsr4[ $prefix ] |
|
175 | + $this->prefixDirsPsr4[$prefix] |
|
176 | 176 | ); |
177 | 177 | } else { |
178 | 178 | // Append directories for an already registered namespace. |
179 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
180 | - $this->prefixDirsPsr4[ $prefix ], |
|
179 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
180 | + $this->prefixDirsPsr4[$prefix], |
|
181 | 181 | (array) $paths |
182 | 182 | ); |
183 | 183 | } |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | * @param string $prefix The prefix |
191 | 191 | * @param array|string $paths The PSR-0 base directories |
192 | 192 | */ |
193 | - public function set( $prefix, $paths ) { |
|
194 | - if ( ! $prefix ) { |
|
193 | + public function set($prefix, $paths) { |
|
194 | + if ( ! $prefix) { |
|
195 | 195 | $this->fallbackDirsPsr0 = (array) $paths; |
196 | 196 | } else { |
197 | - $this->prefixesPsr0[ $prefix[0] ][ $prefix ] = (array) $paths; |
|
197 | + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
@@ -207,16 +207,16 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @throws \InvalidArgumentException |
209 | 209 | */ |
210 | - public function setPsr4( $prefix, $paths ) { |
|
211 | - if ( ! $prefix ) { |
|
210 | + public function setPsr4($prefix, $paths) { |
|
211 | + if ( ! $prefix) { |
|
212 | 212 | $this->fallbackDirsPsr4 = (array) $paths; |
213 | 213 | } else { |
214 | - $length = strlen( $prefix ); |
|
215 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
216 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
214 | + $length = strlen($prefix); |
|
215 | + if ('\\' !== $prefix[$length - 1]) { |
|
216 | + throw new \InvalidArgumentException('A non-empty PSR-4 prefix must end with a namespace separator.'); |
|
217 | 217 | } |
218 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
219 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
218 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
219 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @param bool $useIncludePath |
227 | 227 | */ |
228 | - public function setUseIncludePath( $useIncludePath ) { |
|
228 | + public function setUseIncludePath($useIncludePath) { |
|
229 | 229 | $this->useIncludePath = $useIncludePath; |
230 | 230 | } |
231 | 231 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * |
246 | 246 | * @param bool $classMapAuthoritative |
247 | 247 | */ |
248 | - public function setClassMapAuthoritative( $classMapAuthoritative ) { |
|
248 | + public function setClassMapAuthoritative($classMapAuthoritative) { |
|
249 | 249 | $this->classMapAuthoritative = $classMapAuthoritative; |
250 | 250 | } |
251 | 251 | |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | * |
264 | 264 | * @param string|null $apcuPrefix |
265 | 265 | */ |
266 | - public function setApcuPrefix( $apcuPrefix ) { |
|
267 | - $this->apcuPrefix = function_exists( 'apcu_fetch' ) && filter_var( ini_get( 'apc.enabled' ), FILTER_VALIDATE_BOOLEAN ) ? $apcuPrefix : null; |
|
266 | + public function setApcuPrefix($apcuPrefix) { |
|
267 | + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -281,15 +281,15 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param bool $prepend Whether to prepend the autoloader or not |
283 | 283 | */ |
284 | - public function register( $prepend = false ) { |
|
285 | - spl_autoload_register( array( $this, 'loadClass' ), true, $prepend ); |
|
284 | + public function register($prepend = false) { |
|
285 | + spl_autoload_register(array($this, 'loadClass'), true, $prepend); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
289 | 289 | * Unregisters this instance as an autoloader. |
290 | 290 | */ |
291 | 291 | public function unregister() { |
292 | - spl_autoload_unregister( array( $this, 'loadClass' ) ); |
|
292 | + spl_autoload_unregister(array($this, 'loadClass')); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -298,9 +298,9 @@ discard block |
||
298 | 298 | * @param string $class The name of the class |
299 | 299 | * @return bool|null True if loaded, null otherwise |
300 | 300 | */ |
301 | - public function loadClass( $class ) { |
|
302 | - if ( $file = $this->findFile( $class ) ) { |
|
303 | - includeFile( $file ); |
|
301 | + public function loadClass($class) { |
|
302 | + if ($file = $this->findFile($class)) { |
|
303 | + includeFile($file); |
|
304 | 304 | |
305 | 305 | return true; |
306 | 306 | } |
@@ -313,54 +313,54 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @return string|false The path if found, false otherwise |
315 | 315 | */ |
316 | - public function findFile( $class ) { |
|
316 | + public function findFile($class) { |
|
317 | 317 | // class map lookup |
318 | - if ( isset( $this->classMap[ $class ] ) ) { |
|
319 | - return $this->classMap[ $class ]; |
|
318 | + if (isset($this->classMap[$class])) { |
|
319 | + return $this->classMap[$class]; |
|
320 | 320 | } |
321 | - if ( $this->classMapAuthoritative || isset( $this->missingClasses[ $class ] ) ) { |
|
321 | + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { |
|
322 | 322 | return false; |
323 | 323 | } |
324 | - if ( null !== $this->apcuPrefix ) { |
|
325 | - $file = apcu_fetch( $this->apcuPrefix . $class, $hit ); |
|
326 | - if ( $hit ) { |
|
324 | + if (null !== $this->apcuPrefix) { |
|
325 | + $file = apcu_fetch($this->apcuPrefix.$class, $hit); |
|
326 | + if ($hit) { |
|
327 | 327 | return $file; |
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | - $file = $this->findFileWithExtension( $class, '.php' ); |
|
331 | + $file = $this->findFileWithExtension($class, '.php'); |
|
332 | 332 | |
333 | 333 | // Search for Hack files if we are running on HHVM |
334 | - if ( false === $file && defined( 'HHVM_VERSION' ) ) { |
|
335 | - $file = $this->findFileWithExtension( $class, '.hh' ); |
|
334 | + if (false === $file && defined('HHVM_VERSION')) { |
|
335 | + $file = $this->findFileWithExtension($class, '.hh'); |
|
336 | 336 | } |
337 | 337 | |
338 | - if ( null !== $this->apcuPrefix ) { |
|
339 | - apcu_add( $this->apcuPrefix . $class, $file ); |
|
338 | + if (null !== $this->apcuPrefix) { |
|
339 | + apcu_add($this->apcuPrefix.$class, $file); |
|
340 | 340 | } |
341 | 341 | |
342 | - if ( false === $file ) { |
|
342 | + if (false === $file) { |
|
343 | 343 | // Remember that this class does not exist. |
344 | - $this->missingClasses[ $class ] = true; |
|
344 | + $this->missingClasses[$class] = true; |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | return $file; |
348 | 348 | } |
349 | 349 | |
350 | - private function findFileWithExtension( $class, $ext ) { |
|
350 | + private function findFileWithExtension($class, $ext) { |
|
351 | 351 | // PSR-4 lookup |
352 | - $logicalPathPsr4 = strtr( $class, '\\', DIRECTORY_SEPARATOR ) . $ext; |
|
352 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
353 | 353 | |
354 | 354 | $first = $class[0]; |
355 | - if ( isset( $this->prefixLengthsPsr4[ $first ] ) ) { |
|
355 | + if (isset($this->prefixLengthsPsr4[$first])) { |
|
356 | 356 | $subPath = $class; |
357 | - while ( false !== $lastPos = strrpos( $subPath, '\\' ) ) { |
|
358 | - $subPath = substr( $subPath, 0, $lastPos ); |
|
359 | - $search = $subPath . '\\'; |
|
360 | - if ( isset( $this->prefixDirsPsr4[ $search ] ) ) { |
|
361 | - $pathEnd = DIRECTORY_SEPARATOR . substr( $logicalPathPsr4, $lastPos + 1 ); |
|
362 | - foreach ( $this->prefixDirsPsr4[ $search ] as $dir ) { |
|
363 | - if ( file_exists( $file = $dir . $pathEnd ) ) { |
|
357 | + while (false !== $lastPos = strrpos($subPath, '\\')) { |
|
358 | + $subPath = substr($subPath, 0, $lastPos); |
|
359 | + $search = $subPath.'\\'; |
|
360 | + if (isset($this->prefixDirsPsr4[$search])) { |
|
361 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
362 | + foreach ($this->prefixDirsPsr4[$search] as $dir) { |
|
363 | + if (file_exists($file = $dir.$pathEnd)) { |
|
364 | 364 | return $file; |
365 | 365 | } |
366 | 366 | } |
@@ -369,27 +369,27 @@ discard block |
||
369 | 369 | } |
370 | 370 | |
371 | 371 | // PSR-4 fallback dirs |
372 | - foreach ( $this->fallbackDirsPsr4 as $dir ) { |
|
373 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4 ) ) { |
|
372 | + foreach ($this->fallbackDirsPsr4 as $dir) { |
|
373 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
374 | 374 | return $file; |
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
378 | 378 | // PSR-0 lookup |
379 | - if ( false !== $pos = strrpos( $class, '\\' ) ) { |
|
379 | + if (false !== $pos = strrpos($class, '\\')) { |
|
380 | 380 | // namespaced class name |
381 | - $logicalPathPsr0 = substr( $logicalPathPsr4, 0, $pos + 1 ) |
|
382 | - . strtr( substr( $logicalPathPsr4, $pos + 1 ), '_', DIRECTORY_SEPARATOR ); |
|
381 | + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) |
|
382 | + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
|
383 | 383 | } else { |
384 | 384 | // PEAR-like class name |
385 | - $logicalPathPsr0 = strtr( $class, '_', DIRECTORY_SEPARATOR ) . $ext; |
|
385 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
386 | 386 | } |
387 | 387 | |
388 | - if ( isset( $this->prefixesPsr0[ $first ] ) ) { |
|
389 | - foreach ( $this->prefixesPsr0[ $first ] as $prefix => $dirs ) { |
|
390 | - if ( 0 === strpos( $class, $prefix ) ) { |
|
391 | - foreach ( $dirs as $dir ) { |
|
392 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
388 | + if (isset($this->prefixesPsr0[$first])) { |
|
389 | + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
|
390 | + if (0 === strpos($class, $prefix)) { |
|
391 | + foreach ($dirs as $dir) { |
|
392 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
393 | 393 | return $file; |
394 | 394 | } |
395 | 395 | } |
@@ -398,14 +398,14 @@ discard block |
||
398 | 398 | } |
399 | 399 | |
400 | 400 | // PSR-0 fallback dirs |
401 | - foreach ( $this->fallbackDirsPsr0 as $dir ) { |
|
402 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
401 | + foreach ($this->fallbackDirsPsr0 as $dir) { |
|
402 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
403 | 403 | return $file; |
404 | 404 | } |
405 | 405 | } |
406 | 406 | |
407 | 407 | // PSR-0 include paths. |
408 | - if ( $this->useIncludePath && $file = stream_resolve_include_path( $logicalPathPsr0 ) ) { |
|
408 | + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { |
|
409 | 409 | return $file; |
410 | 410 | } |
411 | 411 | |
@@ -418,6 +418,6 @@ discard block |
||
418 | 418 | * |
419 | 419 | * Prevents access to $this/self from included files. |
420 | 420 | */ |
421 | -function includeFile( $file ) { |
|
421 | +function includeFile($file) { |
|
422 | 422 | include $file; |
423 | 423 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | // autoload_namespaces.php @generated by Composer |
4 | 4 | |
5 | -$vendorDir = dirname( ( __DIR__ ) ); |
|
6 | -$baseDir = dirname( $vendorDir ); |
|
5 | +$vendorDir = dirname((__DIR__)); |
|
6 | +$baseDir = dirname($vendorDir); |
|
7 | 7 | |
8 | 8 | return array(); |
@@ -1,30 +1,30 @@ |
||
1 | 1 | <?php return array( |
2 | - 'root' => |
|
3 | - array( |
|
4 | - 'pretty_version' => 'dev-develop', |
|
5 | - 'version' => 'dev-develop', |
|
6 | - 'aliases' => |
|
7 | - array(), |
|
8 | - 'reference' => '2b5035defcc45dcd4370a5865ba4fe5e91035435', |
|
9 | - 'name' => '__root__', |
|
10 | - ), |
|
11 | - 'versions' => |
|
12 | - array( |
|
13 | - '__root__' => |
|
14 | - array( |
|
15 | - 'pretty_version' => 'dev-develop', |
|
16 | - 'version' => 'dev-develop', |
|
17 | - 'aliases' => |
|
18 | - array(), |
|
19 | - 'reference' => '2b5035defcc45dcd4370a5865ba4fe5e91035435', |
|
20 | - ), |
|
21 | - 'deliciousbrains/wp-background-processing' => |
|
22 | - array( |
|
23 | - 'pretty_version' => '1.0.2', |
|
24 | - 'version' => '1.0.2.0', |
|
25 | - 'aliases' => |
|
26 | - array(), |
|
27 | - 'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800', |
|
28 | - ), |
|
29 | - ), |
|
2 | + 'root' => |
|
3 | + array( |
|
4 | + 'pretty_version' => 'dev-develop', |
|
5 | + 'version' => 'dev-develop', |
|
6 | + 'aliases' => |
|
7 | + array(), |
|
8 | + 'reference' => '2b5035defcc45dcd4370a5865ba4fe5e91035435', |
|
9 | + 'name' => '__root__', |
|
10 | + ), |
|
11 | + 'versions' => |
|
12 | + array( |
|
13 | + '__root__' => |
|
14 | + array( |
|
15 | + 'pretty_version' => 'dev-develop', |
|
16 | + 'version' => 'dev-develop', |
|
17 | + 'aliases' => |
|
18 | + array(), |
|
19 | + 'reference' => '2b5035defcc45dcd4370a5865ba4fe5e91035435', |
|
20 | + ), |
|
21 | + 'deliciousbrains/wp-background-processing' => |
|
22 | + array( |
|
23 | + 'pretty_version' => '1.0.2', |
|
24 | + 'version' => '1.0.2.0', |
|
25 | + 'aliases' => |
|
26 | + array(), |
|
27 | + 'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800', |
|
28 | + ), |
|
29 | + ), |
|
30 | 30 | ); |
@@ -6,119 +6,119 @@ |
||
6 | 6 | |
7 | 7 | class InstalledVersions { |
8 | 8 | |
9 | - private static $installed = array( |
|
10 | - 'root' => |
|
11 | - array( |
|
12 | - 'pretty_version' => 'dev-develop', |
|
13 | - 'version' => 'dev-develop', |
|
14 | - 'aliases' => |
|
15 | - array(), |
|
16 | - 'reference' => '2b5035defcc45dcd4370a5865ba4fe5e91035435', |
|
17 | - 'name' => '__root__', |
|
18 | - ), |
|
19 | - 'versions' => |
|
20 | - array( |
|
21 | - '__root__' => |
|
22 | - array( |
|
23 | - 'pretty_version' => 'dev-develop', |
|
24 | - 'version' => 'dev-develop', |
|
25 | - 'aliases' => |
|
26 | - array(), |
|
27 | - 'reference' => '2b5035defcc45dcd4370a5865ba4fe5e91035435', |
|
28 | - ), |
|
29 | - 'deliciousbrains/wp-background-processing' => |
|
30 | - array( |
|
31 | - 'pretty_version' => '1.0.2', |
|
32 | - 'version' => '1.0.2.0', |
|
33 | - 'aliases' => |
|
34 | - array(), |
|
35 | - 'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800', |
|
36 | - ), |
|
37 | - ), |
|
38 | - ); |
|
39 | - |
|
40 | - public static function getInstalledPackages() { |
|
41 | - return array_keys( self::$installed['versions'] ); |
|
42 | - } |
|
43 | - |
|
44 | - public static function isInstalled( $packageName ) { |
|
45 | - return isset( self::$installed['versions'][ $packageName ] ); |
|
46 | - } |
|
47 | - |
|
48 | - public static function satisfies( VersionParser $parser, $packageName, $constraint ) { |
|
49 | - $constraint = $parser->parseConstraints( $constraint ); |
|
50 | - $provided = $parser->parseConstraints( self::getVersionRanges( $packageName ) ); |
|
51 | - |
|
52 | - return $provided->matches( $constraint ); |
|
53 | - } |
|
54 | - |
|
55 | - public static function getVersionRanges( $packageName ) { |
|
56 | - if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
57 | - throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
58 | - } |
|
59 | - |
|
60 | - $ranges = array(); |
|
61 | - if ( isset( self::$installed['versions'][ $packageName ]['pretty_version'] ) ) { |
|
62 | - $ranges[] = self::$installed['versions'][ $packageName ]['pretty_version']; |
|
63 | - } |
|
64 | - if ( array_key_exists( 'aliases', self::$installed['versions'][ $packageName ] ) ) { |
|
65 | - $ranges = array_merge( $ranges, self::$installed['versions'][ $packageName ]['aliases'] ); |
|
66 | - } |
|
67 | - if ( array_key_exists( 'replaced', self::$installed['versions'][ $packageName ] ) ) { |
|
68 | - $ranges = array_merge( $ranges, self::$installed['versions'][ $packageName ]['replaced'] ); |
|
69 | - } |
|
70 | - if ( array_key_exists( 'provided', self::$installed['versions'][ $packageName ] ) ) { |
|
71 | - $ranges = array_merge( $ranges, self::$installed['versions'][ $packageName ]['provided'] ); |
|
72 | - } |
|
73 | - |
|
74 | - return implode( ' || ', $ranges ); |
|
75 | - } |
|
76 | - |
|
77 | - public static function getVersion( $packageName ) { |
|
78 | - if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
79 | - throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
80 | - } |
|
81 | - |
|
82 | - if ( ! isset( self::$installed['versions'][ $packageName ]['version'] ) ) { |
|
83 | - return null; |
|
84 | - } |
|
85 | - |
|
86 | - return self::$installed['versions'][ $packageName ]['version']; |
|
87 | - } |
|
88 | - |
|
89 | - public static function getPrettyVersion( $packageName ) { |
|
90 | - if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
91 | - throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
92 | - } |
|
93 | - |
|
94 | - if ( ! isset( self::$installed['versions'][ $packageName ]['pretty_version'] ) ) { |
|
95 | - return null; |
|
96 | - } |
|
97 | - |
|
98 | - return self::$installed['versions'][ $packageName ]['pretty_version']; |
|
99 | - } |
|
100 | - |
|
101 | - public static function getReference( $packageName ) { |
|
102 | - if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
103 | - throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! isset( self::$installed['versions'][ $packageName ]['reference'] ) ) { |
|
107 | - return null; |
|
108 | - } |
|
109 | - |
|
110 | - return self::$installed['versions'][ $packageName ]['reference']; |
|
111 | - } |
|
112 | - |
|
113 | - public static function getRootPackage() { |
|
114 | - return self::$installed['root']; |
|
115 | - } |
|
116 | - |
|
117 | - public static function getRawData() { |
|
118 | - return self::$installed; |
|
119 | - } |
|
120 | - |
|
121 | - public static function reload( $data ) { |
|
122 | - self::$installed = $data; |
|
123 | - } |
|
9 | + private static $installed = array( |
|
10 | + 'root' => |
|
11 | + array( |
|
12 | + 'pretty_version' => 'dev-develop', |
|
13 | + 'version' => 'dev-develop', |
|
14 | + 'aliases' => |
|
15 | + array(), |
|
16 | + 'reference' => '2b5035defcc45dcd4370a5865ba4fe5e91035435', |
|
17 | + 'name' => '__root__', |
|
18 | + ), |
|
19 | + 'versions' => |
|
20 | + array( |
|
21 | + '__root__' => |
|
22 | + array( |
|
23 | + 'pretty_version' => 'dev-develop', |
|
24 | + 'version' => 'dev-develop', |
|
25 | + 'aliases' => |
|
26 | + array(), |
|
27 | + 'reference' => '2b5035defcc45dcd4370a5865ba4fe5e91035435', |
|
28 | + ), |
|
29 | + 'deliciousbrains/wp-background-processing' => |
|
30 | + array( |
|
31 | + 'pretty_version' => '1.0.2', |
|
32 | + 'version' => '1.0.2.0', |
|
33 | + 'aliases' => |
|
34 | + array(), |
|
35 | + 'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800', |
|
36 | + ), |
|
37 | + ), |
|
38 | + ); |
|
39 | + |
|
40 | + public static function getInstalledPackages() { |
|
41 | + return array_keys( self::$installed['versions'] ); |
|
42 | + } |
|
43 | + |
|
44 | + public static function isInstalled( $packageName ) { |
|
45 | + return isset( self::$installed['versions'][ $packageName ] ); |
|
46 | + } |
|
47 | + |
|
48 | + public static function satisfies( VersionParser $parser, $packageName, $constraint ) { |
|
49 | + $constraint = $parser->parseConstraints( $constraint ); |
|
50 | + $provided = $parser->parseConstraints( self::getVersionRanges( $packageName ) ); |
|
51 | + |
|
52 | + return $provided->matches( $constraint ); |
|
53 | + } |
|
54 | + |
|
55 | + public static function getVersionRanges( $packageName ) { |
|
56 | + if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
57 | + throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
58 | + } |
|
59 | + |
|
60 | + $ranges = array(); |
|
61 | + if ( isset( self::$installed['versions'][ $packageName ]['pretty_version'] ) ) { |
|
62 | + $ranges[] = self::$installed['versions'][ $packageName ]['pretty_version']; |
|
63 | + } |
|
64 | + if ( array_key_exists( 'aliases', self::$installed['versions'][ $packageName ] ) ) { |
|
65 | + $ranges = array_merge( $ranges, self::$installed['versions'][ $packageName ]['aliases'] ); |
|
66 | + } |
|
67 | + if ( array_key_exists( 'replaced', self::$installed['versions'][ $packageName ] ) ) { |
|
68 | + $ranges = array_merge( $ranges, self::$installed['versions'][ $packageName ]['replaced'] ); |
|
69 | + } |
|
70 | + if ( array_key_exists( 'provided', self::$installed['versions'][ $packageName ] ) ) { |
|
71 | + $ranges = array_merge( $ranges, self::$installed['versions'][ $packageName ]['provided'] ); |
|
72 | + } |
|
73 | + |
|
74 | + return implode( ' || ', $ranges ); |
|
75 | + } |
|
76 | + |
|
77 | + public static function getVersion( $packageName ) { |
|
78 | + if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
79 | + throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
80 | + } |
|
81 | + |
|
82 | + if ( ! isset( self::$installed['versions'][ $packageName ]['version'] ) ) { |
|
83 | + return null; |
|
84 | + } |
|
85 | + |
|
86 | + return self::$installed['versions'][ $packageName ]['version']; |
|
87 | + } |
|
88 | + |
|
89 | + public static function getPrettyVersion( $packageName ) { |
|
90 | + if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
91 | + throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
92 | + } |
|
93 | + |
|
94 | + if ( ! isset( self::$installed['versions'][ $packageName ]['pretty_version'] ) ) { |
|
95 | + return null; |
|
96 | + } |
|
97 | + |
|
98 | + return self::$installed['versions'][ $packageName ]['pretty_version']; |
|
99 | + } |
|
100 | + |
|
101 | + public static function getReference( $packageName ) { |
|
102 | + if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
103 | + throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! isset( self::$installed['versions'][ $packageName ]['reference'] ) ) { |
|
107 | + return null; |
|
108 | + } |
|
109 | + |
|
110 | + return self::$installed['versions'][ $packageName ]['reference']; |
|
111 | + } |
|
112 | + |
|
113 | + public static function getRootPackage() { |
|
114 | + return self::$installed['root']; |
|
115 | + } |
|
116 | + |
|
117 | + public static function getRawData() { |
|
118 | + return self::$installed; |
|
119 | + } |
|
120 | + |
|
121 | + public static function reload( $data ) { |
|
122 | + self::$installed = $data; |
|
123 | + } |
|
124 | 124 | } |
@@ -38,76 +38,76 @@ discard block |
||
38 | 38 | ); |
39 | 39 | |
40 | 40 | public static function getInstalledPackages() { |
41 | - return array_keys( self::$installed['versions'] ); |
|
41 | + return array_keys(self::$installed['versions']); |
|
42 | 42 | } |
43 | 43 | |
44 | - public static function isInstalled( $packageName ) { |
|
45 | - return isset( self::$installed['versions'][ $packageName ] ); |
|
44 | + public static function isInstalled($packageName) { |
|
45 | + return isset(self::$installed['versions'][$packageName]); |
|
46 | 46 | } |
47 | 47 | |
48 | - public static function satisfies( VersionParser $parser, $packageName, $constraint ) { |
|
49 | - $constraint = $parser->parseConstraints( $constraint ); |
|
50 | - $provided = $parser->parseConstraints( self::getVersionRanges( $packageName ) ); |
|
48 | + public static function satisfies(VersionParser $parser, $packageName, $constraint) { |
|
49 | + $constraint = $parser->parseConstraints($constraint); |
|
50 | + $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); |
|
51 | 51 | |
52 | - return $provided->matches( $constraint ); |
|
52 | + return $provided->matches($constraint); |
|
53 | 53 | } |
54 | 54 | |
55 | - public static function getVersionRanges( $packageName ) { |
|
56 | - if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
57 | - throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
55 | + public static function getVersionRanges($packageName) { |
|
56 | + if ( ! isset(self::$installed['versions'][$packageName])) { |
|
57 | + throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $ranges = array(); |
61 | - if ( isset( self::$installed['versions'][ $packageName ]['pretty_version'] ) ) { |
|
62 | - $ranges[] = self::$installed['versions'][ $packageName ]['pretty_version']; |
|
61 | + if (isset(self::$installed['versions'][$packageName]['pretty_version'])) { |
|
62 | + $ranges[] = self::$installed['versions'][$packageName]['pretty_version']; |
|
63 | 63 | } |
64 | - if ( array_key_exists( 'aliases', self::$installed['versions'][ $packageName ] ) ) { |
|
65 | - $ranges = array_merge( $ranges, self::$installed['versions'][ $packageName ]['aliases'] ); |
|
64 | + if (array_key_exists('aliases', self::$installed['versions'][$packageName])) { |
|
65 | + $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']); |
|
66 | 66 | } |
67 | - if ( array_key_exists( 'replaced', self::$installed['versions'][ $packageName ] ) ) { |
|
68 | - $ranges = array_merge( $ranges, self::$installed['versions'][ $packageName ]['replaced'] ); |
|
67 | + if (array_key_exists('replaced', self::$installed['versions'][$packageName])) { |
|
68 | + $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']); |
|
69 | 69 | } |
70 | - if ( array_key_exists( 'provided', self::$installed['versions'][ $packageName ] ) ) { |
|
71 | - $ranges = array_merge( $ranges, self::$installed['versions'][ $packageName ]['provided'] ); |
|
70 | + if (array_key_exists('provided', self::$installed['versions'][$packageName])) { |
|
71 | + $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']); |
|
72 | 72 | } |
73 | 73 | |
74 | - return implode( ' || ', $ranges ); |
|
74 | + return implode(' || ', $ranges); |
|
75 | 75 | } |
76 | 76 | |
77 | - public static function getVersion( $packageName ) { |
|
78 | - if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
79 | - throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
77 | + public static function getVersion($packageName) { |
|
78 | + if ( ! isset(self::$installed['versions'][$packageName])) { |
|
79 | + throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed'); |
|
80 | 80 | } |
81 | 81 | |
82 | - if ( ! isset( self::$installed['versions'][ $packageName ]['version'] ) ) { |
|
82 | + if ( ! isset(self::$installed['versions'][$packageName]['version'])) { |
|
83 | 83 | return null; |
84 | 84 | } |
85 | 85 | |
86 | - return self::$installed['versions'][ $packageName ]['version']; |
|
86 | + return self::$installed['versions'][$packageName]['version']; |
|
87 | 87 | } |
88 | 88 | |
89 | - public static function getPrettyVersion( $packageName ) { |
|
90 | - if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
91 | - throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
89 | + public static function getPrettyVersion($packageName) { |
|
90 | + if ( ! isset(self::$installed['versions'][$packageName])) { |
|
91 | + throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed'); |
|
92 | 92 | } |
93 | 93 | |
94 | - if ( ! isset( self::$installed['versions'][ $packageName ]['pretty_version'] ) ) { |
|
94 | + if ( ! isset(self::$installed['versions'][$packageName]['pretty_version'])) { |
|
95 | 95 | return null; |
96 | 96 | } |
97 | 97 | |
98 | - return self::$installed['versions'][ $packageName ]['pretty_version']; |
|
98 | + return self::$installed['versions'][$packageName]['pretty_version']; |
|
99 | 99 | } |
100 | 100 | |
101 | - public static function getReference( $packageName ) { |
|
102 | - if ( ! isset( self::$installed['versions'][ $packageName ] ) ) { |
|
103 | - throw new \OutOfBoundsException( 'Package "' . $packageName . '" is not installed' ); |
|
101 | + public static function getReference($packageName) { |
|
102 | + if ( ! isset(self::$installed['versions'][$packageName])) { |
|
103 | + throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed'); |
|
104 | 104 | } |
105 | 105 | |
106 | - if ( ! isset( self::$installed['versions'][ $packageName ]['reference'] ) ) { |
|
106 | + if ( ! isset(self::$installed['versions'][$packageName]['reference'])) { |
|
107 | 107 | return null; |
108 | 108 | } |
109 | 109 | |
110 | - return self::$installed['versions'][ $packageName ]['reference']; |
|
110 | + return self::$installed['versions'][$packageName]['reference']; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | public static function getRootPackage() { |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | return self::$installed; |
119 | 119 | } |
120 | 120 | |
121 | - public static function reload( $data ) { |
|
121 | + public static function reload($data) { |
|
122 | 122 | self::$installed = $data; |
123 | 123 | } |
124 | 124 | } |
@@ -6,9 +6,9 @@ |
||
6 | 6 | $baseDir = dirname( $vendorDir ); |
7 | 7 | |
8 | 8 | return array( |
9 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
10 | - 'WP_Async_Request' => $vendorDir . '/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
11 | - 'WP_Background_Process' => $vendorDir . '/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
12 | - 'Wordlift_Plugin_WP_Async_Request' => $baseDir . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
13 | - 'Wordlift_Plugin_WP_Background_Process' => $baseDir . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
9 | + 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
10 | + 'WP_Async_Request' => $vendorDir . '/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
11 | + 'WP_Background_Process' => $vendorDir . '/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
12 | + 'Wordlift_Plugin_WP_Async_Request' => $baseDir . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
13 | + 'Wordlift_Plugin_WP_Background_Process' => $baseDir . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
14 | 14 | ); |
@@ -2,13 +2,13 @@ |
||
2 | 2 | |
3 | 3 | // autoload_classmap.php @generated by Composer |
4 | 4 | |
5 | -$vendorDir = dirname( ( __DIR__ ) ); |
|
6 | -$baseDir = dirname( $vendorDir ); |
|
5 | +$vendorDir = dirname((__DIR__)); |
|
6 | +$baseDir = dirname($vendorDir); |
|
7 | 7 | |
8 | 8 | return array( |
9 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
10 | - 'WP_Async_Request' => $vendorDir . '/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
11 | - 'WP_Background_Process' => $vendorDir . '/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
12 | - 'Wordlift_Plugin_WP_Async_Request' => $baseDir . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
13 | - 'Wordlift_Plugin_WP_Background_Process' => $baseDir . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
9 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
10 | + 'WP_Async_Request' => $vendorDir.'/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
11 | + 'WP_Background_Process' => $vendorDir.'/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
12 | + 'Wordlift_Plugin_WP_Async_Request' => $baseDir.'/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
13 | + 'Wordlift_Plugin_WP_Background_Process' => $baseDir.'/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
14 | 14 | ); |
@@ -6,22 +6,22 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInit30c84c47a44576eaa4b38cc478d5e11b { |
8 | 8 | |
9 | - public static $classMap = array( |
|
10 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
11 | - 'WP_Async_Request' => __DIR__ . '/..' . '/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
12 | - 'WP_Background_Process' => __DIR__ . '/..' . '/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
13 | - 'Wordlift_Plugin_WP_Async_Request' => __DIR__ . '/../..' . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
14 | - 'Wordlift_Plugin_WP_Background_Process' => __DIR__ . '/../..' . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
15 | - ); |
|
9 | + public static $classMap = array( |
|
10 | + 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
11 | + 'WP_Async_Request' => __DIR__ . '/..' . '/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
12 | + 'WP_Background_Process' => __DIR__ . '/..' . '/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
13 | + 'Wordlift_Plugin_WP_Async_Request' => __DIR__ . '/../..' . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
14 | + 'Wordlift_Plugin_WP_Background_Process' => __DIR__ . '/../..' . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
15 | + ); |
|
16 | 16 | |
17 | - public static function getInitializer( ClassLoader $loader ) { |
|
18 | - return \Closure::bind( |
|
19 | - function () use ( $loader ) { |
|
20 | - $loader->classMap = ComposerStaticInit30c84c47a44576eaa4b38cc478d5e11b::$classMap; |
|
17 | + public static function getInitializer( ClassLoader $loader ) { |
|
18 | + return \Closure::bind( |
|
19 | + function () use ( $loader ) { |
|
20 | + $loader->classMap = ComposerStaticInit30c84c47a44576eaa4b38cc478d5e11b::$classMap; |
|
21 | 21 | |
22 | - }, |
|
23 | - null, |
|
24 | - ClassLoader::class |
|
25 | - ); |
|
26 | - } |
|
22 | + }, |
|
23 | + null, |
|
24 | + ClassLoader::class |
|
25 | + ); |
|
26 | + } |
|
27 | 27 | } |
@@ -7,16 +7,16 @@ |
||
7 | 7 | class ComposerStaticInit30c84c47a44576eaa4b38cc478d5e11b { |
8 | 8 | |
9 | 9 | public static $classMap = array( |
10 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
11 | - 'WP_Async_Request' => __DIR__ . '/..' . '/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
12 | - 'WP_Background_Process' => __DIR__ . '/..' . '/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
13 | - 'Wordlift_Plugin_WP_Async_Request' => __DIR__ . '/../..' . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
14 | - 'Wordlift_Plugin_WP_Background_Process' => __DIR__ . '/../..' . '/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
10 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php', |
|
11 | + 'WP_Async_Request' => __DIR__.'/..'.'/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
12 | + 'WP_Background_Process' => __DIR__.'/..'.'/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
13 | + 'Wordlift_Plugin_WP_Async_Request' => __DIR__.'/../..'.'/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-async-request.php', |
|
14 | + 'Wordlift_Plugin_WP_Background_Process' => __DIR__.'/../..'.'/ext/dependencies/deliciousbrains/wp-background-processing/classes/wp-background-process.php', |
|
15 | 15 | ); |
16 | 16 | |
17 | - public static function getInitializer( ClassLoader $loader ) { |
|
17 | + public static function getInitializer(ClassLoader $loader) { |
|
18 | 18 | return \Closure::bind( |
19 | - function () use ( $loader ) { |
|
19 | + function() use ($loader) { |
|
20 | 20 | $loader->classMap = ComposerStaticInit30c84c47a44576eaa4b38cc478d5e11b::$classMap; |
21 | 21 | |
22 | 22 | }, |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | // autoload_psr4.php @generated by Composer |
4 | 4 | |
5 | -$vendorDir = dirname( ( __DIR__ ) ); |
|
6 | -$baseDir = dirname( $vendorDir ); |
|
5 | +$vendorDir = dirname((__DIR__)); |
|
6 | +$baseDir = dirname($vendorDir); |
|
7 | 7 | |
8 | 8 | return array(); |
@@ -4,52 +4,52 @@ |
||
4 | 4 | |
5 | 5 | class ComposerAutoloaderInit30c84c47a44576eaa4b38cc478d5e11b { |
6 | 6 | |
7 | - private static $loader; |
|
8 | - |
|
9 | - public static function loadClassLoader( $class ) { |
|
10 | - if ( 'Composer\Autoload\ClassLoader' === $class ) { |
|
11 | - require __DIR__ . '/ClassLoader.php'; |
|
12 | - } |
|
13 | - } |
|
14 | - |
|
15 | - /** |
|
16 | - * @return \Composer\Autoload\ClassLoader |
|
17 | - */ |
|
18 | - public static function getLoader() { |
|
19 | - if ( null !== self::$loader ) { |
|
20 | - return self::$loader; |
|
21 | - } |
|
22 | - |
|
23 | - require __DIR__ . '/platform_check.php'; |
|
24 | - |
|
25 | - spl_autoload_register( array( 'ComposerAutoloaderInit30c84c47a44576eaa4b38cc478d5e11b', 'loadClassLoader' ), true, true ); |
|
26 | - self::$loader = $loader = new \Composer\Autoload\ClassLoader(); |
|
27 | - spl_autoload_unregister( array( 'ComposerAutoloaderInit30c84c47a44576eaa4b38cc478d5e11b', 'loadClassLoader' ) ); |
|
28 | - |
|
29 | - $useStaticLoader = PHP_VERSION_ID >= 50600 && ! defined( 'HHVM_VERSION' ) && ( ! function_exists( 'zend_loader_file_encoded' ) || ! zend_loader_file_encoded() ); |
|
30 | - if ( $useStaticLoader ) { |
|
31 | - require __DIR__ . '/autoload_static.php'; |
|
32 | - |
|
33 | - call_user_func( \Composer\Autoload\ComposerStaticInit30c84c47a44576eaa4b38cc478d5e11b::getInitializer( $loader ) ); |
|
34 | - } else { |
|
35 | - $map = require __DIR__ . '/autoload_namespaces.php'; |
|
36 | - foreach ( $map as $namespace => $path ) { |
|
37 | - $loader->set( $namespace, $path ); |
|
38 | - } |
|
39 | - |
|
40 | - $map = require __DIR__ . '/autoload_psr4.php'; |
|
41 | - foreach ( $map as $namespace => $path ) { |
|
42 | - $loader->setPsr4( $namespace, $path ); |
|
43 | - } |
|
44 | - |
|
45 | - $classMap = require __DIR__ . '/autoload_classmap.php'; |
|
46 | - if ( $classMap ) { |
|
47 | - $loader->addClassMap( $classMap ); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - $loader->register( true ); |
|
52 | - |
|
53 | - return $loader; |
|
54 | - } |
|
7 | + private static $loader; |
|
8 | + |
|
9 | + public static function loadClassLoader( $class ) { |
|
10 | + if ( 'Composer\Autoload\ClassLoader' === $class ) { |
|
11 | + require __DIR__ . '/ClassLoader.php'; |
|
12 | + } |
|
13 | + } |
|
14 | + |
|
15 | + /** |
|
16 | + * @return \Composer\Autoload\ClassLoader |
|
17 | + */ |
|
18 | + public static function getLoader() { |
|
19 | + if ( null !== self::$loader ) { |
|
20 | + return self::$loader; |
|
21 | + } |
|
22 | + |
|
23 | + require __DIR__ . '/platform_check.php'; |
|
24 | + |
|
25 | + spl_autoload_register( array( 'ComposerAutoloaderInit30c84c47a44576eaa4b38cc478d5e11b', 'loadClassLoader' ), true, true ); |
|
26 | + self::$loader = $loader = new \Composer\Autoload\ClassLoader(); |
|
27 | + spl_autoload_unregister( array( 'ComposerAutoloaderInit30c84c47a44576eaa4b38cc478d5e11b', 'loadClassLoader' ) ); |
|
28 | + |
|
29 | + $useStaticLoader = PHP_VERSION_ID >= 50600 && ! defined( 'HHVM_VERSION' ) && ( ! function_exists( 'zend_loader_file_encoded' ) || ! zend_loader_file_encoded() ); |
|
30 | + if ( $useStaticLoader ) { |
|
31 | + require __DIR__ . '/autoload_static.php'; |
|
32 | + |
|
33 | + call_user_func( \Composer\Autoload\ComposerStaticInit30c84c47a44576eaa4b38cc478d5e11b::getInitializer( $loader ) ); |
|
34 | + } else { |
|
35 | + $map = require __DIR__ . '/autoload_namespaces.php'; |
|
36 | + foreach ( $map as $namespace => $path ) { |
|
37 | + $loader->set( $namespace, $path ); |
|
38 | + } |
|
39 | + |
|
40 | + $map = require __DIR__ . '/autoload_psr4.php'; |
|
41 | + foreach ( $map as $namespace => $path ) { |
|
42 | + $loader->setPsr4( $namespace, $path ); |
|
43 | + } |
|
44 | + |
|
45 | + $classMap = require __DIR__ . '/autoload_classmap.php'; |
|
46 | + if ( $classMap ) { |
|
47 | + $loader->addClassMap( $classMap ); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + $loader->register( true ); |
|
52 | + |
|
53 | + return $loader; |
|
54 | + } |
|
55 | 55 | } |
@@ -6,9 +6,9 @@ discard block |
||
6 | 6 | |
7 | 7 | private static $loader; |
8 | 8 | |
9 | - public static function loadClassLoader( $class ) { |
|
10 | - if ( 'Composer\Autoload\ClassLoader' === $class ) { |
|
11 | - require __DIR__ . '/ClassLoader.php'; |
|
9 | + public static function loadClassLoader($class) { |
|
10 | + if ('Composer\Autoload\ClassLoader' === $class) { |
|
11 | + require __DIR__.'/ClassLoader.php'; |
|
12 | 12 | } |
13 | 13 | } |
14 | 14 | |
@@ -16,39 +16,39 @@ discard block |
||
16 | 16 | * @return \Composer\Autoload\ClassLoader |
17 | 17 | */ |
18 | 18 | public static function getLoader() { |
19 | - if ( null !== self::$loader ) { |
|
19 | + if (null !== self::$loader) { |
|
20 | 20 | return self::$loader; |
21 | 21 | } |
22 | 22 | |
23 | - require __DIR__ . '/platform_check.php'; |
|
23 | + require __DIR__.'/platform_check.php'; |
|
24 | 24 | |
25 | - spl_autoload_register( array( 'ComposerAutoloaderInit30c84c47a44576eaa4b38cc478d5e11b', 'loadClassLoader' ), true, true ); |
|
25 | + spl_autoload_register(array('ComposerAutoloaderInit30c84c47a44576eaa4b38cc478d5e11b', 'loadClassLoader'), true, true); |
|
26 | 26 | self::$loader = $loader = new \Composer\Autoload\ClassLoader(); |
27 | - spl_autoload_unregister( array( 'ComposerAutoloaderInit30c84c47a44576eaa4b38cc478d5e11b', 'loadClassLoader' ) ); |
|
27 | + spl_autoload_unregister(array('ComposerAutoloaderInit30c84c47a44576eaa4b38cc478d5e11b', 'loadClassLoader')); |
|
28 | 28 | |
29 | - $useStaticLoader = PHP_VERSION_ID >= 50600 && ! defined( 'HHVM_VERSION' ) && ( ! function_exists( 'zend_loader_file_encoded' ) || ! zend_loader_file_encoded() ); |
|
30 | - if ( $useStaticLoader ) { |
|
31 | - require __DIR__ . '/autoload_static.php'; |
|
29 | + $useStaticLoader = PHP_VERSION_ID >= 50600 && ! defined('HHVM_VERSION') && ( ! function_exists('zend_loader_file_encoded') || ! zend_loader_file_encoded()); |
|
30 | + if ($useStaticLoader) { |
|
31 | + require __DIR__.'/autoload_static.php'; |
|
32 | 32 | |
33 | - call_user_func( \Composer\Autoload\ComposerStaticInit30c84c47a44576eaa4b38cc478d5e11b::getInitializer( $loader ) ); |
|
33 | + call_user_func(\Composer\Autoload\ComposerStaticInit30c84c47a44576eaa4b38cc478d5e11b::getInitializer($loader)); |
|
34 | 34 | } else { |
35 | - $map = require __DIR__ . '/autoload_namespaces.php'; |
|
36 | - foreach ( $map as $namespace => $path ) { |
|
37 | - $loader->set( $namespace, $path ); |
|
35 | + $map = require __DIR__.'/autoload_namespaces.php'; |
|
36 | + foreach ($map as $namespace => $path) { |
|
37 | + $loader->set($namespace, $path); |
|
38 | 38 | } |
39 | 39 | |
40 | - $map = require __DIR__ . '/autoload_psr4.php'; |
|
41 | - foreach ( $map as $namespace => $path ) { |
|
42 | - $loader->setPsr4( $namespace, $path ); |
|
40 | + $map = require __DIR__.'/autoload_psr4.php'; |
|
41 | + foreach ($map as $namespace => $path) { |
|
42 | + $loader->setPsr4($namespace, $path); |
|
43 | 43 | } |
44 | 44 | |
45 | - $classMap = require __DIR__ . '/autoload_classmap.php'; |
|
46 | - if ( $classMap ) { |
|
47 | - $loader->addClassMap( $classMap ); |
|
45 | + $classMap = require __DIR__.'/autoload_classmap.php'; |
|
46 | + if ($classMap) { |
|
47 | + $loader->addClassMap($classMap); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | - $loader->register( true ); |
|
51 | + $loader->register(true); |
|
52 | 52 | |
53 | 53 | return $loader; |
54 | 54 | } |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | */ |
11 | 11 | function wl_set_entity_main_type( $post_id, $type_uri ) { |
12 | 12 | |
13 | - Wordlift_Entity_Type_Service::get_instance() |
|
14 | - ->set( $post_id, $type_uri ); |
|
13 | + Wordlift_Entity_Type_Service::get_instance() |
|
14 | + ->set( $post_id, $type_uri ); |
|
15 | 15 | |
16 | 16 | } |
17 | 17 | |
@@ -20,39 +20,39 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function wl_print_entity_type_inline_js() { |
22 | 22 | |
23 | - $terms = get_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'get' => 'all' ) ); |
|
24 | - |
|
25 | - // Load the type data. |
|
26 | - $schema_service = Wordlift_Schema_Service::get_instance(); |
|
27 | - $entity_types = array_reduce( |
|
28 | - $terms, |
|
29 | - function ( $carry, $term ) use ( $schema_service ) { |
|
30 | - $type = $schema_service->get_schema( $term->slug ); |
|
31 | - |
|
32 | - // Skip if no `uri`. |
|
33 | - if ( empty( $type['uri'] ) ) { |
|
34 | - return $carry; |
|
35 | - } |
|
36 | - |
|
37 | - $carry[] = array( |
|
38 | - 'label' => $term->name, |
|
39 | - 'uri' => $type['uri'], |
|
40 | - 'css' => $type['css_class'], |
|
41 | - 'sameAs' => isset( $type['same_as'] ) ? $type['same_as'] : array(), |
|
42 | - 'slug' => $term->slug, |
|
43 | - 'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ), |
|
44 | - ); |
|
45 | - |
|
46 | - return $carry; |
|
47 | - }, |
|
48 | - array() |
|
49 | - ); |
|
50 | - |
|
51 | - // Hook to the Block Editor script. |
|
52 | - wp_localize_script( 'wl-block-editor', '_wlEntityTypes', $entity_types ); |
|
53 | - |
|
54 | - // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
|
55 | - wp_localize_script( 'wl-classic-editor', '_wlEntityTypes', $entity_types ); |
|
23 | + $terms = get_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'get' => 'all' ) ); |
|
24 | + |
|
25 | + // Load the type data. |
|
26 | + $schema_service = Wordlift_Schema_Service::get_instance(); |
|
27 | + $entity_types = array_reduce( |
|
28 | + $terms, |
|
29 | + function ( $carry, $term ) use ( $schema_service ) { |
|
30 | + $type = $schema_service->get_schema( $term->slug ); |
|
31 | + |
|
32 | + // Skip if no `uri`. |
|
33 | + if ( empty( $type['uri'] ) ) { |
|
34 | + return $carry; |
|
35 | + } |
|
36 | + |
|
37 | + $carry[] = array( |
|
38 | + 'label' => $term->name, |
|
39 | + 'uri' => $type['uri'], |
|
40 | + 'css' => $type['css_class'], |
|
41 | + 'sameAs' => isset( $type['same_as'] ) ? $type['same_as'] : array(), |
|
42 | + 'slug' => $term->slug, |
|
43 | + 'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ), |
|
44 | + ); |
|
45 | + |
|
46 | + return $carry; |
|
47 | + }, |
|
48 | + array() |
|
49 | + ); |
|
50 | + |
|
51 | + // Hook to the Block Editor script. |
|
52 | + wp_localize_script( 'wl-block-editor', '_wlEntityTypes', $entity_types ); |
|
53 | + |
|
54 | + // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
|
55 | + wp_localize_script( 'wl-classic-editor', '_wlEntityTypes', $entity_types ); |
|
56 | 56 | |
57 | 57 | } |
58 | 58 |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | * |
9 | 9 | * @deprecated use Wordlift_Entity_Type_Service::get_instance()->set( $post_id, $type_uri ) |
10 | 10 | */ |
11 | -function wl_set_entity_main_type( $post_id, $type_uri ) { |
|
11 | +function wl_set_entity_main_type($post_id, $type_uri) { |
|
12 | 12 | |
13 | 13 | Wordlift_Entity_Type_Service::get_instance() |
14 | - ->set( $post_id, $type_uri ); |
|
14 | + ->set($post_id, $type_uri); |
|
15 | 15 | |
16 | 16 | } |
17 | 17 | |
@@ -20,17 +20,17 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function wl_print_entity_type_inline_js() { |
22 | 22 | |
23 | - $terms = get_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'get' => 'all' ) ); |
|
23 | + $terms = get_terms(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array('get' => 'all')); |
|
24 | 24 | |
25 | 25 | // Load the type data. |
26 | 26 | $schema_service = Wordlift_Schema_Service::get_instance(); |
27 | 27 | $entity_types = array_reduce( |
28 | 28 | $terms, |
29 | - function ( $carry, $term ) use ( $schema_service ) { |
|
30 | - $type = $schema_service->get_schema( $term->slug ); |
|
29 | + function($carry, $term) use ($schema_service) { |
|
30 | + $type = $schema_service->get_schema($term->slug); |
|
31 | 31 | |
32 | 32 | // Skip if no `uri`. |
33 | - if ( empty( $type['uri'] ) ) { |
|
33 | + if (empty($type['uri'])) { |
|
34 | 34 | return $carry; |
35 | 35 | } |
36 | 36 | |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | 'label' => $term->name, |
39 | 39 | 'uri' => $type['uri'], |
40 | 40 | 'css' => $type['css_class'], |
41 | - 'sameAs' => isset( $type['same_as'] ) ? $type['same_as'] : array(), |
|
41 | + 'sameAs' => isset($type['same_as']) ? $type['same_as'] : array(), |
|
42 | 42 | 'slug' => $term->slug, |
43 | - 'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ), |
|
43 | + 'templates' => (isset($type['templates']) ? $type['templates'] : array()), |
|
44 | 44 | ); |
45 | 45 | |
46 | 46 | return $carry; |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | ); |
50 | 50 | |
51 | 51 | // Hook to the Block Editor script. |
52 | - wp_localize_script( 'wl-block-editor', '_wlEntityTypes', $entity_types ); |
|
52 | + wp_localize_script('wl-block-editor', '_wlEntityTypes', $entity_types); |
|
53 | 53 | |
54 | 54 | // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
55 | - wp_localize_script( 'wl-classic-editor', '_wlEntityTypes', $entity_types ); |
|
55 | + wp_localize_script('wl-classic-editor', '_wlEntityTypes', $entity_types); |
|
56 | 56 | |
57 | 57 | } |
58 | 58 | |
59 | 59 | // Allow Classic and Block Editor scripts to register first. |
60 | -add_action( 'admin_print_scripts-post.php', 'wl_print_entity_type_inline_js', 11 ); |
|
61 | -add_action( 'admin_print_scripts-post-new.php', 'wl_print_entity_type_inline_js', 11 ); |
|
60 | +add_action('admin_print_scripts-post.php', 'wl_print_entity_type_inline_js', 11); |
|
61 | +add_action('admin_print_scripts-post-new.php', 'wl_print_entity_type_inline_js', 11); |