*Deprecated: instead of magic parameter binding, use ParameterProvider with constants
composer require symplify/auto-bind-parameter
<?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());
}
}
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;
}
}