1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSHttpCacheBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FOS\HttpCacheBundle\Configuration; |
13
|
|
|
|
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation; |
15
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @Annotation |
19
|
|
|
*/ |
20
|
|
|
class InvalidateRoute extends ConfigurationAnnotation |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $name; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
private $params; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Handle route name given without explicit key. |
34
|
|
|
* |
35
|
|
|
* @param string $value The route name |
36
|
|
|
*/ |
37
|
|
|
public function setValue($value) |
38
|
|
|
{ |
39
|
|
|
$this->setName($value); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $name |
44
|
|
|
*/ |
45
|
|
|
public function setName($name) |
46
|
|
|
{ |
47
|
|
|
$this->name = $name; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getName() |
54
|
|
|
{ |
55
|
|
|
return $this->name; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param array $params |
60
|
|
|
*/ |
61
|
|
|
public function setParams($params) |
62
|
|
|
{ |
63
|
|
|
if (!is_array($params)) { |
64
|
|
|
throw new \RuntimeException('InvalidateRoute params must be an array'); |
65
|
|
|
} |
66
|
|
|
foreach ($params as $name => $value) { |
67
|
|
|
if (is_array($value)) { |
68
|
|
|
if (1 !== count($value) || !isset($value['expression'])) { |
69
|
|
|
throw new \RuntimeException(sprintf( |
70
|
|
|
'@InvalidateRoute param %s must be string or {"expression"="<expression>"}', |
71
|
|
|
$name, |
72
|
|
|
print_r($value, true) |
73
|
|
|
)); |
74
|
|
|
} |
75
|
|
|
// @codeCoverageIgnoreStart |
76
|
|
|
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { |
77
|
|
|
throw new InvalidConfigurationException(sprintf( |
78
|
|
|
'@InvalidateRoute param %s uses an expression but the ExpressionLanguage is not available.', |
79
|
|
|
$name |
80
|
|
|
)); |
81
|
|
|
} |
82
|
|
|
// @codeCoverageIgnoreEnd |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$this->params = $params; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function getParams() |
93
|
|
|
{ |
94
|
|
|
return $this->params; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function getAliasName() |
101
|
|
|
{ |
102
|
|
|
return 'invalidate_route'; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function allowArray() |
109
|
|
|
{ |
110
|
|
|
return true; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|