Skip to content

Commit a00237d

Browse files
committed
RouteList: parameter $oneWay is bool (BC break)
1 parent 89c14e3 commit a00237d

File tree

7 files changed

+17
-25
lines changed

7 files changed

+17
-25
lines changed

.phpstorm.meta.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,14 @@ Global filters give you the ability to adjust the behavior of the route in absol
333333
If a parameter has a custom filter defined and a global filter exists at the same time, custom `FILTER_IN` is executed before the global and vice versa global `FILTER_OUT` is executed before the custom. Thus, inside the global filter are the values of the parameters `controller` resp. `action` written in PascalCase resp. camelCase style.
334334

335335

336-
ONE_WAY flag
336+
OneWay flag
337337
------------
338338

339-
One-way routes are used to preserve the functionality of old URLs that the application no longer generates but still accepts. We flag them with `ONE_WAY`:
339+
One-way routes are used to preserve the functionality of old URLs that the application no longer generates but still accepts. We flag them with `oneWay`:
340340

341341
```php
342342
// old URL /product-info?id=123
343-
$router->addRoute('product-info', [...], $router::ONE_WAY);
343+
$router->addRoute('product-info', [...], oneWay: true);
344344
// new URL /product/123
345345
$router->addRoute('product/<id>', [...]);
346346
```
@@ -450,7 +450,7 @@ SEO and Canonization
450450

451451
The framework increases SEO (search engine optimization) by preventing duplication of content at different URLs. If multiple addresses link to a same destination, eg `/index` and `/index.html`, the framework determines the first one as primary (canonical) and redirects the others to it using HTTP code 301. Thanks to this, search engines will not index pages twice and do not break their page rank. .
452452

453-
This process is called canonization. The canonical URL is the one generated by the router, i.e. by the first matching route in the [collection ](#route-collection) without the ONE_WAY flag. Therefore, in the collection, we list **primary routes first**.
453+
This process is called canonization. The canonical URL is the one generated by the router, i.e. by the first matching route in the [collection ](#route-collection) without the OneWay flag. Therefore, in the collection, we list **primary routes first**.
454454

455455
Canonization is performed by the controller, more in the chapter [canonization ](controllers#Canonization).
456456

src/Routing/RouteList.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function warmupCache(): void
188188
/**
189189
* Adds a router.
190190
*/
191-
public function add(Router $router, int $oneWay = 0): static
191+
public function add(Router $router, bool $oneWay = false): static
192192
{
193193
$this->list[] = [$router, $oneWay];
194194
$this->ranks = null;
@@ -199,7 +199,7 @@ public function add(Router $router, int $oneWay = 0): static
199199
/**
200200
* Prepends a router.
201201
*/
202-
public function prepend(Router $router, int $oneWay = 0): void
202+
public function prepend(Router $router, bool $oneWay = false): void
203203
{
204204
array_splice($this->list, 0, 0, [[$router, $oneWay]]);
205205
$this->ranks = null;
@@ -221,7 +221,7 @@ protected function modify(int $index, ?Router $router): void
221221
}
222222

223223

224-
public function addRoute(string $mask, array $metadata = [], int $oneWay = 0): static
224+
public function addRoute(string $mask, array $metadata = [], bool $oneWay = false): static
225225
{
226226
$this->add(new Route($mask, $metadata), $oneWay);
227227
return $this;
@@ -269,11 +269,11 @@ public function getRouters(): array
269269

270270

271271
/**
272-
* @return int[]
272+
* @return bool[][]
273273
*/
274274
public function getFlags(): array
275275
{
276-
return array_column($this->list, 1);
276+
return array_map(fn($info) => ['oneWay' => (bool) $info[1]], $this->list);
277277
}
278278

279279

src/Routing/Router.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
interface Router
1919
{
20-
/** for back compatibility */
21-
public const ONE_WAY = 0b0001;
20+
/** @deprecated */
21+
public const ONE_WAY = true;
2222

2323
/**
2424
* Maps HTTP request to an array.

tests/RouteList/addRoute.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require __DIR__ . '/../bootstrap.php';
99

1010

1111
$list = new RouteList;
12-
$list->addRoute('foo', ['route' => 'foo'], RouteList::ONE_WAY);
13-
$list->addRoute('bar', ['route' => 'bar'], RouteList::ONE_WAY);
12+
$list->addRoute('foo', ['route' => 'foo'], oneWay: true);
13+
$list->addRoute('bar', ['route' => 'bar'], oneWay: true);
1414
$list->addRoute('hello', ['route' => 'hello']);
1515

1616

tests/RouteList/cache.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $list = new RouteList;
1414
$list->add(new Route('bar', ['presenter' => 'bar']));
1515
$list->add(new Route('<foo>', ['presenter' => 'foo']));
1616
$list->add(new Route('<presenter>/<action>', ['presenter' => 'xxx']));
17-
$list->add(new Route('oneway'), $list::ONE_WAY);
17+
$list->add(new Route('oneway'), oneWay: true);
1818

1919
[$r1, $r2, $r3, $r4] = $list->getRouters();
2020

tests/RouteList/oneWay.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ require __DIR__ . '/../bootstrap.php';
1111

1212

1313
$list = new RouteList;
14-
$list->add(new Route('foo', ['route' => 'foo']), RouteList::ONE_WAY);
15-
$list->addRoute('bar', ['route' => 'bar'], RouteList::ONE_WAY);
14+
$list->add(new Route('foo', ['route' => 'foo']), oneWay: true);
15+
$list->addRoute('bar', ['route' => 'bar'], oneWay: true);
1616
$list->add(new Route('hello', ['route' => 'hello']));
1717

18-
Assert::same([RouteList::ONE_WAY, RouteList::ONE_WAY, 0], $list->getFlags());
18+
Assert::same([['oneWay' => true], ['oneWay' => true], ['oneWay' => false]], $list->getFlags());
1919

2020
testRouteIn($list, '/foo', ['route' => 'foo', 'test' => 'testvalue']);
2121
testRouteIn($list, '/bar', ['route' => 'bar', 'test' => 'testvalue']);

0 commit comments

Comments
 (0)