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