本文整理汇总了PHP中Dir::listElements方法的典型用法代码示例。如果您正苦于以下问题:PHP Dir::listElements方法的具体用法?PHP Dir::listElements怎么用?PHP Dir::listElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dir
的用法示例。
在下文中一共展示了Dir::listElements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listElements
/**
*
* List all the elements inside this directory, excluding the ones that matches at least one of the specified patterns.
*
* @param int $mode Only the following values, specified as constants inside this class, can be used :
* MODE_FILES_ONLY, MODE_FOLDERS_ONLY, MODE_FILES_AND_FOLDERS.
* @param mixed $myExcludes an array of regexp patterns used to match excluded elements against their full name.
* @param bool $deep if true searches inside all the contained folders, otherwise only in this one.
* @return array an array of two arrays, with all the files that matched and all the directories that matched,
* as a \Mbcraft\Piol\File and \Mbcraft\Piol\Dir instances.
*
* @api
*/
public function listElements($mode = self::MODE_FILES_AND_FOLDERS, $myExcludes = self::DEFAULT_EXCLUDES, $deep = false)
{
$excludesSet = false;
if (!$excludesSet && $myExcludes === self::NO_HIDDEN_FILES) {
$excludesSet = true;
$excludes = array(self::NO_HIDDEN_FILES_PATTERN);
}
if (!$excludesSet && $myExcludes === self::SHOW_HIDDEN_FILES) {
$excludesSet = true;
$excludes = array(self::SHOW_HIDDEN_FILES_PATTERN);
}
if (!isset($excludes) || !$excludesSet) {
$excludes = $myExcludes;
}
$all_results = scandir($this->__full_path);
$all_files = array();
$all_dirs = array();
foreach ($all_results as $element) {
if ($element == "." || $element == "..") {
//always skip . and ..
continue;
}
$skip = false;
foreach ($excludes as $pt) {
if (preg_match($pt, $element)) {
$skip = true;
}
}
$partial_path = $this->__path . $element;
//è da saltare?
if (!$skip) {
if (($mode & self::MODE_FOLDERS_ONLY) === self::MODE_FOLDERS_ONLY && FileSystemUtils::isDir($partial_path)) {
$all_dirs[] = new Dir($partial_path);
} else {
if (($mode & self::MODE_FILES_ONLY) === self::MODE_FILES_ONLY && FileSystemUtils::isFile($partial_path)) {
$all_files[] = new File($partial_path);
continue;
}
}
}
if ($deep && FileSystemUtils::isDir($partial_path)) {
$d = new Dir($partial_path);
$partial_results = $d->listElements($mode, $myExcludes, true);
$all_files = array_merge($all_files, $partial_results[0]);
$all_dirs = array_merge($all_dirs, $partial_results[1]);
}
}
return array($all_files, $all_dirs);
}
示例2: getProtectedStorage
/**
*
* Returns the verified storage folder. If it does not exists, it is created.
*
* @return \Mbcraft\Piol\Dir the directory, as a \Mbcraft\Piol\Dir instance, pointing to the verified storage.
* @throws \Mbcraft\Piol\IOException if the storage root does not exists or is not valid.
*
* @api
*/
public static function getProtectedStorage()
{
$protected_storage_dir = new Dir(self::$storage_root);
if (!$protected_storage_dir->exists()) {
throw new IOException("The storage folder does not exist : " . self::$storage_root);
}
if (!$protected_storage_dir->isWritable()) {
throw new IOException("The storage folder is not readable and writable : " . self::$storage_root);
}
$results = $protected_storage_dir->listElements();
if (count($results[0]) == 0 && count($results[1]) <= 1) {
if ($protected_storage_dir->isEmpty()) {
$protected_storage_dir->newRandomSubdir();
}
return $protected_storage_dir->getUniqueSubdir();
} else {
throw new IOException("The storage root folder is invalid : it must contain at most just one folder.");
}
}