Ejemplo n.º 1
0
 /**
  * Set unique name for folder
  *
  * @param Folder $folder
  * @return Folder
  */
 public function folder(Folder $folder)
 {
     if (FileSystem::exists($folder->fullPath())) {
         $original_name = $folder->name();
         $folder->setName($original_name . '-1');
         for ($i = 2; FileSystem::exists($folder->fullPath()); $i++) {
             $folder->setName($original_name . '-' . $i);
         }
     }
     return $folder;
 }
Ejemplo n.º 2
0
 /**
  * @param $path
  *
  * @return array
  *
  * @throws FileManagerException
  */
 public function get()
 {
     $this->sys_path = $this->getPath()->path();
     if (!FileSystem::exists($this->sys_path)) {
         throw new FileManagerException($this, 'err_folder_not_found');
     }
     $this->readDir()->map(function ($item_name) {
         $this->content->push($this->readItem($item_name));
     });
     return $this->content->toArray();
 }
Ejemplo n.º 3
0
 /**
  * Change path
  *
  * @param string $path
  * @return $this
  * @throws FileManagerException
  */
 public function change($path)
 {
     $this->relative_path = trim(FileSystem::canonical($path), '/');
     $this->sys_path = FileSystem::canonical(FileSystem::join($this->sys_root_dir, $this->relative_path));
     if (!FileSystem::exists($this->sys_path)) {
         throw new FileManagerException($this, 'err_path_not_exist', ['path' => $this->relative_path]);
     }
     if (FileSystem::type($this->sys_path) !== 'dir') {
         throw new FileManagerException($this, 'err_path_not_dir', ['path' => $this->relative_path]);
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Get file content
  *
  * @param string|null $size
  * @return string
  * @throws FileManagerException
  */
 public function content($size = null)
 {
     $file_path = $this->fullPath();
     if ($size and array_key_exists($size, $this->thumb->getSizes())) {
         $thumb_path = $this->getPath()->thumbPath($size, $this);
         if (FileSystem::exists($thumb_path)) {
             $file_path = $thumb_path;
         }
     }
     if (FileSystem::exists($file_path)) {
         return LaravelFile::get($file_path);
     }
     throw new FileManagerException($this, 'err_file_not_found');
 }
Ejemplo n.º 5
0
 /**
  * @param Folder $folder
  *
  * @return bool
  *
  * @throws FileManagerException
  */
 public function deleteFolder(Folder $folder)
 {
     $path = $folder->fullPath();
     if (!FileSystem::exists($path)) {
         throw new FileManagerException($this, 'err_folder_not_found');
     }
     if (!Perms::canDelete($path)) {
         throw new FileManagerException($this, 'err_folder_delete_perm');
     }
     return FileSystem::deleteDirectory($path);
 }
Ejemplo n.º 6
0
 /**
  * Delete file thumbs from filesystem
  *
  * @param File $file
  * @throws \Crip\FileManager\Exceptions\FileManagerException
  */
 public function delete(File $file)
 {
     collect(array_keys($this->sizes))->each(function ($size) use($file) {
         $path = $file->getPath()->thumbPath($size, $file);
         if (FileSystem::exists($path)) {
             FileSystem::delete($path);
         }
     });
 }