RequestHandlerService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace SmartboxSkeletonBundle\Services;
4
5
use Smartbox\Integration\FrameworkBundle\Core\Endpoints\EndpointFactory;
6
use Smartbox\Integration\FrameworkBundle\Core\Messages\Context;
7
use Smartbox\Integration\FrameworkBundle\Core\Messages\Message;
8
9
/**
10
 * Class RequestHandlerService.
11
 */
12
class RequestHandlerService
13
{
14
    protected $kernel;
15
16
    public function __construct($kernel)
17
    {
18
        $this->kernel = $kernel;
19
    }
20
21
    /**
22
     * @param $serviceName
23
     * @param $apiVersion
24
     * @param $methodName
25
     * @param $messageBody
26
     * @param $messageHeaders
27
     * @param $context
28
     * @param bool $async
29
     *
30
     * @return mixed
31
     */
32
    public function handleCall(
33
        $serviceName,
34
        $apiVersion,
35
        $methodName,
36
        $messageBody,
37
        $messageHeaders,
38
        $context,
39
        $async = false
40
    ) {
41
        $apiPrefix = 'api';
42
        $fromUri = $apiPrefix.'://entry/'.$serviceName.'/'.$apiVersion.'/'.$methodName;
43
        $helper = $this->getContainer()->get('smartesb.helper');
44
        $messageFactory = $helper->getMessageFactory();
45
        $contextExtra = [];
46
        $contextExtra['from'] = $fromUri;
47
        $priority = 'normal';
48
        $contextExtra['api_mode'] = 'real';
49
        $contextExtra['priority'] = $priority;
50
        $context = new Context(array_merge($context->toArray(), $contextExtra));
51
        $messageHeaders[Message::HEADER_FROM] = $fromUri;
52
        $messageHeaders['api_mode'] = 'real';
53
        $messageHeaders['async'] = $async ? 'true' : 'false';
54
        $message = $messageFactory->createMessage($messageBody, $messageHeaders, $context);
55
        $endpoint = $this->getContainer()->get('smartesb.endpoint_factory')->createEndpoint($message->getHeader(Message::HEADER_FROM), EndpointFactory::MODE_CONSUME);
56
        $resultMessage = $endpoint->handle($message);
57
58
        return $resultMessage;
59
    }
60
61
    /**
62
     * @return mixed
63
     */
64
    public function getContainer()
65
    {
66
        return $this->kernel->getContainer();
67
    }
68
}
69