Skip to content

Commit c079114

Browse files
Merge branch 'v5.1-development'
2 parents 0639e9a + 1f6aae5 commit c079114

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/Pecee/SimpleRouter/SimpleRouter.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,36 +416,35 @@ public static function controller(string $url, string $controller, array $settin
416416

417417
public static function loadRoutes(string $controller)
418418
{
419-
$group = new RouteGroup();
419+
$group_settings = array();
420+
$group_prefix = '';
420421

421422
$class = new \ReflectionClass($controller);
422423
$attributes = $class->getAttributes(\Pecee\Http\Input\Attributes\RouteGroup::class);
423424
if(sizeof($attributes) > 0){
424425
/**
425-
* @var $attribute RouteGroup
426+
* @var $attribute \Pecee\Http\Input\Attributes\RouteGroup
426427
*/
427428
$attribute = $attributes[0]->newInstance();
428-
$group->setPrefix($attribute->getRoute());
429-
if($attribute->getSettings() !== null)
430-
$group->setSettings($attribute->getSettings());
429+
$group_prefix = $attribute->getRoute();
430+
$group_settings = $attribute->getSettings() ?? array();
431431
}
432432

433433
foreach($class->getMethods() as $method){
434434
$attributes = $method->getAttributes(\Pecee\Http\Input\Attributes\Route::class);
435435
foreach($attributes as $attribute){
436436
/**
437-
* @var $attribute_attr Route
437+
* @var $attribute_attr \Pecee\Http\Input\Attributes\Route
438438
*/
439439
$attribute_attr = $attribute->newInstance();
440+
error_log(json_encode($group_prefix . $attribute_attr->getRoute() . '-' . $attribute_attr->getMethod() . '-' . $class->getNamespaceName() . $class->getShortName() . '-' . $method->getName()));
440441

441-
$route = new RouteUrl($attribute_attr->getRoute(), sprintf('%s@%s', $class->getName(), $method->getName()));
442+
$route = new RouteUrl($group_prefix . $attribute_attr->getRoute(), sprintf('%s@%s', '\\' . $class->getName(), $method->getName()));
442443
$route->setRequestMethods([$attribute_attr->getMethod()]);
443-
if($attribute_attr->getSettings() !== null)
444-
$route->setSettings($attribute_attr->getSettings());
445-
$route->setGroup($group);
444+
$route->setSettings(array_merge($attribute_attr->getSettings() ?? array(), $group_settings));
445+
446446
static::router()->addRoute($route);
447447
}
448-
449448
}
450449
}
451450

0 commit comments

Comments
 (0)