17 const FILENAME =
'autoload_data.php';
18 const KEY_CLASSES =
'classes';
19 const KEY_SCANNED_DIRS =
'scannedDirs';
29 protected $scannedDirs = [];
34 protected $altered =
false;
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;
62 $this->loader->addFallback($dir);
80 $dir = new \DirectoryIterator($dir);
83 foreach ($dir as
$file) {
85 if (!$file->isFile() || !$file->isReadable()) {
89 $path = $file->getRealPath();
91 if (pathinfo(
$path, PATHINFO_EXTENSION) !==
'php') {
95 $class = $file->getBasename(
'.php');
111 $map = $this->loader->getClassMap();
112 if ($this->altered || $map->getAltered()) {
114 self::KEY_CLASSES => $map->getMap(),
115 self::KEY_SCANNED_DIRS => $this->scannedDirs,
118 $this->cache->save(self::FILENAME, $spec);
130 $cache = $this->getCacheFileContents();
134 $this->loader->getClassMap()
135 ->setMap($cache[self::KEY_CLASSES])
137 $this->scannedDirs = $cache[self::KEY_SCANNED_DIRS];
140 $this->altered =
true;
154 $spec = $this->cache->load(self::FILENAME);
155 if (isset($spec[self::KEY_CLASSES])) {
169 $this->cache->delete(self::FILENAME);
172 $this->loader->getClassMap()->setMap([])->setAltered(
true);
173 $this->scannedDirs = [];
174 $this->altered =
true;
saveCache()
If necessary, save necessary state details.
if(!array_key_exists($filename, $text_files)) $file
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 ...
getLoader()
Get the class loader.
__construct(\Elgg\ClassLoader $loader)
Constructor.
trait Cacheable
Utility trait for injecting cache.
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.