From 89c2f9e0ab62f1a2523d146501fb6f09df633bf5 Mon Sep 17 00:00:00 2001 From: Ivan Zorin Date: Fri, 20 Nov 2026 16:33:12 +0300 Subject: [PATCH 1/3] fix: make nullable router callbacks and options explicit --- Router.php | 12 +++++++----- src/RouteObject.php | 2 +- tests/Unit/RouteTest.php | 7 +++++++ tests/phpunit.xml | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Router.php b/Router.php index 491b405..2a51f8d 100644 --- a/Router.php +++ b/Router.php @@ -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; @@ -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)) { @@ -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)) { @@ -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); diff --git a/src/RouteObject.php b/src/RouteObject.php index 10d68d7..8aa04f7 100644 --- a/src/RouteObject.php +++ b/src/RouteObject.php @@ -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; diff --git a/tests/Unit/RouteTest.php b/tests/Unit/RouteTest.php index 1ece0d8..682b842 100644 --- a/tests/Unit/RouteTest.php +++ b/tests/Unit/RouteTest.php @@ -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 () { diff --git a/tests/phpunit.xml b/tests/phpunit.xml index c3dc3fb..ff25e59 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -6,7 +6,8 @@ cacheDirectory=".phpunit.cache" executionOrder="depends,defects" failOnRisky="true" - failOnWarning="true"> + failOnWarning="true" + failOnDeprecation="true"> Unit From 9dfdda83a047af3f5ee27ed9e45eab607b593742 Mon Sep 17 00:00:00 2001 From: Ivan Zorin Date: Fri, 20 Nov 2026 16:41:56 +0300 Subject: [PATCH 2/3] ci: validate all branch pushes --- .github/workflows/php.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index d521c32..064286d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -2,7 +2,6 @@ name: PHP package checks on: push: - branches: [main, master] pull_request: branches: [main, master] workflow_dispatch: From ca493de3c984c344f89b15c30066c74940b4d49e Mon Sep 17 00:00:00 2001 From: Ivan Zorin Date: Sat, 21 Nov 2026 03:32:46 +0300 Subject: [PATCH 3/3] docs(router): correct Engine 9 release compatibility --- README.en.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.en.md b/README.en.md index c643702..0fe6466 100644 --- a/README.en.md +++ b/README.en.md @@ -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 diff --git a/README.md b/README.md index 10a33b5..4e7eda5 100644 --- a/README.md +++ b/README.md @@ -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 должно само подавить тело ответа.