Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

40 rindas
1.1KB

  1. <?php
  2. namespace common\logic;
  3. use yii\base\ErrorException;
  4. abstract class AbstractManager extends AbstractSingleton implements ManagerInterface
  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. [$serviceClass::getInstance(), $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. public function initContainer(): void
  28. {
  29. $containerFqcn = $this->getContainerFqcn();
  30. $this->setContainer($containerFqcn::getInstance());
  31. }
  32. }