Add new version in repository
This commit is contained in:
98
app/Repositories/Core/Storage.php
Normal file
98
app/Repositories/Core/Storage.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Facades\Storage as Storage2;
|
||||
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
use SoftCreatR\MimeDetector\MimeDetector;
|
||||
use SoftCreatR\MimeDetector\MimeDetectorException;
|
||||
|
||||
class Storage
|
||||
{
|
||||
public static function checkDirOrCreate($dir)
|
||||
{
|
||||
return self::checkDir($dir) ? true : self::createDir($dir);
|
||||
}
|
||||
|
||||
public static function checkDir($dir)
|
||||
{
|
||||
return Storage2::disk('local')->has($dir);
|
||||
}
|
||||
|
||||
public static function checkFile($file)
|
||||
{
|
||||
return Storage2::exists($file);
|
||||
}
|
||||
|
||||
public static function createDir($dir)
|
||||
{
|
||||
Storage2::makeDirectory($dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function deleteDir($dir)
|
||||
{
|
||||
Storage2::deleteDirectory($dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function deleteFile($file)
|
||||
{
|
||||
Storage2::delete($file);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function secureDeleteFile($file)
|
||||
{
|
||||
$process = new Process(['srm', $file]);
|
||||
$process->run();
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
throw new ProcessFailedException($process);
|
||||
}
|
||||
}
|
||||
|
||||
public static function createFile($file, $content)
|
||||
{
|
||||
Storage2::put($file, $content);
|
||||
}
|
||||
|
||||
public static function getFile($file)
|
||||
{
|
||||
return Storage2::get($file);
|
||||
}
|
||||
|
||||
public static function getFilesize($file)
|
||||
{
|
||||
return Storage2::size($file);
|
||||
}
|
||||
|
||||
public static function getUrlFile($file)
|
||||
{
|
||||
return Storage2::url($file);
|
||||
}
|
||||
|
||||
public static function download($file, $name = false, $headers = false)
|
||||
{
|
||||
return Storage2::download($file, $name, $headers);
|
||||
}
|
||||
|
||||
public static function getPublicPath($file = false)
|
||||
{
|
||||
return public_path($file);
|
||||
}
|
||||
|
||||
public static function getFileType($file)
|
||||
{
|
||||
$file = self::getStoragePath() . $file;
|
||||
return File::getFileType($file);
|
||||
}
|
||||
|
||||
public static function getStoragePath($file = false)
|
||||
{
|
||||
return storage_path($file);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user