Skip to content

Add the container as an extension constructor parameter to build "composable extensions".#85

Open
sukei wants to merge 1 commit into
xefi:mainfrom
sukei:feature/composable-extensions
Open

Add the container as an extension constructor parameter to build "composable extensions".#85
sukei wants to merge 1 commit into
xefi:mainfrom
sukei:feature/composable-extensions

Conversation

@sukei

@sukei sukei commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

With an access to the container into the extensions, we unlock the possibility to compose them.

class MyPersonExtension extends Extension
{
    public function nameWithTitle(?string $gender = null): string
    {
        return sprintf('%s %s %s', $this->container->title($gender), $this->container->name($gender));
    }
}

This may be a trivial example, but I there is use-case where you have to combine things and its better to reuse existing logics.

BTW, I would like to discuss the need of all the traits (except HasLocale). Each of them only have their usage in the Container and therefore could be inlined.

Summary by CodeRabbit

  • Bug Fixes
    • Improved how extensions are created so they now receive the active container context during setup.
    • This helps extension-based features initialize more reliably and behave consistently across different locales and app states.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bebf5b8e-5139-476f-acf1-254dec6c8453

📥 Commits

Reviewing files that changed from the base of the PR and between 772724b and 04e2084.

📒 Files selected for processing (2)
  • src/Container/Traits/HasExtensions.php
  • src/Extensions/Extension.php

📝 Walkthrough

Walkthrough

The Extension base class constructor now accepts and stores a Container instance in addition to Randomizer, and is marked final. HasExtensions::resolve() updates extension instantiation to pass the current container instance to the constructor.

Changes

Extension container injection

Layer / File(s) Summary
Extension constructor and resolution wiring
src/Extensions/Extension.php, src/Container/Traits/HasExtensions.php
Extension adds a Container import, a protected Container $container property, and a final constructor accepting both Randomizer and Container; HasExtensions::resolve() now instantiates extensions with new $extension(new Randomizer(), $this).

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: passing the container into extension constructors to enable composable extensions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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