forked from avalanche123/AvalancheImagineBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImagineExtension.php
58 lines (51 loc) · 1.34 KB
/
ImagineExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Avalanche\Bundle\ImagineBundle\Templating;
use Avalanche\Bundle\ImagineBundle\Imagine\CachePathResolver;
use Symfony\Component\Filesystem\Filesystem;
class ImagineExtension extends \Twig_Extension
{
/**
* @var Avalanche\Bundle\ImagineBundle\Imagine\CachePathResolver
*/
private $cachePathResolver;
/**
* Constructs by setting $cachePathResolver
*
* @param Avalanche\Bundle\ImagineBundle\Imagine\CachePathResolver $cachePathResolver
*/
public function __construct(CachePathResolver $cachePathResolver)
{
$this->cachePathResolver = $cachePathResolver;
}
/**
* (non-PHPdoc)
* @see Twig_Extension::getFilters()
*/
public function getFilters()
{
return array(
'apply_filter' => new \Twig_Filter_Method($this, 'applyFilter'),
);
}
/**
* Gets cache path of an image to be filtered
*
* @param string $path
* @param string $filter
* @param boolean $absolute
*
* @return string
*/
public function applyFilter($path, $filter, $absolute = false)
{
return $this->cachePathResolver->getBrowserPath($path, $filter, $absolute);
}
/**
* (non-PHPdoc)
* @see Twig_ExtensionInterface::getName()
*/
public function getName()
{
return 'imagine';
}
}