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