Lines
0.00%
0 / 28
Methods
0.00%
0 / 13
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| get | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| post | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| put | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| patch | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| delete | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| method | 0.00% | 0 / 8 | 0.00% | 0 / 1 | 12 | ||
| defaultController | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | ||
| prefix | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | ||
| setBasePrefix | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | ||
| buildPath | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 12 | ||
| [Lucent\Routing\RouteGroup] __construct | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | ||
| [Lucent\Routing\RouteGroup] middleware | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | ||
| [Lucent\Routing\RouteGroup] registerRoute | 0.00% | 0 / 3 | 0.00% | 0 / 1 | 2 | ||
| 17 | class RestRouteGroup extends RouteGroup | |
| 18 | { | |
| 19 | ||
| 20 | /** | |
| 21 | * Fully-qualified controller class used when a verb helper is called | |
| 22 | * without an explicit $controller. Null until {@see defaultController()} | |
| 23 | * is called. | |
| 24 | * | |
| 25 | * @var class-string|null | |
| 26 | */ | |
| 27 | protected ?string $defaultControllerClass = null; | |
| 28 | ||
| 29 | /** Optional URI prefix applied to every route registered in this group. */ | |
| 30 | protected ?string $prefix = null; | |
| 31 | ||
| 32 | /** | |
| 33 | * Register a GET route. | |
| 34 | * | |
| 35 | * @param string $path The URI path (relative to any group prefix). | |
| 36 | * @param string $method The controller method to invoke. | |
| 37 | * @param class-string|null $controller The controller class; falls back to the group default. | |
| 38 | */ | |
| 39 | public function get(string $path, string $method, ?string $controller = null): static | |
| 40 | { | |
| 41 | return $this->method('GET', $path, $method, $controller); | |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * Register a POST route. | |
| 46 | * | |
| 47 | * @param string $path The URI path (relative to any group prefix). | |
| 48 | * @param string $method The controller method to invoke. | |
| 49 | * @param class-string|null $controller The controller class; falls back to the group default. | |
| 50 | */ | |
| 51 | public function post(string $path, string $method, ?string $controller = null): static | |
| 52 | { | |
| 53 | return $this->method('POST', $path, $method, $controller); | |
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * Register a PUT route. | |
| 58 | * | |
| 59 | * @param string $path The URI path (relative to any group prefix). | |
| 60 | * @param string $method The controller method to invoke. | |
| 61 | * @param class-string|null $controller The controller class; falls back to the group default. | |
| 62 | */ | |
| 63 | public function put(string $path, string $method, ?string $controller = null): static | |
| 64 | { | |
| 65 | return $this->method('PUT', $path, $method, $controller); | |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Register a PATCH route. | |
| 70 | * | |
| 71 | * @param string $path The URI path (relative to any group prefix). | |
| 72 | * @param string $method The controller method to invoke. | |
| 73 | * @param class-string|null $controller The controller class; falls back to the group default. | |
| 74 | */ | |
| 75 | public function patch(string $path, string $method, ?string $controller = null): static | |
| 76 | { | |
| 77 | return $this->method('PATCH', $path, $method, $controller); | |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * Register a DELETE route. | |
| 82 | * | |
| 83 | * @param string $path The URI path (relative to any group prefix). | |
| 84 | * @param string $method The controller method to invoke. | |
| 85 | * @param class-string|null $controller The controller class; falls back to the group default. | |
| 86 | */ | |
| 87 | public function delete(string $path, string $method, ?string $controller = null): static | |
| 88 | { | |
| 89 | return $this->method('DELETE', $path, $method, $controller); | |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * Register a route for an arbitrary HTTP method (e.g. 'HEAD', 'OPTIONS', | |
| 94 | * or any custom verb the router should accept). | |
| 95 | * | |
| 96 | * This is the single registration point that all verb helpers delegate to. | |
| 97 | * | |
| 98 | * @param string $httpMethod The HTTP verb (case-insensitive; uppercased here). | |
| 99 | * @param string $path The URI path (relative to any group prefix). | |
| 100 | * @param string $method The controller method to invoke. | |
| 101 | * @param class-string|null $controller The controller class; falls back to the group default. | |
| 102 | */ | |
| 103 | public function method(string $httpMethod, string $path, string $method, ?string $controller = null): static | |
| 104 | { | |
| 105 | if ($controller === null) { | |
| 106 | $controller = $this->defaultControllerClass; | |
| 107 | } | |
| 108 | if ($controller === null) { | |
| 109 | throw new RuntimeException( | |
| 110 | "No controller resolved for route [{$httpMethod} {$path}]. " . | |
| 111 | 'Pass a $controller or call defaultController() on the group first.' | |
| 112 | ); | |
| 113 | } | |
| 114 | return $this->registerRoute($path, strtoupper($httpMethod), [$controller, $method]); | |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Set the default controller class used by verb helpers when none is given. | |
| 119 | * | |
| 120 | * @param class-string $class The fully-qualified controller class name. | |
| 121 | */ | |
| 122 | public function defaultController(string $class): static | |
| 123 | { | |
| 124 | $this->defaultControllerClass = $class; | |
| 125 | return $this; | |
| 126 | } | |
| 127 | ||
| 128 | /** | |
| 129 | * Append a URI prefix to this group. | |
| 130 | * | |
| 131 | * Appends to any existing prefix (which may have been inherited from an | |
| 132 | * outer Router::group()) so nested group prefixes accumulate. | |
| 133 | * | |
| 134 | * @param string $prefix The prefix segment(s) to append. | |
| 135 | */ | |
| 136 | public function prefix(string $prefix): static | |
| 137 | { | |
| 138 | // Append to any existing prefix (which may have been inherited from | |
| 139 | // an outer Router::group()) so nested group prefixes accumulate. | |
| 140 | $this->prefix = ($this->prefix ?? '') . '/' . ltrim($prefix, '/'); | |
| 141 | return $this; | |
| 142 | } | |
| 143 | ||
| 144 | /** | |
| 145 | * Set the base prefix directly (replacement, not appending). | |
| 146 | * | |
| 147 | * Used by RestRouteBuilder to inherit the outer Router group prefix. | |
| 148 | * | |
| 149 | * @param string $prefix The prefix to set, replacing any existing value. | |
| 150 | */ | |
| 151 | public function setBasePrefix(string $prefix): static | |
| 152 | { | |
| 153 | $this->prefix = $prefix; | |
| 154 | return $this; | |
| 155 | } | |
| 156 | ||
| 157 | /** | |
| 158 | * Build the full URI path for a route by combining the group prefix with | |
| 159 | * the given path, normalising slashes. | |
| 160 | * | |
| 161 | * @param string $path The route path relative to the group prefix. | |
| 162 | */ | |
| 163 | protected function buildPath(string $path): string | |
| 164 | { | |
| 165 | $prefix = $this->prefix ? rtrim($this->prefix, '/') : ''; | |
| 166 | return $prefix ? $prefix . '/' . ltrim($path, '/') : $path; | |
| 167 | } | |
| 168 | } |
Inherited from Lucent\Routing\RouteGroup
| 16 | public function __construct(string $name, Router $router) | |
| 17 | { | |
| 18 | $this->name = $name; | |
| 19 | $this->router = $router; | |
| 20 | } |
| 22 | public function middleware(array $middleware): static | |
| 23 | { | |
| 24 | $this->middleware = $middleware; | |
| 25 | return $this; | |
| 26 | } |
| 28 | protected function registerRoute(string $path, string $type, array $handler): static | |
| 29 | { | |
| 30 | $fullPath = $this->buildPath($path); | |
| 31 | $this->router->registerRoute($fullPath, $type, $handler[1], $handler[0], $this->middleware); | |
| 32 | return $this; | |
| 33 | } |