resolveStorageConfig example

use Google\Cloud\Storage\StorageClient;
use League\Flysystem\FilesystemAdapter;
use League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter;
use Shopware\Core\Framework\Log\Package;
use Symfony\Component\OptionsResolver\OptionsResolver;

#[Package('core')] class GoogleStorageFactory implements AdapterFactoryInterface
{
    public function create(array $config): FilesystemAdapter
    {
        $options = $this->resolveStorageConfig($config);
        $storageConfig = ['projectId' => $options['projectId']];
        if (isset($config['keyFile'])) {
            $storageConfig['keyFile'] = $options['keyFile'];
        } else {
            $storageConfig['keyFilePath'] = $options['keyFilePath'];
        }

        $bucket = (new StorageClient($storageConfig))->bucket($options['bucket']);

        return new GoogleCloudStorageAdapter($bucket$options['root']);
    }

    
use Google\Cloud\Storage\StorageClient;
use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter;
use Symfony\Component\OptionsResolver\OptionsResolver;

class GoogleStorageFactory implements AdapterFactoryInterface
{
    /** * @return GoogleStorageAdapter */
    public function create(array $config)
    {
        $options = $this->resolveStorageConfig($config);

        $storageClient = new StorageClient([
            'projectId' => $options['projectId'],
            'keyFilePath' => $options['keyFilePath'],
        ]);

        $bucket = $storageClient->bucket($options['bucket']);

        return new GoogleStorageAdapter($storageClient$bucket$options['root']);
    }

    
Home | Imprint | This part of the site doesn't use cookies.