Skip to content

Support for invokable objects in Container::call() #185

@andersonamuller

Description

@andersonamuller

I know this is future compatibility feature (PHP 5.4), but I cannot use a object that implements the method __invoke in the container->call method. Now it throws an exception.

Example:

class SendMailAction 
{
    private $mailer;

    public function __construct(MailerInterface $mailer) 
    {
        $this->mailer = $mailer;
    }

    public function __invoke($sender, $recipient, $subject, $content) 
    {
        $message = $this->mailer->compose($sender, $recipient, $subject, $content);
        return $this->mailer->send($message);
    }
}

$container->call(
    $container->make(SendMailAction::class),
    [
        'sender' => '[email protected]',
        'recipient' => '[email protected]',
        'subject' => 'Testing',
        'content' => 'This is a test message'
    ]
);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions