Skip to content

Commit 2a7b076

Browse files
v1.4.1 Release
ルーティング設定のグルーピング機能追加
1 parent 0ec5479 commit 2a7b076

3 files changed

Lines changed: 207 additions & 139 deletions

File tree

app/InitClass/InitForRestApi.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function __construct(ParameterForRestApi $p_unit_parameter, array $p_rout
7676
if($p_routing === [])
7777
{
7878
$this->routing['routes'] = [];
79+
$this->routing['expect'] = null;
7980
$this->routing['mismatch'] = null;
8081
}
8182
$this->parsers = $p_parsers;
@@ -159,14 +160,16 @@ public function getCommandDispatcher()
159160
continue;
160161
}
161162

162-
$uri = trim($route['uri'], '/');
163+
$base_uri = trim($route['uri'], '/');
164+
$uri = trim($route['prefix'] . $route['uri'], '/');
163165

164166
/**
165167
* URI 全体正規表現ルート
166168
*/
167-
if(preg_match('/^:(.+):$/', $uri, $m))
169+
if(preg_match('/^:(.+):$/', $base_uri, $m))
168170
{
169171
$regex = $m[1];
172+
$regex = $route['prefix'] . $regex;
170173
$regex = trim($regex, '/');
171174

172175
$regex = str_replace('/', '\\/', $regex);

app/MainClass/MainForRestApi.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,40 @@ public function exec()
171171
}
172172
$ins_command = new $class_command();
173173

174+
/**
175+
* ルーティングのパース
176+
*/
177+
$flat_routing = [];
178+
foreach($conf_routing['routes'] as $route)
179+
{
180+
// グループ形式
181+
if(isset($route['group']))
182+
{
183+
$prefix = $route['uri'];
184+
foreach($route['group'] as $child)
185+
{
186+
$flat_routing[] = [
187+
'prefix' => $prefix,
188+
'method' => $child['method'],
189+
'uri' => $child['uri'],
190+
'event' => $child['event'],
191+
];
192+
}
193+
}
194+
195+
// 単独ルート
196+
else
197+
{
198+
$flat_routing[] = [
199+
'prefix' => '',
200+
'method' => $route['method'],
201+
'uri' => $route['uri'],
202+
'event' => $route['event'],
203+
];
204+
}
205+
}
206+
$conf_routing['routes'] = $flat_routing;
207+
174208
$queues = [];
175209
foreach($conf_routing['routes'] as $route)
176210
{

0 commit comments

Comments
 (0)