Skip to content

Support any type for container variables and factory functions#307

Open
clue wants to merge 1 commit into
clue:mainfrom
clue-labs:container-mixed
Open

Support any type for container variables and factory functions#307
clue wants to merge 1 commit into
clue:mainfrom
clue-labs:container-mixed

Conversation

@clue

@clue clue commented Jun 15, 2026

Copy link
Copy Markdown
Owner

This changeset updates the Container to accept a value of any type for container variables and factory function return values. Previously, values were restricted to objects, scalars, array and null, so providing any other value (such as a resource) would throw a TypeError. This removes that remaining restriction. Closures continue to be treated as factory functions rather than plain values.

$container = new FrameworkX\Container([
    'stream' => STDERR,
    Acme\Todo\UserController::class => function ($stream) {
        return new Acme\Todo\UserController($stream);
    }
]);

This includes new test cases covering resource values for container variables and factory functions. This has 100% code coverage and should be safe to apply.

Builds on top of #306, #303, #302, #284, #182 and others

@clue clue added this to the v0.18.0 milestone Jun 15, 2026
@clue clue added the new feature New feature or request label Jun 15, 2026
@clue clue requested a review from Copilot June 15, 2026 23:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR relaxes FrameworkX\Container’s value restrictions so container variables and variable factory functions can yield any PHP value type (e.g. resource), while continuing to treat Closure values as factories (and rejecting factories that return a Closure).

Changes:

  • Loosens Container’s internal type constraints by removing the “object|scalar|array|null” restriction for variable values and variable factory return values.
  • Updates tests to cover successful use of resource values in variable injection scenarios.
  • Updates controller best-practices documentation to describe the expanded supported types.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Container.php Removes the remaining hard-coded type restriction for container variables / variable factory return values and updates phpdoc to mixed.
tests/ContainerTest.php Drops tests that expected resources to be rejected and adds new tests that verify resource values work in variable injection.
docs/best-practices/controllers.md Updates docs to state container variables/factory returns can be “any type”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/best-practices/controllers.md
Comment thread tests/ContainerTest.php
@clue clue force-pushed the container-mixed branch from ef44ef8 to ea48c04 Compare June 15, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants