Skip to content

feat/use di resource container#225

Closed
loks0n wants to merge 31 commits intomasterfrom
feat/use-di-resource-container
Closed

feat/use di resource container#225
loks0n wants to merge 31 commits intomasterfrom
feat/use-di-resource-container

Conversation

@loks0n
Copy link
Contributor

@loks0n loks0n commented Mar 13, 2026

  • Fix array to string conversion warning in Request::getSize()
  • feat: remove validators and use utopia validators lib
  • Convert hostname to lowercase (Convert hostname to lowercase #214)
  • chore: bump validators lib (chore: bump validators lib #218)
  • Use utopia-php/di for resource injection
  • Move resource ownership into utopia-php/di
  • Update DI branch dependency
  • update getting started
  • update
  • update
  • update appwrite base version
  • update to use php 8.2
  • fix: restore php 8.2 test runtime
  • chore: use container scopes
  • remove utopia keyword
  • remove optional container in run
  • remove optional container in run
  • renaming
  • remove public getContainer
  • fix getcontainer
  • fix getcontainer
  • update
  • remove tests
  • make public
  • remove tests
  • add scoped request containers
  • cleanup
  • feat: request scopes

Summary by CodeRabbit

Release Notes

  • Breaking Changes

    • Minimum PHP version requirement updated to 8.2
    • HTTP server constructor now requires a dependency injection container parameter
    • Resource management changed from Http::setResource() to container-based approach
    • Built-in validators relocated; several validators removed
  • New Features

    • Added dependency injection container integration for managing application resources
  • Documentation

    • Updated getting started guide and examples with new initialization patterns
  • Chores

    • Updated base Docker image to PHP 8.2-FPM

ChiragAgg5k and others added 30 commits December 11, 2025 18:30
Headers can now be arrays (after recent changes allowing array headers).
The getSize() method was attempting to directly implode headers, causing
a warning when a header value was an array.

This fix properly handles both string and array header values by joining
array values with commas (standard HTTP header format) before calculating
the request size.

Added test case to verify the fix works correctly with array headers.
feat: remove validators and use utopia validators lib
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cea2fa1e-db51-47c6-9a1e-3de947b81040

📥 Commits

Reviewing files that changed from the base of the PR and between b704e80 and bcb4562.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (66)
  • .github/workflows/test.yml
  • Dockerfile.fpm
  • Dockerfile.swoole
  • README.md
  • composer.json
  • docker-compose.yml
  • docs/Getting-Starting-Guide.md
  • example/Dockerfile
  • example/src/server.php
  • src/Http/Adapter.php
  • src/Http/Adapter/FPM/Request.php
  • src/Http/Adapter/FPM/Server.php
  • src/Http/Adapter/Swoole/Request.php
  • src/Http/Adapter/Swoole/Server.php
  • src/Http/Hook.php
  • src/Http/Http.php
  • src/Http/Request.php
  • src/Http/Response.php
  • src/Http/Validator.php
  • src/Http/Validator/AllOf.php
  • src/Http/Validator/AnyOf.php
  • src/Http/Validator/ArrayList.php
  • src/Http/Validator/Assoc.php
  • src/Http/Validator/Boolean.php
  • src/Http/Validator/Domain.php
  • src/Http/Validator/FloatValidator.php
  • src/Http/Validator/HexColor.php
  • src/Http/Validator/Host.php
  • src/Http/Validator/Hostname.php
  • src/Http/Validator/IP.php
  • src/Http/Validator/Integer.php
  • src/Http/Validator/JSON.php
  • src/Http/Validator/NoneOf.php
  • src/Http/Validator/Nullable.php
  • src/Http/Validator/Numeric.php
  • src/Http/Validator/Range.php
  • src/Http/Validator/Text.php
  • src/Http/Validator/URL.php
  • src/Http/Validator/WhiteList.php
  • src/Http/Validator/Wildcard.php
  • tests/HookTest.php
  • tests/HttpTest.php
  • tests/RequestTest.php
  • tests/RouteTest.php
  • tests/Validator/ArrayListTest.php
  • tests/Validator/AssocTest.php
  • tests/Validator/BooleanTest.php
  • tests/Validator/DomainTest.php
  • tests/Validator/FloatValidatorTest.php
  • tests/Validator/HexColorTest.php
  • tests/Validator/HostTest.php
  • tests/Validator/HostnameTest.php
  • tests/Validator/IPTest.php
  • tests/Validator/IntegerTest.php
  • tests/Validator/JSONTest.php
  • tests/Validator/MultipleOfTest.php
  • tests/Validator/NullableTest.php
  • tests/Validator/NumericTest.php
  • tests/Validator/RangeTest.php
  • tests/Validator/TextTest.php
  • tests/Validator/URLTest.php
  • tests/Validator/WhiteListTest.php
  • tests/Validator/WildcardTest.php
  • tests/docker/start
  • tests/docker/supervisord.conf
  • tests/e2e/init.php

Walkthrough

This pull request performs a major architectural refactor upgrading the framework from PHP 8.0/8.1 to 8.2, integrating a dependency injection (DI) container pattern, and relocating validators to a separate namespace. The Http class API is modified to accept a Container parameter and use container-based resource management instead of static context-based resources. All validator classes in src/Http/Validator/ are removed (moved to external package utopia-php/validators). Corresponding updates are made across Docker configurations, documentation, and tests to reflect the DI-centric approach. Adapter implementations (FPM, Swoole) are refactored to support per-request DI containers.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Key Changes

Architecture & API:

  • Http class constructor signature changed to require Container $container as third parameter
  • Replaced Http::setResource(), Http::getResource(), Http::getResources() with container-based alternatives; removed context parameter throughout
  • Added getContainer(): Container abstract method to Adapter base class
  • Core resource injection now uses DI container instead of static per-context caches

Validator System:

  • Deleted entire src/Http/Validator/ directory (22 validator classes including Boolean, Integer, Text, URL, Domain, Range, Hostname, IP, JSON, and composite validators AllOf/AnyOf/NoneOf)
  • Updated imports across codebase from Utopia\Http\Validator\* to Utopia\Validator\*
  • Base Validator abstract class removed

Adapter Implementations:

  • FPM Server: Constructor now requires Container $container; refactored onRequest() to use container for request/response injection
  • Swoole Server: Added optional Container $container parameter; implements per-request container via coroutine context with fallback to default container

Dependencies:

  • Added utopia-php/di (0.3.) and utopia-php/validators (0.2.)
  • Bumped PHP requirement to >=8.2

Testing:

  • Deleted 20+ validator test files (now handled by external package)
  • Updated HttpTest to use container-based resource setup instead of Http::setResource()
  • Updated imports in route/hook tests to reference new validator namespace
✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 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
📝 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.

@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.

4 participants