vendor/shopware/core/Framework/Adapter/Filesystem/Adapter/AwsS3v3Factory.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Adapter\Filesystem\Adapter;
  3. use Aws\S3\S3Client;
  4. use League\Flysystem\AdapterInterface;
  5. use League\Flysystem\AwsS3v3\AwsS3Adapter;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. #[Package('core')]
  9. class AwsS3v3Factory implements AdapterFactoryInterface
  10. {
  11.     public function create(array $config): AdapterInterface
  12.     {
  13.         $options $this->resolveS3Options($config);
  14.         $client = new S3Client($options);
  15.         return new AwsS3Adapter($client$options['bucket'], $options['root'], $options['options'], false);
  16.     }
  17.     public function getType(): string
  18.     {
  19.         return 'amazon-s3';
  20.     }
  21.     private function resolveS3Options(array $definition): array
  22.     {
  23.         $options = new OptionsResolver();
  24.         $options->setRequired(['bucket''region']);
  25.         $options->setDefined(['credentials''version''root''options''endpoint''use_path_style_endpoint''url']);
  26.         $options->setAllowedTypes('credentials''array');
  27.         $options->setAllowedTypes('region''string');
  28.         $options->setAllowedTypes('version''string');
  29.         $options->setAllowedTypes('root''string');
  30.         $options->setAllowedTypes('options''array');
  31.         $options->setAllowedTypes('endpoint''string');
  32.         $options->setAllowedTypes('use_path_style_endpoint''bool');
  33.         $options->setDefault('version''latest');
  34.         $options->setDefault('root''');
  35.         $options->setDefault('options', []);
  36.         $config $options->resolve($definition);
  37.         if (\array_key_exists('credentials'$config)) {
  38.             $config['credentials'] = $this->resolveCredentialsOptions($config['credentials']);
  39.         }
  40.         return $config;
  41.     }
  42.     private function resolveCredentialsOptions(array $credentials): array
  43.     {
  44.         $options = new OptionsResolver();
  45.         $options->setRequired(['key''secret']);
  46.         $options->setAllowedTypes('key''string');
  47.         $options->setAllowedTypes('secret''string');
  48.         return $options->resolve($credentials);
  49.     }
  50. }