]> BookStack Code Mirror - bookstack/blob - app/Services/UploadService.php
Refactored the code to first check for the permissions before sorting the book.
[bookstack] / app / Services / UploadService.php
1 <?php namespace BookStack\Services;
2
3 use Illuminate\Contracts\Filesystem\Factory as FileSystem;
4 use Illuminate\Contracts\Filesystem\Filesystem as FileSystemInstance;
5
6 class UploadService
7 {
8
9     /**
10      * @var FileSystem
11      */
12     protected $fileSystem;
13
14     /**
15      * @var FileSystemInstance
16      */
17     protected $storageInstance;
18
19
20     /**
21      * FileService constructor.
22      * @param $fileSystem
23      */
24     public function __construct(FileSystem $fileSystem)
25     {
26         $this->fileSystem = $fileSystem;
27     }
28
29     /**
30      * Get the storage that will be used for storing images.
31      * @return FileSystemInstance
32      */
33     protected function getStorage()
34     {
35         if ($this->storageInstance !== null) return $this->storageInstance;
36
37         $storageType = config('filesystems.default');
38         $this->storageInstance = $this->fileSystem->disk($storageType);
39
40         return $this->storageInstance;
41     }
42
43
44     /**
45      * Check whether or not a folder is empty.
46      * @param $path
47      * @return bool
48      */
49     protected function isFolderEmpty($path)
50     {
51         $files = $this->getStorage()->files($path);
52         $folders = $this->getStorage()->directories($path);
53         return (count($files) === 0 && count($folders) === 0);
54     }
55
56     /**
57      * Check if using a local filesystem.
58      * @return bool
59      */
60     protected function isLocal()
61     {
62         return strtolower(config('filesystems.default')) === 'local';
63     }
64 }