<?php
namespace Aqarmap\Bundle\MainBundle\Twig;
use Aqarmap\Bundle\MainBundle\Service\ThumbURL;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
class ThumbnailExtension extends \Twig\Extension\AbstractExtension
{
/** @var ThumbURL */
protected $thumbURL;
/** @var array */
protected $config = [];
/** @var ThumbURL */
protected $imagine;
public function __construct(ThumbURL $thumbURL, CacheManager $imagine, array $config)
{
$this->thumbURL = $thumbURL;
$this->config = $config;
$this->imagine = $imagine;
}
/**
* @param string $file Image URI
* @param string $filter Thumbnail Filter
*
* @return string
*/
public function getThumbnail($file, $filter)
{
if ($this->config['enabled']) {
return $this->thumbURL->generateURL($file, $filter);
}
return $this->imagine->getBrowserPath($file, $filter, [], null);
}
public function getFilters()
{
return [
new \Twig\TwigFilter('thumbnail', [$this, 'getThumbnail']),
];
}
public function getName()
{
return 'aqarmap_thumbnail_extension';
}
}