SkeletonSendPingCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SmartboxSkeletonBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use SmartboxSkeletonBundle\Entity\PingMessage;
11
use Smartbox\Integration\FrameworkBundle\Core\Messages\Context;
12
13
class SkeletonSendPingCommand extends ContainerAwareCommand
14
{
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('skeleton:send:ping')
19
            ->setDescription('Send a synchronous Ping.')
20
        ;
21
    }
22
23
    protected function execute(InputInterface $input, OutputInterface $output)
24
    {
25
        $requestHandler = $this->getContainer()->get('smartbox_skeleton_request_handler');
26
        $pingMessage = new PingMessage();
27
        $now = new \DateTime();
28
        $pingMessage->setTimestamp($now->getTimestamp());
29
        $pingMessage->setMessage('Ping');
30
31
        $context = new Context([
32
            Context::FLOWS_VERSION => '0',
33
            Context::TRANSACTION_ID => uniqid('', true),
34
            Context::ORIGINAL_FROM => 'api',
35
        ]);
36
37
        $responseMessage = $requestHandler->handleCall(
38
            'skeleton',
39
            'v0',
40
            'ping',
41
            $pingMessage,
42
            [],
43
            $context,
44
            false
45
        );
46
        $response = $responseMessage->getBody();
47
        $responseContext = $responseMessage->getContext();
48
        $transactionId = $responseContext->get('transaction_id');
49
        $output->writeln('Transaction Id: '.$transactionId);
50
        $serializer = $this->getContainer()->get('jms_serializer');
51
        $json = $serializer->serialize($response, 'json');
52
        $output->writeln('Command result.'.$json);
53
    }
54
}
55