getFiles() public method

Same as in getFile() but in a list. array( array( path => path to the file/folder for usage in the administration and modules. Not the full http path. No trailing slash! name => basename(path) ctime => as unix timestamps mtime => as unix timestamps size => filesize in bytes (not for folders) type => 'file' | 'dir' mount => boolean (if the folder is a mount point) ) )
public getFiles ( string $path ) : File[]
$path string
return Jarves\Model\File[]
示例#1
0
 /**
  * @param string $path
  * @return \Jarves\Model\File[]
  */
 public function getFiles($path)
 {
     $items = parent::getFiles($path);
     $fs = $this->getAdapter($path);
     if ($fs->getMountPath()) {
         foreach ($items as &$file) {
             $file->setMountPoint($fs->getMountPath());
         }
     }
     if ('/' === $path) {
         foreach ($this->jarvesConfig->getSystemConfig()->getMountPoints() as $mountPoint) {
             $fileInfo = new FileInfo();
             $fileInfo->setPath('/' . $mountPoint->getPath());
             //                $fileInfo->setIcon($mountPoint->getIcon());
             $fileInfo->setType(FileInfo::DIR);
             $fileInfo->setMountPoint(true);
             array_unshift($items, $fileInfo);
         }
     }
     return $this->wrap($items);
 }
示例#2
0
 /**
  * {@inheritDoc}
  */
 public function getBranch($pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null)
 {
     $result = null;
     $path = $pk['path'];
     if ($depth === null) {
         $depth = 1;
     }
     if ($path) {
         $path = '@' . trim($path, '/@');
         $path = str_replace(':', '/', $path);
     }
     $c = 0;
     $offset = $options['offset'];
     $limit = $options['limit'];
     $result = array();
     if (!$path) {
         $result = array();
         $bundles = array_keys($this->jarves->getBundles());
         foreach ($bundles as $bundleName) {
             $directory = $this->jarves->resolvePath('@' . $bundleName, 'Resources/views', true);
             if (!$this->localFilesystem->has($directory)) {
                 continue;
             }
             $file = $this->localFilesystem->getFile($directory);
             if (!$file) {
                 $result[] = $directory;
                 continue;
             }
             $file = $file->toArray();
             $file['name'] = $bundleName;
             $file['path'] = $bundleName;
             if ($offset && $offset > $c) {
                 continue;
             }
             if ($limit && $limit < $c) {
                 continue;
             }
             if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $file)) {
                 $result[] = $directory;
                 continue;
             }
             $c++;
             if ($depth > 0) {
                 $children = self::getBranch(array('path' => $bundleName), $condition, $depth - 1);
                 $file['_childrenCount'] = count($children);
                 if ($depth > 1 && $file['type'] == 'dir') {
                     $file['_children'] = $children;
                 }
             }
         }
     } else {
         if (!($bundleName = $this->jarves->getBundleFromPath($path))) {
             return [];
         }
         $directory = $this->jarves->resolvePath($path, 'Resources/views', true) . '/';
         if (!$this->localFilesystem->has($directory)) {
             return [];
         }
         $files = $this->localFilesystem->getFiles($directory);
         foreach ($files as $file) {
             $item = $file->toArray();
             if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $item, 'jarves/file')) {
                 continue;
             }
             $c++;
             if ($offset && $offset >= $c) {
                 continue;
             }
             if ($limit && $limit < $c) {
                 continue;
             }
             $item = array('name' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory)), 'path' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory)));
             if ($file->isDir()) {
                 $children = self::getBranch(array('path' => $item['path']), $condition, $depth - 1);
                 foreach ($children as $child) {
                     //                        $child['name'] = $item['name'] . '/' . $child['name'];
                     $result[] = $child;
                 }
             }
             if ($file->isFile()) {
                 $result[] = $item;
             }
         }
     }
     return $result;
 }