/
Console.php
68 lines (58 loc) · 2.08 KB
/
Console.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Extend;
use Flarum\Extension\Extension;
use Illuminate\Contracts\Container\Container;
class Console implements ExtenderInterface
{
protected $addCommands = [];
protected $scheduled = [];
/**
* Add a command to the console.
*
* @param string $command: ::class attribute of command class, which must extend Flarum\Console\AbstractCommand.
* @return self
*/
public function command(string $command): self
{
$this->addCommands[] = $command;
return $this;
}
/**
* Schedule a command to run on an interval.
*
* @param string $command: ::class attribute of command class, which must extend Flarum\Console\AbstractCommand.
* @param callable|string $callback
*
* The callback can be a closure or invokable class, and should accept:
* - \Illuminate\Console\Scheduling\Event $event
*
* The callback should apply relevant methods to $event, and does not need to return anything.
*
* @see https://laravel.com/api/8.x/Illuminate/Console/Scheduling/Event.html
* @see https://laravel.com/docs/8.x/scheduling#schedule-frequency-options
* for more information on available methods and what they do.
*
* @param array $args An array of args to call the command with.
* @return self
*/
public function schedule(string $command, $callback, $args = []): self
{
$this->scheduled[] = compact('args', 'callback', 'command');
return $this;
}
public function extend(Container $container, Extension $extension = null)
{
$container->extend('flarum.console.commands', function ($existingCommands) {
return array_merge($existingCommands, $this->addCommands);
});
$container->extend('flarum.console.scheduled', function ($existingScheduled) {
return array_merge($existingScheduled, $this->scheduled);
});
}
}