16 const FILENAME =
'autoload_data.php';
17 const KEY_CLASSES =
'classes';
18 const KEY_SCANNED_DIRS =
'scannedDirs';
28 protected $scannedDirs = [];
33 protected $altered =
false;
43 $this->loader = $loader;
45 if (!$config->AutoloaderManager_skip_storage) {
63 if (!in_array($dir, $this->scannedDirs)) {
64 $map = $this->loader->getClassMap();
65 $map->mergeMap($this->scanClassesDir($dir));
66 $this->scannedDirs[] = $dir;
67 $this->altered =
true;
70 $this->loader->addFallback($dir);
89 $dir = new \DirectoryIterator($dir);
92 foreach ($dir as $file) {
94 if (!$file->isFile() || !$file->isReadable()) {
98 $path = $file->getRealPath();
100 if (pathinfo(
$path, PATHINFO_EXTENSION) !==
'php') {
104 $class = $file->getBasename(
'.php');
121 $map = $this->loader->getClassMap();
123 if ($this->altered || $map->getAltered()) {
125 $scanned_dirs = $this->scannedDirs;
127 if (empty(
$classes) && empty($scanned_dirs)) {
132 $this->cache->save(self::FILENAME, [
134 self::KEY_SCANNED_DIRS => $scanned_dirs,
147 $cache = $this->getCacheFileContents();
151 $this->loader->getClassMap()
152 ->setMap($cache[self::KEY_CLASSES])
154 $this->scannedDirs = $cache[self::KEY_SCANNED_DIRS];
158 $this->altered =
true;
172 $spec = $this->cache->load(self::FILENAME);
173 if (isset($spec[self::KEY_CLASSES])) {
186 $this->cache?->delete(self::FILENAME);
187 $this->loader->getClassMap()->setMap([])->setAltered(
true);
188 $this->scannedDirs = [];
189 $this->altered =
true;
200 return $this->loader;
__construct(\Elgg\ClassLoader $loader,\Elgg\Config $config,\Elgg\Cache\BaseCache $cache)
Constructor.
saveCache()
If necessary, save necessary state details.
loadCache()
Set the state of the manager from the cache.
A class/interface/trait autoloader for PHP.
scanClassesDir($dir)
Scan (non-recursively) a /classes directory for PHP files to map directly to classes.
addClasses($dir)
Add classes found in this directory to the class map and allow classes in subdirectories to be found ...
$config
Advanced site settings, debugging section.
getLoader()
Get the class loader.
The Elgg cache base class.
Manages core autoloading and caching of class maps.
getCacheFileContents()
Tries to read the contents of the cache file and if valid returns the content.
deleteCache()
Delete the cache file.
setCache(BaseCache $cache)
Set cache.
trait Cacheable
Utility trait for injecting cache.