Skip to content

Switch DI container from illuminate/container to entropy/entropy - #8362

Merged
TomasVotruba merged 1 commit into
mainfrom
switch-container-illuminate-to-entropy
Aug 23, 2026
Merged

Switch DI container from illuminate/container to entropy/entropy#8362
TomasVotruba merged 1 commit into
mainfrom
switch-container-illuminate-to-entropy

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Swaps the dependency-injection container from illuminate/container to entropy/entropy.

RectorConfig now extends Entropy\Container\Container and bridges the former Illuminate surface, so configs and rules keep working unchanged.

What changed

  • tagged() / findByContract() return a plain 0-indexed list. entropy keys results by class-string; variadic spreads such as new NodeTraverser(...$visitors) need a positional list, not name-keyed args.
  • when()->needs()->giveTagged() is a no-op shim. entropy injects tagged collections from the constructor docblock instead:
    /**
     * @param AttributeDecoratorInterface[] $decorators
     */
    public function __construct(array $decorators) { /* ... */ }
    Collection params must therefore be typed array (not iterable) and carry no default value.
  • Deferred afterResolving draining. Callbacks are drained only when the outermost make() unwinds, so aggregate cycles (a service and the collection it belongs to, e.g. the type mappers and PHPStanStaticTypeMapper) resolve without looping.
  • WeakMap-tracked "already injected" set. spl_object_id is recycled after an object is freed; keying by the object itself stops a rebuilt rule from wrongly skipping setter injection ($currentFileProvider must not be accessed before initialization).
  • ServiceCreationFailedException names the failing service and keeps the root cause as previous, preserving the previous container's error output.

Performance (build + resolve, 79 services, warmup + 5 iterations)

utils/bench-container.php measures the same boot both ways:

peak memory delta build + resolve
illuminate/container ~7.2 MB ~15 ms
entropy/entropy ~1.0 MB ~7-13 ms

Peak memory during boot drops by roughly 6 MB; wall time is comparable to faster (varies with load).

Checks

  • composer complete-check (ECS, PHPStan level 8, PHPUnit) green
  • composer rector green
  • full tests/ (690) and rules-tests/ (4588) green

@TomasVotruba
TomasVotruba force-pushed the switch-container-illuminate-to-entropy branch from cf23a49 to cb29b00 Compare August 22, 2026 20:58
@TomasVotruba
TomasVotruba marked this pull request as ready for review August 22, 2026 21:27
@TomasVotruba
TomasVotruba force-pushed the switch-container-illuminate-to-entropy branch 2 times, most recently from d7c10ad to 2c5d712 Compare August 22, 2026 22:04
Replace the Illuminate container with entropy/entropy. RectorConfig extends
Entropy\Container\Container and reuses the container's own primitives:

- register() makes a factory-less service discoverable by contract, so
  findByContract() returns it without any tag layer (tag/tagged/autotag gone)
- findByContract() returns a plain 0-indexed list, so variadic spreads such as
  new NodeTraverser(...$visitors) stay positional
- afterResolving() runs setter injection once after a service is built, drained
  at the outermost make() so aggregate cycles (type mappers <-> the collection
  they belong to) resolve without a loop
- forgetByContract() drops a service from the container; RectorConfig extends it
  to clear its own bookkeeping, so skip()/test reset need no reflection

Removed along the way: the giveTagged() contextual-binding API, service aliases
(the one alias was already backed by a factory), the RegisteredService value
object, and the ContainerMemento reflection helper. No WeakMap, to keep the
source downgradable; service build failures propagate as entropy throws them.
@TomasVotruba
TomasVotruba force-pushed the switch-container-illuminate-to-entropy branch from 2c5d712 to 630dafc Compare August 22, 2026 22:04
@TomasVotruba

Copy link
Copy Markdown
Member Author

Seems ready, lets give it a go 👍

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant