52 protected $prefixes = array();
53 protected $fallbacks = array();
93 return $this->prefixes;
103 foreach ($namespaces as $namespace => $locations) {
104 $this->namespaces[$namespace] = (array)$locations;
116 $this->namespaces[$namespace] = (array)
$paths;
126 foreach ($classes as $prefix => $locations) {
127 $this->prefixes[$prefix] = (array)$locations;
139 $this->prefixes[$prefix] = (array)
$paths;
149 $this->fallbacks[] = rtrim(
$path,
'/\\');
157 public function register() {
158 spl_autoload_register(array($this,
'loadClass'));
177 $this->map->setAltered(
true);
194 $pos = strrpos(
$class,
'\\');
195 if (
false !== $pos) {
197 $namespace = substr(
$class, 0, $pos);
198 $className = substr(
$class, $pos + 1);
199 $normalizedClass = str_replace(
'\\', DIRECTORY_SEPARATOR, $namespace)
200 . DIRECTORY_SEPARATOR
201 . str_replace(
'_', DIRECTORY_SEPARATOR, $className) .
'.php';
202 foreach ($this->namespaces as $ns => $dirs) {
203 if (0 !== strpos($namespace, $ns)) {
207 foreach ($dirs as $dir) {
208 $file = $dir . DIRECTORY_SEPARATOR . $normalizedClass;
209 if (is_file(
$file)) {
217 $normalizedClass = str_replace(
'_', DIRECTORY_SEPARATOR,
$class) .
'.php';
218 foreach ($this->prefixes as $prefix => $dirs) {
219 if (0 !== strpos(
$class, $prefix)) {
223 foreach ($dirs as $dir) {
224 $file = $dir . DIRECTORY_SEPARATOR . $normalizedClass;
225 if (is_file(
$file)) {
232 foreach ($this->fallbacks as $dir) {
233 $file = $dir . DIRECTORY_SEPARATOR . $normalizedClass;
234 if (is_file(
$file)) {
registerNamespaces(array $namespaces)
Registers an array of namespaces.
if(!array_key_exists($filename, $text_files)) $file
__construct(\Elgg\ClassMap $map)
Constructor.
$paths
We handle here two possible locations of composer-generated autoload file.
loadClass($class)
Loads the given class or interface, possibly updating the class map.
addFallback($path)
Add a directory to search if no registered directory is found.
registerNamespace($namespace, $paths)
Registers a namespace.
getNamespaces()
Gets the configured namespaces.
elgg require
Throw an error if the required package isn't present.
registerPrefix($prefix, $paths)
Registers a set of classes using the PEAR naming convention.
findFile($class)
Finds the path to the file where the class is defined.
registerPrefixes(array $classes)
Registers an array of classes using the PEAR naming convention.
getPrefixes()
Gets the configured class prefixes.
getClassMap()
Get the class map.