Symfony - `storage_filename_strategy` configuration not evaluated

Aperta
#216 5 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
php, symfony
Ambito
backend, databases

Direzione di ricerca

Start in src/Bridge/Symfony/DependencyInjection/DbToolsExtension.php, especially the configuration handling around lines 88-109 and 115. Trace how db_tools.storage_filename_strategy and db_tools.connections.<connection_name>.storage_filename_strategy are passed to db_tools.storage. Done means both configuration paths are evaluated and the service receives the corresponding strategies, while the deprecated path remains understood from the referenced code.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

The Symfony integration as of version 2.0 of this bundle does not evaluate the storage_filename_strategy and connections.<connection_name>.storage.filename_strategy configuration.

The service db_tools.storage will be configured with strategies resolved from the deprecated configuration path db_tools.storage.filename_strategy at https://github.com/makinacorpus/DbToolsBundle/blob/d0cb6322305a9a050917b70a2392fe31f4d83142/src/Bridge/Symfony/DependencyInjection/DbToolsExtension.php#L88-L109

Due to the initialization of the configuration object at https://github.com/makinacorpus/DbToolsBundle/blob/d0cb6322305a9a050917b70a2392fe31f4d83142/src/Bridge/Symfony/DependencyInjection/DbToolsExtension.php#L115 its not possible anymore to use this configuration path.

The configuration at db_tools.storage_filename_strategy and db_tools.connections.<connection_name>.storage_filename_strategy does not seem to be taken into account at all.


For anyone facing the same issue, as temporary a workaround, it is possible to update the definition of the service `db_tools.storage` through a custom compiler pass.
<?php

declare(strict_types=1);

namespace App\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Reference;

class DbToolsCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        /**
         * @var array<int, array{
         *      storage_filename_strategy?: 'default'|'datetime'|string,
         *      connections: array<string, array{
         *          storage_filename_strategy?: 'default'|'datetime'|string,
         *      }
         *  } $dbToolsConfigurations
         */
        $dbToolsConfigurations = $container->getExtensionConfig('db_tools');
        if (count($dbToolsConfigurations) > 1) {
            throw new LogicException('More than one db tool configuration defined.');
        }

        $dbToolsConfiguration = $dbToolsConfigurations[0];
        if ([] === $dbToolsConfiguration) {
            return;
        }

        $storageFilenameStrategies = [];

        $defaultStorageFilenameStrategy = $this->retrieveStorageFilenameStrategyFromConfiguration(
            $dbToolsConfiguration,
        );
        if (null !== $defaultStorageFilenameStrategy) {
            $storageFilenameStrategies['default'] = $defaultStorageFilenameStrategy;
        }

        if (array_key_exists('connections', $dbToolsConfiguration)) {
            foreach ($dbToolsConfiguration['connections'] as $connectionName => $connectionConfiguration) {
                $storageFilenameStrategy = $this->retrieveStorageFilenameStrategyFromConfiguration(
                    $connectionConfiguration,
                );
                if (null === $storageFilenameStrategy) {
                    continue;
                }

                $storageFilenameStrategies[$connectionName] = $storageFilenameStrategy;
            }
        }

        if ($storageFilenameStrategies === []) {
            return;
        }

        $dbToolsStorageDefinition = $container->getDefinition('db_tools.storage');

        $dbToolsStorageDefinition->replaceArgument(1, $storageFilenameStrategies);
    }

    /**
     * @param array{storage_filename_strategy?: 'default'|'datetime'|string} $configuration
     *
     * @return Reference|null
     */
    private function retrieveStorageFilenameStrategyFromConfiguration(array $configuration): ?Reference
    {
        if (!array_key_exists('storage_filename_strategy', $configuration)
            || in_array($configuration['storage_filename_strategy'], ['default', 'datetime'])
        ) {
            return null;
        }

        return new Reference($configuration['storage_filename_strategy']);
    }
}
Lingua principale
PHP
Stelle
235
Fork
17
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di makinacorpus/DbToolsBundle

Tutte le issue di makinacorpus/DbToolsBundle

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.