forked from liip/LiipImagineBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImagineController.php
More file actions
69 lines (59 loc) · 1.75 KB
/
ImagineController.php
File metadata and controls
69 lines (59 loc) · 1.75 KB
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
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Liip\ImagineBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
class ImagineController
{
/**
* @var DataManager
*/
protected $dataManager;
/**
* @var FilterManager
*/
protected $filterManager;
/**
* @var CacheManager
*/
protected $cacheManager;
/**
* Constructor
*
* @param DataManager $dataManager
* @param FilterManager $filterManager
* @param CacheManager $cacheManager
*/
public function __construct(DataManager $dataManager, FilterManager $filterManager, CacheManager $cacheManager)
{
$this->dataManager = $dataManager;
$this->filterManager = $filterManager;
$this->cacheManager = $cacheManager;
}
/**
* This action applies a given filter to a given image,
* optionally saves the image and
* outputs it to the browser at the same time
*
* @param Request $request
* @param string $path
* @param string $filter
*
* @return Response
*/
public function filterAction(Request $request, $path, $filter)
{
$targetPath = $this->cacheManager->resolve($request, $path, $filter);
if ($targetPath instanceof Response) {
return $targetPath;
}
$image = $this->dataManager->find($filter, $path);
$response = $this->filterManager->get($request, $filter, $image, $path);
if ($targetPath) {
$response = $this->cacheManager->store($response, $targetPath, $filter);
}
return $response;
}
}