Removing old folder validator.

parent a7bfdf0f
......@@ -62,8 +62,6 @@ class MediaServiceProvider extends ServiceProvider
public function boot(DispatcherContract $events)
{
$this->registerMaxFolderSizeValidator();
$this->publishConfig('media', 'config');
$this->publishConfig('media', 'permissions');
$this->publishConfig('media', 'assets');
......@@ -90,8 +88,8 @@ class MediaServiceProvider extends ServiceProvider
private function registerBindings()
{
$this->app->bind(FileRepository::class, function ($app) {
return new EloquentFileRepository(new File(), $app['filesystem.disk']);
$this->app->bind(FileRepository::class, function () {
return new EloquentFileRepository(new File());
});
}
......@@ -115,11 +113,6 @@ class MediaServiceProvider extends ServiceProvider
$this->commands('command.media.refresh');
}
private function registerMaxFolderSizeValidator()
{
Validator::extend('max_size', '\Modules\Media\Validators\MaxFolderSizeValidator@validateMaxSize');
}
private function registerThumbnails()
{
$this->app[ThumbnailManager::class]->registerThumbnail('smallThumb', [
......
<?php
namespace Modules\Media\Validators;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class MaxFolderSizeValidator
{
public function validateMaxSize($attribute, UploadedFile $value, $parameters)
{
$mediaPath = public_path(config('asgard.media.config.files-path'));
$folderSize = $this->getDirSize($mediaPath);
preg_match('/([0-9]+)/', $folderSize, $match);
return ($match[0] + $value->getSize()) < config('asgard.media.config.max-total-size');
}
/**
* Get the directory size
* @param string $directory
* @return int
*/
public function getDirSize($directory)
{
$size = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
$size += $file->getSize();
}
return $size;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment