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) {
62 if (!in_array($dir, $this->scannedDirs)) {
63 $map = $this->loader->getClassMap();
64 $map->mergeMap($this->scanClassesDir($dir));
65 $this->scannedDirs[] = $dir;
66 $this->altered =
true;
68 $this->loader->addFallback($dir);
86 $dir = new \DirectoryIterator($dir);
89 foreach ($dir as $file) {
91 if (!$file->isFile() || !$file->isReadable()) {
95 $path = $file->getRealPath();
97 if (pathinfo(
$path, PATHINFO_EXTENSION) !==
'php') {
101 $class = $file->getBasename(
'.php');
117 $map = $this->loader->getClassMap();
119 if ($this->altered || $map->getAltered()) {
121 $scanned_dirs = $this->scannedDirs;
123 if (empty(
$classes) && empty($scanned_dirs)) {
128 $this->cache->save(self::FILENAME, [
130 self::KEY_SCANNED_DIRS => $scanned_dirs,
143 $cache = $this->getCacheFileContents();
147 $this->loader->getClassMap()
148 ->setMap($cache[self::KEY_CLASSES])
150 $this->scannedDirs = $cache[self::KEY_SCANNED_DIRS];
153 $this->altered =
true;
167 $spec = $this->cache->load(self::FILENAME);
168 if (isset($spec[self::KEY_CLASSES])) {
182 $this->cache->delete(self::FILENAME);
185 $this->loader->getClassMap()->setMap([])->setAltered(
true);
186 $this->scannedDirs = [];
187 $this->altered =
true;
198 return $this->loader;
saveCache()
If necessary, save necessary state details.
setCache(ElggCache $cache)
Set cache.
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 ...
__construct(\Elgg\ClassLoader $loader,\Elgg\Config $config,\ElggCache $cache)
Constructor.
$config
Advanced site settings, debugging section.
getLoader()
Get the class loader.
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.
trait Cacheable
Utility trait for injecting cache.