1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FondBot\Toolbelt; |
6
|
|
|
|
7
|
|
|
use FondBot\Application\Kernel; |
8
|
|
|
use Symfony\Component\Console\Application; |
9
|
|
|
use League\Container\ServiceProvider\AbstractServiceProvider; |
10
|
|
|
|
11
|
|
|
abstract class ToolbeltServiceProvider extends AbstractServiceProvider |
12
|
|
|
{ |
13
|
|
|
protected $provides = [ |
14
|
|
|
'toolbelt', |
15
|
|
|
]; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Console commands. |
19
|
|
|
* |
20
|
|
|
* @return Command[] |
21
|
|
|
*/ |
22
|
|
|
abstract public function commands(): array; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Use the register method to register items with the container via the |
26
|
|
|
* protected $this->container property or the `getContainer` method |
27
|
|
|
* from the ContainerAwareTrait. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
* |
31
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
32
|
|
|
*/ |
33
|
|
|
public function register(): void |
34
|
|
|
{ |
35
|
1 |
|
$this->container->share('toolbelt', function () { |
36
|
1 |
|
$kernel = $this->container->get(Kernel::class); |
37
|
|
|
|
38
|
1 |
|
$application = new Application('FondBot', Kernel::VERSION); |
39
|
1 |
|
$application->addCommands([ |
40
|
1 |
|
new Commands\MakeIntent($kernel), |
41
|
1 |
|
new Commands\MakeInteraction($kernel), |
42
|
1 |
|
new Commands\ListDrivers($kernel), |
43
|
1 |
|
new Commands\InstallDriver($kernel), |
44
|
1 |
|
new Commands\ListChannels($kernel), |
45
|
1 |
|
new Commands\Log($kernel), |
46
|
1 |
|
new Commands\QueueWorker($kernel), |
47
|
|
|
]); |
48
|
|
|
|
49
|
1 |
|
foreach ($this->commands() as $command) { |
50
|
1 |
|
$application->add($command); |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
return $application; |
54
|
1 |
|
}); |
55
|
1 |
|
} |
56
|
|
|
} |
57
|
|
|
|