101 foreach ($namespaces as $namespace => $locations) {
102 $this->namespaces[$namespace] = (array)$locations;
114 $this->namespaces[$namespace] = (array)$paths;
124 foreach ($classes as $prefix => $locations) {
125 $this->prefixes[$prefix] = (array)$locations;
137 $this->prefixes[$prefix] = (array)$paths;
147 $this->fallbacks[] = rtrim(
$path,
'/\\');
155 public function register() {
156 spl_autoload_register(array($this,
'loadClass'));
166 $file = $this->map->getPath(
$class);
167 if ($file && is_readable($file)) {
173 if ($file && is_readable($file)) {
174 $this->map->setPath(
$class, $file);
175 $this->map->setAltered(
true);
192 $pos = strrpos(
$class,
'\\');
193 if (
false !== $pos) {
195 $namespace = substr(
$class, 0, $pos);
196 $className = substr(
$class, $pos + 1);
197 $normalizedClass = str_replace(
'\\', DIRECTORY_SEPARATOR, $namespace)
198 . DIRECTORY_SEPARATOR
199 . str_replace(
'_', DIRECTORY_SEPARATOR, $className) .
'.php';
200 foreach ($this->namespaces as $ns => $dirs) {
201 if (0 !== strpos($namespace, $ns)) {
205 foreach ($dirs as $dir) {
206 $file = $dir . DIRECTORY_SEPARATOR . $normalizedClass;
207 if (is_file($file)) {
215 $normalizedClass = str_replace(
'_', DIRECTORY_SEPARATOR,
$class) .
'.php';
216 foreach ($this->prefixes as $prefix => $dirs) {
217 if (0 !== strpos(
$class, $prefix)) {
221 foreach ($dirs as $dir) {
222 $file = $dir . DIRECTORY_SEPARATOR . $normalizedClass;
223 if (is_file($file)) {
230 foreach ($this->fallbacks as $dir) {
231 $file = $dir . DIRECTORY_SEPARATOR . $normalizedClass;
232 if (is_file($file)) {
addFallback($path)
Add a directory to search if no registered directory is found.
registerNamespaces(array $namespaces)
Registers an array of namespaces.
if(isset($vars['id'])) $class
getClassMap()
Get the class map.
getNamespaces()
Gets the configured namespaces.
elgg require
Throw an error if the required package isn't present.
__construct(Elgg_ClassMap $map)
Constructor.
loadClass($class)
Loads the given class or interface, possibly updating the class map.
getPrefixes()
Gets the configured class prefixes.
findFile($class)
Finds the path to the file where the class is defined.
registerPrefix($prefix, $paths)
Registers a set of classes using the PEAR naming convention.
registerPrefixes(array $classes)
Registers an array of classes using the PEAR naming convention.
registerNamespace($namespace, $paths)
Registers a namespace.