PHP code example of symplify / autowire-array-parameter

1. Go to this page and download the library: Download symplify/autowire-array-parameter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

symplify / autowire-array-parameter example snippets


use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireArrayParameterCompilerPass;

class AppKernel extends Kernel
{
    protected function build(ContainerBuilder $containerBuilder): void
    {
        $containerBuilder->addCompilerPass(
            new AutowireArrayParameterCompilerPass(
                [
                    // place for excluding types to resolve edge cases
                    'Sonata\CoreBundle\Model\Adapter\AdapterInterface',
                ]
            )
        );
    }
}

class Application
{
    /**
     * @var Command[]
     */
    private $commands = [];

    /**
     * @param Command[] $commands
     */
    public function __construct(array $commands)
    {
        $this->commands = $commands;
        // instance of Command collected from all services
        var_dump($commands);
    }
}