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