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

Open in your IDE?
  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.     private bool $elasticsearchEnabled;
  7.     public function __construct(bool $elasticsearchEnabled)
  8.     {
  9.         $this->elasticsearchEnabled $elasticsearchEnabled;
  10.     }
  11.     public function __invoke(ResponseEvent $event): void
  12.     {
  13.         if ($event->getRequest()->attributes->get('_route') !== 'api.info.config') {
  14.             return;
  15.         }
  16.         /** @var array{'version': string} $json */
  17.         $json json_decode((string) $event->getResponse()->getContent(), true512\JSON_THROW_ON_ERROR);
  18.         $json['settings']['elasticsearchEnabled'] = $this->elasticsearchEnabled;
  19.         $event->getResponse()->setContent(json_encode($json\JSON_THROW_ON_ERROR));
  20.     }
  21. }