custom/plugins/FroshTools/src/Components/Elasticsearch/AdminInfoSubscriber.php line 13

  1. <?php declare(strict_types=1);
  2. namespace Frosh\Tools\Components\Elasticsearch;
  3. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  4. final class AdminInfoSubscriber
  5. {
  6.     public function __construct(private readonly bool $elasticsearchEnabled)
  7.     {
  8.     }
  9.     public function __invoke(ResponseEvent $event): void
  10.     {
  11.         if ($event->getRequest()->attributes->get('_route') !== 'api.info.config') {
  12.             return;
  13.         }
  14.         /** @var array{'version': string} $json */
  15.         $json json_decode((string) $event->getResponse()->getContent(), true512\JSON_THROW_ON_ERROR);
  16.         $json['settings']['elasticsearchEnabled'] = $this->elasticsearchEnabled;
  17.         $event->getResponse()->setContent(json_encode($json\JSON_THROW_ON_ERROR));
  18.     }
  19. }