1 | <?php |
||
39 | class SplClassLoader |
||
40 | { |
||
41 | private $_fileExtension = '.php'; |
||
42 | private $_namespace; |
||
43 | private $_includePath; |
||
44 | private $_namespaceSeparator = '\\'; |
||
45 | |||
46 | /** |
||
47 | * Creates a new <tt>SplClassLoader</tt> that loads classes of the |
||
48 | * specified namespace. |
||
49 | * |
||
50 | * @param string $ns The namespace to use. |
||
51 | */ |
||
52 | public function __construct($ns = null, $includePath = null) |
||
53 | { |
||
54 | $this->_namespace = $ns; |
||
55 | $this->_includePath = $includePath; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Sets the namespace separator used by classes in the namespace of this class loader. |
||
60 | * |
||
61 | * @param string $sep The separator to use. |
||
62 | */ |
||
63 | public function setNamespaceSeparator($sep) |
||
64 | { |
||
65 | $this->_namespaceSeparator = $sep; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Gets the namespace seperator used by classes in the namespace of this class loader. |
||
70 | * |
||
71 | * @return void |
||
72 | */ |
||
73 | public function getNamespaceSeparator() |
||
74 | { |
||
75 | return $this->_namespaceSeparator; |
||
|
|||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Sets the base include path for all class files in the namespace of this class loader. |
||
80 | * |
||
81 | * @param string $includePath |
||
82 | */ |
||
83 | public function setIncludePath($includePath) |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Gets the base include path for all class files in the namespace of this class loader. |
||
90 | * |
||
91 | * @return string $includePath |
||
92 | */ |
||
93 | public function getIncludePath() |
||
94 | { |
||
95 | return $this->_includePath; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Sets the file extension of class files in the namespace of this class loader. |
||
100 | * |
||
101 | * @param string $fileExtension |
||
102 | */ |
||
103 | public function setFileExtension($fileExtension) |
||
104 | { |
||
105 | $this->_fileExtension = $fileExtension; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Gets the file extension of class files in the namespace of this class loader. |
||
110 | * |
||
111 | * @return string $fileExtension |
||
112 | */ |
||
113 | public function getFileExtension() |
||
114 | { |
||
115 | return $this->_fileExtension; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Installs this class loader on the SPL autoload stack. |
||
120 | */ |
||
121 | public function register() |
||
122 | { |
||
123 | spl_autoload_register(array($this, 'loadClass')); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Uninstalls this class loader from the SPL autoloader stack. |
||
128 | */ |
||
129 | public function unregister() |
||
130 | { |
||
131 | spl_autoload_unregister(array($this, 'loadClass')); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Loads the given class or interface. |
||
136 | * |
||
137 | * @param string $className The name of the class to load. |
||
138 | * @return void |
||
139 | */ |
||
140 | 6 | public function loadClass($className) |
|
156 | } |
||
157 | } |
||
158 | } |
||
159 | } |