Skip to content

Add Support for #[Bind] Attribute in Console Command Handle Methods#191

Merged
techmahedy merged 1 commit intodoppar:3.xfrom
techmahedy:techmahedy-3.x
Feb 14, 2026
Merged

Add Support for #[Bind] Attribute in Console Command Handle Methods#191
techmahedy merged 1 commit intodoppar:3.xfrom
techmahedy:techmahedy-3.x

Conversation

@techmahedy
Copy link
Member

@techmahedy techmahedy commented Feb 14, 2026

This PR adds support for PHP 8 attributes in console command handle methods, specifically the #[Bind] attribute. Currently, the router supports this attribute in controller methods, but console commands lack the same functionality. This change brings feature parity between HTTP controllers and console commands.

Changes

  1. Enhanced Container::call() Method with Attribute Support

Why This Change?

Previously, this would not work in console commands:

class DopparApplication extends Command
{
    public function handle(
        #[Bind(UserRepository::class)] UserRepositoryInterface $userRepository,  // Attribute ignored
        User $user  // Regular dependency works
    ): int {
        // $userRepository would not be properly bound
    }
}

After this change, it works:

class DopparApplication extends Command
{
    public function handle(
        #[Bind(UserRepository::class)] UserRepositoryInterface $userRepository,  // Now works!
        User $user  // Still works
    ): int {
        $users = $userRepository->getUsers();  // Properly resolved with binding
    }
}

Console commands now support the same attribute-based injection as controllers. Reduce boilerplate by using attributes for interface bindings. Bind interfaces to concrete implementations directly in method signatures.

Breaking Changes

None. This change is fully backward compatible. Existing commands without attributes continue to work exactly as before. The container's call() method maintains the same signature and behavior for non-attributed parameters.

@techmahedy techmahedy requested a review from rrr63 February 14, 2026 15:33
@techmahedy
Copy link
Member Author

@rrr63 would you please check it? Why does the test fail in Windows?

@techmahedy techmahedy merged commit 84ceadc into doppar:3.x Feb 14, 2026
63 of 99 checks passed
@techmahedy
Copy link
Member Author

@rrr63 it works

@rrr63
Copy link
Member

rrr63 commented Feb 15, 2026

Thank you @techmahedy

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.

2 participants