2016-10-09 13:58:22 -04:00
|
|
|
<?php namespace BookStack\Services;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Filesystem\Factory as FileSystem;
|
|
|
|
use Illuminate\Contracts\Filesystem\Filesystem as FileSystemInstance;
|
|
|
|
|
|
|
|
class UploadService
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 07:41:52 -04:00
|
|
|
return $this->fileSystem->disk($storageType);
|
2016-10-09 13:58:22 -04: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 11:58:52 -05:00
|
|
|
}
|