Completed
Pull Request — develop (#605)
by
unknown
14:48
created

ProxyProcessor::process()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 15
cp 0
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 13
nc 4
nop 3
crap 12
1
<?php
2
/**
3
 * Schema Class for output data.
4
 */
5
namespace Graviton\ProxyApiBundle\Processor;
6
7
use Graviton\ProxyApiBundle\Helper\HttpHelper;
8
use Graviton\ProxyApiBundle\Model\ProxyModel;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12
/**
13
 * Before Proxy Request process and prepare data for orequest
14
 *
15
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
16
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
17
 * @link     http://swisscom.ch
18
 */
19
class ProxyProcessor implements ProxyProcessorInterface
20
{
21
    /**
22
     * Process data
23
     *
24
     * @param Request    $originalRequest Incoming current request
25
     * @param HttpHelper $httpHelper      Building the new request
26
     * @param ProxyModel $proxyModel      Configuration model
27
     * @return Response
28
     */
29
    public function process(
30
        Request $originalRequest,
31
        HttpHelper $httpHelper,
32
        ProxyModel $proxyModel
33
    ) {
34
        // Original Request service
35
        $serviceUri = $originalRequest->get('service');
36
        $serviceUri = $serviceUri ? '/' . $serviceUri : '';
37
38
        // Append endpoint to request uri, /endpoint/
39
        $endpoint = $proxyModel->getServiceEndpoint();
40
        $uri = $endpoint ?
41
            str_replace('//', '/', $endpoint . $serviceUri) :
42
            $serviceUri;
43
        $httpHelper->setRequestUri($uri);
44
45
        /** @var Response $response */
46
        $response = $httpHelper->execute();
47
48
        return $response;
49
    }
50
}
51