示例#1
0
文件: File.php 项目: mbcraft/piol
 /**
  *
  * Ensures that a File object is used always returning a \Piol\File instance.
  *
  * @param \Mbcraft\Piol\File|string $file_or_path The string or path pointing to the file system file.
  * @return \Mbcraft\Piol\File The \Piol\File instance.
  * @throws \Mbcraft\Piol\IOException if the specified parameter is not a valid path or \Piol\File instance.
  *
  * @api
  */
 public static function asFile($file_or_path)
 {
     if ($file_or_path instanceof File) {
         return $file_or_path;
     }
     if (FileSystemUtils::isFile($file_or_path)) {
         return new File($file_or_path);
     }
     throw new IOException("The specified parameter is not a valid file path or \\Piol\\File instance : " . $file_or_path);
 }
示例#2
0
 function findFiles($myIncludes)
 {
     if (is_array($myIncludes)) {
         $includes = $myIncludes;
     } else {
         $includes = array($myIncludes);
     }
     $all_results = scandir($this->__full_path);
     $all_dirs = array();
     $all_files = array();
     foreach ($all_results as $element) {
         $include = false;
         $done = false;
         foreach ($includes as $pt) {
             if (!$done && preg_match($pt, $element)) {
                 $include = true;
                 $done = true;
             }
         }
         //è da saltare?
         if ($include) {
             if ($this->isDir()) {
                 $partial_path = $this->__path . $element;
             }
             if (FileSystemUtils::isDir($this->__path . $element)) {
                 $all_dirs[] = new Dir($partial_path);
             } else {
                 if (FileSystemUtils::isFile($this->__path . DS . $element)) {
                     $all_files[] = new File($partial_path);
                 }
             }
         }
     }
     return array_merge($all_dirs, $all_files);
 }
示例#3
0
文件: Dir.php 项目: mbcraft/piol
 /**
  * 
  * Finds all matching elements inside this folder.
  * 
  * @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 array $myIncludes an array of regexp pattern of the elements to match using their full names.
  * @param boolean $deep if true the search is done recursively on all subfolders, otherwise only inside 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 findMatchingElements($mode, $myIncludes, $deep = false)
 {
     if (is_array($myIncludes)) {
         $includes = $myIncludes;
     } else {
         $includes = array($myIncludes);
     }
     $all_results = scandir($this->__full_path);
     $all_files = array();
     $all_dirs = array();
     foreach ($all_results as $element) {
         if ($element == "." || $element == "..") {
             //always skip . and ..
             continue;
         }
         $include = false;
         $done = false;
         foreach ($includes as $pt) {
             if (!$done && preg_match($pt, $element)) {
                 $include = true;
                 $done = true;
             }
         }
         $partial_path = $this->__path . $element;
         //è da aggiungere?
         if ($include) {
             if (($mode & self::MODE_FILES_ONLY) === self::MODE_FILES_ONLY && FileSystemUtils::isFile($partial_path)) {
                 $all_files[] = new File($partial_path);
                 continue;
             }
             if (($mode & self::MODE_FOLDERS_ONLY) === self::MODE_FOLDERS_ONLY && FileSystemUtils::isDir($partial_path)) {
                 $all_dirs[] = new Dir($partial_path);
             }
         }
         if ($deep && FileSystemUtils::isDir($partial_path)) {
             $d = new Dir($partial_path);
             $partial_results = $d->findMatchingElements($mode, $myIncludes, 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);
 }
示例#4
0
 function testIsFile()
 {
     $this->assertTrue(FileSystemUtils::isFile("/" . FRAMEWORK_CORE_PATH . "tests/io/file_system_utils_test.php"));
     $this->assertTrue(FileSystemUtils::isFile("/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/.hidden_file"));
 }