| Total Complexity | 4 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class ResponderSubscriber implements EventSubscriberInterface |
||
| 10 | { |
||
| 11 | /** @var ResponderInterface[] $responders */ |
||
| 12 | private $responders; |
||
| 13 | |||
| 14 | public function __construct(iterable $responders) |
||
| 15 | { |
||
| 16 | $this->responders = (function (ResponderInterface ...$responders): iterable { |
||
| 17 | return $responders; |
||
| 18 | })(...$responders); |
||
| 19 | } |
||
| 20 | |||
| 21 | public function onKernelView(GetResponseForControllerResultEvent $event): void |
||
| 22 | { |
||
| 23 | $result = $event->getControllerResult(); |
||
| 24 | $meta = new ResultMetadata(get_class($result)); |
||
| 25 | |||
| 26 | $specificResponder = array_find( |
||
| 27 | $this->responders, |
||
| 28 | function (ResponderInterface $responder) use ($meta, $result): bool { |
||
| 29 | return $responder->supports($result, $meta); |
||
| 30 | } |
||
| 31 | ); |
||
| 32 | |||
| 33 | if ($specificResponder) { |
||
| 34 | $response = $specificResponder->make($result, $meta); |
||
| 35 | $event->setResponse($response); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | public static function getSubscribedEvents() |
||
| 43 | ]; |
||
| 44 | } |
||
| 45 | } |
||
| 46 |