Skip to content

Commit 94371de

Browse files
loks0nclaude
andcommitted
Drop Http::getRoute()
The supported way to consume the matched route is via the 'route' injection inside hooks/actions: Http::init() ->inject('route') ->action(function (?Route $route) { ... }); getRoute() was a convenience accessor on the shared Http instance. Reading mutable per-request state through a method on a shared object encourages racy patterns under coroutines (e.g. caching a Route reference, calling getRoute() outside a request scope). Drop it; tests that needed the matched route now consume it via the injection or via the RouteMatch returned from match() directly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 08545da commit 94371de

2 files changed

Lines changed: 2 additions & 22 deletions

File tree

src/Http/Http.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -404,21 +404,6 @@ public static function getRoutes(): array
404404
return Router::getRoutes();
405405
}
406406

407-
/**
408-
* Get the route matched for the current request, or null if none matched
409-
* yet (or no match was found). Populated by {@see Http::match()}.
410-
*/
411-
public function getRoute(): ?Route
412-
{
413-
$context = $this->context();
414-
if (!$context->has('route')) {
415-
return null;
416-
}
417-
418-
$route = $context->get('route');
419-
return $route instanceof Route ? $route : null;
420-
}
421-
422407
/**
423408
* Add Route
424409
*

tests/HttpTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ public function testCanMatchRoute(string $method, string $path, ?string $url = n
623623
$_SERVER['REQUEST_URI'] = $url;
624624

625625
$this->assertSame($expected, $this->http->match(new Request())?->route);
626-
$this->assertSame($expected, $this->http->getRoute());
627626
}
628627

629628
public function testNoMismatchRoute(): void
@@ -652,7 +651,6 @@ public function testNoMismatchRoute(): void
652651
$route = $this->http->match(new Request());
653652

654653
$this->assertNull($route);
655-
$this->assertNull($this->http->getRoute());
656654
}
657655
}
658656

@@ -666,12 +664,10 @@ public function testMatchReflectsCurrentRequest(): void
666664
$_SERVER['REQUEST_URI'] = '/path1';
667665
$matched = $this->http->match(new Request());
668666
$this->assertSame($route1, $matched?->route);
669-
$this->assertSame($route1, $this->http->getRoute());
670667

671668
$_SERVER['REQUEST_URI'] = '/path2';
672669
$matched = $this->http->match(new Request());
673670
$this->assertSame($route2, $matched?->route);
674-
$this->assertSame($route2, $this->http->getRoute());
675671
} catch (\Exception $e) {
676672
$this->fail($e->getMessage());
677673
}
@@ -685,7 +681,6 @@ public function testCanMatchRootRouteWhenUriHasNoPath(): void
685681
$_SERVER['REQUEST_URI'] = 'https://example.com?x=1';
686682

687683
$this->assertSame($route, $this->http->match(new Request())?->route);
688-
$this->assertSame($route, $this->http->getRoute());
689684
}
690685

691686
public function testCanRunRequest(): void
@@ -724,8 +719,8 @@ public function testWildcardRoute(): void
724719
$_SERVER['REQUEST_URI'] = '/unknown_path';
725720

726721
Http::init()
727-
->action(function () {
728-
$route = $this->http->getRoute();
722+
->inject('route')
723+
->action(function (?Route $route) {
729724
$this->resources->set('myRoute', fn() => $route);
730725
});
731726

0 commit comments

Comments
 (0)