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