1 <?php namespace BookStack\Services;
3 use Illuminate\Contracts\Filesystem\Factory as FileSystem;
4 use Illuminate\Contracts\Filesystem\Filesystem as FileSystemInstance;
12 protected $fileSystem;
15 * @var FileSystemInstance
17 protected $storageInstance;
21 * FileService constructor.
24 public function __construct(FileSystem $fileSystem)
26 $this->fileSystem = $fileSystem;
30 * Get the storage that will be used for storing images.
31 * @return FileSystemInstance
33 protected function getStorage()
35 if ($this->storageInstance !== null) {
36 return $this->storageInstance;
39 $storageType = config('filesystems.default');
40 $this->storageInstance = $this->fileSystem->disk($storageType);
42 return $this->storageInstance;
46 * Check whether or not a folder is empty.
50 protected function isFolderEmpty($path)
52 $files = $this->getStorage()->files($path);
53 $folders = $this->getStorage()->directories($path);
54 return (count($files) === 0 && count($folders) === 0);
58 * Check if using a local filesystem.
61 protected function isLocal()
63 return strtolower(config('filesystems.default')) === 'local';