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.

BaseManager.php 841B

12345678910111213141516171819202122232425262728293031323334
  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. }