1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Loaders;
9:
10: use Nette;
11:
12:
13: 14: 15: 16:
17: class NetteLoader
18: {
19:
20: private static $instance;
21:
22:
23: public $renamed = array(
24: 'Nette\Config\Configurator' => 'Nette\Configurator',
25: 'Nette\Config\CompilerExtension' => 'Nette\DI\CompilerExtension',
26: 'Nette\Http\User' => 'Nette\Security\User',
27: 'Nette\Templating\DefaultHelpers' => 'Nette\Templating\Helpers',
28: 'Nette\Templating\FilterException' => 'Latte\CompileException',
29: 'Nette\Utils\PhpGenerator\ClassType' => 'Nette\PhpGenerator\ClassType',
30: 'Nette\Utils\PhpGenerator\Helpers' => 'Nette\PhpGenerator\Helpers',
31: 'Nette\Utils\PhpGenerator\Method' => 'Nette\PhpGenerator\Method',
32: 'Nette\Utils\PhpGenerator\Parameter' => 'Nette\PhpGenerator\Parameter',
33: 'Nette\Utils\PhpGenerator\PhpLiteral' => 'Nette\PhpGenerator\PhpLiteral',
34: 'Nette\Utils\PhpGenerator\Property' => 'Nette\PhpGenerator\Property',
35: 'Nette\Diagnostics\Bar' => 'Tracy\Bar',
36: 'Nette\Diagnostics\BlueScreen' => 'Tracy\BlueScreen',
37: 'Nette\Diagnostics\DefaultBarPanel' => 'Tracy\DefaultBarPanel',
38: 'Nette\Diagnostics\Dumper' => 'Tracy\Dumper',
39: 'Nette\Diagnostics\FireLogger' => 'Tracy\FireLogger',
40: 'Nette\Diagnostics\Logger' => 'Tracy\Logger',
41: 'Nette\Diagnostics\OutputDebugger' => 'Tracy\OutputDebugger',
42: 'Nette\Latte\ParseException' => 'Latte\CompileException',
43: 'Nette\Latte\CompileException' => 'Latte\CompileException',
44: 'Nette\Latte\Compiler' => 'Latte\Compiler',
45: 'Nette\Latte\HtmlNode' => 'Latte\HtmlNode',
46: 'Nette\Latte\IMacro' => 'Latte\IMacro',
47: 'Nette\Latte\MacroNode' => 'Latte\MacroNode',
48: 'Nette\Latte\MacroTokens' => 'Latte\MacroTokens',
49: 'Nette\Latte\Parser' => 'Latte\Parser',
50: 'Nette\Latte\PhpWriter' => 'Latte\PhpWriter',
51: 'Nette\Latte\Token' => 'Latte\Token',
52: 'Nette\Latte\Macros\CoreMacros' => 'Latte\Macros\CoreMacros',
53: 'Nette\Latte\Macros\MacroSet' => 'Latte\Macros\MacroSet',
54: 'Nette\Latte\Macros\CacheMacro' => 'Nette\Bridges\CacheLatte\CacheMacro',
55: 'Nette\Latte\Macros\FormMacros' => 'Nette\Bridges\FormsLatte\FormMacros',
56: 'Nette\Latte\Macros\UIMacros' => 'Nette\Bridges\ApplicationLatte\UIMacros',
57: 'Nette\ArrayHash' => 'Nette\Utils\ArrayHash',
58: 'Nette\ArrayList' => 'Nette\Utils\ArrayList',
59: 'Nette\DateTime' => 'Nette\Utils\DateTime',
60: 'Nette\Image' => 'Nette\Utils\Image',
61: 'Nette\ObjectMixin' => 'Nette\Utils\ObjectMixin',
62: 'Nette\Utils\NeonException' => 'Nette\Neon\Exception',
63: 'Nette\Utils\NeonEntity' => 'Nette\Neon\Entity',
64: 'Nette\Utils\Neon' => 'Nette\Neon\Neon',
65: );
66:
67:
68: public $list = array(
69: 'Latte\CompileException' => 'Latte/exceptions',
70: 'Latte\Compiler' => 'Latte/Compiler/Compiler',
71: 'Latte\Engine' => 'Latte/Engine',
72: 'Latte\Helpers' => 'Latte/Helpers',
73: 'Latte\HtmlNode' => 'Latte/Compiler/HtmlNode',
74: 'Latte\ILoader' => 'Latte/ILoader',
75: 'Latte\IMacro' => 'Latte/IMacro',
76: 'Latte\Loaders\FileLoader' => 'Latte/Loaders/FileLoader',
77: 'Latte\Loaders\StringLoader' => 'Latte/Loaders/StringLoader',
78: 'Latte\MacroNode' => 'Latte/Compiler/MacroNode',
79: 'Latte\MacroTokens' => 'Latte/Compiler/MacroTokens',
80: 'Latte\Macros\BlockMacros' => 'Latte/Macros/BlockMacros',
81: 'Latte\Macros\CoreMacros' => 'Latte/Macros/CoreMacros',
82: 'Latte\Macros\MacroSet' => 'Latte/Macros/MacroSet',
83: 'Latte\Parser' => 'Latte/Compiler/Parser',
84: 'Latte\PhpHelpers' => 'Latte/Compiler/PhpHelpers',
85: 'Latte\PhpWriter' => 'Latte/Compiler/PhpWriter',
86: 'Latte\RegexpException' => 'Latte/exceptions',
87: 'Latte\RuntimeException' => 'Latte/exceptions',
88: 'Latte\Runtime\CachingIterator' => 'Latte/Runtime/CachingIterator',
89: 'Latte\Runtime\FilterExecutor' => 'Latte/Runtime/FilterExecutor',
90: 'Latte\Runtime\FilterInfo' => 'Latte/Runtime/FilterInfo',
91: 'Latte\Runtime\Filters' => 'Latte/Runtime/Filters',
92: 'Latte\Runtime\Html' => 'Latte/Runtime/Html',
93: 'Latte\Runtime\IHtmlString' => 'Latte/Runtime/IHtmlString',
94: 'Latte\Runtime\ISnippetBridge' => 'Latte/Runtime/ISnippetBridge',
95: 'Latte\Runtime\SnippetDriver' => 'Latte/Runtime/SnippetDriver',
96: 'Latte\Runtime\Template' => 'Latte/Runtime/Template',
97: 'Latte\Strict' => 'Latte/Strict',
98: 'Latte\Token' => 'Latte/Compiler/Token',
99: 'Latte\TokenIterator' => 'Latte/Compiler/TokenIterator',
100: 'Latte\Tokenizer' => 'Latte/Compiler/Tokenizer',
101: 'NetteModule\ErrorPresenter' => 'Application/ErrorPresenter',
102: 'NetteModule\MicroPresenter' => 'Application/MicroPresenter',
103: 'Nette\Application\AbortException' => 'Application/exceptions',
104: 'Nette\Application\ApplicationException' => 'Application/exceptions',
105: 'Nette\Application\BadRequestException' => 'Application/exceptions',
106: 'Nette\Application\ForbiddenRequestException' => 'Application/exceptions',
107: 'Nette\Application\InvalidPresenterException' => 'Application/exceptions',
108: 'Nette\ArgumentOutOfRangeException' => 'Utils/exceptions',
109: 'Nette\Caching\Storages\PhpFileStorage' => 'deprecated/Caching/PhpFileStorage',
110: 'Nette\Callback' => 'deprecated/Callback',
111: 'Nette\Configurator' => 'Bootstrap/Configurator',
112: 'Nette\DI\MissingServiceException' => 'DI/exceptions',
113: 'Nette\DI\ServiceCreationException' => 'DI/exceptions',
114: 'Nette\Database\ConnectionException' => 'Database/exceptions',
115: 'Nette\Database\ConstraintViolationException' => 'Database/exceptions',
116: 'Nette\Database\ForeignKeyConstraintViolationException' => 'Database/exceptions',
117: 'Nette\Database\NotNullConstraintViolationException' => 'Database/exceptions',
118: 'Nette\Database\UniqueConstraintViolationException' => 'Database/exceptions',
119: 'Nette\DeprecatedException' => 'Utils/exceptions',
120: 'Nette\Diagnostics\Debugger' => 'deprecated/Diagnostics/Debugger',
121: 'Nette\Diagnostics\Helpers' => 'deprecated/Diagnostics/Helpers',
122: 'Nette\Diagnostics\IBarPanel' => 'deprecated/Diagnostics/IBarPanel',
123: 'Nette\DirectoryNotFoundException' => 'Utils/exceptions',
124: 'Nette\Environment' => 'deprecated/Environment',
125: 'Nette\FileNotFoundException' => 'Utils/exceptions',
126: 'Nette\FreezableObject' => 'deprecated/Utils/FreezableObject',
127: 'Nette\IFreezable' => 'deprecated/Utils/IFreezable',
128: 'Nette\IOException' => 'Utils/exceptions',
129: 'Nette\InvalidArgumentException' => 'Utils/exceptions',
130: 'Nette\InvalidStateException' => 'Utils/exceptions',
131: 'Nette\Latte\Engine' => 'deprecated/Latte/Engine',
132: 'Nette\LegacyObject' => 'Utils/LegacyObject',
133: 'Nette\Loaders\RobotLoader' => 'RobotLoader/RobotLoader',
134: 'Nette\Localization\ITranslator' => 'Utils/ITranslator',
135: 'Nette\Mail\FallbackMailerException' => 'Mail/exceptions',
136: 'Nette\Mail\SendException' => 'Mail/exceptions',
137: 'Nette\Mail\SmtpException' => 'Mail/exceptions',
138: 'Nette\MemberAccessException' => 'Utils/exceptions',
139: 'Nette\NotImplementedException' => 'Utils/exceptions',
140: 'Nette\NotSupportedException' => 'Utils/exceptions',
141: 'Nette\OutOfRangeException' => 'Utils/exceptions',
142: 'Nette\SmartObject' => 'Utils/SmartObject',
143: 'Nette\StaticClass' => 'Utils/StaticClass',
144: 'Nette\StaticClassException' => 'Utils/exceptions',
145: 'Nette\Templating\FileTemplate' => 'deprecated/Templating/FileTemplate',
146: 'Nette\Templating\Helpers' => 'deprecated/Templating/Helpers',
147: 'Nette\Templating\IFileTemplate' => 'deprecated/Templating/IFileTemplate',
148: 'Nette\Templating\ITemplate' => 'deprecated/Templating/ITemplate',
149: 'Nette\Templating\Template' => 'deprecated/Templating/Template',
150: 'Nette\UnexpectedValueException' => 'Utils/exceptions',
151: 'Nette\Utils\AssertionException' => 'Utils/exceptions',
152: 'Nette\Utils\ImageException' => 'Utils/exceptions',
153: 'Nette\Utils\JsonException' => 'Utils/exceptions',
154: 'Nette\Utils\LimitedScope' => 'deprecated/Utils/LimitedScope',
155: 'Nette\Utils\MimeTypeDetector' => 'deprecated/Utils/MimeTypeDetector',
156: 'Nette\Utils\RegexpException' => 'Utils/exceptions',
157: 'Nette\Utils\SafeStream' => 'SafeStream/SafeStream',
158: 'Nette\Utils\UnknownImageFileException' => 'Utils/exceptions',
159: 'Tracy\Bar' => 'Tracy/Bar',
160: 'Tracy\BlueScreen' => 'Tracy/BlueScreen',
161: 'Tracy\Bridges\Nette\Bridge' => 'Bridges/Nette/Bridge',
162: 'Tracy\Bridges\Nette\MailSender' => 'Bridges/Nette/MailSender',
163: 'Tracy\Bridges\Nette\TracyExtension' => 'Bridges/Nette/TracyExtension',
164: 'Tracy\Debugger' => 'Tracy/Debugger',
165: 'Tracy\DefaultBarPanel' => 'Tracy/DefaultBarPanel',
166: 'Tracy\Dumper' => 'Tracy/Dumper',
167: 'Tracy\FireLogger' => 'Tracy/FireLogger',
168: 'Tracy\Helpers' => 'Tracy/Helpers',
169: 'Tracy\IBarPanel' => 'Tracy/IBarPanel',
170: 'Tracy\ILogger' => 'Tracy/ILogger',
171: 'Tracy\Logger' => 'Tracy/Logger',
172: 'Tracy\OutputDebugger' => 'Tracy/OutputDebugger',
173: );
174:
175:
176: 177: 178: 179:
180: public static function getInstance()
181: {
182: if (self::$instance === null) {
183: self::$instance = new static;
184: }
185: return self::$instance;
186: }
187:
188:
189: 190: 191: 192: 193:
194: public function register($prepend = false)
195: {
196: spl_autoload_register(array($this, 'tryLoad'), true, (bool) $prepend);
197: }
198:
199:
200: 201: 202: 203: 204:
205: public function tryLoad($type)
206: {
207: $type = ltrim($type, '\\');
208: if (isset($this->renamed[$type])) {
209: class_alias($this->renamed[$type], $type);
210: trigger_error("Class $type has been renamed to {$this->renamed[$type]}.", E_USER_WARNING);
211:
212: } elseif (isset($this->list[$type])) {
213: require __DIR__ . '/../' . $this->list[$type] . '.php';
214:
215: } elseif (substr($type, 0, 6) === 'Nette\\' && is_file($file = __DIR__ . '/../' . strtr(substr($type, 5), '\\', '/') . '.php')) {
216: require $file;
217: }
218: }
219: }
220: