1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FrankDeJonge\SymfonyI18nRouting\Routing\Annotation; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use function is_array; |
7
|
|
|
use function ucfirst; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* I18nRoute annotation. |
11
|
|
|
* |
12
|
|
|
* @Annotation |
13
|
|
|
* @Target({"CLASS", "METHOD"}) |
14
|
|
|
*/ |
15
|
|
|
class I18nRoute |
16
|
|
|
{ |
17
|
|
|
private $path; |
18
|
|
|
|
19
|
|
|
private $locales = []; |
20
|
|
|
|
21
|
|
|
private $name; |
22
|
|
|
|
23
|
|
|
private $requirements = []; |
24
|
|
|
|
25
|
|
|
private $options = []; |
26
|
|
|
|
27
|
|
|
private $defaults = []; |
28
|
|
|
|
29
|
|
|
private $host; |
30
|
|
|
|
31
|
|
|
private $methods = []; |
32
|
|
|
|
33
|
|
|
private $schemes = []; |
34
|
|
|
|
35
|
|
|
private $condition; |
36
|
|
|
|
37
|
52 |
|
public function __construct(array $data) |
38
|
|
|
{ |
39
|
52 |
|
if (isset($data['value'])) { |
40
|
28 |
|
$data[is_array($data['value']) ? 'locales' : 'path'] = $data['value']; |
41
|
28 |
|
unset($data['value']); |
42
|
|
|
} |
43
|
|
|
|
44
|
52 |
|
foreach ($data as $key => $value) { |
45
|
52 |
|
$method = 'set' . str_replace('_', '', ucfirst($key)); |
46
|
|
|
|
47
|
52 |
|
if ( ! method_exists($this, $method)) { |
48
|
2 |
|
throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, get_class($this))); |
49
|
|
|
} |
50
|
50 |
|
$this->$method($value); |
51
|
|
|
} |
52
|
50 |
|
} |
53
|
|
|
|
54
|
18 |
|
public function setPath($path) |
55
|
|
|
{ |
56
|
18 |
|
$this->path = $path; |
57
|
18 |
|
} |
58
|
|
|
|
59
|
28 |
|
public function getPath() |
60
|
|
|
{ |
61
|
28 |
|
return $this->path; |
62
|
|
|
} |
63
|
|
|
|
64
|
4 |
|
public function setHost($pattern) |
65
|
|
|
{ |
66
|
4 |
|
$this->host = $pattern; |
67
|
4 |
|
} |
68
|
|
|
|
69
|
26 |
|
public function getHost() |
70
|
|
|
{ |
71
|
26 |
|
return $this->host; |
72
|
|
|
} |
73
|
|
|
|
74
|
26 |
|
public function setName($name) |
75
|
|
|
{ |
76
|
26 |
|
$this->name = $name; |
77
|
26 |
|
} |
78
|
|
|
|
79
|
28 |
|
public function getName() |
80
|
|
|
{ |
81
|
28 |
|
return $this->name; |
82
|
|
|
} |
83
|
|
|
|
84
|
2 |
|
public function setRequirements($requirements) |
85
|
|
|
{ |
86
|
2 |
|
$this->requirements = $requirements; |
87
|
2 |
|
} |
88
|
|
|
|
89
|
26 |
|
public function getRequirements() |
90
|
|
|
{ |
91
|
26 |
|
return $this->requirements; |
92
|
|
|
} |
93
|
|
|
|
94
|
2 |
|
public function setOptions($options) |
95
|
|
|
{ |
96
|
2 |
|
$this->options = $options; |
97
|
2 |
|
} |
98
|
|
|
|
99
|
26 |
|
public function getOptions() |
100
|
|
|
{ |
101
|
26 |
|
return $this->options; |
102
|
|
|
} |
103
|
|
|
|
104
|
2 |
|
public function setDefaults($defaults) |
105
|
|
|
{ |
106
|
2 |
|
$this->defaults = $defaults; |
107
|
2 |
|
} |
108
|
|
|
|
109
|
26 |
|
public function getDefaults() |
110
|
|
|
{ |
111
|
26 |
|
return $this->defaults; |
112
|
|
|
} |
113
|
|
|
|
114
|
2 |
|
public function setSchemes($schemes) |
115
|
|
|
{ |
116
|
2 |
|
$this->schemes = is_array($schemes) ? $schemes : [$schemes]; |
117
|
2 |
|
} |
118
|
|
|
|
119
|
26 |
|
public function getSchemes() |
120
|
|
|
{ |
121
|
26 |
|
return $this->schemes; |
122
|
|
|
} |
123
|
|
|
|
124
|
6 |
|
public function setMethods($methods) |
125
|
|
|
{ |
126
|
6 |
|
$this->methods = is_array($methods) ? $methods : [$methods]; |
127
|
6 |
|
} |
128
|
|
|
|
129
|
26 |
|
public function getMethods() |
130
|
|
|
{ |
131
|
26 |
|
return $this->methods; |
132
|
|
|
} |
133
|
|
|
|
134
|
4 |
|
public function setCondition($condition) |
135
|
|
|
{ |
136
|
4 |
|
$this->condition = $condition; |
137
|
4 |
|
} |
138
|
|
|
|
139
|
26 |
|
public function getCondition() |
140
|
|
|
{ |
141
|
26 |
|
return $this->condition; |
142
|
|
|
} |
143
|
|
|
|
144
|
28 |
|
public function getLocales() |
145
|
|
|
{ |
146
|
28 |
|
return $this->locales; |
147
|
|
|
} |
148
|
|
|
|
149
|
18 |
|
public function setLocales(array $locales) |
150
|
|
|
{ |
151
|
18 |
|
$this->locales = $locales; |
152
|
|
|
} |
153
|
|
|
} |