Skip to content

feat: migrate resource management to utopia-php/di container (0.33.x backport)#224

Closed
ChiragAgg5k wants to merge 1 commit into0.33.xfrom
feat/use-di-resource-container-0.33.x
Closed

feat: migrate resource management to utopia-php/di container (0.33.x backport)#224
ChiragAgg5k wants to merge 1 commit into0.33.xfrom
feat/use-di-resource-container-0.33.x

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Summary

This PR backports the DI container integration from the 0.34.x branch (feat/use-di-resource-container) to the 0.33.x branch.

Changes

  • Resource Management Migration: Replaced internal array-based resource management with utopia-php/di Container
  • Constructor Update: Added optional Container parameter to Http constructor
  • New Methods: Added getContainer() and getRequestContainer() for accessing the DI container
  • API Changes:
    • setResource() changed from static to instance method
    • getResource() and getResources() now require a Container scope parameter
  • Request Scoping: Each request now gets its own scoped container for resource isolation
  • Adapter Updates: Removed static Http::setResource() calls from FPM and Swoole adapters
  • Test Updates: All tests updated to use the new container-based API

Dependencies

  • Added utopia-php/di: 0.3.* to composer.json

Breaking Changes

⚠️ BREAKING CHANGE: Http::setResource() is now an instance method instead of static.

Before:

Http::setResource('myService', fn() => new MyService());

After:

$http = new Http('UTC');
$http->setResource('myService', fn() => new MyService());
// or
$http->getContainer()->set('myService', fn() => new MyService());

Testing

  • All 121 unit tests pass
  • Linting passes (pint)
  • Type checking passes (PHPStan)
  • E2E tests fail due to missing Docker environment (expected)

Related

This is a backport of the changes from PR targeting 0.34.x to ensure 0.33.x branch also benefits from the improved resource management architecture.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 13, 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: 2d143d63-281c-4a8b-94e0-4423b497d9c7

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-0.33.x
📝 Coding Plan
  • Generate coding plan for human review comments

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.

This backports the DI container integration from the 0.34.x branch to 0.33.x:

- Replace internal array-based resource management with Utopia\DI\Container
- Update constructor to accept optional Container parameter
- Add getContainer() and getRequestContainer() methods
- Change setResource() from static to instance method
- Update getResource() and getResources() to use Container scope
- Create request-scoped containers for each request lifecycle
- Update all internal calls to use new container-based API
- Remove static resource callbacks array
- Update adapters to remove static Http::setResource() calls
- Update tests to use container-based approach

BREAKING CHANGE: Http::setResource() is now an instance method instead of static.
Users should now call $http->setResource() instead of Http::setResource().
@ChiragAgg5k ChiragAgg5k force-pushed the feat/use-di-resource-container-0.33.x branch from f7975c6 to 90b7249 Compare March 13, 2026 09:33
@loks0n loks0n closed this Mar 13, 2026
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.

2 participants