2018-09-25 13:30:50 +02:00
|
|
|
<?php namespace BookStack\Uploads;
|
2016-10-09 19:58:22 +02:00
|
|
|
|
|
|
|
use Illuminate\Contracts\Filesystem\Factory as FileSystem;
|
|
|
|
use Illuminate\Contracts\Filesystem\Filesystem as FileSystemInstance;
|
|
|
|
|
2018-09-25 13:30:50 +02:00
|
|
|
abstract class UploadService
|
2016-10-09 19:58:22 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var FileSystem
|
|
|
|
*/
|
|
|
|
protected $fileSystem;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FileService constructor.
|
|
|
|
* @param $fileSystem
|
|
|
|
*/
|
|
|
|
public function __construct(FileSystem $fileSystem)
|
|
|
|
{
|
|
|
|
$this->fileSystem = $fileSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the storage that will be used for storing images.
|
|
|
|
* @return FileSystemInstance
|
|
|
|
*/
|
|
|
|
protected function getStorage()
|
|
|
|
{
|
|
|
|
$storageType = config('filesystems.default');
|
2018-03-25 13:41:52 +02:00
|
|
|
return $this->fileSystem->disk($storageType);
|
2016-10-09 19:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether or not a folder is empty.
|
|
|
|
* @param $path
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function isFolderEmpty($path)
|
|
|
|
{
|
|
|
|
$files = $this->getStorage()->files($path);
|
|
|
|
$folders = $this->getStorage()->directories($path);
|
|
|
|
return (count($files) === 0 && count($folders) === 0);
|
|
|
|
}
|
2018-01-28 17:58:52 +01:00
|
|
|
}
|