Primo Committ

This commit is contained in:
paoloar77
2024-05-07 12:17:25 +02:00
commit e73d0e5113
7204 changed files with 884387 additions and 0 deletions

View 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]);
}
}

View 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;
}
}

View 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().')';
}
}

View 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);
}
}

View File

@@ -0,0 +1,8 @@
<?php
use Spatie\Backup\Helpers\ConsoleOutput;
function consoleOutput(): ConsoleOutput
{
return app(ConsoleOutput::class);
}