Skip to content

Support array type for container variables and factory functions#306

Merged
clue merged 1 commit into
clue:mainfrom
clue-labs:container-array
Jun 15, 2026
Merged

Support array type for container variables and factory functions#306
clue merged 1 commit into
clue:mainfrom
clue-labs:container-array

Conversation

@clue

@clue clue commented Jun 14, 2026

Copy link
Copy Markdown
Owner

This changeset adds support for the array type for Container variables and factory function parameters and return values. Previously, providing an array as a container variable or returning one from a factory function would throw a TypeError, even though array is a valid type.

$container = new FrameworkX\Container([
    'settings' => ['debug' => true, 'name' => 'Acme'],
    Acme\Todo\UserController::class => function (array $settings) {
        return new Acme\Todo\UserController($settings);
    }
]);

This includes new test cases covering array values for container variables and factory functions, plus the interactions with the existing iterable and callable types and the getEnv() error path. This has 100% code coverage and should be safe to apply.

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

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

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 extends FrameworkX\Container to accept PHP array values as container variables and to allow injecting/validating array-typed parameters in factory functions, aligning runtime behavior with expected PHP built-in types.

Changes:

  • Allow array values in container variable configuration and in variable factory return validation.
  • Extend factory-function parameter type validation to support the array built-in type.
  • Add/adjust PHPUnit coverage for array interactions (including iterable, callable, and getEnv() error paths) and update docs accordingly.

Reviewed changes

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

File Description
src/Container.php Permits array values for container variables and adds array handling in validateType() and related type assertions/messages.
tests/ContainerTest.php Updates existing tests and adds new cases to cover arrays in variables and factory functions, plus getEnv() cases.
docs/best-practices/controllers.md Documents that container variables / factory return values may be array in addition to object/scalar/null.

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

Comment thread src/Container.php
Comment thread src/Container.php
Comment thread src/Container.php
Comment thread src/Container.php
Comment thread tests/ContainerTest.php
Comment thread tests/ContainerTest.php
Comment thread tests/ContainerTest.php
Comment thread tests/ContainerTest.php
@clue clue merged commit 19a37c9 into clue:main Jun 15, 2026
75 checks passed
@clue clue deleted the container-array branch June 15, 2026 22:04
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