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
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\Templating\FilterException' => '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: 'Nette\Diagnostics\Bar' => 'Tracy\Bar',
37: 'Nette\Diagnostics\BlueScreen' => 'Tracy\BlueScreen',
38: 'Nette\Diagnostics\DefaultBarPanel' => 'Tracy\DefaultBarPanel',
39: 'Nette\Diagnostics\Dumper' => 'Tracy\Dumper',
40: 'Nette\Diagnostics\FireLogger' => 'Tracy\FireLogger',
41: 'Nette\Diagnostics\Logger' => 'Tracy\Logger',
42: 'Nette\Diagnostics\OutputDebugger' => 'Tracy\OutputDebugger',
43: 'Nette\Latte\ParseException' => 'Latte\CompileException',
44: 'Nette\Latte\CompileException' => 'Latte\CompileException',
45: 'Nette\Latte\Compiler' => 'Latte\Compiler',
46: 'Nette\Latte\HtmlNode' => 'Latte\HtmlNode',
47: 'Nette\Latte\IMacro' => 'Latte\IMacro',
48: 'Nette\Latte\MacroNode' => 'Latte\MacroNode',
49: 'Nette\Latte\MacroTokens' => 'Latte\MacroTokens',
50: 'Nette\Latte\Parser' => 'Latte\Parser',
51: 'Nette\Latte\PhpWriter' => 'Latte\PhpWriter',
52: 'Nette\Latte\Token' => 'Latte\Token',
53: 'Nette\Latte\Macros\CoreMacros' => 'Latte\Macros\CoreMacros',
54: 'Nette\Latte\Macros\MacroSet' => 'Latte\Macros\MacroSet',
55: 'Nette\Latte\Macros\CacheMacro' => 'Nette\Bridges\CacheLatte\CacheMacro',
56: 'Nette\Latte\Macros\FormMacros' => 'Nette\Bridges\FormsLatte\FormMacros',
57: 'Nette\Latte\Macros\UIMacros' => 'Nette\Bridges\ApplicationLatte\UIMacros',
58: 'Nette\ArrayHash' => 'Nette\Utils\ArrayHash',
59: 'Nette\ArrayList' => 'Nette\Utils\ArrayList',
60: 'Nette\DateTime' => 'Nette\Utils\DateTime',
61: 'Nette\Image' => 'Nette\Utils\Image',
62: 'Nette\ObjectMixin' => 'Nette\Utils\ObjectMixin',
63: 'Nette\Utils\NeonException' => 'Nette\Neon\Exception',
64: 'Nette\Utils\NeonEntity' => 'Nette\Neon\Entity',
65: 'Nette\Utils\Neon' => 'Nette\Neon\Neon',
66: );
67:
68:
69: public $list = array(
70: 'Latte\CompileException' => 'Latte/exceptions',
71: 'Latte\Compiler' => 'Latte/Compiler',
72: 'Latte\Engine' => 'Latte/Engine',
73: 'Latte\Helpers' => 'Latte/Helpers',
74: 'Latte\HtmlNode' => 'Latte/HtmlNode',
75: 'Latte\ILoader' => 'Latte/ILoader',
76: 'Latte\IMacro' => 'Latte/IMacro',
77: 'Latte\Loaders\FileLoader' => 'Latte/Loaders/FileLoader',
78: 'Latte\Loaders\StringLoader' => 'Latte/Loaders/StringLoader',
79: 'Latte\MacroNode' => 'Latte/MacroNode',
80: 'Latte\MacroTokens' => 'Latte/MacroTokens',
81: 'Latte\Macros\BlockMacros' => 'Latte/Macros/BlockMacros',
82: 'Latte\Macros\CoreMacros' => 'Latte/Macros/CoreMacros',
83: 'Latte\Macros\MacroSet' => 'Latte/Macros/MacroSet',
84: 'Latte\Object' => 'Latte/Object',
85: 'Latte\Parser' => 'Latte/Parser',
86: 'Latte\PhpWriter' => 'Latte/PhpWriter',
87: 'Latte\RegexpException' => 'Latte/exceptions',
88: 'Latte\RuntimeException' => 'Latte/exceptions',
89: 'Latte\Runtime\CachingIterator' => 'Latte/Runtime/CachingIterator',
90: 'Latte\Runtime\Filters' => 'Latte/Runtime/Filters',
91: 'Latte\Runtime\Html' => 'Latte/Runtime/Html',
92: 'Latte\Runtime\IHtmlString' => 'Latte/Runtime/IHtmlString',
93: 'Latte\Template' => 'Latte/Template',
94: 'Latte\Token' => 'Latte/Token',
95: 'Latte\TokenIterator' => 'Latte/TokenIterator',
96: 'Latte\Tokenizer' => 'Latte/Tokenizer',
97: 'NetteModule\ErrorPresenter' => 'Application/ErrorPresenter',
98: 'NetteModule\MicroPresenter' => 'Application/MicroPresenter',
99: 'Nette\Application\AbortException' => 'Application/exceptions',
100: 'Nette\Application\ApplicationException' => 'Application/exceptions',
101: 'Nette\Application\BadRequestException' => 'Application/exceptions',
102: 'Nette\Application\ForbiddenRequestException' => 'Application/exceptions',
103: 'Nette\Application\InvalidPresenterException' => 'Application/exceptions',
104: 'Nette\ArgumentOutOfRangeException' => 'Utils/exceptions',
105: 'Nette\Caching\Storages\PhpFileStorage' => 'deprecated/Caching/PhpFileStorage',
106: 'Nette\Callback' => 'deprecated/Callback',
107: 'Nette\Configurator' => 'Bootstrap/Configurator',
108: 'Nette\DI\MissingServiceException' => 'DI/exceptions',
109: 'Nette\DI\ServiceCreationException' => 'DI/exceptions',
110: 'Nette\Database\Reflection\AmbiguousReferenceKeyException' => 'Database/Reflection/exceptions',
111: 'Nette\Database\Reflection\MissingReferenceException' => 'Database/Reflection/exceptions',
112: 'Nette\DeprecatedException' => 'Utils/exceptions',
113: 'Nette\Diagnostics\Debugger' => 'deprecated/Diagnostics/Debugger',
114: 'Nette\Diagnostics\Helpers' => 'deprecated/Diagnostics/Helpers',
115: 'Nette\Diagnostics\IBarPanel' => 'deprecated/Diagnostics/IBarPanel',
116: 'Nette\DirectoryNotFoundException' => 'Utils/exceptions',
117: 'Nette\Environment' => 'deprecated/Environment',
118: 'Nette\FileNotFoundException' => 'Utils/exceptions',
119: 'Nette\FreezableObject' => 'deprecated/FreezableObject',
120: 'Nette\IFreezable' => 'deprecated/IFreezable',
121: 'Nette\IOException' => 'Utils/exceptions',
122: 'Nette\InvalidArgumentException' => 'Utils/exceptions',
123: 'Nette\InvalidStateException' => 'Utils/exceptions',
124: 'Nette\Latte\Engine' => 'deprecated/Latte/Engine',
125: 'Nette\Loaders\RobotLoader' => 'RobotLoader/RobotLoader',
126: 'Nette\Localization\ITranslator' => 'Utils/ITranslator',
127: 'Nette\Mail\SmtpException' => 'Mail/SmtpMailer',
128: 'Nette\MemberAccessException' => 'Utils/exceptions',
129: 'Nette\NotImplementedException' => 'Utils/exceptions',
130: 'Nette\NotSupportedException' => 'Utils/exceptions',
131: 'Nette\Object' => 'Utils/Object',
132: 'Nette\OutOfRangeException' => 'Utils/exceptions',
133: 'Nette\StaticClassException' => 'Utils/exceptions',
134: 'Nette\Templating\FileTemplate' => 'deprecated/Templating/FileTemplate',
135: 'Nette\Templating\Helpers' => 'deprecated/Templating/Helpers',
136: 'Nette\Templating\IFileTemplate' => 'deprecated/Templating/IFileTemplate',
137: 'Nette\Templating\ITemplate' => 'deprecated/Templating/ITemplate',
138: 'Nette\Templating\Template' => 'deprecated/Templating/Template',
139: 'Nette\UnexpectedValueException' => 'Utils/exceptions',
140: 'Nette\Utils\AssertionException' => 'Utils/Validators',
141: 'Nette\Utils\CallbackFilterIterator' => 'Finder/CallbackFilterIterator',
142: 'Nette\Utils\Finder' => 'Finder/Finder',
143: 'Nette\Utils\JsonException' => 'Utils/Json',
144: 'Nette\Utils\LimitedScope' => 'deprecated/Utils/LimitedScope',
145: 'Nette\Utils\MimeTypeDetector' => 'deprecated/Utils/MimeTypeDetector',
146: 'Nette\Utils\RecursiveCallbackFilterIterator' => 'Finder/RecursiveCallbackFilterIterator',
147: 'Nette\Utils\RegexpException' => 'Utils/Strings',
148: 'Nette\Utils\SafeStream' => 'SafeStream/SafeStream',
149: 'Nette\Utils\TokenIterator' => 'Tokenizer/TokenIterator',
150: 'Nette\Utils\Tokenizer' => 'Tokenizer/Tokenizer',
151: 'Nette\Utils\TokenizerException' => 'Tokenizer/TokenizerException',
152: 'Nette\Utils\UnknownImageFileException' => 'Utils/Image',
153: 'Tracy\Bar' => 'Tracy/Bar',
154: 'Tracy\BlueScreen' => 'Tracy/BlueScreen',
155: 'Tracy\Debugger' => 'Tracy/Debugger',
156: 'Tracy\DefaultBarPanel' => 'Tracy/DefaultBarPanel',
157: 'Tracy\Dumper' => 'Tracy/Dumper',
158: 'Tracy\FireLogger' => 'Tracy/FireLogger',
159: 'Tracy\Helpers' => 'Tracy/Helpers',
160: 'Tracy\IBarPanel' => 'Tracy/IBarPanel',
161: 'Tracy\Logger' => 'Tracy/Logger',
162: 'Tracy\OutputDebugger' => 'Tracy/OutputDebugger',
163: );
164:
165:
166: 167: 168: 169:
170: public static function getInstance()
171: {
172: if (self::$instance === NULL) {
173: self::$instance = new static;
174: }
175: return self::$instance;
176: }
177:
178:
179: 180: 181: 182: 183:
184: public function register($prepend = FALSE)
185: {
186: spl_autoload_register(array($this, 'tryLoad'), TRUE, (bool) $prepend);
187: }
188:
189:
190: 191: 192: 193: 194:
195: public function tryLoad($type)
196: {
197: $type = ltrim($type, '\\');
198: if (isset($this->renamed[$type])) {
199: class_alias($this->renamed[$type], $type);
200: trigger_error("Class $type has been renamed to {$this->renamed[$type]}.", E_USER_WARNING);
201:
202: } elseif (isset($this->list[$type])) {
203: require __DIR__ . '/../' . $this->list[$type] . '.php';
204:
205: } elseif (substr($type, 0, 6) === 'Nette\\' && is_file($file = __DIR__ . '/../' . strtr(substr($type, 5), '\\', '/') . '.php')) {
206: require $file;
207: }
208: }
209:
210: }
211: