symplify/auto-bind-parameter

This package is abandoned and no longer maintained. The author suggests using the symplify/package-builder package instead.

Auto bind parameters for your Symfony applications


README

*Deprecated: instead of magic parameter binding, use ParameterProvider with constants

Downloads total

Install

composer require symplify/auto-bind-parameter

Usage

1. Register Compiler Pass in kernel

<?php declare(strict_types=1);

namespace App;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symplify\AutoBindParameter\DependencyInjection\CompilerPass\AutoBindParameterCompilerPass;

class AppKernel extends Kernel
{
    protected function build(ContainerBuilder $containerBuilder): void
    {
        $containerBuilder->addCompilerPass(new AutoBindParameterCompilerPass());
    }
}

2. Auto Bind Parameters

Keep your configs simple enough:

 parameters:
     entity_repository_class: 'Doctrine\ORM\EntityRepository'
     entity_manager_class: 'Doctrine\ORM\EntityManager'

 services:
-    _defaults:
-        bind:
-            $entityRepositoryClass: '%entity_repository_class%'
-            $entityManagerClass: '%entity_manager_class%'
-
     Rector\:
         resource: ..

And as any other bind:

<?php declare(strict_types=1);

class SomeClass
{
    /**
     * @var string
     */
    private $entityRepositoryClass;

    public function __construct(string $entityRepositoryClass)
    {
        $this->entityRepositoryClass = $entityRepositoryClass;
    }
}