Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variadic variable to __invoke #18

Open
roquie opened this issue Jan 11, 2016 · 4 comments
Open

Add variadic variable to __invoke #18

roquie opened this issue Jan 11, 2016 · 4 comments

Comments

@roquie
Copy link

roquie commented Jan 11, 2016

Hi!
I suggest to add variadic variable to __invoke() method.

Example usages (DTO - Data Transfer Object):

$pipeline = (new Pipeline)
->pipe(function ($payload, DTO $dto) {
    $dto['ten'] = 10;
    return $payload * 2;
})
->pipe(function ($payload, DTO $dto) {
    return $payload + $dto['key'];
});

$pipeline->process(5, new DTO);
//returns 20

process method has ...$params

//https://github.com/thephpleague/pipeline/blob/master/src/Pipeline.php
/**
     * Process the payload.
     * @param $payload
     * @return mixed
     */
    public function process($payload, ...$params)
    {
        foreach ($this->stages as $stage) {
            $payload = $stage($payload, ...$params);
        }
        return $payload;
    }

My example (old code, before update): https://github.com/Roquie/pipeline/commits/master

Note: PHP 5.6 required.
What do you think about it?

@sergiors
Copy link

Maybe $params = array_slice(func_get_args(), 1); solve the problem with older versions

@shadowhand
Copy link
Member

shadowhand commented Jun 8, 2018

I actually like this idea a lot. Would you be willing to make a fresh PR?

@roquie
Copy link
Author

roquie commented Jun 13, 2018

Ok. It will take me a little time.

@roquie
Copy link
Author

roquie commented Jun 13, 2018

@shadowhand check it please #45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants