51 protected $prefixes = [];
52 protected $fallbacks = [];
67 protected $missing = [];
75 $this->map = new \Elgg\ClassMap();
105 return $this->prefixes;
115 foreach ($namespaces as $namespace => $locations) {
116 $this->namespaces[$namespace] = (array) $locations;
128 $this->namespaces[$namespace] = (array)
$paths;
138 foreach ($classes as $prefix => $locations) {
139 $this->prefixes[$prefix] = (array) $locations;
151 $this->prefixes[$prefix] = (array)
$paths;
169 public function register() {
170 spl_autoload_register([$this,
'loadClass']);
181 if (isset($this->missing[
$class])) {
185 $file = $this->map->getPath($class);
186 if (!empty($file) && (!$this->config->class_loader_verify_file_existence || is_file($file))) {
191 $file = $this->findFile($class);
193 $this->map->setPath($class, $file);
194 $this->map->setAltered(
true);
199 $this->missing[
$class] =
true;
215 if (
false !== $pos) {
219 $normalizedClass =
str_replace(
'\\', DIRECTORY_SEPARATOR, $namespace)
220 . DIRECTORY_SEPARATOR
221 .
str_replace(
'_', DIRECTORY_SEPARATOR, $className) .
'.php';
222 foreach ($this->namespaces as $ns => $dirs) {
223 if (0 !==
strpos($namespace, $ns)) {
227 foreach ($dirs as $dir) {
228 $file = $dir . DIRECTORY_SEPARATOR . $normalizedClass;
229 if (is_file($file)) {
237 foreach ($this->prefixes as $prefix => $dirs) {
242 foreach ($dirs as $dir) {
243 $file = $dir . DIRECTORY_SEPARATOR . $normalizedClass;
244 if (is_file($file)) {
251 foreach ($this->fallbacks as $dir) {
252 $file = $dir . DIRECTORY_SEPARATOR . $normalizedClass;
253 if (is_file($file)) {
registerNamespaces(array $namespaces)
Registers an array of namespaces.
$paths
We handle here two possible locations of composer-generated autoload file.
A class/interface/trait autoloader for PHP.
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.
$config
Advanced site settings, debugging section.
registerNamespace($namespace, $paths)
Registers a namespace.
getNamespaces()
Gets the configured namespaces.
registerPrefix($prefix, $paths)
Registers a set of classes using the PEAR naming convention.
elgg require
Throw an error if the required package isn't present.
__construct(Config $config)
Constructor.
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.