diff --git a/EventListener/ResponseListener.php b/EventListener/ResponseListener.php index faef217..502aaf4 100644 --- a/EventListener/ResponseListener.php +++ b/EventListener/ResponseListener.php @@ -1,5 +1,15 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace ShortCode\EventListener; use Maiorano\Shortcodes\Library\SimpleShortcode; @@ -10,6 +20,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\Event\ResponseEvent; @@ -21,9 +32,6 @@ class ResponseListener implements EventSubscriberInterface /** @var EventDispatcherInterface */ protected $eventDispatcher; - /** - * @param EventDispatcherInterface $eventDispatcher - */ public function __construct( EventDispatcherInterface $eventDispatcher ) { @@ -33,19 +41,24 @@ public function __construct( public static function getSubscribedEvents() { return [ - KernelEvents::RESPONSE => [['dispatchShortCodeEvents', 64]] + KernelEvents::RESPONSE => [['dispatchShortCodeEvents', 64]], ]; } - public function dispatchShortCodeEvents(ResponseEvent $event) + public function dispatchShortCodeEvents(ResponseEvent $event): void { if ($event->getRequest()->get('disable_shortcode', 0) == 1) { return; } - + $response = $event->getResponse(); - if ($response instanceof BinaryFileResponse || $response instanceof StreamedResponse || $response instanceof RedirectResponse) { + if ( + $response instanceof BinaryFileResponse + || $response instanceof StreamedResponse + || $response instanceof RedirectResponse + || $response instanceof JsonResponse + ) { return; } @@ -62,6 +75,7 @@ public function dispatchShortCodeEvents(ResponseEvent $event) $simpleShortCodes[$shortCode->getTag()] = new SimpleShortcode($shortCode->getTag(), null, function ($content, $attributes) use ($shortCode, $dispatcher) { $shortCodeEvent = new ShortCodeEvent($content, $attributes); $dispatcher->dispatch($shortCodeEvent, $shortCode->getEvent()); + return $shortCodeEvent->getResult(); }); }