Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
routingconfiguration.php
1<?php
9namespace Bitrix\Main\Routing;
10
12
25{
27 protected $configurator;
28
30 protected $routeContainer;
31
33 protected $options;
34
35 public static $configurationList = [
36 'get', 'post', 'put', 'patch', 'options', 'delete', 'any', 'group'
37 ];
38
39 public function __call($method, $arguments)
40 {
41 // setting option
42 if (in_array($method, Options::$optionList, true))
43 {
44 $this->options->$method(...$arguments);
45 return $this;
46 }
47
48 throw new SystemException(sprintf(
49 'Unknown method `%s` for object `%s`', $method, get_called_class()
50 ));
51 }
52
57 {
58 $this->configurator = $configurator;
59 }
60
64 public function setOptions($options)
65 {
66 $this->options = $options;
67 }
68
69 public function get($uri, $controller)
70 {
71 $this->options->methods(['GET', 'HEAD']);
72
73 $route = new Route($uri, $controller);
74 $this->routeContainer = $route;
75
76 return $this;
77 }
78
79 public function post($uri, $controller)
80 {
81 $this->options->methods(['POST']);
82
83 $route = new Route($uri, $controller);
84 $this->routeContainer = $route;
85
86 return $this;
87 }
88
89 public function put($uri, $controller)
90 {
91 $this->options->methods(['PUT']);
92
93 $route = new Route($uri, $controller);
94 $this->routeContainer = $route;
95
96 return $this;
97 }
98
99 public function patch($uri, $controller)
100 {
101 $this->options->methods(['PATCH']);
102
103 $route = new Route($uri, $controller);
104 $this->routeContainer = $route;
105
106 return $this;
107 }
108
109 public function options($uri, $controller)
110 {
111 $this->options->methods(['OPTIONS']);
112
113 $route = new Route($uri, $controller);
114 $this->routeContainer = $route;
115
116 return $this;
117 }
118
119 public function delete($uri, $controller)
120 {
121 $this->options->methods(['DELETE']);
122
123 $route = new Route($uri, $controller);
124 $this->routeContainer = $route;
125
126 return $this;
127 }
128
129 public function any($uri, $controller)
130 {
131 $route = new Route($uri, $controller);
132 $this->routeContainer = $route;
133
134 return $this;
135 }
136
137 public function match($methods, $uri, $controller)
138 {
139 $this->options->methods($methods);
140
141 $route = new Route($uri, $controller);
142 $this->routeContainer = $route;
143
144 return $this;
145 }
146
147 public function group($callback)
148 {
149 $this->routeContainer = $callback;
150
151 // add inner configuration to the router
152 $subConfigurator = clone $this->configurator;
153 $subConfigurator->mergeOptionsWith($this->options);
154
155 // call
156 $callback = $this->routeContainer;
157 $callback($subConfigurator);
158 }
159
160 public function release()
161 {
162 $routes = [];
163
164 if ($this->routeContainer instanceof Route)
165 {
166 $route = $this->routeContainer;
167 $route->setOptions($this->options);
168
169 $routes[] = $route;
170 }
171
172 return $routes;
173 }
174}