16 const FILENAME =
'autoload_data.php';
17 const KEY_CLASSES =
'classes';
18 const KEY_SCANNED_DIRS =
'scannedDirs';
23 protected array $scannedDirs = [];
28 protected bool $altered =
false;
38 if (!$config->AutoloaderManager_skip_storage) {
56 if (!in_array($dir, $this->scannedDirs)) {
57 $map = $this->loader->getClassMap();
58 $map->mergeMap($this->scanClassesDir($dir));
59 $this->scannedDirs[] = $dir;
60 $this->altered =
true;
63 $this->loader->addFallback($dir);
82 $dir = new \DirectoryIterator($dir);
85 foreach ($dir as $file) {
87 if (!$file->isFile() || !$file->isReadable()) {
91 $path = $file->getRealPath();
93 if (pathinfo(
$path, PATHINFO_EXTENSION) !==
'php') {
97 $class = $file->getBasename(
'.php');
114 $map = $this->loader->getClassMap();
116 if ($this->altered || $map->getAltered()) {
118 $scanned_dirs = $this->scannedDirs;
120 if (empty(
$classes) && empty($scanned_dirs)) {
125 $this->cache->save(self::FILENAME, [
127 self::KEY_SCANNED_DIRS => $scanned_dirs,
140 $cache = $this->getCacheFileContents();
144 $this->loader->getClassMap()
145 ->setMap($cache[self::KEY_CLASSES])
147 $this->scannedDirs = $cache[self::KEY_SCANNED_DIRS];
151 $this->altered =
true;
165 $spec = $this->cache->load(self::FILENAME);
166 if (isset($spec[self::KEY_CLASSES])) {
179 $this->cache?->delete(self::FILENAME);
180 $this->loader->getClassMap()->setMap([])->setAltered(
true);
181 $this->scannedDirs = [];
182 $this->altered =
true;
193 return $this->loader;
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.
__construct(protected\Elgg\ClassLoader $loader,\Elgg\Config $config,\Elgg\Cache\BaseCache $cache)
Constructor.
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.