src/Aqarmap/Bundle/MainBundle/Twig/ThumbnailExtension.php line 35

Open in your IDE?
  1. <?php
  2. namespace Aqarmap\Bundle\MainBundle\Twig;
  3. use Aqarmap\Bundle\MainBundle\Service\ThumbURL;
  4. use Liip\ImagineBundle\Imagine\Cache\CacheManager;
  5. class ThumbnailExtension extends \Twig\Extension\AbstractExtension
  6. {
  7.     /** @var ThumbURL */
  8.     protected $thumbURL;
  9.     /** @var array */
  10.     protected $config = [];
  11.     /** @var ThumbURL */
  12.     protected $imagine;
  13.     public function __construct(ThumbURL $thumbURLCacheManager $imagine, array $config)
  14.     {
  15.         $this->thumbURL $thumbURL;
  16.         $this->config $config;
  17.         $this->imagine $imagine;
  18.     }
  19.     /**
  20.      * @param string $file Image URI
  21.      * @param string $filter Thumbnail Filter
  22.      *
  23.      * @return string
  24.      */
  25.     public function getThumbnail($file$filter)
  26.     {
  27.         if ($this->config['enabled']) {
  28.             return $this->thumbURL->generateURL($file$filter);
  29.         }
  30.         return $this->imagine->getBrowserPath($file$filter, [], null);
  31.     }
  32.     public function getFilters()
  33.     {
  34.         return [
  35.             new \Twig\TwigFilter('thumbnail', [$this'getThumbnail']),
  36.         ];
  37.     }
  38.     public function getName()
  39.     {
  40.         return 'aqarmap_thumbnail_extension';
  41.     }
  42. }