Esempio n. 1
0
 /**
  * @return array(IFile) The list of the files contained in the "file" itself if this
  * one is a directory, or the files contained in the parent directory if this one is
  * a normal file
  */
 public function listFiles($pattern = '*', $flags = AdvancedPathLib::GLOB_NORMAL)
 {
     if ($this->realFile === null) {
         throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path);
     }
     if ($this->isLink() && $this->getLinkTarget()->isDirectory()) {
         return $this->getLinkTarget()->listFiles($pattern, $flags);
     }
     if (!$this->isDirectory()) {
         throw new EyeBadMethodCallException('Cannot list files: ' . $this->getPath() . ' is not a directory.');
     }
     $this->checkReadPermission();
     $myVirtualPath = $this->getAbsolutePath();
     $realFiles = $this->realFile->listFiles($pattern, $flags);
     $return = array();
     $params = array();
     $thisClass = get_class($this);
     foreach ($realFiles as $realFile) {
         $return[] = FSI::getFile($myVirtualPath . '/' . $realFile->getName(), $params);
     }
     //notify listeners
     $this->fireEvent('fileRead', new FileEvent($this));
     return $return;
 }
 /**
  * TODO: a good algorithm with a stack would be much better here...
  * 
  * @param IFile $root
  * @param IFile $leaf
  * @param int $depth
  * @return mixed An array of serialized IFiles (see self::toArray),
  *         or FALSE if the maximum depth has been reached.
  */
 private static function getFilesAsTree_private(IFile $root, IFile $leaf = null, $depth)
 {
     if ($depth < 0) {
         if ($leaf === null || stripos($leaf->getAbsolutePath(), $root->getAbsolutePath()) !== 0) {
             //We're not in the branch leading to the specified leaf: stop recursion here
             return false;
         }
     }
     $folders = array();
     foreach ($root->listFiles('*', AdvancedPathLib::GLOB_ONLY_DIR) as $folder) {
         try {
             $subFolders = self::getFilesAsTree_private($folder, $leaf, $depth - 1);
         } catch (Exception $e) {
             $subFolders = array(self::toArray(false));
         }
         $folder = self::toArray($folder);
         $folder['subFolders'] = $subFolders;
         $folders[] = $folder;
     }
     return $folders;
 }