-
Notifications
You must be signed in to change notification settings - Fork 380
/
AbstractWebPathResolver.php
100 lines (86 loc) · 2.37 KB
/
AbstractWebPathResolver.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Liip\ImagineBundle\Imagine\Cache\Resolver;
use Liip\ImagineBundle\Binary\BinaryInterface;
use Liip\ImagineBundle\Utility\Path\PathResolverInterface;
use Symfony\Component\Filesystem\Filesystem;
abstract class AbstractWebPathResolver implements ResolverInterface
{
/**
* @var Filesystem
*/
protected $filesystem;
/**
* @var PathResolverInterface
*/
protected $pathResolver;
/**
* @param Filesystem $filesystem
* @param PathResolverInterface $pathResolver
*/
public function __construct(
Filesystem $filesystem,
PathResolverInterface $pathResolver
) {
$this->filesystem = $filesystem;
$this->pathResolver = $pathResolver;
}
/**
* Checks whether the given path is stored within this Resolver.
*
* @param string $path
* @param string $filter
*
* @return bool
*/
public function isStored($path, $filter)
{
return is_file($this->pathResolver->getFilePath($path, $filter));
}
/**
* {@inheritdoc}
*/
public function store(BinaryInterface $binary, $path, $filter)
{
$this->filesystem->dumpFile(
$this->pathResolver->getFilePath($path, $filter),
$binary->getContent()
);
}
/**
* {@inheritdoc}
*/
public function remove(array $paths, array $filters)
{
if (empty($paths) && empty($filters)) {
return;
}
if (empty($paths)) {
$filtersCacheDir = [];
foreach ($filters as $filter) {
$filtersCacheDir[] = $this->pathResolver->getCacheRoot().'/'.$filter;
}
$this->filesystem->remove($filtersCacheDir);
return;
}
foreach ($paths as $path) {
foreach ($filters as $filter) {
$this->filesystem->remove($this->pathResolver->getFilePath($path, $filter));
}
}
}
/**
* @return PathResolverInterface
*/
protected function getPathResolver()
{
return $this->pathResolver;
}
}