You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[job-queue] Change type hint from Closure to callable #286
In the JobRunner (and possibly other areas), the type hint currently limits you to working with closures. For more complex jobs, it is nicer to have an object because you can utilize DI and autoloading. Changing Closure to callable would maintain backwards compatibility and open up more options to the end user.
As of PHP 5.4.0, when declared in the context of a class, the current class is automatically bound to it, making $this available inside of the function's scope.
which means that the queue processor itself can utilize DI and more complex code can be broken down into class methods on the processor instance instead of putting all of the code inside of the closure.
The above example works without any changes. I was just sharing a workaround that I found for my initial problem after I learned that $this is accessible as the queue processor instance from inside the closure.
I think that callable is still better than Closure because it gives the end user more flexibility for how they want to design their queue processor, such as moving the logic to an external class or domain object. I need to look through the enqueue code to see if anything specifically depends on closures then I will submit a PR if the change is okay to do.
Activity
msheakoski commentedon Dec 4, 2017
I recently learned on http://php.net/manual/en/functions.anonymous.php
which means that the queue processor itself can utilize DI and more complex code can be broken down into class methods on the processor instance instead of putting all of the code inside of the closure.
makasim commentedon Dec 4, 2017
Could you open a PR?
msheakoski commentedon Dec 4, 2017
The above example works without any changes. I was just sharing a workaround that I found for my initial problem after I learned that
$thisis accessible as the queue processor instance from inside the closure.I think that
callableis still better thanClosurebecause it gives the end user more flexibility for how they want to design their queue processor, such as moving the logic to an external class or domain object. I need to look through the enqueue code to see if anything specifically depends on closures then I will submit a PR if the change is okay to do.