1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Loaders;
9:
10: use Nette;
11:
12:
13: 14: 15: 16: 17:
18: class NetteLoader extends Nette\Object
19: {
20:
21: private static $instance;
22:
23:
24: public $renamed = array(
25: 'Nette\Config\Configurator' => 'Nette\Configurator',
26: 'Nette\Config\CompilerExtension' => 'Nette\DI\CompilerExtension',
27: 'Nette\Http\User' => 'Nette\Security\User',
28: 'Nette\Templating\DefaultHelpers' => 'Nette\Templating\Helpers',
29: 'Nette\Latte\ParseException' => 'Nette\Latte\CompileException',
30: 'Nette\Utils\PhpGenerator\ClassType' => 'Nette\PhpGenerator\ClassType',
31: 'Nette\Utils\PhpGenerator\Helpers' => 'Nette\PhpGenerator\Helpers',
32: 'Nette\Utils\PhpGenerator\Method' => 'Nette\PhpGenerator\Method',
33: 'Nette\Utils\PhpGenerator\Parameter' => 'Nette\PhpGenerator\Parameter',
34: 'Nette\Utils\PhpGenerator\PhpLiteral' => 'Nette\PhpGenerator\PhpLiteral',
35: 'Nette\Utils\PhpGenerator\Property' => 'Nette\PhpGenerator\Property',
36: );
37:
38:
39: public $list = array(
40: 'NetteModule\ErrorPresenter' => 'Application/ErrorPresenter',
41: 'NetteModule\MicroPresenter' => 'Application/MicroPresenter',
42: 'Nette\Application\AbortException' => 'Application/exceptions',
43: 'Nette\Application\ApplicationException' => 'Application/exceptions',
44: 'Nette\Application\BadRequestException' => 'Application/exceptions',
45: 'Nette\Application\ForbiddenRequestException' => 'Application/exceptions',
46: 'Nette\Application\InvalidPresenterException' => 'Application/exceptions',
47: 'Nette\ArgumentOutOfRangeException' => 'common/exceptions',
48: 'Nette\ArrayHash' => 'common/ArrayHash',
49: 'Nette\ArrayList' => 'common/ArrayList',
50: 'Nette\Callback' => 'common/Callback',
51: 'Nette\Configurator' => 'common/Configurator',
52: 'Nette\DI\MissingServiceException' => 'DI/exceptions',
53: 'Nette\DI\ServiceCreationException' => 'DI/exceptions',
54: 'Nette\Database\Reflection\AmbiguousReferenceKeyException' => 'Database/Reflection/exceptions',
55: 'Nette\Database\Reflection\MissingReferenceException' => 'Database/Reflection/exceptions',
56: 'Nette\DateTime' => 'common/DateTime',
57: 'Nette\DeprecatedException' => 'common/exceptions',
58: 'Nette\DirectoryNotFoundException' => 'common/exceptions',
59: 'Nette\Environment' => 'common/Environment',
60: 'Nette\FatalErrorException' => 'common/exceptions',
61: 'Nette\FileNotFoundException' => 'common/exceptions',
62: 'Nette\Framework' => 'common/Framework',
63: 'Nette\FreezableObject' => 'common/FreezableObject',
64: 'Nette\IFreezable' => 'common/IFreezable',
65: 'Nette\IOException' => 'common/exceptions',
66: 'Nette\Image' => 'common/Image',
67: 'Nette\InvalidArgumentException' => 'common/exceptions',
68: 'Nette\InvalidStateException' => 'common/exceptions',
69: 'Nette\Latte\CompileException' => 'Latte/exceptions',
70: 'Nette\Mail\SmtpException' => 'Mail/SmtpMailer',
71: 'Nette\MemberAccessException' => 'common/exceptions',
72: 'Nette\NotImplementedException' => 'common/exceptions',
73: 'Nette\NotSupportedException' => 'common/exceptions',
74: 'Nette\Object' => 'common/Object',
75: 'Nette\ObjectMixin' => 'common/ObjectMixin',
76: 'Nette\OutOfRangeException' => 'common/exceptions',
77: 'Nette\StaticClassException' => 'common/exceptions',
78: 'Nette\UnexpectedValueException' => 'common/exceptions',
79: 'Nette\UnknownImageFileException' => 'common/Image',
80: 'Nette\Utils\AssertionException' => 'Utils/Validators',
81: 'Nette\Utils\JsonException' => 'Utils/Json',
82: 'Nette\Utils\NeonEntity' => 'Utils/Neon',
83: 'Nette\Utils\NeonException' => 'Utils/Neon',
84: 'Nette\Utils\RegexpException' => 'Utils/Strings',
85: 'Nette\Utils\TokenizerException' => 'Utils/Tokenizer',
86: );
87:
88:
89: 90: 91: 92:
93: public static function getInstance()
94: {
95: if (self::$instance === NULL) {
96: self::$instance = new static;
97: }
98: return self::$instance;
99: }
100:
101:
102: 103: 104: 105: 106:
107: public function register($prepend = FALSE)
108: {
109: spl_autoload_register(array($this, 'tryLoad'), TRUE, (bool) $prepend);
110: }
111:
112:
113: 114: 115: 116: 117:
118: public function tryLoad($type)
119: {
120: $type = ltrim($type, '\\');
121: if (isset($this->renamed[$type])) {
122: class_alias($this->renamed[$type], $type);
123: trigger_error("Class $type has been renamed to {$this->renamed[$type]}.", E_USER_WARNING);
124:
125: } elseif (isset($this->list[$type])) {
126: require __DIR__ . '/../' . $this->list[$type] . '.php';
127:
128: } elseif (substr($type, 0, 6) === 'Nette\\' && is_file($file = __DIR__ . '/../' . strtr(substr($type, 5), '\\', '/') . '.php')) {
129: require $file;
130: }
131: }
132:
133: }
134: