You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
841B

  1. <?php
  2. namespace common\logic;
  3. use yii\base\ErrorException;
  4. class BaseManager
  5. {
  6. protected ContainerInterface $container;
  7. public function __call($method, $args)
  8. {
  9. foreach($this->getContainer()->getServices() as $serviceClass) {
  10. if(method_exists($serviceClass, $method)) {
  11. return call_user_func_array(
  12. [new $serviceClass, $method],
  13. $args
  14. );
  15. }
  16. }
  17. throw new ErrorException('La méthode '.$method.' est introuvable dans les services du container '.get_class($this->container));
  18. }
  19. protected function setContainer(ContainerInterface $container): void
  20. {
  21. $this->container = $container;
  22. }
  23. public function getContainer(): ContainerInterface
  24. {
  25. return $this->container;
  26. }
  27. }