我现在和Laravel合作了一段时间,从一开始我一直想知道他们如何能够以随机顺序链接方法并仍然将整个链作为一个操作执行。
例如,在控制台内核中:
protected function schedule(Schedule $schedule) { $schedule->command('some-command') ->everyThirtyMinutes() ->before(function (Schedule $schedule) { $schedule->command('some-other-command'); }); }首先调用command方法,但该命令每30分钟才会运行一次。 调用command方法后会出现该信息,但在执行之前仍会处理。 before一种方法也是如此。 该方法最后调用,但some-other-command命令仍在执行。
我在互联网上搜索了答案,但我找不到答案。 我希望你知道答案。
I'm working with Laravel for a little while now and since the start I have been wondering how they are able to chain methods in a random order and still execute the whole chain as one operation.
For example, in the console kernel:
protected function schedule(Schedule $schedule) { $schedule->command('some-command') ->everyThirtyMinutes() ->before(function (Schedule $schedule) { $schedule->command('some-other-command'); }); }The command method is called first, but the command will only run every thirty minutes. That information came after calling the command method, but is still processed before executing it. The same goes for the before method. That method is called last, but the some-other-command command is still being executed first.
I've searched the internet for the answer, but I couldn't find one. I hope you know the answer.
最满意答案
该方法最后调用,但some-other-command命令仍在执行。
因为这是before()方法所做的,所以在当前命令之前放置另一个命令(因此命名)。 正如类名称Scheduler所暗示的那样,它正在设置一些调度,而不是按原样执行代码,所以问题在于对代码的作用有误解。
That method is called last, but the some-other-command command is still being executed first.
Because that is what the before() method does, placing another command before (hence the name) the current command. And as the class name Scheduler implies, it's setting up some schedule, not executing the code as is, so the question is rather a misunderstanding of what the code does.
更多推荐
发布评论