Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: PHP package checks

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Triangle Router matches HTTP methods and URI paths against route patterns and re
- PHP 8.1 or later (`^8.1` in Composer).
- `triangle/engine` `^8.1 || ^9.0` in the current source branch.

Engine 9 does not yet have a stable release tag. The source constraint is not proof that a stable published Composer release is available or verified against Engine 9. Check the resolved packages with `composer show triangle/router triangle/engine`.
Triangle Engine 9.0.0 is available as a stable release. Router 2.0.6 supports Engine `^8.1 || ^9.0`; check the versions resolved by your application with `composer show triangle/router triangle/engine`.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ $dispatcher = simpleRouteDispatcher(function(Triangle\Router $r) {

## Версия и совместимость

Текущий исходный код требует PHP 8.1+ и объявляет совместимость с `triangle/engine` `^8.1 || ^9.0`. Ветка Engine 9 пока не имеет стабильного релизного тега: наличие ограничения в исходной ветке не означает, что опубликованный пакет Composer уже выпущен и проверен с Engine 9. Проверяйте фактически установленную версию через `composer show triangle/router triangle/engine`.
Текущий исходный код требует PHP 8.1+ и объявляет совместимость с `triangle/engine` `^8.1 || ^9.0`. Стабильная версия Triangle Engine 9.0.0 опубликована; Router 2.0.6 поддерживает Engine `^8.1 || ^9.0`. Фактически выбранные приложением версии проверяйте через `composer show triangle/router triangle/engine`.

Пакет подключает глобальные функции `simpleRouteDispatcher()`, `cachedRouteDispatcher()` и `route()` через Composer autoload. Маршрутизатор возвращает кортеж статуса, обработчика и параметров; формирование HTTP-ответа и заголовка `Allow` для 405 остаётся задачей приложения. При использовании GET-маршрута для HEAD приложение вне PHP SAPI должно само подавить тело ответа.

Expand Down
12 changes: 7 additions & 5 deletions Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ public function addChild(Router $route): void
$this->children[] = $route;
}

public static function child(string $path, callable $callback = null): static
public static function child(string $path, ?callable $callback = null): static
{
$prevInstance = static::$instance;
$nextInstance = static::$instance = new static;

$callback(static::$instance);
if ($callback !== null) {
$callback(static::$instance);
}

$prevInstance?->addChild($nextInstance);
static::$instance = $prevInstance;
Expand Down Expand Up @@ -167,7 +169,7 @@ public static function routes(): array
}


public static function disableDefaultRoute(?string $plugin = '', string $app = null): bool
public static function disableDefaultRoute(?string $plugin = '', ?string $app = null): bool
{
// Is [controller action]
if (is_array($plugin)) {
Expand Down Expand Up @@ -198,7 +200,7 @@ public static function disableDefaultRoute(?string $plugin = '', string $app = n
return false;
}

public static function isDefaultRouteDisabled($plugin = '', string $app = null): bool
public static function isDefaultRouteDisabled($plugin = '', ?string $app = null): bool
{
// Is [controller action]
if (is_array($plugin)) {
Expand Down Expand Up @@ -310,7 +312,7 @@ public static function any(string $path, mixed $callback): RouteObject
return static::instance()->addRoute('*', $path, $callback);
}

public static function resource(string $name, string $controller, array $actions = null, string $prefix = ''): void
public static function resource(string $name, string $controller, ?array $actions = null, string $prefix = ''): void
{
$name = trim($name, '/');
$selected = !empty($actions);
Expand Down
2 changes: 1 addition & 1 deletion src/RouteObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function getMiddleware(): array
* @param mixed $default Значение по умолчанию
* @return array|mixed|null
*/
public function param(string $name = null, mixed $default = null): mixed
public function param(?string $name = null, mixed $default = null): mixed
{
if ($name === null) {
return $this->params;
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ private function dispatch(string $method, string $path): array
return Router::dispatch($method, $path);
}

public function testChildCallbackCanBeOmitted(): void
{
$child = Router::child('/optional');

$this->assertInstanceOf(Router::class, $child);
}

public function testRouteRegistration(): void
{
Router::get('/tests/route-registration', function () {
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true">
failOnWarning="true"
failOnDeprecation="true">
<testsuites>
<testsuite name="Unit">
<directory>Unit</directory>
Expand Down