Skip to content

Commit

Permalink
fix: console extender does not accept ::class
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Oct 18, 2023
1 parent 82e08e3 commit 94908eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion framework/core/src/Extend/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Flarum\Extend;

use Flarum\Extension\Extension;
use Flarum\Foundation\ContainerUtil;
use Illuminate\Contracts\Container\Container;

class Console implements ExtenderInterface
Expand Down Expand Up @@ -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);
});
}
Expand Down
25 changes: 25 additions & 0 deletions framework/core/tests/integration/extenders/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -95,3 +112,11 @@ protected function fire()
$this->info('Custom Command.');
}
}

class ScheduledCommandCallback
{
public function __invoke(Event $event)
{
$event->everyMinute();
}
}

0 comments on commit 94908eb

Please sign in to comment.