Skip to content

Commit 0c7eae8

Browse files
committed
improved PHPDoc descriptions
1 parent 96994a0 commit 0c7eae8

File tree

4 files changed

+28
-34
lines changed

4 files changed

+28
-34
lines changed

src/Routing/Route.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414

1515
/**
16-
* The bidirectional route is responsible for mapping
17-
* HTTP request to an array for dispatch and vice-versa.
16+
* Bidirectional route mapping between HTTP requests and parameter arrays using a URL mask.
1817
*/
1918
class Route implements Router
2019
{
@@ -107,9 +106,6 @@ public function __construct(string $mask, array $metadata = [])
107106
}
108107

109108

110-
/**
111-
* Returns mask.
112-
*/
113109
public function getMask(): string
114110
{
115111
return $this->mask;
@@ -126,10 +122,7 @@ protected function getMetadata(): array
126122
}
127123

128124

129-
/**
130-
* Returns default values.
131-
* @return array<string, mixed>
132-
*/
125+
/** @return array<string, mixed> */
133126
public function getDefaults(): array
134127
{
135128
$defaults = [];
@@ -144,6 +137,7 @@ public function getDefaults(): array
144137

145138

146139
/**
140+
* Returns parameters that must have a specific fixed value for the route to match.
147141
* @internal
148142
* @return array<string, mixed>
149143
*/
@@ -620,7 +614,7 @@ private function parseQuery(array $parts): bool
620614

621615

622616
/**
623-
* Rename keys in array.
617+
* Renames keys in array according to the translation table.
624618
* @param array<string, mixed> $arr
625619
* @param array<string, string> $xlat
626620
* @return array<string, mixed>
@@ -647,7 +641,7 @@ private static function renameKeys(array $arr, array $xlat): array
647641

648642

649643
/**
650-
* Url encode.
644+
* Encodes a parameter value for use in a URL path segment, leaving allowed characters unencoded.
651645
*/
652646
public static function param2path(string $s): string
653647
{

src/Routing/RouteList.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
/**
15-
* The router broker.
15+
* Router collection that tries each router in sequence and caches URL construction lookups.
1616
*/
1717
class RouteList implements Router
1818
{
@@ -38,7 +38,6 @@ public function __construct()
3838

3939

4040
/**
41-
* Maps HTTP request to an array.
4241
* @return ?array<string, mixed>
4342
* @final
4443
*/
@@ -95,10 +94,7 @@ protected function completeParameters(array $params): ?array
9594
}
9695

9796

98-
/**
99-
* Constructs absolute URL from array.
100-
* @param array<string, mixed> $params
101-
*/
97+
/** @param array<string, mixed> $params */
10298
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
10399
{
104100
if ($this->domain) {
@@ -141,6 +137,10 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri
141137
}
142138

143139

140+
/**
141+
* Builds an internal lookup index of routers grouped by their most discriminating constant parameter.
142+
* Call this before URL generation to improve performance; called automatically on first use.
143+
*/
144144
public function warmupCache(): void
145145
{
146146
// find best key
@@ -232,6 +232,7 @@ protected function modify(int $index, ?Router $router): void
232232

233233

234234
/**
235+
* Creates a Route from the mask and adds it to the list.
235236
* @param string $mask e.g. '<presenter>/<action>/<id \d{1,3}>'
236237
* @param array<string, mixed> $metadata default values or metadata
237238
* @return static
@@ -244,7 +245,7 @@ public function addRoute(string $mask, array $metadata = [], int $oneWay = 0)
244245

245246

246247
/**
247-
* Returns an iterator over all routers.
248+
* Creates a child RouteList scoped to the given domain and adds it to this list.
248249
*/
249250
public function withDomain(string $domain): static
250251
{
@@ -257,6 +258,9 @@ public function withDomain(string $domain): static
257258
}
258259

259260

261+
/**
262+
* Creates a child RouteList scoped to the given path prefix and adds it to this list.
263+
*/
260264
public function withPath(string $path): static
261265
{
262266
$router = new static;
@@ -268,13 +272,17 @@ public function withPath(string $path): static
268272
}
269273

270274

275+
/**
276+
* Returns the parent RouteList, used to end a withDomain()/withPath() chain.
277+
*/
271278
public function end(): ?self
272279
{
273280
return $this->parent;
274281
}
275282

276283

277284
/**
285+
* Returns all routers in this list.
278286
* @return list<Router>
279287
*/
280288
public function getRouters(): array
@@ -284,6 +292,7 @@ public function getRouters(): array
284292

285293

286294
/**
295+
* Returns the flags (e.g. ONE_WAY) for each router in this list.
287296
* @return list<int>
288297
*/
289298
public function getFlags(): array

src/Routing/Router.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111

1212

1313
/**
14-
* The bi-directional router.
14+
* Bidirectional router converting between HTTP requests and parameter arrays.
1515
*/
1616
interface Router
1717
{
18-
/** for back compatibility */
18+
/** @deprecated for backward compatibility */
1919
public const ONE_WAY = 0b0001;
2020

2121
/**
22-
* Maps HTTP request to an array.
22+
* Matches an HTTP request and returns its parameters, or null if the route does not match.
2323
* @return ?array<string, mixed>
2424
*/
2525
function match(Nette\Http\IRequest $httpRequest): ?array;
2626

2727
/**
28-
* Constructs absolute URL from array.
28+
* Constructs an absolute URL from parameters, or null if the route cannot generate it.
2929
* @param array<string, mixed> $params
3030
*/
3131
function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string;

src/Routing/SimpleRouter.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ public function __construct(
2323
}
2424

2525

26-
/**
27-
* Maps HTTP request to an array.
28-
* @return ?array<string, mixed>
29-
*/
26+
/** @return ?array<string, mixed> */
3027
public function match(Nette\Http\IRequest $httpRequest): ?array
3128
{
3229
return $httpRequest->getUrl()->getPathInfo() === ''
@@ -35,10 +32,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
3532
}
3633

3734

38-
/**
39-
* Constructs absolute URL from array.
40-
* @param array<string, mixed> $params
41-
*/
35+
/** @param array<string, mixed> $params */
4236
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
4337
{
4438
// remove default values; null values are retain
@@ -61,10 +55,7 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri
6155
}
6256

6357

64-
/**
65-
* Returns default values.
66-
* @return array<string, mixed>
67-
*/
58+
/** @return array<string, mixed> */
6859
public function getDefaults(): array
6960
{
7061
return $this->defaults;

0 commit comments

Comments
 (0)