src/Service/Client/MarketingImageService.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Service\Client;
  3. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
  4. use Symfony\Contracts\Cache\ItemInterface;
  5. class MarketingImageService extends AbstractClient implements CacheWarmerInterface
  6. {
  7.     /**
  8.      * @return bool
  9.      */
  10.     public function isOptional(): bool
  11.     {
  12.         return true;
  13.     }
  14.     /**
  15.      * @param string $cacheDir
  16.      * @throws \Psr\Cache\InvalidArgumentException
  17.      * @throws \ReflectionException
  18.      */
  19.     public function warmUp($cacheDir)
  20.     {
  21.         $this->getCurrentMarketingImage();
  22.     }
  23.     /**
  24.      * @return array|null
  25.      * @throws \Psr\Cache\InvalidArgumentException
  26.      * @throws \ReflectionException
  27.      */
  28.     public function getCurrentMarketingImage(): ?array
  29.     {
  30.         $key = (new \ReflectionClass($this))->getShortName() . '_' __FUNCTION__;
  31.         return $this->getCacheService()->get($key, function(ItemInterface $item) {
  32.             $date = new \DateTime(date('Y-m-d H:i') . ':59');
  33.             $item->expiresAt($date);
  34.             $response $this->issueGet('api/public/marketing/image/current');
  35.             if($response && $this->isSuccess($response)) {
  36.                 return json_decode($response->getContent(), true);
  37.             }
  38.             return null;
  39.         });
  40.     }
  41. }