Skip to content

Move resource ownership into utopia-php/di#220

Open
ChiragAgg5k wants to merge 5 commits into0.34.xfrom
feat/use-di-resource-container
Open

Move resource ownership into utopia-php/di#220
ChiragAgg5k wants to merge 5 commits into0.34.xfrom
feat/use-di-resource-container

Conversation

@ChiragAgg5k
Copy link
Member

@ChiragAgg5k ChiragAgg5k commented Mar 10, 2026

Summary

  • remove the public HTTP resource registration API and move resource ownership to Utopia\DI\Container
  • inject a DI container into Http and use it internally for request-scoped framework resources like request, response, route, error, and adapter-specific raw resources
  • update adapters, tests, and docs to register custom resources directly on the DI container instead of Http::setResource()
  • keep hook and route ->inject() semantics in HTTP, but delegate resolution and lifecycle cleanup to DI

Verification

  • vendor/bin/phpunit --configuration phpunit.xml --do-not-cache-result tests/HttpTest.php
  • vendor/bin/phpstan analyse -c phpstan.neon --memory-limit 512M

Notes

  • this intentionally breaks the old Http::setResource() / Http::getResource() usage in favor of explicit DI ownership
  • a full vendor/bin/phpunit --configuration phpunit.xml --do-not-cache-result run still hits the existing e2e environment failures because this machine cannot resolve the fpm and swoole service hosts

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 10, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 114d98c7-7105-4a96-8fa9-ba748b9efef5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/use-di-resource-container

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ChiragAgg5k ChiragAgg5k changed the title Use utopia-php/di for resource injection Move resource ownership into utopia-php/di Mar 10, 2026
@ChiragAgg5k
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 10, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates HTTP “resource” ownership out of utopia-php/http and into utopia-php/di by injecting a DI container into Http and using it for request-scoped resources and adapter-provided raw resources.

Changes:

  • Removed Http::setResource() / Http::getResource() and delegated resource resolution/cleanup to Utopia\DI\Container.
  • Updated FPM/Swoole adapters to pass adapter-specific raw resources into Http’s request lifecycle.
  • Updated tests and docs to register custom resources directly on the DI container, and bumped minimum PHP version to 8.2.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Http/Http.php Introduces DI container integration for resource wiring, resolution, refresh/purge lifecycle, and removes legacy resource APIs.
src/Http/Adapter/FPM/Server.php Passes adapter raw resources through the onRequest callback to be registered per request.
src/Http/Adapter/Swoole/Server.php Same as FPM: provides raw Swoole request/response as request-scoped resources.
tests/HttpTest.php Refactors tests to use the DI container for resource registration/resolution instead of Http.
README.md Updates docs/examples to use the DI container and the new Http constructor signature.
docs/Getting-Starting-Guide.md Attempts to update the getting-started snippet and PHP requirement.
composer.json Adds utopia-php/di dependency, VCS repository entry, and raises PHP constraint to >=8.2.
composer.lock Locks the new DI dependency and updates platform PHP to >=8.2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


namespace Utopia\Http;

use Utopia\DI\Container as DIContainer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it just be Container?

@@ -82,21 +87,21 @@ public function testCanGetEnvironmentVariable(): void

public function testCanGetResources(): void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just remove this test instead right?

@@ -119,11 +124,11 @@ public function testCanGetResources(): void

public function testCanGetDefaultValueWithFunction(): void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants