1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Crummy\Phlack\Bridge\Symfony\Console; |
4
|
|
|
|
5
|
|
|
use Crummy\Phlack\Bot\BotInterface; |
6
|
|
|
use Crummy\Phlack\Bot\Mainframe\Adapter\AdapterInterface; |
7
|
|
|
use Crummy\Phlack\Bot\Mainframe\Mainframe; |
8
|
|
|
use Crummy\Phlack\Common\Matcher\MatcherInterface; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
|
13
|
|
|
class BotCommand extends Command implements AdapterInterface |
14
|
|
|
{ |
15
|
|
|
private $adapter; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param ConsoleAdapter $adapter |
19
|
|
|
* @param string $name |
20
|
|
|
*/ |
21
|
6 |
|
public function __construct(ConsoleAdapter $adapter, $name = 'bot_command') |
22
|
|
|
{ |
23
|
6 |
|
parent::__construct($name); |
24
|
|
|
|
25
|
6 |
|
$this->adapter = $adapter; |
26
|
6 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param Mainframe $mainframe |
30
|
|
|
* |
31
|
|
|
* @return self |
32
|
|
|
*/ |
33
|
1 |
|
public function setMainframe(Mainframe $mainframe) |
34
|
|
|
{ |
35
|
1 |
|
$this->adapter->setMainframe($mainframe); |
36
|
|
|
|
37
|
1 |
|
return $this; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return \Crummy\Phlack\WebHook\Converter\ConverterInterface |
42
|
|
|
*/ |
43
|
1 |
|
public function getConverter() |
44
|
|
|
{ |
45
|
1 |
|
return $this->adapter->getConverter(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param BotInterface $bot |
50
|
|
|
* @param MatcherInterface|callable $matcher |
51
|
|
|
* @param int $priority |
52
|
|
|
* |
53
|
|
|
* @return self |
54
|
|
|
*/ |
55
|
1 |
|
public function attach(BotInterface $bot, $matcher = null, $priority = 0) |
56
|
|
|
{ |
57
|
1 |
|
$this->adapter->attach($bot, $matcher, $priority); |
58
|
|
|
|
59
|
1 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
66
|
|
|
{ |
67
|
|
|
$this->adapter->execute($input, $output); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|