forked from yamiko-ninja/CacheAdministrationBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CacheManager.php
128 lines (114 loc) · 2.91 KB
/
CacheManager.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace Yamiko\CacheAdministrationBundle;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
/**
* Class CacheManager
* @package Yamiko\CacheAdministrationBundle
*/
class CacheManager
{
/** @var Filesystem */
private $filesystm;
/** @var string path to cache directory */
private $cacheDir;
/**
* @param string $cacheDir path to application root directory
*/
public function __construct($cacheDir)
{
if (!is_dir($cacheDir)) {
throw new FileNotFoundException(null, 0, null, $cacheDir);
}
$this->cacheDir = $cacheDir;
$this->filesystm = new Filesystem();
}
/**
* Clear annotations cache
*/
public function clearAnnotations()
{
$this->filesystm->remove($this->cacheDir.'/annotations');
}
/**
* clear assetic cache
*/
public function clearAssetic()
{
$this->filesystm->remove($this->cacheDir.'/assetic');
}
/**
* clear doctrine cache
*/
public function clearDoctrine()
{
$this->filesystm->remove($this->cacheDir.'/doctrine');
}
/**
* clear translations cache
*/
public function clearTranslations()
{
$this->filesystm->remove($this->cacheDir.'/translations');
}
/**
* clear profiles cache
*/
public function clearProfiles()
{
$this->filesystm->remove($this->cacheDir.'/profiler');
}
/**
* clear container cache
*/
public function clearContainer()
{
$finder = new Finder();
$finder->name('*ProjectContainer*');
$this->filesystm->remove($finder->in($this->cacheDir.DIRECTORY_SEPARATOR));
}
/**
* clear routing cache
*/
public function clearRouting()
{
$finder = new Finder();
$finder->name('*UrlGenerator*');
$this->filesystm->remove($finder->in($this->cacheDir.'/'));
$finder->name('*UrlMatcher*');
$this->filesystm->remove($finder->in($this->cacheDir.'/'));
}
/**
* clear classes cache
*/
public function clearClasses()
{
$finder = new Finder();
$finder->name('classes*');
$this->filesystm->remove($finder->in($this->cacheDir.'/'));
}
/**
* clear templates cache
*/
public function clearTemplates()
{
$this->filesystm->remove($this->cacheDir.'/twig');
$finder = new Finder();
$finder->name('templates*');
$this->filesystm->remove($finder->in($this->cacheDir.'/'));
}
/**
* clear all caches
*/
public function clearAll()
{
$this->clearAnnotations();
$this->clearAssetic();
$this->clearContainer();
$this->clearClasses();
$this->clearDoctrine();
$this->clearRouting();
$this->clearTemplates();
}
}