/** * clear the invalid cache * * @since 3.0.0 * * @param integer $lifetime lifetime of the bundle * * @return Cache */ public function clearInvalid($lifetime = 3600) { $cacheDirectory = new Directory(); $cacheDirectory->init($this->_directory); $cacheDirectoryArray = $cacheDirectory->getArray(); /* process cache */ foreach ($cacheDirectoryArray as $value) { $path = $this->_directory . '/' . $value; if (is_file($path) && !$this->_validateFile($path, $lifetime)) { $cacheDirectory->remove($value); } } return $this; }
/** * Remove directory * * @param boolean $recursive (empty directory contents and remove) * @return boolean */ public function remove($recursive = false) { if (!$this->__isDir()) { return false; } if (!$recursive) { if (!@rmdir($this->_path)) { $this->error = parent::_getLastError(); return false; } return true; } // recursive remove foreach ($this->read(false, true) as $asset) { if ($asset['type'] === 'dir') { $dir = new Directory($this->_path . $asset['name'], false); if (!$dir->remove(true)) { $this->error = 'Failed to remove subdirectory \'' . $dir->getPath() . '\' (' . $dir->error . '), try elevated chmod'; return false; } } else { $file = new File($this->_path . $asset['name'], false); if (!$file->remove()) { $this->error = 'Failed to remove file \'' . $file->getPath() . '\' (' . $file->error . '), try elevated chmod'; return false; } } } return $this->remove(); // finally remove base directory }
<?php /* |-------------------------------------------------------------------------- | Removing an object. |-------------------------------------------------------------------------- | | Removing an object from it's parent directory resolves in | an invalid object since it has no longer a parent. We should | be able to unset all be we cannot. */ $root = new Root(); $application = new Directory('application', $root); $dashboard = new File('dashboard.php', $application); $application->remove($dashboard); /** * Speculation * ------------------------------------------------------------------------- */ /** * What do we need to do with $dashboard's parent here? It should not be null * because a file always has a directory parent. The best solution is to delete it * completely (removing all references) but we do not have that possibility. */ /** * Solution * ------------------------------------------------------------------------- */ /** * Solved, Leaving the object intact is no problem at all, just don't remove the parent. * The object can still be used to do whatever the developper wants with it, he just needs