當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Dir::listElements方法代碼示例

本文整理匯總了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);
 }
開發者ID:mbcraft,項目名稱:piol,代碼行數:62,代碼來源:Dir.php

示例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.");
     }
 }
開發者ID:mbcraft,項目名稱:piol,代碼行數:28,代碼來源:StorageFactory.php


注:本文中的Dir::listElements方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。