src/Sylius/Bundle/AdminBundle/Controller/NotificationController.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\AdminBundle\Controller;
  12. use GuzzleHttp\ClientInterface;
  13. use GuzzleHttp\Exception\GuzzleException;
  14. use GuzzleHttp\Psr7\Uri;
  15. use Http\Message\MessageFactory;
  16. use Sylius\Bundle\CoreBundle\SyliusCoreBundle;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\Request;
  19. final class NotificationController
  20. {
  21.     private Uri $hubUri;
  22.     public function __construct(
  23.         private ClientInterface $client,
  24.         private MessageFactory $messageFactory,
  25.         string $hubUri,
  26.         private string $environment,
  27.     ) {
  28.         $this->hubUri = new Uri($hubUri);
  29.     }
  30.     public function getVersionAction(Request $request): JsonResponse
  31.     {
  32.         $content = [
  33.             'version' => SyliusCoreBundle::VERSION,
  34.             'hostname' => $request->getHost(),
  35.             'locale' => $request->getLocale(),
  36.             'user_agent' => $request->headers->get('User-Agent'),
  37.             'environment' => $this->environment,
  38.         ];
  39.         $headers = ['Content-Type' => 'application/json'];
  40.         $hubRequest $this->messageFactory->createRequest(
  41.             Request::METHOD_GET,
  42.             $this->hubUri,
  43.             $headers,
  44.             json_encode($content),
  45.         );
  46.         try {
  47.             $hubResponse $this->client->send($hubRequest, ['verify' => false]);
  48.         } catch (GuzzleException) {
  49.             return new JsonResponse(''JsonResponse::HTTP_NO_CONTENT);
  50.         }
  51.         $hubResponse json_decode($hubResponse->getBody()->getContents(), true);
  52.         return new JsonResponse($hubResponse);
  53.     }
  54. }