13 const FILENAME =
'autoload_data.php';
14 const KEY_CLASSES =
'classes';
15 const KEY_SCANNED_DIRS =
'scannedDirs';
25 protected $scannedDirs = array();
30 protected $altered =
false;
35 protected $storage = null;
57 if (!in_array($dir, $this->scannedDirs)) {
58 $map = $this->
loader->getClassMap();
59 $map->mergeMap($this->scanClassesDir($dir));
60 $this->scannedDirs[] = $dir;
61 $this->altered =
true;
63 $this->
loader->addFallback($dir);
77 $dir = new \DirectoryIterator($dir);
80 foreach ($dir as $file) {
82 if (!$file->isFile() || !$file->isReadable()) {
86 $path = $file->getRealPath();
88 if (pathinfo(
$path, PATHINFO_EXTENSION) !==
'php') {
92 $class = $file->getBasename(
'.php');
116 if ($this->storage) {
117 $map = $this->
loader->getClassMap();
118 if ($this->altered || $map->getAltered()) {
119 $spec[self::KEY_CLASSES] = $map->getMap();
120 $spec[self::KEY_SCANNED_DIRS] = $this->scannedDirs;
121 $this->storage->save(self::FILENAME, serialize($spec));
133 $spec = $this->getSpec();
137 $this->
loader->getClassMap()
138 ->setMap($spec[self::KEY_CLASSES])
140 $this->scannedDirs = $spec[self::KEY_SCANNED_DIRS];
143 $this->altered =
true;
154 if ($this->storage) {
155 $serialization = $this->storage->load(self::FILENAME);
156 if ($serialization) {
157 $spec = unserialize($serialization);
158 if (isset($spec[self::KEY_CLASSES])) {
172 if ($this->storage) {
173 $this->storage->delete(self::FILENAME);
194 $this->storage = $storage;
saveCache()
If necessary, save necessary state details.
loadCache()
Set the state of the manager from the cache.
scanClassesDir($dir)
Scan (non-recursively) a /classes directory for PHP files to map directly to classes.
if(isset($vars['id'])) $class
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.
setClassPath($class, $path)
Register the location of a class on the class map.
getSpec()
Some method that does something.
deleteCache()
Delete the cache file.
setStorage(\ElggCache $storage)
Set the cache storage object.