|
|
@@ -12,6 +12,7 @@ use Liip\ImagineBundle\Imagine\Cache\CacheManager; |
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
use Twig\Extension\AbstractExtension; |
|
|
|
use Twig\TwigFilter; |
|
|
@@ -29,10 +30,11 @@ class FrontendTwigExtension extends AbstractExtension |
|
|
|
protected $productFamilyRepository; |
|
|
|
protected $liipCacheHelper; |
|
|
|
protected $parameterBag; |
|
|
|
protected $kernel; |
|
|
|
|
|
|
|
public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils, |
|
|
|
FormFactoryInterface $formFactory, RequestStack $requestStack, CacheManager $liipCacheHelper, |
|
|
|
ParameterBagInterface $parameterBag) |
|
|
|
ParameterBagInterface $parameterBag, KernelInterface $kernel) |
|
|
|
{ |
|
|
|
$this->em = $em; |
|
|
|
$this->security = $security; |
|
|
@@ -44,6 +46,7 @@ class FrontendTwigExtension extends AbstractExtension |
|
|
|
$this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetadata(ProductFamilyInterface::class)->getName()); |
|
|
|
$this->liipCacheHelper = $liipCacheHelper; |
|
|
|
$this->parameterBag = $parameterBag; |
|
|
|
$this->kernel = $kernel; |
|
|
|
} |
|
|
|
|
|
|
|
public function getFunctions() |
|
|
@@ -62,9 +65,20 @@ class FrontendTwigExtension extends AbstractExtension |
|
|
|
return [ |
|
|
|
new TwigFilter('format_price', [$this, 'formatPrice']), |
|
|
|
new TwigFilter('lc_liip', [$this, 'lcLiip']), |
|
|
|
new TwigFilter('lc_cache', [$this, 'lcCache']), |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function lcCache($file){ |
|
|
|
$cacheTime = filemtime($this->kernel->getProjectDir().'/public'.$file); |
|
|
|
if($cacheTime){ |
|
|
|
return $file.'?c='.$cacheTime; |
|
|
|
}else{ |
|
|
|
return $file."?c=0"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg') |
|
|
|
{ |
|
|
|
if (substr($path, 0, 1) === '/') $path = substr($path, 1); |