Skip to content

09: Loader resolution and registration - #9

Open
nikolaystrikhar wants to merge 1 commit into
mainfrom
09-loader-resolve
Open

09: Loader resolution and registration#9
nikolaystrikhar wants to merge 1 commit into
mainfrom
09-loader-resolve

Conversation

@nikolaystrikhar

@nikolaystrikhar nikolaystrikhar commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What: Loader resolves its interface-backed collaborators — from the container when one is bound, else a plain new — and buffers registrations until boot.

Usage:

use Nexcess\PluginAbsorber\Contracts\Registrar_Interface;

Config::set_hook_prefix( 'give' );

Loader::register( [
    'slug'                   => 'give-recurring',
    'bundled_plugin_file'    => __DIR__ . '/sub-plugins/give-recurring/give-recurring.php',
    'plugin_loaded_constant' => 'GIVE_RECURRING_VERSION',
] );

// Order does not matter — this still wins, and still receives the registration above.
$container->singleton( Registrar_Interface::class, My_Registrar::class );
Config::set_container( $container );

Loader::all(); // ['give-recurring' => Sub_Plugin]

Why this way: resolving inside register() pinned the default registrar at the host's first registration, so a container set afterwards was silently dropped — and the fix for that was a documented ordering rule nobody would read until it bit them. Buffering the built Sub_Plugin and draining it on the first read costs one array and makes set_container() order-independent like every other configuration call. The registrar keeps sole ownership of duplicate-slug detection and ordering rather than the buffer restating them, and the price of that is a duplicate slug being reported at boot instead of at the second register() call; an unusable config array is still rejected inside register(), where the host's stack trace points at it. There is no Loader::reset()Registrar_Interface has no reset() to call, and a reset on the facade would be permanent public API bought for the test suite, so the statics are cleared by reflection from tests/_support/Loader_State.php.

Verify: slic run unit tests/unit/LoaderResolveTest.php (21 tests, 20 of them cases) and composer test:analysis. Both suite legs pass. Not covered here: boot(), the hook wiring and the load loop, which are #11; the container is only exercised through Registrar_Interface, since the other three collaborators do not exist yet.

@nikolaystrikhar

nikolaystrikhar commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@d4mation I don't think I like the static approach here as it will contain more logic.. In the end, I want to give it all to Justin to review the architecture as it's the first lib I'm working on and he has better ideas on consistensy and approaches.

@nikolaystrikhar nikolaystrikhar changed the title 09: Loader resolution and registration 09: Loader resolution and registration (merge after #8) Aug 11, 2026
@nikolaystrikhar nikolaystrikhar changed the title 09: Loader resolution and registration (merge after #8) 9A: Loader resolution and registration (merge after #8) Aug 11, 2026
Base automatically changed from 08-registrar to main August 11, 2026 14:58
@nikolaystrikhar nikolaystrikhar changed the title 9A: Loader resolution and registration (merge after #8) 10: Loader resolution and registration (merge after #8) Aug 11, 2026
@nikolaystrikhar nikolaystrikhar changed the title 10: Loader resolution and registration (merge after #8) 09: Loader resolution and registration (merge after #8) Aug 11, 2026
Loader::register() buffers the Sub_Plugin it builds rather than handing it
straight to the registrar, and the buffer drains on the first read. Resolving
inside register() pinned the default registrar at the host's first registration,
so a container set afterwards was silently ignored; buffering makes
Config::set_container() order-independent, like every other configuration call.

The registrar stays the single source of truth for duplicate-slug detection and
ordering, so that collision is now reported at boot rather than at the second
register() call. An unusable config array is still rejected on the spot, where
the host's own stack trace points at it.

There is no Loader::reset(): Registrar_Interface carries no reset() to call, and
a reset on the facade would be API the library supports forever for the suite's
benefit. The suite clears the statics through tests/_support/Loader_State.php.
@nikolaystrikhar nikolaystrikhar changed the title 09: Loader resolution and registration (merge after #8) 09: Loader resolution and registration Aug 11, 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.

1 participant