mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-20 18:31:36 +00:00
25 lines
557 B
PHP
25 lines
557 B
PHP
<?php
|
|
|
|
namespace App\SSH;
|
|
|
|
trait HasS3Storage
|
|
{
|
|
private function prepareS3Path(string $path, string $prefix = ''): string
|
|
{
|
|
$path = trim($path);
|
|
$path = ltrim($path, '/');
|
|
$path = preg_replace('/[^a-zA-Z0-9\-_\.\/]/', '_', $path);
|
|
$path = preg_replace('/\/+/', '/', (string) $path);
|
|
|
|
if ($prefix !== '' && $prefix !== '0') {
|
|
return trim($prefix, '/').'/'.$path;
|
|
}
|
|
|
|
if ($path === null) {
|
|
throw new \Exception('Invalid S3 path');
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
}
|