本文整理汇总了PHP中DirectoryIterator::getRealPath方法的典型用法代码示例。如果您正苦于以下问题:PHP DirectoryIterator::getRealPath方法的具体用法?PHP DirectoryIterator::getRealPath怎么用?PHP DirectoryIterator::getRealPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DirectoryIterator
的用法示例。
在下文中一共展示了DirectoryIterator::getRealPath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: patchValidatorXml
/**
* @param DirectoryIterator $fileInfo
*/
private function patchValidatorXml($fileInfo)
{
if ($fileInfo->isFile()) {
$filePath = $fileInfo->getRealPath();
$content = file_get_contents($filePath);
$contentMap = ['"DateInterval"' => '"\\Common\\CoreBundle\\Validator\\Constraints\\DateInterval"'];
$content = str_replace(array_keys($contentMap), array_values($contentMap), $content);
file_put_contents($filePath, $content);
}
}
示例2: delete
public static function delete($dir)
{
$dir = new DirectoryIterator($dir);
foreach ($dir as $file) {
if ($file->isDot()) {
continue;
} else {
if ($file->isDir()) {
self::delete($file->getRealPath());
} else {
if ($file->isFile()) {
unlink($file->getRealPath());
}
}
}
}
$dir->rewind();
rmdir($dir->getRealPath());
}
示例3: move_dir
protected static function move_dir($source, $destination, $overwrite)
{
if (!self::is_dir($source)) {
throw new Exception('Only directory must be passed to move_dir() as source');
}
if (!self::is_dir($destination)) {
throw new Exception('Only directory must be passed to move_dir() as destination');
}
$basename = pathinfo($source, PATHINFO_BASENAME);
if (!self::is_dir($destination . '/' . $basename)) {
if (!mkdir($destination . '/' . $basename, fileperms($source), TRUE)) {
throw new Exception('Can not create directory ' . $destination . '/' . $basename);
}
}
$dir = new DirectoryIterator($source);
while ($dir->valid()) {
if (!$dir->isDot()) {
self::move($dir->getRealPath(), $destination . '/' . $basename, $overwrite);
}
$dir->next();
}
self::delete_dir($source);
}
示例4: _delete_file
/**
* Deletes files recursively and returns FALSE on any errors
*
* // Delete a file or folder whilst retaining parent directory and ignore all errors
* $this->_delete_file($folder, TRUE, TRUE);
*
* @param SplFileInfo file
* @param boolean retain the parent directory
* @param boolean ignore_errors to prevent all exceptions interrupting exec
* @param boolean only expired files
* @return boolean
* @throws Kohana_Cache_Exception
*/
protected function _delete_file(SplFileInfo $file, $retain_parent_directory = FALSE, $ignore_errors = FALSE, $only_expired = FALSE)
{
// Allow graceful error handling
try {
// If is file
if ($file->isFile()) {
try {
// If only expired is not set
if ($only_expired === FALSE) {
// We want to delete the file
$delete = TRUE;
} else {
// Assess the file expiry to flag it for deletion
$json = $file->openFile('r')->current();
$data = json_decode($json);
$delete = $data->expiry < time();
}
// If the delete flag is set
if ($delete === TRUE) {
// Try to delete
unlink($file->getRealPath());
}
} catch (ErrorException $e) {
// Catch any delete file warnings
if ($e->getCode() === E_WARNING) {
throw new Kohana_Cache_Exception(__METHOD__ . ' failed to delete file : :file', array(':file' => $file->getRealPath()));
}
}
} else {
if ($file->isDir()) {
// Create new DirectoryIterator
$files = new DirectoryIterator($file->getPathname());
// Iterate over each entry
while ($files->valid()) {
// Extract the entry name
$name = $files->getFilename();
// If the name is not a dot
if ($name != '.' and $name != '..') {
// Create new file resource
$fp = new SplFileInfo($files->getRealPath());
// Delete the file
$this->_delete_file($fp);
}
// Move the file pointer on
$files->next();
}
// If set to retain parent directory, return now
if ($retain_parent_directory) {
return TRUE;
}
try {
// Remove the files iterator
// (fixes Windows PHP which has permission issues with open iterators)
unset($files);
// Try to remove the parent directory
return rmdir($file->getRealPath());
} catch (ErrorException $e) {
// Catch any delete directory warnings
if ($e->getCode() === E_WARNING) {
throw new Kohana_Cache_Exception(__METHOD__ . ' failed to delete directory : :directory', array(':directory' => $file->getRealPath()));
}
}
}
}
} catch (Exception $e) {
// If ignore_errors is on
if ($ignore_errors === TRUE) {
// Return
return FALSE;
}
// Throw exception
throw $e;
}
}
示例5: _delete_file
/**
* Deletes files recursively and returns FALSE on any errors
*
* // Delete a file or folder whilst retaining parent directory and ignore all errors
* $this->_delete_file($folder, TRUE, TRUE);
*
* @param SplFileInfo file
* @param boolean retain the parent directory
* @param boolean ignore_errors to prevent all exceptions interrupting exec
* @return boolean
* @throws Kohana_Cache_Exception
*/
protected function _delete_file(SplFileInfo $file, $retain_parent_directory = FALSE, $ignore_errors = FALSE)
{
// Allow graceful error handling
try {
// If is file
if ($file->isFile()) {
try {
// Try to delete
unlink($file->getRealPath());
} catch (ErrorException $e) {
// Catch any delete file warnings
if ($e->getCode() === E_WARNING) {
throw new Kohana_Cache_Exception(__METHOD__ . ' failed to delete file : :file', array(':file' => $file->getRealPath()));
}
}
} else {
if ($file->isDir()) {
// Create new DirectoryIterator
$files = new DirectoryIterator($file->getPathname());
// Iterate over each entry
while ($files->valid()) {
// Extract the entry name
$name = $files->getFilename();
// If the name is not a dot
if ($name != '.' and $name != '..') {
// Create new file resource
$fp = new SplFileInfo($files->getRealPath());
// Delete the file
$this->_delete_file($fp);
}
// Move the file pointer on
$files->next();
}
// If set to retain parent directory, return now
if ($retain_parent_directory) {
return TRUE;
}
try {
// Try to remove the parent directory
return rmdir($file->getRealPath());
} catch (ErrorException $e) {
// Catch any delete directory warnings
if ($e->getCode() === E_WARNING) {
throw new Kohana_Cache_Exception(__METHOD__ . ' failed to delete directory : :directory', array(':directory' => $file->getRealPath()));
}
}
}
}
} catch (Exception $e) {
// If ignore_errors is on
if ($ignore_errors === TRUE) {
// Return
return FALSE;
}
// Throw exception
throw $e;
}
}
示例6: _cleanDir
/**
* Try to clean directory using recorsion.
* No ensurance for wrong permissions
*/
private function _cleanDir(DirectoryIterator $dir)
{
X_Debug::i('Cleaning dir ' . $dir->getRealPath());
foreach ($dir as $entry) {
/* @var $entry DirectoryIterator */
if ($entry->isDot()) {
continue;
}
if ($entry->isFile()) {
@unlink($entry->getRealPath());
} elseif ($entry->isDir()) {
$this->_cleanDir($entry);
@rmdir($entry->getRealPath());
}
}
}
示例7: _getItemStats
/**
* Determine file/directory statistics for input item.
*
* @param DirectoryIterator $item Item passed from a DirectoryIterator
* @return array Listing with stats
*/
private static function _getItemStats(DirectoryIterator $item)
{
$list = array();
// add filename
$list['name'] = (string) $item;
// add directory/file type
$list['type'] = $item->getType();
// add modification time
$list['modified'] = date('Y-m-d H:i:s', $item->getMTime());
// get permissions
$list['permissions'] = $item->getPerms();
// is writable?
$list['writable'] = $item->isWritable() ? 1 : 0;
// add path
$list['path'] = $item->getPathName();
$list['real_path'] = $item->getRealPath();
// add size
$list['size'] = Fari_Format::bytes($item->getSize());
return $list;
}
示例8: className
/**
* Convert a file to class name of the test case class
*
* @param DirectoryIterator $file test case file
* @return string test case class name
*/
private function className($file)
{
return str_replace('/', '_', str_replace(array($this->root, '.php'), '', $file->getRealPath()));
}
示例9: resolve
protected function resolve($groups, $input)
{
$resolved = array();
if (strpos($input, '@') === false) {
return array($this->webdir . '/' . $input);
}
$cleaned = str_replace('@', '', $input);
if (isset($groups[$cleaned])) {
foreach ($groups[$cleaned]['inputs'] as $candidate) {
$resolved = array_merge($resolved, $this->resolve($groups, $candidate));
}
return $resolved;
}
if (($star = strpos($input, '*')) === false) {
return array($this->kernel->locateResource($input));
} else {
$dir = $this->kernel->locateResource(substr($input, 0, $star));
$it = new \DirectoryIterator($dir);
foreach ($it as $file) {
if ($file->isFile()) {
array_push($resolved, $it->getRealPath());
}
}
}
return $resolved;
}