Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 64 lines (54 sloc) 2.089 kb
5bd91e2 @fabpot [ClassLoader] added a debug class loader
fabpot authored
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 /**
15 * Checks that the class is actually declared in the included file.
16 *
17 * @author Fabien Potencier <fabien@symfony.com>
18 */
19 class DebugUniversalClassLoader extends UniversalClassLoader
20 {
21 /**
22 * Replaces all regular UniversalClassLoader instances by a DebugUniversalClassLoader ones.
23 */
5256043 @fabpot fixed CS
fabpot authored
24 public static function enable()
5bd91e2 @fabpot [ClassLoader] added a debug class loader
fabpot authored
25 {
26 if (!is_array($functions = spl_autoload_functions())) {
27 return;
28 }
29
30 foreach ($functions as $function) {
31 spl_autoload_unregister($function);
32 }
33
34 foreach ($functions as $function) {
35 if (is_array($function) && $function[0] instanceof UniversalClassLoader) {
36 $loader = new static();
8fc2dac @fabpot fixed previous commit
fabpot authored
37 $loader->registerNamespaceFallbacks($function[0]->getNamespaceFallbacks());
38 $loader->registerPrefixFallbacks($function[0]->getPrefixFallbacks());
5bd91e2 @fabpot [ClassLoader] added a debug class loader
fabpot authored
39 $loader->registerNamespaces($function[0]->getNamespaces());
40 $loader->registerPrefixes($function[0]->getPrefixes());
d7b4565 @henrikbjorn [ClassLoader] Support for autoloading include_path incl. tests.
henrikbjorn authored
41 $loader->useIncludePath($function[0]->getUseIncludePath());
5bd91e2 @fabpot [ClassLoader] added a debug class loader
fabpot authored
42
43 $function[0] = $loader;
44 }
45
46 spl_autoload_register($function);
47 }
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 public function loadClass($class)
54 {
55 if ($file = $this->findFile($class)) {
56 require $file;
57
c36b0fc @fabpot [ClassLoader] fixed usage of trait_exists()
fabpot authored
58 if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
c00f87a @Seldaek [ClassLoader] Improve exception messages of the debug class loader
Seldaek authored
59 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));
5bd91e2 @fabpot [ClassLoader] added a debug class loader
fabpot authored
60 }
61 }
62 }
63 }
Something went wrong with that request. Please try again.