dunglas / DunglasActionBundle

Symfony controllers, redesigned
https://dunglas.fr/2016/01/dunglasactionbundle-symfony-controllers-redesigned/
MIT License
256 stars 14 forks source link

Directories Injection #60

Closed Spomky closed 8 years ago

Spomky commented 8 years ago

Hi,

I have a little DX issue with that bundle. My project uses the excellent matthiasnoback/symfony-bundle-plugins) and actions are stored in each plugin folders.

Developers can modify the dunglas_action.directories configuration value to add folders containing classes. Hoever, I think this step could be avoided by adding a compiler class that will add the concerned folders without any configuration modification. Something that look like the following class:

<?php

namespace AppBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

final class DirectoryModificatorCompilerPass implements CompilerPassInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('dunglas_action.directory_manager')) {
            return;
        }

        $definition = $container->getDefinition('dunglas_action.directory_manager');
        $patterns = [
            '/my/custom/directory/Actions',
            '/another/directory/Command',
        ];
        $definition->addMethodCall('addPatterns', [$patterns]);
    }
}

Do you think it is possible to provide a service (I named it dunglas_action.directory_manager in my example) that will provide a addPatterns(array $patterns) (or addPattern(string $pattern)) method?

From my point of view it will requires to move all the logic in the DunglasActionExtension.php to that dedicated service.

GuilhemN commented 8 years ago

That's not possible to have a service as this bundle works at compile time. However you can dynamically update this bundle configuration using an extension (with PrependExtensionInterdace).

dunglas commented 8 years ago

@Ener-Getick is right, as always 🙂

GuilhemN commented 8 years ago

@dunglas I wouldn't say that :stuck_out_tongue: We learn from each other :slightly_smiling_face: