3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license.
29 * Accepted HTTP methods for this route.
33 private $methods = array('GET', 'POST', 'PUT', 'DELETE');
36 * Target for this route, can be anything.
42 * The name of this route, used for reversed routing
48 * Custom parameter filters for this route
51 private $filters = array();
54 * Array containing parameters passed through request URL
57 private $parameters = array();
66 * @param array $config
68 public function __construct($resource, array $config)
70 $this->url = $resource;
71 $this->config = $config;
72 $this->methods = isset($config['methods']) ? $config['methods'] : array();
73 $this->target = isset($config['target']) ? $config['target'] : null;
76 public function getUrl()
81 public function setUrl($url)
85 // make sure that the URL is suffixed with a forward slash
86 if (substr($url, -1) !== '/') {
93 public function getTarget()
98 public function setTarget($target)
100 $this->target = $target;
103 public function getMethods()
105 return $this->methods;
108 public function setMethods(array $methods)
110 $this->methods = $methods;
113 public function getName()
118 public function setName($name)
120 $this->name = (string)$name;
123 public function setFilters(array $filters)
125 $this->filters = $filters;
128 public function getRegex()
130 return preg_replace_callback("/:(\w+)/", array(&$this, 'substituteFilter'), $this->url);
133 private function substituteFilter($matches)
135 if (isset($matches[1]) && isset($this->filters[$matches[1]])) {
136 return $this->filters[$matches[1]];
142 public function getParameters()
144 return $this->parameters;
147 public function setParameters(array $parameters)
149 $this->parameters = $parameters;
152 public function dispatch()
154 $action = explode('::', $this->config['_controller']);
155 $instance = new $action[0];
156 call_user_func_array(array($instance, $action[1]), $this->parameters);