Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
options.php
1<?php
9namespace Bitrix\Main\Routing;
10
16{
17 // could be auto-generated by Reflection and prop-prefixes
18 public static $optionList = [
19 'methods', 'middleware', 'prefix', 'name', 'domain', 'where', 'default'
20 ];
21
22 protected $methods = [];
23
24 protected $middleware = [];
25
26 protected $prefix;
27
28 protected $parentPrefixes = [];
29
30 protected $name;
31
32 protected $parentNames = [];
33
34 protected $domain;
35
36 protected $where = [];
37
38 protected $default = [];
39
43 public function mergeWith($anotherOptions)
44 {
45 $this->where = array_merge($this->where, $anotherOptions->where);
46 $this->middleware = array_merge($this->middleware, $anotherOptions->middleware);
47
48 if ($anotherOptions->prefix != '')
49 {
50 $this->parentPrefixes[] = $anotherOptions->prefix;
51 }
52
53 if ($anotherOptions->name != '')
54 {
55 $this->parentNames[] = $anotherOptions->name;
56 }
57 }
58
59 public function methods($methods)
60 {
61 $this->methods = $methods;
62 }
63
67 public function getMethods()
68 {
69 return $this->methods;
70 }
71
72 public function middleware($middleware)
73 {
74 if (is_array($middleware))
75 {
76 $this->middleware = array_merge($this->middleware, $middleware);
77 }
78 else
79 {
80 $this->middleware[] = $middleware;
81 }
82 }
83
84 public function prefix($prefix)
85 {
86 $this->prefix = $prefix;
87 }
88
89 public function hasPrefix()
90 {
91 return $this->prefix != '' || !empty($this->parentPrefixes);
92 }
93
94 public function getFullPrefix()
95 {
96 // concat parentPrefixes with this prefix
97 $prefixes = $this->parentPrefixes ?: [];
98
99 if ($this->prefix != '')
100 {
101 $prefixes[] = $this->prefix;
102 }
103
104
105 return '/'.join('/', $prefixes);
106 }
107
108 public function name($name)
109 {
110 $this->name = $name;
111 }
112
113 public function hasName()
114 {
115 return $this->name != '';
116 }
117
118 public function getFullName()
119 {
120 if ($this->name == '')
121 {
122 // route should have its own name
123 return '';
124 }
125
126 // concat parentPrefixes with this prefix
127 $parts = $this->parentNames ?: [];
128 $parts[] = $this->name;
129
130 return join('', $parts);
131 }
132
136 public function domain($domain)
137 {
138 $this->domain = $domain;
139 }
140
141 public function where($parameter, $pattern)
142 {
143 $this->where[$parameter] = $pattern;
144 }
145
146 public function hasWhere($parameter)
147 {
148 return array_key_exists($parameter, $this->where);
149 }
150
151 public function getWhere($parameter = null)
152 {
153 if ($parameter === null)
154 {
155 return $this->where;
156 }
157 else
158 {
159 return $this->where[$parameter];
160 }
161 }
162
163 public function default($parameter, $value)
164 {
165 $this->default[$parameter] = $value;
166 }
167
168 public function hasDefault($parameter)
169 {
170 return array_key_exists($parameter, $this->default);
171 }
172
173 public function getDefault($parameter = null)
174 {
175 if ($parameter === null)
176 {
177 return $this->default;
178 }
179 else
180 {
181 return $this->default[$parameter];
182 }
183 }
184
189 public function clearCurrent()
190 {
191 $this->prefix = null;
192 $this->name = null;
193 }
194}
where($parameter, $pattern)
Definition options.php:141
mergeWith($anotherOptions)
Definition options.php:43
getWhere($parameter=null)
Definition options.php:151
getDefault($parameter=null)
Definition options.php:173