|
0
|
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 |
*/ |
|
|
24 |
static public function enable() |
|
|
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(); |
|
|
37 |
$loader->registerNamespaceFallbacks($function[0]->getNamespaceFallbacks()); |
|
|
38 |
$loader->registerPrefixFallbacks($function[0]->getPrefixFallbacks()); |
|
|
39 |
$loader->registerNamespaces($function[0]->getNamespaces()); |
|
|
40 |
$loader->registerPrefixes($function[0]->getPrefixes()); |
|
|
41 |
|
|
|
42 |
$function[0] = $loader; |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
spl_autoload_register($function); |
|
|
46 |
} |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
/** |
|
|
50 |
* {@inheritDoc} |
|
|
51 |
*/ |
|
|
52 |
public function loadClass($class) |
|
|
53 |
{ |
|
|
54 |
if ($file = $this->findFile($class)) { |
|
|
55 |
require $file; |
|
|
56 |
|
|
|
57 |
if (!class_exists($class, false) && !interface_exists($class, false)) { |
|
|
58 |
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)); |
|
|
59 |
} |
|
|
60 |
} |
|
|
61 |
} |
|
|
62 |
} |