<?php
namespace App\Service\Client;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Contracts\Cache\ItemInterface;
class MarketingImageService extends AbstractClient implements CacheWarmerInterface
{
/**
* @return bool
*/
public function isOptional(): bool
{
return true;
}
/**
* @param string $cacheDir
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
*/
public function warmUp($cacheDir)
{
$this->getCurrentMarketingImage();
}
/**
* @return array|null
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
*/
public function getCurrentMarketingImage(): ?array
{
$key = (new \ReflectionClass($this))->getShortName() . '_' . __FUNCTION__;
return $this->getCacheService()->get($key, function(ItemInterface $item) {
$date = new \DateTime(date('Y-m-d H:i') . ':59');
$item->expiresAt($date);
$response = $this->issueGet('api/public/marketing/image/current');
if($response && $this->isSuccess($response)) {
return json_decode($response->getContent(), true);
}
return null;
});
}
}