4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Routing\Annotation;
15 * Annotation class for @Route().
18 * @Target({"CLASS", "METHOD"})
20 * @author Fabien Potencier <fabien@symfony.com>
26 private $requirements = array();
27 private $options = array();
28 private $defaults = array();
30 private $methods = array();
31 private $schemes = array();
37 * @param array $data An array of key/value parameters
39 * @throws \BadMethodCallException
41 public function __construct(array $data)
43 if (isset($data['value'])) {
44 $data['path'] = $data['value'];
45 unset($data['value']);
48 foreach ($data as $key => $value) {
49 $method = 'set'.str_replace('_', '', $key);
50 if (!method_exists($this, $method)) {
51 throw new \BadMethodCallException(sprintf('Unknown property "%s" on annotation "%s".', $key, get_class($this)));
53 $this->$method($value);
58 * @deprecated since version 2.2, to be removed in 3.0. Use setPath instead.
60 public function setPattern($pattern)
62 @trigger_error('The '.__METHOD__.' method is deprecated since version 2.2 and will be removed in 3.0. Use the setPath() method instead and use the "path" option instead of the "pattern" option in the route definition.', E_USER_DEPRECATED);
64 $this->path = $pattern;
68 * @deprecated since version 2.2, to be removed in 3.0. Use getPath instead.
70 public function getPattern()
72 @trigger_error('The '.__METHOD__.' method is deprecated since version 2.2 and will be removed in 3.0. Use the getPath() method instead and use the "path" option instead of the "pattern" option in the route definition.', E_USER_DEPRECATED);
77 public function setPath($path)
82 public function getPath()
87 public function setHost($pattern)
89 $this->host = $pattern;
92 public function getHost()
97 public function setName($name)
102 public function getName()
107 public function setRequirements($requirements)
109 if (isset($requirements['_method'])) {
110 if (0 === count($this->methods)) {
111 $this->methods = explode('|', $requirements['_method']);
114 @trigger_error('The "_method" requirement is deprecated since version 2.2 and will be removed in 3.0. Use the "methods" option instead.', E_USER_DEPRECATED);
117 if (isset($requirements['_scheme'])) {
118 if (0 === count($this->schemes)) {
119 $this->schemes = explode('|', $requirements['_scheme']);
122 @trigger_error('The "_scheme" requirement is deprecated since version 2.2 and will be removed in 3.0. Use the "schemes" option instead.', E_USER_DEPRECATED);
125 $this->requirements = $requirements;
128 public function getRequirements()
130 return $this->requirements;
133 public function setOptions($options)
135 $this->options = $options;
138 public function getOptions()
140 return $this->options;
143 public function setDefaults($defaults)
145 $this->defaults = $defaults;
148 public function getDefaults()
150 return $this->defaults;
153 public function setSchemes($schemes)
155 $this->schemes = is_array($schemes) ? $schemes : array($schemes);
158 public function getSchemes()
160 return $this->schemes;
163 public function setMethods($methods)
165 $this->methods = is_array($methods) ? $methods : array($methods);
168 public function getMethods()
170 return $this->methods;
173 public function setCondition($condition)
175 $this->condition = $condition;
178 public function getCondition()
180 return $this->condition;