191aa68a57a18fdd2bb667281e2a41be9fc1f019
[yaffs-website] / vendor / symfony / routing / Annotation / Route.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Routing\Annotation;
13
14 /**
15  * Annotation class for @Route().
16  *
17  * @Annotation
18  * @Target({"CLASS", "METHOD"})
19  *
20  * @author Fabien Potencier <fabien@symfony.com>
21  */
22 class Route
23 {
24     private $path;
25     private $name;
26     private $requirements = array();
27     private $options = array();
28     private $defaults = array();
29     private $host;
30     private $methods = array();
31     private $schemes = array();
32     private $condition;
33
34     /**
35      * Constructor.
36      *
37      * @param array $data An array of key/value parameters
38      *
39      * @throws \BadMethodCallException
40      */
41     public function __construct(array $data)
42     {
43         if (isset($data['value'])) {
44             $data['path'] = $data['value'];
45             unset($data['value']);
46         }
47
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)));
52             }
53             $this->$method($value);
54         }
55     }
56
57     /**
58      * @deprecated since version 2.2, to be removed in 3.0. Use setPath instead.
59      */
60     public function setPattern($pattern)
61     {
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);
63
64         $this->path = $pattern;
65     }
66
67     /**
68      * @deprecated since version 2.2, to be removed in 3.0. Use getPath instead.
69      */
70     public function getPattern()
71     {
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);
73
74         return $this->path;
75     }
76
77     public function setPath($path)
78     {
79         $this->path = $path;
80     }
81
82     public function getPath()
83     {
84         return $this->path;
85     }
86
87     public function setHost($pattern)
88     {
89         $this->host = $pattern;
90     }
91
92     public function getHost()
93     {
94         return $this->host;
95     }
96
97     public function setName($name)
98     {
99         $this->name = $name;
100     }
101
102     public function getName()
103     {
104         return $this->name;
105     }
106
107     public function setRequirements($requirements)
108     {
109         if (isset($requirements['_method'])) {
110             if (0 === count($this->methods)) {
111                 $this->methods = explode('|', $requirements['_method']);
112             }
113
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);
115         }
116
117         if (isset($requirements['_scheme'])) {
118             if (0 === count($this->schemes)) {
119                 $this->schemes = explode('|', $requirements['_scheme']);
120             }
121
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);
123         }
124
125         $this->requirements = $requirements;
126     }
127
128     public function getRequirements()
129     {
130         return $this->requirements;
131     }
132
133     public function setOptions($options)
134     {
135         $this->options = $options;
136     }
137
138     public function getOptions()
139     {
140         return $this->options;
141     }
142
143     public function setDefaults($defaults)
144     {
145         $this->defaults = $defaults;
146     }
147
148     public function getDefaults()
149     {
150         return $this->defaults;
151     }
152
153     public function setSchemes($schemes)
154     {
155         $this->schemes = is_array($schemes) ? $schemes : array($schemes);
156     }
157
158     public function getSchemes()
159     {
160         return $this->schemes;
161     }
162
163     public function setMethods($methods)
164     {
165         $this->methods = is_array($methods) ? $methods : array($methods);
166     }
167
168     public function getMethods()
169     {
170         return $this->methods;
171     }
172
173     public function setCondition($condition)
174     {
175         $this->condition = $condition;
176     }
177
178     public function getCondition()
179     {
180         return $this->condition;
181     }
182 }