src/ModuleHandler/ModuleHandlerManager.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\ModuleHandler;
  3. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  4. class ModuleHandlerManager
  5. {
  6. private $handlers;
  7. public function __construct(iterable $handlers)
  8. {
  9. $this->handlers = $handlers;
  10. }
  11. public function handle(string $module, string $slug): array
  12. {
  13. foreach ($this->handlers as $handler) {
  14. if ($handler instanceof ModuleHandlerInterface) {
  15. if (strtolower((new \ReflectionClass($handler))->getShortName()) === strtolower($module.'Service')) {
  16. return $handler->handle($slug);
  17. }
  18. }
  19. }
  20. throw new NotFoundHttpException('No handler found for module: ' . $module);
  21. }
  22. }