vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/Controller/NotificationController.php line 51

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 Psr\Http\Message\UriInterface;
  17. use Sylius\Bundle\CoreBundle\Application\Kernel;
  18. use Symfony\Component\HttpFoundation\JsonResponse;
  19. use Symfony\Component\HttpFoundation\Request;
  20. final class NotificationController
  21. {
  22.     /** @var ClientInterface */
  23.     private $client;
  24.     /** @var MessageFactory */
  25.     private $messageFactory;
  26.     /** @var UriInterface */
  27.     private $hubUri;
  28.     /** @var string */
  29.     private $environment;
  30.     public function __construct(
  31.         ClientInterface $client,
  32.         MessageFactory $messageFactory,
  33.         string $hubUri,
  34.         string $environment
  35.     ) {
  36.         $this->client $client;
  37.         $this->messageFactory $messageFactory;
  38.         $this->hubUri = new Uri($hubUri);
  39.         $this->environment $environment;
  40.     }
  41.     public function getVersionAction(Request $request): JsonResponse
  42.     {
  43.         $content = [
  44.             'version' => Kernel::VERSION,
  45.             'hostname' => $request->getHost(),
  46.             'locale' => $request->getLocale(),
  47.             'user_agent' => $request->headers->get('User-Agent'),
  48.             'environment' => $this->environment,
  49.         ];
  50.         $headers = ['Content-Type' => 'application/json'];
  51.         $hubRequest $this->messageFactory->createRequest(
  52.             Request::METHOD_GET,
  53.             $this->hubUri,
  54.             $headers,
  55.             json_encode($content)
  56.         );
  57.         try {
  58.             $hubResponse $this->client->send($hubRequest, ['verify' => false]);
  59.         } catch (GuzzleException $exception) {
  60.             return JsonResponse::create(''JsonResponse::HTTP_NO_CONTENT);
  61.         }
  62.         $hubResponse json_decode($hubResponse->getBody()->getContents(), true);
  63.         return new JsonResponse($hubResponse);
  64.     }
  65. }