[ROUTER] Add option is_system_path
, to allow specifying that a route, such as gsactor_view_nickname
should not be considered a system path, when checking for the collision of nicknames
This commit is contained in:
parent
e563c393f8
commit
15a2a69274
@ -96,7 +96,7 @@ class RouteLoader extends Loader
|
||||
* @param mixed $target Some kind of callable, typically class with `__invoke` or [object, method]
|
||||
* @param null|array $param_reqs Array of {param} => regex
|
||||
* @param null|array $options Possible keys are ['condition', 'defaults', 'format',
|
||||
* 'fragment', 'http-methods', 'locale', 'methods', 'schemes', 'accept']
|
||||
* 'fragment', 'http-methods', 'locale', 'methods', 'schemes', 'accept', 'is_system_path']
|
||||
* 'http-methods' and 'methods' are aliases
|
||||
*/
|
||||
public function connect(string $id, string $uri_path, $target, ?array $options = [], ?array $param_reqs = [])
|
||||
@ -109,12 +109,13 @@ class RouteLoader extends Loader
|
||||
// and special configuration options
|
||||
defaults: array_merge(
|
||||
[
|
||||
'_controller' => is_array($target) ? $target : [$target, '__invoke'],
|
||||
'_format' => $options['format'] ?? 'html',
|
||||
'_fragment' => $options['fragment'] ?? '',
|
||||
'_locale' => $options['locale'] ?? 'en',
|
||||
'template' => $options['template'] ?? '',
|
||||
'accept' => $options['accept'] ?? [],
|
||||
'_controller' => is_array($target) ? $target : [$target, '__invoke'],
|
||||
'_format' => $options['format'] ?? 'html',
|
||||
'_fragment' => $options['fragment'] ?? '',
|
||||
'_locale' => $options['locale'] ?? 'en',
|
||||
'template' => $options['template'] ?? '',
|
||||
'accept' => $options['accept'] ?? [],
|
||||
'is_system_path' => $options['is_system_path'] ?? true,
|
||||
],
|
||||
$options['defaults'] ?? []
|
||||
),
|
||||
|
@ -43,6 +43,6 @@ abstract class GSActor
|
||||
public static function load(RouteLoader $r): void
|
||||
{
|
||||
$r->connect(id: 'gsactor_view_id', uri_path: '/actor/{id<\d+>}', target: [C\GSActor::class, 'GSActorShowId']);
|
||||
$r->connect(id: 'gsactor_view_nickname', uri_path: '/{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\GSActor::class, 'GSActorShowNickname']);
|
||||
$r->connect(id: 'gsactor_view_nickname', uri_path: '/{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\GSActor::class, 'GSActorShowNickname'], options: ['is_system_path' => false]);
|
||||
}
|
||||
}
|
||||
|
@ -154,8 +154,8 @@ abstract class Common
|
||||
public static function isSystemPath(string $str): bool
|
||||
{
|
||||
try {
|
||||
Router::match('/' . $str);
|
||||
return true;
|
||||
$route = Router::match('/' . $str);
|
||||
return $route['is_system_path'] ?? true;
|
||||
} catch (ResourceNotFoundException $e) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user