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\DateTime' => '/common/DateTime',
51: 'Nette\DeprecatedException' => '/common/exceptions',
52: 'Nette\DirectoryNotFoundException' => '/common/exceptions',
53: 'Nette\Environment' => '/common/Environment',
54: 'Nette\FatalErrorException' => '/common/exceptions',
55: 'Nette\FileNotFoundException' => '/common/exceptions',
56: 'Nette\Framework' => '/common/Framework',
57: 'Nette\FreezableObject' => '/common/FreezableObject',
58: 'Nette\IFreezable' => '/common/IFreezable',
59: 'Nette\IOException' => '/common/exceptions',
60: 'Nette\Image' => '/common/Image',
61: 'Nette\InvalidArgumentException' => '/common/exceptions',
62: 'Nette\InvalidStateException' => '/common/exceptions',
63: 'Nette\Latte\CompileException' => '/Latte/exceptions',
64: 'Nette\Mail\SmtpException' => '/Mail/SmtpMailer',
65: 'Nette\MemberAccessException' => '/common/exceptions',
66: 'Nette\NotImplementedException' => '/common/exceptions',
67: 'Nette\NotSupportedException' => '/common/exceptions',
68: 'Nette\Object' => '/common/Object',
69: 'Nette\ObjectMixin' => '/common/ObjectMixin',
70: 'Nette\OutOfRangeException' => '/common/exceptions',
71: 'Nette\StaticClassException' => '/common/exceptions',
72: 'Nette\UnexpectedValueException' => '/common/exceptions',
73: 'Nette\UnknownImageFileException' => '/common/Image',
74: 'Nette\Utils\AssertionException' => '/Utils/Validators',
75: 'Nette\Utils\JsonException' => '/Utils/Json',
76: 'Nette\Utils\NeonEntity' => '/Utils/Neon',
77: 'Nette\Utils\NeonException' => '/Utils/Neon',
78: 'Nette\Utils\RegexpException' => '/Utils/Strings',
79: 'Nette\Utils\TokenizerException' => '/Utils/Tokenizer',
80: );
81:
82:
83:
84: 85: 86: 87:
88: public static function getInstance()
89: {
90: if (self::$instance === NULL) {
91: self::$instance = new static;
92: }
93: return self::$instance;
94: }
95:
96:
97:
98: 99: 100: 101: 102:
103: public function tryLoad($type)
104: {
105: $type = ltrim($type, '\\');
106: if (isset($this->renamed[$type])) {
107: class_alias($this->renamed[$type], $type);
108: trigger_error("Class $type has been renamed to {$this->renamed[$type]}.", E_USER_WARNING);
109:
110: } elseif (isset($this->list[$type])) {
111: Nette\Utils\LimitedScope::load(NETTE_DIR . $this->list[$type] . '.php', TRUE);
112: self::$count++;
113:
114: } elseif (substr($type, 0, 6) === 'Nette\\' && is_file($file = NETTE_DIR . strtr(substr($type, 5), '\\', '/') . '.php')) {
115: Nette\Utils\LimitedScope::load($file, TRUE);
116: self::$count++;
117: }
118: }
119:
120: }
121: