Created
April 6, 2021 14:22
-
-
Save takali/5e711bc4f2246e5bb1bd4b9a8647913b to your computer and use it in GitHub Desktop.
Symfony : Inject all class implementing a specific interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Handler; | |
class CalculatorHandler | |
{ | |
/** | |
* @var CalculatorInterface[] | |
*/ | |
private $calculatorList = []; | |
public function __construct(iterable $calculatorList) | |
{ | |
$this->calculatorList = $calculatorList; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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