1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Mremi\Flowdock library. |
5
|
|
|
* |
6
|
|
|
* (c) Rémi Marseille <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Mremi\Flowdock\Command; |
13
|
|
|
|
14
|
|
|
use Mremi\Flowdock\Api\Push\ChatMessage; |
15
|
|
|
use Mremi\Flowdock\Api\Push\Push; |
16
|
|
|
|
17
|
|
|
use Symfony\Component\Console\Command\Command; |
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Input\InputOption; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Sends a message to a flow's chat |
25
|
|
|
* |
26
|
|
|
* @author Rémi Marseille <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class SendChatMessageCommand extends Command |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
protected function configure() |
34
|
|
|
{ |
35
|
|
|
$this |
36
|
|
|
->setName('send-chat-message') |
37
|
|
|
->setDescription('Sends a message to a flow\'s chat') |
38
|
|
|
|
39
|
|
|
->addArgument('flow-api-token', InputArgument::REQUIRED, 'The flow API token') |
40
|
|
|
->addArgument('content', InputArgument::REQUIRED, 'The content of the message') |
41
|
|
|
->addArgument('external-user-name', InputArgument::REQUIRED, 'The name of the user sending the message') |
42
|
|
|
|
43
|
|
|
->addOption('message-id', null, InputOption::VALUE_REQUIRED, 'The identifier of an another message to comment') |
44
|
|
|
->addOption('tags', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'The message tags') |
45
|
|
|
->addOption('options', null, InputOption::VALUE_REQUIRED, 'An array of options used by request'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
52
|
|
|
{ |
53
|
|
|
$push = new Push($input->getArgument('flow-api-token')); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$message = ChatMessage::create() |
|
|
|
|
56
|
|
|
->setContent($input->getArgument('content')) |
|
|
|
|
57
|
|
|
->setExternalUserName($input->getArgument('external-user-name')) |
58
|
|
|
->setTags($input->getOption('tags')) |
59
|
|
|
->setMessageId($input->getOption('message-id')); |
60
|
|
|
|
61
|
|
|
$options = $input->getOption('options') ? json_decode($input->getOption('options'), true) : array(); |
62
|
|
|
|
63
|
|
|
if ($push->sendChatMessage($message, $options)) { |
64
|
|
|
$output->writeln('<info>Success:</info> the message has been sent'); |
65
|
|
|
|
66
|
|
|
return; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$output->writeln(sprintf('<error>Failure:</error> %s', $message->getResponseMessage())); |
70
|
|
|
$output->writeln(var_export($message->getResponseErrors(), true)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.