diff --git a/framework/core/src/Extend/Console.php b/framework/core/src/Extend/Console.php index dfa1945a2f..605202eaef 100644 --- a/framework/core/src/Extend/Console.php +++ b/framework/core/src/Extend/Console.php @@ -10,6 +10,7 @@ namespace Flarum\Extend; use Flarum\Extension\Extension; +use Flarum\Foundation\ContainerUtil; use Illuminate\Contracts\Container\Container; class Console implements ExtenderInterface @@ -61,7 +62,11 @@ public function extend(Container $container, Extension $extension = null) return array_merge($existingCommands, $this->addCommands); }); - $container->extend('flarum.console.scheduled', function ($existingScheduled) { + $container->extend('flarum.console.scheduled', function ($existingScheduled) use ($container) { + foreach ($this->scheduled as &$schedule) { + $schedule['callback'] = ContainerUtil::wrapCallback($schedule['callback'], $container); + } + return array_merge($existingScheduled, $this->scheduled); }); } diff --git a/framework/core/tests/integration/extenders/ConsoleTest.php b/framework/core/tests/integration/extenders/ConsoleTest.php index 8241118fbc..b09c71339d 100644 --- a/framework/core/tests/integration/extenders/ConsoleTest.php +++ b/framework/core/tests/integration/extenders/ConsoleTest.php @@ -75,6 +75,23 @@ public function scheduled_command_exists_when_added() $this->assertStringContainsString('cache:clear', $this->runCommand($input)); } + + /** + * @test + */ + public function scheduled_command_exists_when_added_with_class_syntax() + { + $this->extend( + (new Extend\Console()) + ->schedule('cache:clear', ScheduledCommandCallback::class) + ); + + $input = [ + 'command' => 'schedule:list' + ]; + + $this->assertStringContainsString('cache:clear', $this->runCommand($input)); + } } class CustomCommand extends AbstractCommand @@ -95,3 +112,11 @@ protected function fire() $this->info('Custom Command.'); } } + +class ScheduledCommandCallback +{ + public function __invoke(Event $event) + { + $event->everyMinute(); + } +}