Skip to content

Commit 6a86d7e

Browse files
loks0nclaude
andcommitted
Use plain 'route'/'matchedPath' keys in the request container
The framework already exposes per-request resources under plain names ('request', 'response', 'error', 'server', 'route'), so the namespaced sentinel constants were inconsistent. Drop them and use the same convention. As a side effect, 'matchedPath' is now injectable into hooks and actions like any other request resource. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b226bf5 commit 6a86d7e

1 file changed

Lines changed: 4 additions & 14 deletions

File tree

src/Http/Http.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ class Http
103103
*/
104104
protected static array $requestHooks = [];
105105

106-
/**
107-
* Per-request container keys for the currently matched route and
108-
* the prepared-path string it was matched under. Storing these on
109-
* the per-request container (which is coroutine-local in the Swoole
110-
* adapters) keeps concurrent requests from clobbering each other's
111-
* routing state on the shared Http singleton.
112-
*/
113-
private const string ROUTE_CONTEXT_KEY = '__utopia_http_route';
114-
private const string MATCHED_PATH_CONTEXT_KEY = '__utopia_http_matched_path';
115-
116106
/**
117107
* Wildcard route
118108
* If set, this get's executed if no other route is matched
@@ -468,15 +458,15 @@ public function getRoute(): ?Route
468458
{
469459
$container = $this->server->getContainer();
470460

471-
return $container->has(self::ROUTE_CONTEXT_KEY) ? $container->get(self::ROUTE_CONTEXT_KEY) : null;
461+
return $container->has('route') ? $container->get('route') : null;
472462
}
473463

474464
/**
475465
* Set the current route
476466
*/
477467
public function setRoute(?Route $route): self
478468
{
479-
$this->server->getContainer()->set(self::ROUTE_CONTEXT_KEY, fn() => $route);
469+
$this->server->getContainer()->set('route', fn() => $route);
480470

481471
return $this;
482472
}
@@ -490,12 +480,12 @@ private function getMatchedPath(): string
490480
{
491481
$container = $this->server->getContainer();
492482

493-
return $container->has(self::MATCHED_PATH_CONTEXT_KEY) ? $container->get(self::MATCHED_PATH_CONTEXT_KEY) : '';
483+
return $container->has('matchedPath') ? $container->get('matchedPath') : '';
494484
}
495485

496486
private function setMatchedPath(string $path): void
497487
{
498-
$this->server->getContainer()->set(self::MATCHED_PATH_CONTEXT_KEY, fn() => $path);
488+
$this->server->getContainer()->set('matchedPath', fn() => $path);
499489
}
500490

501491
/**

0 commit comments

Comments
 (0)