mirror of
https://github.com/flarum/core.git
synced 2025-08-05 16:07:34 +02:00
fix: console extender does not accept ::class (#3900)
This commit is contained in:
@@ -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 @@ 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);
|
||||
});
|
||||
}
|
||||
|
@@ -75,6 +75,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
|
||||
@@ -95,3 +112,11 @@ class CustomCommand extends AbstractCommand
|
||||
$this->info('Custom Command.');
|
||||
}
|
||||
}
|
||||
|
||||
class ScheduledCommandCallback
|
||||
{
|
||||
public function __invoke(Event $event)
|
||||
{
|
||||
$event->everyMinute();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user