mirror of
https://github.com/flarum/framework.git
synced 2025-03-15 00:05:12 +08:00
fix: console extender does not accept ::class attribute for schedule (#3903)
This commit is contained in:
parent
db0d9cb006
commit
94de8b42b4
@ -11,6 +11,7 @@ namespace Flarum\Extend;
|
||||
|
||||
use Flarum\Console\AbstractCommand;
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Foundation\ContainerUtil;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class Console implements ExtenderInterface
|
||||
@ -62,7 +63,11 @@ class Console implements ExtenderInterface
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
@ -78,6 +78,23 @@ class ConsoleTest extends ConsoleTestCase
|
||||
|
||||
$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
|
||||
@ -94,3 +111,11 @@ class CustomCommand extends AbstractCommand
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
class ScheduledCommandCallback
|
||||
{
|
||||
public function __invoke(Event $event)
|
||||
{
|
||||
$event->everyMinute();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user