Primo Committ
This commit is contained in:
28
vendor/spatie/laravel-backup/src/Helpers/ConsoleOutput.php
vendored
Normal file
28
vendor/spatie/laravel-backup/src/Helpers/ConsoleOutput.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Backup\Helpers;
|
||||
|
||||
class ConsoleOutput
|
||||
{
|
||||
/** @var \Illuminate\Console\OutputStyle */
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Console\OutputStyle $output
|
||||
*/
|
||||
public function setOutput($output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function __call(string $method, array $arguments)
|
||||
{
|
||||
$consoleOutput = app(static::class);
|
||||
|
||||
if (! $consoleOutput->output) {
|
||||
return;
|
||||
}
|
||||
|
||||
$consoleOutput->output->$method($arguments[0]);
|
||||
}
|
||||
}
|
||||
49
vendor/spatie/laravel-backup/src/Helpers/File.php
vendored
Normal file
49
vendor/spatie/laravel-backup/src/Helpers/File.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Backup\Helpers;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
|
||||
class File
|
||||
{
|
||||
/** @var array */
|
||||
protected static $allowedMimeTypes = [
|
||||
'application/zip',
|
||||
'application/x-zip',
|
||||
'application/x-gzip',
|
||||
];
|
||||
|
||||
public function isZipFile(?Filesystem $disk, string $path): bool
|
||||
{
|
||||
if ($this->hasZipExtension($path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasAllowedMimeType($disk, $path);
|
||||
}
|
||||
|
||||
protected function hasZipExtension(string $path): bool
|
||||
{
|
||||
return pathinfo($path, PATHINFO_EXTENSION) === 'zip';
|
||||
}
|
||||
|
||||
protected function hasAllowedMimeType(?Filesystem $disk, string $path)
|
||||
{
|
||||
return in_array($this->mimeType($disk, $path), self::$allowedMimeTypes);
|
||||
}
|
||||
|
||||
protected function mimeType(?Filesystem $disk, string $path)
|
||||
{
|
||||
try {
|
||||
if ($disk && method_exists($disk, 'mimeType')) {
|
||||
return $disk->mimeType($path) ?: false;
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
// Some drivers throw exceptions when checking mime types, we'll
|
||||
// just fallback to `false`.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
36
vendor/spatie/laravel-backup/src/Helpers/Format.php
vendored
Normal file
36
vendor/spatie/laravel-backup/src/Helpers/Format.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Backup\Helpers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Format
|
||||
{
|
||||
public static function humanReadableSize(float $sizeInBytes): string
|
||||
{
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
if ($sizeInBytes === 0) {
|
||||
return '0 '.$units[1];
|
||||
}
|
||||
for ($i = 0; $sizeInBytes > 1024; $i++) {
|
||||
$sizeInBytes /= 1024;
|
||||
}
|
||||
|
||||
return round($sizeInBytes, 2).' '.$units[$i];
|
||||
}
|
||||
|
||||
public static function emoji(bool $bool): string
|
||||
{
|
||||
if ($bool) {
|
||||
return '✅';
|
||||
}
|
||||
|
||||
return '❌';
|
||||
}
|
||||
|
||||
public static function ageInDays(Carbon $date): string
|
||||
{
|
||||
return number_format(round($date->diffInMinutes() / (24 * 60), 2), 2).' ('.$date->diffForHumans().')';
|
||||
}
|
||||
}
|
||||
13
vendor/spatie/laravel-backup/src/Helpers/RightAlignedTableStyle.php
vendored
Normal file
13
vendor/spatie/laravel-backup/src/Helpers/RightAlignedTableStyle.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Backup\Helpers;
|
||||
|
||||
use Symfony\Component\Console\Helper\TableStyle;
|
||||
|
||||
class RightAlignedTableStyle extends TableStyle
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setPadType(STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
8
vendor/spatie/laravel-backup/src/Helpers/functions.php
vendored
Normal file
8
vendor/spatie/laravel-backup/src/Helpers/functions.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Spatie\Backup\Helpers\ConsoleOutput;
|
||||
|
||||
function consoleOutput(): ConsoleOutput
|
||||
{
|
||||
return app(ConsoleOutput::class);
|
||||
}
|
||||
Reference in New Issue
Block a user