diff --git a/DependencyInjection/LiipImagineExtension.php b/DependencyInjection/LiipImagineExtension.php index 12c077250..c7169d6fe 100644 --- a/DependencyInjection/LiipImagineExtension.php +++ b/DependencyInjection/LiipImagineExtension.php @@ -14,6 +14,7 @@ use Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface; use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface; use Liip\ImagineBundle\Imagine\Cache\CacheManager; +use Liip\ImagineBundle\Imagine\Cache\CacheManagerInterface; use Liip\ImagineBundle\Imagine\Data\DataManager; use Liip\ImagineBundle\Imagine\Filter\FilterManager; use Symfony\Component\Config\FileLocator; @@ -98,6 +99,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setAlias('liip_imagine', new Alias('liip_imagine.'.$config['driver'])); $container->setAlias(CacheManager::class, new Alias('liip_imagine.cache.manager', false)); + $container->setAlias(CacheManagerInterface::class, new Alias('liip_imagine.cache.manager', false)); $container->setAlias(DataManager::class, new Alias('liip_imagine.data.manager', false)); $container->setAlias(FilterManager::class, new Alias('liip_imagine.filter.manager', false)); diff --git a/Imagine/Cache/CacheManager.php b/Imagine/Cache/CacheManager.php index 389127ba7..27d39e05b 100644 --- a/Imagine/Cache/CacheManager.php +++ b/Imagine/Cache/CacheManager.php @@ -22,7 +22,7 @@ use Symfony\Component\Routing\RouterInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; -class CacheManager +class CacheManager implements CacheManagerInterface { /** * @var FilterConfiguration @@ -63,7 +63,7 @@ class CacheManager * Constructs the cache manager to handle Resolvers based on the provided FilterConfiguration. * * @param string $defaultResolver - * @param bool $webpGenerate + * @param bool $webpGenerate */ public function __construct( FilterConfiguration $filterConfig, @@ -99,15 +99,20 @@ public function addResolver($filter, ResolverInterface $resolver) * Gets filtered path for rendering in the browser. * It could be the cached one or an url of filter action. * - * @param string $path The path where the resolved file is expected + * @param string $path The path where the resolved file is expected * @param string $filter * @param string $resolver - * @param int $referenceType + * @param int $referenceType * * @return string */ - public function getBrowserPath($path, $filter, array $runtimeConfig = [], $resolver = null, $referenceType = UrlGeneratorInterface::ABSOLUTE_URL) - { + public function getBrowserPath( + $path, + $filter, + array $runtimeConfig = [], + $resolver = null, + $referenceType = UrlGeneratorInterface::ABSOLUTE_URL + ) { if (!empty($runtimeConfig)) { $rcPath = $this->getRuntimePath($path, $runtimeConfig); @@ -136,15 +141,20 @@ public function getRuntimePath($path, array $runtimeConfig) /** * Returns a web accessible URL. * - * @param string $path The path where the resolved file is expected - * @param string $filter The name of the imagine filter in effect + * @param string $path The path where the resolved file is expected + * @param string $filter The name of the imagine filter in effect * @param string $resolver - * @param int $referenceType The type of reference to be generated (one of the UrlGenerator constants) + * @param int $referenceType The type of reference to be generated (one of the UrlGenerator constants) * * @return string */ - public function generateUrl($path, $filter, array $runtimeConfig = [], $resolver = null, $referenceType = UrlGeneratorInterface::ABSOLUTE_URL) - { + public function generateUrl( + $path, + $filter, + array $runtimeConfig = [], + $resolver = null, + $referenceType = UrlGeneratorInterface::ABSOLUTE_URL + ) { $params = [ 'path' => ltrim($path, '/'), 'filter' => $filter, @@ -187,20 +197,25 @@ public function isStored($path, $filter, $resolver = null) * @param string $filter * @param string $resolver * + * @return string The url of resolved image * @throws NotFoundHttpException if the path can not be resolved * - * @return string The url of resolved image */ public function resolve($path, $filter, $resolver = null) { if (false !== mb_strpos($path, '/../') || 0 === mb_strpos($path, '../')) { - throw new NotFoundHttpException(sprintf("Source image was searched with '%s' outside of the defined root path", $path)); + throw new NotFoundHttpException( + sprintf("Source image was searched with '%s' outside of the defined root path", $path) + ); } $preEvent = new CacheResolveEvent($path, $filter); $this->dispatchWithBC($preEvent, ImagineEvents::PRE_RESOLVE); - $url = $this->getResolver($preEvent->getFilter(), $resolver)->resolve($preEvent->getPath(), $preEvent->getFilter()); + $url = $this->getResolver($preEvent->getFilter(), $resolver)->resolve( + $preEvent->getPath(), + $preEvent->getFilter() + ); $postEvent = new CacheResolveEvent($preEvent->getPath(), $preEvent->getFilter(), $url); $this->dispatchWithBC($postEvent, ImagineEvents::POST_RESOLVE); @@ -209,11 +224,11 @@ public function resolve($path, $filter, $resolver = null) } /** - * @see ResolverInterface::store - * * @param string $path * @param string $filter * @param string $resolver + * @see ResolverInterface::store + * */ public function store(BinaryInterface $binary, $path, $filter, $resolver = null) { @@ -262,9 +277,9 @@ public function remove($paths = null, $filters = null) * @param string $filter * @param string $resolver * + * @return ResolverInterface * @throws \OutOfBoundsException If neither a specific nor a default resolver is available * - * @return ResolverInterface */ protected function getResolver($filter, $resolver) { @@ -278,7 +293,9 @@ protected function getResolver($filter, $resolver) } if (!isset($this->resolvers[$resolverName])) { - throw new \OutOfBoundsException(sprintf('Could not find resolver "%s" for "%s" filter type', $resolverName, $filter)); + throw new \OutOfBoundsException( + sprintf('Could not find resolver "%s" for "%s" filter type', $resolverName, $filter) + ); } return $this->resolvers[$resolverName]; diff --git a/Imagine/Cache/CacheManagerInterface.php b/Imagine/Cache/CacheManagerInterface.php new file mode 100644 index 000000000..16ffa5939 --- /dev/null +++ b/Imagine/Cache/CacheManagerInterface.php @@ -0,0 +1,50 @@ +