Version 1
[yaffs-website] / vendor / symfony / class-loader / DebugUniversalClassLoader.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\ClassLoader;
13
14 @trigger_error('The '.__NAMESPACE__.'\DebugUniversalClassLoader class is deprecated since version 2.4 and will be removed in 3.0. Use the Symfony\Component\Debug\DebugClassLoader class instead.', E_USER_DEPRECATED);
15
16 /**
17  * Checks that the class is actually declared in the included file.
18  *
19  * @author Fabien Potencier <fabien@symfony.com>
20  *
21  * @deprecated since version 2.4, to be removed in 3.0.
22  *             Use the {@link \Symfony\Component\Debug\DebugClassLoader} class instead.
23  */
24 class DebugUniversalClassLoader extends UniversalClassLoader
25 {
26     /**
27      * Replaces all regular UniversalClassLoader instances by a DebugUniversalClassLoader ones.
28      */
29     public static function enable()
30     {
31         if (!is_array($functions = spl_autoload_functions())) {
32             return;
33         }
34
35         foreach ($functions as $function) {
36             spl_autoload_unregister($function);
37         }
38
39         foreach ($functions as $function) {
40             if (is_array($function) && $function[0] instanceof UniversalClassLoader) {
41                 $loader = new static();
42                 $loader->registerNamespaceFallbacks($function[0]->getNamespaceFallbacks());
43                 $loader->registerPrefixFallbacks($function[0]->getPrefixFallbacks());
44                 $loader->registerNamespaces($function[0]->getNamespaces());
45                 $loader->registerPrefixes($function[0]->getPrefixes());
46                 $loader->useIncludePath($function[0]->getUseIncludePath());
47
48                 $function[0] = $loader;
49             }
50
51             spl_autoload_register($function);
52         }
53     }
54
55     /**
56      * {@inheritdoc}
57      */
58     public function loadClass($class)
59     {
60         if ($file = $this->findFile($class)) {
61             require $file;
62
63             if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
64                 throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
65             }
66         }
67     }
68 }