fix(continuous-integration): correction php-cs-fixer
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
This commit is contained in:
@ -4,16 +4,14 @@ namespace App\Service;
|
||||
|
||||
use Aws\S3\Exception\S3Exception;
|
||||
use Exception;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class MinioService
|
||||
{
|
||||
const ERR_UNAVAILABLE = 'Service de gestion de fichiers momentanément indisponible.';
|
||||
const ERR_FILE_NOT_FOUND = 'messages.minio.404';
|
||||
|
||||
public const ERR_UNAVAILABLE = 'Service de gestion de fichiers momentanément indisponible.';
|
||||
public const ERR_FILE_NOT_FOUND = 'messages.minio.404';
|
||||
|
||||
private $rootPath;
|
||||
private $client;
|
||||
private $listClient;
|
||||
@ -26,7 +24,7 @@ class MinioService
|
||||
{
|
||||
$this->rootPath = $rootPath;
|
||||
$this->minioBucket = $minioBucket;
|
||||
$this->minioPathStyle = ($minioPathstyle==1?true:false);
|
||||
$this->minioPathStyle = (1 == $minioPathstyle ? true : false);
|
||||
$this->minioRoot = $minioRoot;
|
||||
$this->client = $this->getClient($minioUrl, $minioKey, $minioSecret, $minioPathstyle, $minioSecure);
|
||||
$this->initBucket();
|
||||
@ -36,11 +34,11 @@ class MinioService
|
||||
{
|
||||
// On s'assure que le repertoire temporaire de destination existe bien
|
||||
$fs = new Filesystem();
|
||||
$tmpdir=$this->rootPath."/var/tmp";
|
||||
$fs->mkdir($tmpdir."/".dirname($filename));
|
||||
$tmpdir = $this->rootPath.'/var/tmp';
|
||||
$fs->mkdir($tmpdir.'/'.dirname($filename));
|
||||
|
||||
// Approche repassant par le serveur d'appel
|
||||
if(!$usecache||!$fs->exists($tmpdir.'/'.$filename)) {
|
||||
if (!$usecache || !$fs->exists($tmpdir.'/'.$filename)) {
|
||||
try {
|
||||
$result = $this->client->getObject([
|
||||
'Bucket' => $this->minioBucket,
|
||||
@ -51,11 +49,11 @@ class MinioService
|
||||
switch ($e->getResponse()->getStatusCode()) {
|
||||
case 404:
|
||||
throw new NotFoundHttpException(self::ERR_FILE_NOT_FOUND);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
\Sentry\captureException($e);
|
||||
throw new Exception(self::ERR_UNAVAILABLE);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
\Sentry\captureException($e);
|
||||
@ -80,8 +78,8 @@ class MinioService
|
||||
}
|
||||
|
||||
if ($deleteSource) {
|
||||
$tmpdir=$this->rootPath."/var/tmp";
|
||||
@unlink($tmpdir."/".$filename);
|
||||
$tmpdir = $this->rootPath.'/var/tmp';
|
||||
@unlink($tmpdir.'/'.$filename);
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +133,7 @@ class MinioService
|
||||
*/
|
||||
public function countKeys(string $prefix)
|
||||
{
|
||||
//On utilise un path spécifique car listObjectsV2 utilise une autre config de client
|
||||
// On utilise un path spécifique car listObjectsV2 utilise une autre config de client
|
||||
try {
|
||||
$response = $this->client->listObjectsV2([
|
||||
'Bucket' => $this->minioBucket,
|
||||
@ -156,7 +154,7 @@ class MinioService
|
||||
*/
|
||||
public function listKeys(string $prefix)
|
||||
{
|
||||
//On utilise un path spécifique car listObjectsV2 utilise une autre config de client
|
||||
// On utilise un path spécifique car listObjectsV2 utilise une autre config de client
|
||||
try {
|
||||
$response = $this->client->listObjectsV2([
|
||||
'Bucket' => $this->minioBucket,
|
||||
@ -177,21 +175,19 @@ class MinioService
|
||||
* @param string $filename Nom du fichier dans la réponse
|
||||
* @param bool $returnFile Retourner un fichier ou une réponse
|
||||
*/
|
||||
|
||||
|
||||
protected function getClient($minioUrl, $minioKey, $minioSecret, bool $minioPathstyle, bool $minioSecure)
|
||||
{
|
||||
$client = new \Aws\S3\S3Client([
|
||||
'version' => 'latest',
|
||||
'region' => 'eu-west-1',
|
||||
'endpoint' => $minioUrl,
|
||||
//On force le mode DNS
|
||||
// On force le mode DNS
|
||||
'use_path_style_endpoint' => $minioPathstyle,
|
||||
'credentials' => [
|
||||
'key' => $minioKey,
|
||||
'secret' => $minioSecret,
|
||||
],
|
||||
//On désactive les checks SSL pour le moment
|
||||
// On désactive les checks SSL pour le moment
|
||||
'http' => [
|
||||
'verify' => $minioSecure,
|
||||
],
|
||||
|
Reference in New Issue
Block a user