<?php
namespace Cofondateur\SocleTechniqueBundle\Twig;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Templating\FilterExtension as BaseFilterExtension;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class LiipFilterExtension extends BaseFilterExtension
{
/**
* @var CacheManager
*/
private $cache;
/** @var DataManager */
private $dataManager;
public function __construct(CacheManager $cache, DataManager $dataManager)
{
parent::__construct($cache);
$this->cache = $cache;
$this->dataManager = $dataManager;
}
/**
* Gets the browser path for the image and filter to apply.
*
* @param string $path
* @param string $filter
* @param string|null $resolver
* @param int $referenceType
*
* @return string
*/
public function filter($path, $filter, array $config = [], $resolver = null, $referenceType = UrlGeneratorInterface::ABSOLUTE_URL)
{
if (!$path) {
$path = $this->dataManager->getDefaultImageUrl($filter);
}
return $this->cache->getBrowserPath(parse_url($path, PHP_URL_PATH), $filter, $config, $resolver, $referenceType);
}
}