vendor/liip/imagine-bundle/Templating/FilterTrait.php line 14

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the `liip/LiipImagineBundle` project.
  4. *
  5. * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
  6. *
  7. * For the full copyright and license information, please view the LICENSE.md
  8. * file that was distributed with this source code.
  9. */
  10. namespace Liip\ImagineBundle\Templating;
  11. @trigger_error('The '.FilterTrait::class.' trait is deprecated since version 2.7 and will be removed in 3.0; use Twig instead.', E_USER_DEPRECATED);
  12. use Liip\ImagineBundle\Imagine\Cache\CacheManager;
  13. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  14. /**
  15. * @deprecated
  16. */
  17. trait FilterTrait
  18. {
  19. /**
  20. * @var CacheManager
  21. */
  22. private $cache;
  23. public function __construct(CacheManager $cache)
  24. {
  25. $this->cache = $cache;
  26. }
  27. /**
  28. * Gets the browser path for the image and filter to apply.
  29. *
  30. * @param string $path
  31. * @param string $filter
  32. * @param string|null $resolver
  33. * @param int $referenceType
  34. *
  35. * @return string
  36. */
  37. public function filter($path, $filter, array $config = [], $resolver = null, $referenceType = UrlGeneratorInterface::ABSOLUTE_URL)
  38. {
  39. return $this->cache->getBrowserPath(parse_url($path, PHP_URL_PATH), $filter, $config, $resolver, $referenceType);
  40. }
  41. /**
  42. * Gets the cache path for the image and filter to apply.
  43. */
  44. public function filterCache(
  45. string $path,
  46. string $filter,
  47. array $config = [],
  48. ?string $resolver = null
  49. ): string {
  50. $path = parse_url($path, PHP_URL_PATH);
  51. if (!empty($config)) {
  52. $path = $this->cache->getRuntimePath($path, $config);
  53. }
  54. return $this->cache->resolve($path, $filter, $resolver);
  55. }
  56. /**
  57. * @return string
  58. */
  59. public function getName()
  60. {
  61. return 'liip_imagine';
  62. }
  63. }