Inheritance: implements Jarves\File\FileInfoInterface, use trait FileInfoTrait
Example #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);
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function getFiles($path)
 {
     $path = $this->getFullPath($path);
     $path = str_replace('..', '', $path);
     if (!file_exists($path)) {
         throw new FileNotFoundException(sprintf('File `%s` does not exists.', $path));
     }
     if (!is_dir($path)) {
         throw new NotADirectoryException(sprintf('File `%s` is not a directory.', $path));
     }
     if (substr($path, -1) != '/') {
         $path .= '/';
     }
     $h = @opendir($path);
     if (!$h) {
         throw new \Exception(sprintf('Can not open `%s`. Probably no permissions.', $path));
     }
     $items = array();
     while ($file = readdir($h)) {
         $fileInfo = new FileInfo();
         if ($file == '.' || $file == '..') {
             continue;
         }
         $file = $path . $file;
         $fileInfo->setPath(substr($file, strlen($this->getRoot()) - 1));
         $fileInfo->setType(is_dir($file) ? FileInfo::DIR : FileInfo::FILE);
         if (!is_link($file)) {
             $fileInfo->setCreatedTime(filectime($file));
             $fileInfo->setModifiedTime(filemtime($file));
             if (is_file($file)) {
                 $fileInfo->setSize(filesize($file));
             }
         }
         $items[] = $fileInfo;
     }
     return $items;
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function getFile($path)
 {
     $file = new \Jarves\File\FileInfo();
     $file->setPath($path ?: '/');
     $path = $this->getFullPath($path ?: '/');
     if (!file_exists($path)) {
         throw new FileNotFoundException(sprintf('File `%s` does not exists.', $path));
     }
     if (!is_readable($path)) {
         throw new FileNotFoundException(sprintf('File `%s` is not readable.', $path));
     }
     $file->setType(is_dir($path) ? 'dir' : 'file');
     $file->setCreatedTime(filectime($path));
     $file->setModifiedTime(filectime($path));
     $file->setSize(filesize($path));
     return $file;
 }
Example #4
0
 public function checkFileValues(FileInfo $file, File $databaseFile)
 {
     if ($file->getSize() != $databaseFile->getSize()) {
         $databaseFile->setSize($file->getSize());
     }
     if ($file->getHash() != $databaseFile->getHash()) {
         $databaseFile->setHash($file->getHash());
     }
     if ($file->getType() != $databaseFile->getType()) {
         $databaseFile->setType($file->getType());
     }
     if ($file->getCreatedTime() != $databaseFile->getCreatedTime()) {
         $databaseFile->setCreatedTime($file->getCreatedTime());
     }
     if ($file->getModifiedTime() != $databaseFile->getModifiedTime()) {
         $databaseFile->setModifiedTime($file->getModifiedTime());
     }
 }