Skip to content

refactor: replace the in-tree DI container with internal/container - #218

Merged
roxblnfk merged 4 commits into
masterfrom
feature/internal-container
Sep 8, 2026
Merged

roxblnfk merged 4 commits into
masterfrom
feature/internal-container

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Sep 8, 2026

Copy link
Copy Markdown
Member

What was changed

  • The in-tree Service\Container is replaced by internal/container's ObjectContainer (a superset of the old API); yiisoft/injector drops from the root require and stays only as a transitive dependency.
  • Config hydration no longer lives in a hard-coded namespace check inside make() — it is a container inflector (ConfigInflector) registered in Bootstrap. Config classes opt in with the #[InflectableConfig] marker attribute instead of relying on their FQCN prefix.
  • ConfigInflector and its attributes live under Buggregator\Trap\Application\Config\Internal, ported verbatim from the shared reference implementation so the whole subtree can later be extracted into a package or container module by swapping the namespace alone.

Why?

Several projects carried their own copy of the same container. internal/container is that code, extracted and grown, so Trap moves onto the shared package and keeps config hydration as project code wired back in through an inflector.

Review notes

  • internal/container requires PHP >=8.2 while Trap still declares >=8.1 and tests 8.1 in CI; the package requirement is being lowered to >=8.1 separately, so this branch keeps Trap on >=8.1 and does not touch the matrix.
  • The only project-specific edit inside the ported inflector is Testo\Common\ErrorReporter → the Trap Logger; everything else is a pure namespace swap.

Checklist

  • PHP 8.1 php-internal/container#4
  • Tested
    • Tested manually — end-to-end config hydration through the inflector (#[InputOption], #[Env], comma-list arrays)
    • Unit tests added — ConfigInflectorTest (moved from ConfigLoaderTest)

Drops src/Service/Container.php in favour of internal/container's ObjectContainer, whose public surface is a superset of the old one. yiisoft/injector leaves the root require and becomes a transitive dependency.

Config hydration moved out of a hard-coded namespace check in make() into a container inflector. ConfigInflector and its attributes are ported verbatim from the reference implementation under Buggregator\Trap\Application\Config\Internal (only Testo\Common\ErrorReporter is swapped for the Trap Logger), so the whole subtree can later be extracted into a package or container module by swapping the namespace alone. Config classes now opt in with the #[InflectableConfig] marker attribute instead of relying on their FQCN prefix.

Assisted-By: Claude Opus 4.8 (1M context)
@github-actions github-actions Bot added enhancement New feature or request tests Changes in the tests labels Sep 8, 2026
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.91%. Comparing base (a0634a3) to head (bc71895).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...rc/Application/Config/Internal/ConfigInflector.php 46.22% 57 Missing ⚠️
src/Client/TrapHandle/ContextProvider/Source.php 0.00% 3 Missing ⚠️
...c/Application/Config/Internal/Attribute/PhpIni.php 0.00% 2 Missing ⚠️
...plication/Config/Internal/Attribute/XPathEmbed.php 0.00% 2 Missing ⚠️
...ation/Config/Internal/Attribute/XPathEmbedList.php 0.00% 2 Missing ⚠️
src/Bootstrap.php 0.00% 2 Missing ⚠️
src/Traffic/Dispatcher/Http.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #218      +/-   ##
============================================
- Coverage     27.78%   26.91%   -0.88%     
- Complexity     1403     1411       +8     
============================================
  Files           159      160       +1     
  Lines          4373     4411      +38     
============================================
- Hits           1215     1187      -28     
- Misses         3158     3224      +66     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roxblnfk
roxblnfk force-pushed the feature/internal-container branch 2 times, most recently from 06560bd to 9729b3b Compare September 8, 2026 09:50
@roxblnfk
roxblnfk force-pushed the feature/internal-container branch from 9729b3b to bc71895 Compare September 8, 2026 09:54
@roxblnfk
roxblnfk merged commit 5a1d162 into master Sep 8, 2026
21 of 23 checks passed
@roxblnfk
roxblnfk deleted the feature/internal-container branch September 8, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tests Changes in the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant