[!!!][FEATURE] Introduce Backend Routing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Routing / Route.php
1 <?php
2 namespace TYPO3\CMS\Backend\Routing;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * This is a single entity for a Route.
19 *
20 * The architecture is highly inspired by the Symfony Routing Component.
21 */
22 class Route {
23
24 /**
25 * @var string
26 */
27 protected $path = '/';
28
29 /**
30 * @var array
31 */
32 protected $options = array();
33
34 /**
35 * Constructor setting up the required path and options
36 *
37 * @param string $path The path pattern to match
38 * @param array $options An array of options
39 */
40 public function __construct($path, $options) {
41 $this->setPath($path)->setOptions($options);
42 }
43
44 /**
45 * Returns the path
46 *
47 * @return string The path pattern
48 */
49 public function getPath() {
50 return $this->path;
51 }
52
53 /**
54 * Sets the pattern for the path
55 * A pattern must start with a slash and must not have multiple slashes at the beginning because the
56 * generated path for this route would be confused with a network path, e.g. '//domain.com/path'.
57 *
58 * This method implements a fluent interface.
59 *
60 * @param string $pattern The path pattern
61 * @return Route The current Route instance
62 */
63 public function setPath($pattern) {
64 $this->path = '/' . ltrim(trim($pattern), '/');
65 return $this;
66 }
67
68 /**
69 * Returns the options set
70 *
71 * @return array The options
72 */
73 public function getOptions() {
74 return $this->options;
75 }
76
77 /**
78 * Sets the options
79 *
80 * This method implements a fluent interface.
81 *
82 * @param array $options The options
83 * @return Route The current Route instance
84 */
85 public function setOptions(array $options) {
86 $this->options = $options;
87 return $this;
88 }
89
90 /**
91 * Sets an option value
92 *
93 * This method implements a fluent interface.
94 *
95 * @param string $name An option name
96 * @param mixed $value The option value
97 * @return Route The current Route instance
98 */
99 public function setOption($name, $value) {
100 $this->options[$name] = $value;
101 return $this;
102 }
103
104 /**
105 * Get an option value
106 *
107 * @param string $name An option name
108 * @return mixed The option value or NULL when not given
109 */
110 public function getOption($name) {
111 return isset($this->options[$name]) ? $this->options[$name] : NULL;
112 }
113
114 /**
115 * Checks if an option has been set
116 *
117 * @param string $name An option name
118 * @return bool TRUE if the option is set, FALSE otherwise
119 */
120 public function hasOption($name) {
121 return array_key_exists($name, $this->options);
122 }
123 }