09: Loader resolution and registration - #9
Open
nikolaystrikhar wants to merge 4 commits into
Open
Conversation
resolve() returned object and cached whatever the container handed back, so a mis-bound interface was stored and then failed on the accessor's return type -- a TypeError blaming this library rather than the binding. reset() threw the same one, so there was no way back out of it. It throws Config_Exception at the boundary now, before the memo. The per-accessor @var annotations are gone: verified against the pinned PHPStan 1.12 that an object return narrowing to an interface is unreported at level 5 and 6 either way, so they silenced nothing. resolve() carries @template T instead. The README pointed hosts at Loader::reset() to pick up a container set late, but reset() also drops every registration -- following that advice left nothing to load, silently. It now states the real rule: set the container before the first register() call.
The memo map holds a different type per key, so it cannot be typed as T as a whole and the cache hit returned a bare object. Required by PHPStan level 8.
nikolaystrikhar
force-pushed
the
08-registrar
branch
from
August 6, 2026 14:22
62f5859 to
73d7de8
Compare
nikolaystrikhar
force-pushed
the
09-loader-resolve
branch
from
August 6, 2026 14:22
084004a to
bdb09e3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Loader's collaborator resolution and registration — container-or-new, memoized — plusregister(),all()andreset().boot()and the load loop land in #11.Stacked on #8.
The container is never required: with none set every collaborator is a plain
new. Resolution is memoized and deliberately does not swap a collaborator that arrives late, since anything already holding the old instance would keep it.TypeError: Loader::registrar(): Return value must be of type Registrar_Interface, stdClass returned, blaming this library rather than the binding. Andreset()callsregistrar(), so it threw the same TypeError — the host could not reset out of it. It throwsConfig_Exceptionbefore the memo now.reset()— butreset()also empties every registration, soregister()→set_container()→reset()→boot()loaded nothing, with no exception and no notice. The rule is: set the container before your firstregister().Tas a whole and the cache hit returned a bareobject. Required by PHPStan level 8 (05: Static analysis in CI #5).Verify:
slic run unit— 99 tests, 144 assertions.composer test:analysis→[OK] No errors.