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 */publicfunction__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 deltabuild + 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
TomasVotrubaforce-pushed the switch-container-illuminate-to-entropy branch from cf23a49 to cb29b00CompareAugust 22, 2026 20:58
@TomasVotruba
TomasVotruba marked this pull request as ready for review August 22, 2026 21:27
@TomasVotruba
TomasVotrubaforce-pushed the switch-container-illuminate-to-entropy branch 2 times, most recently from d7c10ad to 2c5d712CompareAugust 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
TomasVotrubaforce-pushed the switch-container-illuminate-to-entropy branch from 2c5d712 to 630dafcCompareAugust 22, 2026 22:04
@TomasVotruba

Copy link
Copy Markdown
MemberAuthor

Seems ready, lets give it a go 👍

if (! isset($this->registeredRectorClasses[$rectorClass])) {
$this->registeredRectorClasses[$rectorClass] = true;

$this->tag($rectorClass, RectorInterface::class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

with tag method removed, it seems cause bc break, for example usage is on rector-laravel:

https://github.com/driftingly/rector-laravel/blob/f6763fe6d52af55066558c28bd23551a0ffb5b06/config/config.php#L14-L18

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

These should be replaced by findByContract() method.

Can you add failing CI Laravel Rector check here, so we test it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sign up for freeto 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.

2 participants

@TomasVotruba@samsonasik