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\Push; |
15
|
|
|
use Mremi\Flowdock\Api\Push\TeamInboxMessage; |
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 mail-like message to the team inbox of a flow |
25
|
|
|
* |
26
|
|
|
* @author Rémi Marseille <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class SendTeamInboxMessageCommand extends Command |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
protected function configure() |
34
|
|
|
{ |
35
|
|
|
$this |
36
|
|
|
->setName('send-team-inbox-message') |
37
|
|
|
->setDescription('Sends a mail-like message to the team inbox of a flow') |
38
|
|
|
|
39
|
|
|
->addArgument('flow-api-token', InputArgument::REQUIRED, 'The flow API token') |
40
|
|
|
->addArgument('source', InputArgument::REQUIRED, 'The human readable identifier of the application that uses the Flowdock Push API') |
41
|
|
|
->addArgument('from-address', InputArgument::REQUIRED, 'The email address of the message sender') |
42
|
|
|
->addArgument('subject', InputArgument::REQUIRED, 'The subject line of the message') |
43
|
|
|
->addArgument('content', InputArgument::REQUIRED, 'The content of the message') |
44
|
|
|
|
45
|
|
|
->addOption('from-name', null, InputOption::VALUE_REQUIRED, 'The name of the message sender') |
46
|
|
|
->addOption('reply-to', null, InputOption::VALUE_REQUIRED, 'The email address for replies') |
47
|
|
|
->addOption('project', null, InputOption::VALUE_REQUIRED, 'The human readable identifier for more detailed message categorization') |
48
|
|
|
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The format of the message content') |
49
|
|
|
->addOption('link', null, InputOption::VALUE_REQUIRED, 'The link associated with the message') |
50
|
|
|
->addOption('tags', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'The message tags') |
51
|
|
|
->addOption('options', null, InputOption::VALUE_REQUIRED, 'An array of options used by request'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
58
|
|
|
{ |
59
|
|
|
$push = new Push($input->getArgument('flow-api-token')); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$message = TeamInboxMessage::create() |
|
|
|
|
62
|
|
|
->setSource($input->getArgument('source')) |
63
|
|
|
->setFromAddress($input->getArgument('from-address')) |
64
|
|
|
->setSubject($input->getArgument('subject')) |
65
|
|
|
->setContent($input->getArgument('content')) |
66
|
|
|
->setFromName($input->getOption('from-name')) |
67
|
|
|
->setReplyTo($input->getOption('reply-to')) |
68
|
|
|
->setProject($input->getOption('project')) |
69
|
|
|
->setFormat($input->getOption('format')) |
70
|
|
|
->setLink($input->getOption('link')) |
71
|
|
|
->setTags($input->getOption('tags')); |
72
|
|
|
|
73
|
|
|
$options = $input->getOption('options') ? json_decode($input->getOption('options'), true) : array(); |
74
|
|
|
|
75
|
|
|
if ($push->sendTeamInboxMessage($message, $options)) { |
76
|
|
|
$output->writeln('<info>Success:</info> the message has been sent'); |
77
|
|
|
|
78
|
|
|
return; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$output->writeln(sprintf('<error>Failure:</error> %s', $message->getResponseMessage())); |
82
|
|
|
$output->writeln(var_export($message->getResponseErrors(), true)); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.