Skip to content

Support more built-in types for container factory functions#303

Merged
clue merged 1 commit intoclue:mainfrom
clue-labs:container-more-types
Apr 2, 2026
Merged

Support more built-in types for container factory functions#303
clue merged 1 commit intoclue:mainfrom
clue-labs:container-more-types

Conversation

@clue
Copy link
Copy Markdown
Owner

@clue clue commented Apr 1, 2026

This changeset adds support for object (PHP 7.2+), iterable, callable, true (PHP 8.2+) and false (PHP 8.0+ union or PHP 8.2+ standalone) types for Container factory function parameters. Previously, using these types would incorrectly report a type mismatch even though the values were valid.

$container = new FrameworkX\Container([
    'data' => new \ArrayObject(),
    'items' => new \ArrayIterator([1, 2, 3]),
    'fn' => 'strtoupper',
    AccessLogHandler::class => function (object $data, iterable $items, callable $fn) {
        // ...
    }
]);

This includes 10 new test cases to verify correct type validation and error reporting for each new type. This has 100% code coverage and should be safe to apply.

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

@clue clue added the new feature New feature or request label Apr 1, 2026
@clue clue force-pushed the container-more-types branch from 01a427e to 4e42238 Compare April 1, 2026 13:16
@clue clue requested a review from Copilot April 1, 2026 13:18
Copy link
Copy Markdown

Copilot AI left a comment

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’s factory-function parameter type validation to recognize additional PHP built-in types (object, iterable, callable, true, false) so valid container values no longer incorrectly fail type checks.

Changes:

  • Extend Container::validateType() to accept object, iterable, callable, true, and false parameter types.
  • Add new test cases covering both successful resolution and type-mismatch errors for these types.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Container.php Expands runtime type validation to handle additional built-in types in factory parameters.
tests/ContainerTest.php Adds test coverage for the new supported built-in types and their error messages.

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

@clue clue merged commit 62b4f70 into clue:main Apr 2, 2026
79 checks passed
@clue clue deleted the container-more-types branch April 2, 2026 07:49
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