Skip to content

Commit 8701b93

Browse files
Simplify DI container API by removing Dependency class usage (#228)
* chore: upgrade utopia-php/servers to 0.3.* and utopia-php/di to 0.3.* - Replace all Dependency class usage with new Container::set(string, callable) API - Add executeHook() method to Http class to replace removed Container::inject() - Update Route to call parent::__construct() for Hook's new constructor - Update all test files and examples to use new DI API - Resolves breaking changes from DI dropping Dependency/Injection classes https://claude.ai/code/session_0196tmVsX1KjJKmuHncp7HiV * fix: set request factory on cloned context in testCanRunRequest The test was setting the request factory on $this->context instead of the cloned $context, so run() never received the HEAD request. Fixed the target container and updated the assertion to match actual HEAD behavior. https://claude.ai/code/session_0196tmVsX1KjJKmuHncp7HiV * refactor: rename $context to $container in Http.php for consistency Consolidates the DI variable naming to $container throughout, avoiding confusion with the legacy array-based context pattern. https://claude.ai/code/session_0196tmVsX1KjJKmuHncp7HiV * refactor: use child containers instead of clone for request scoping Replace `clone $this->container` with `new Container($this->container)` to use the parent-child delegation pattern introduced in utopia-php/di 0.3, consistent with how Base::prepare() already creates scoped containers. https://claude.ai/code/session_0196tmVsX1KjJKmuHncp7HiV * test: add container isolation tests to verify no state bleed between requests - testContainerIsolationBetweenRequests: verifies child containers resolve their own request/response independently and parent is not polluted - testContainerIsolationForErrors: verifies error state from one request does not leak into subsequent requests https://claude.ai/code/session_0196tmVsX1KjJKmuHncp7HiV * fix: remove unused \$name key variable in foreach loop Drops the unused key variable from the getInjections() foreach at Http.php:175 to silence static analysis warnings. https://claude.ai/code/session_0196tmVsX1KjJKmuHncp7HiV * fix: remove unreachable duplicate OPTIONS handling block The elseif branch for REQUEST_METHOD_OPTIONS at line 661 was dead code — OPTIONS requests are already handled and returned earlier (lines 628-657). Removing the duplicate simplifies the control flow. https://claude.ai/code/session_0196tmVsX1KjJKmuHncp7HiV --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent b704e80 commit 8701b93

File tree

11 files changed

+311
-379
lines changed

11 files changed

+311
-379
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"require": {
3131
"php": ">=8.1",
3232
"ext-swoole": "*",
33-
"utopia-php/servers": "0.2.*",
33+
"utopia-php/servers": "0.3.*",
3434
"utopia-php/validators": "0.2.*",
3535
"utopia-php/compression": "0.1.*",
3636
"utopia-php/telemetry": "0.2.*"

composer.lock

Lines changed: 25 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/server.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require_once __DIR__.'/../vendor/autoload.php';
44

55
use Utopia\DI\Container;
6-
use Utopia\DI\Dependency;
76
use Utopia\Http\Http;
87
use Utopia\Http\Response;
98
use Utopia\Http\Adapter\Swoole\Server;
@@ -18,9 +17,7 @@ public function __construct(public $name)
1817

1918
$container = new Container();
2019

21-
$user = new Dependency();
22-
$user->setName('user')->setCallback(fn () => new User("Demo user"));
23-
$container->set($user);
20+
$container->set('user', fn () => new User("Demo user"));
2421

2522
Http::get('/')
2623
->param('name', 'World', new Text(256), 'Name to greet. Optional, max length 256.', true)

0 commit comments

Comments
 (0)