Skip to content

Instantly share code, notes, and snippets.

@takali
Created April 6, 2021 14:22
Show Gist options
  • Save takali/5e711bc4f2246e5bb1bd4b9a8647913b to your computer and use it in GitHub Desktop.
Save takali/5e711bc4f2246e5bb1bd4b9a8647913b to your computer and use it in GitHub Desktop.
Symfony : Inject all class implementing a specific interface
<?php
namespace App\Handler;
class CalculatorHandler
{
/**
* @var CalculatorInterface[]
*/
private $calculatorList = [];
public function __construct(iterable $calculatorList)
{
$this->calculatorList = $calculatorList;
}
}
services:
App\Handler\CalculatorHandler:
arguments: [!tagged app.calculator]
_instanceof:
App\Calculator\CalculatorInterface:
tags: ['app.calculator']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment