1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\Loaders;
9:
10: use Nette;
11:
12:
13: /**
14: * Auto loader is responsible for loading classes and interfaces.
15: *
16: * @author David Grudl
17: * @deprecated
18: */
19: abstract class AutoLoader extends Nette\Object
20: {
21: /** @var array list of registered loaders */
22: static private $loaders = array();
23:
24:
25: /**
26: * Try to load the requested class.
27: * @param string class/interface name
28: * @return void
29: */
30: public static function load($type)
31: {
32: trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
33: foreach (func_get_args() as $type) {
34: if (!class_exists($type)) {
35: throw new Nette\InvalidStateException("Unable to load class or interface '$type'.");
36: }
37: }
38: }
39:
40:
41: /**
42: * Return all registered autoloaders.
43: * @return AutoLoader[]
44: */
45: public static function getLoaders()
46: {
47: trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
48: return array_values(self::$loaders);
49: }
50:
51:
52: /**
53: * Register autoloader.
54: * @param bool prepend autoloader?
55: * @return void
56: */
57: public function register($prepend = FALSE)
58: {
59: if (!function_exists('spl_autoload_register')) {
60: throw new Nette\NotSupportedException('spl_autoload does not exist in this PHP installation.');
61: }
62:
63: spl_autoload_register(array($this, 'tryLoad'), TRUE, (bool) $prepend);
64: self::$loaders[spl_object_hash($this)] = $this;
65: }
66:
67:
68: /**
69: * Unregister autoloader.
70: * @return bool
71: */
72: public function unregister()
73: {
74: unset(self::$loaders[spl_object_hash($this)]);
75: return spl_autoload_unregister(array($this, 'tryLoad'));
76: }
77:
78:
79: /**
80: * Handles autoloading of classes or interfaces.
81: * @param string
82: * @return void
83: */
84: abstract public function tryLoad($type);
85:
86: }
87: