Completed
Pull Request — develop (#605)
by
unknown
05:24
created

ProxyProcessor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 33
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 22 2
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
37
        // Append endpoint to request uri, /endpoint/
38
        $endpoint = $proxyModel->getServiceEndpoint();
39
        $uri = $endpoint ?
40
            str_replace('//', '/', $endpoint . '/' . $serviceUri) :
41
            $serviceUri;
42
        $httpHelper->setRequestUri($uri);
43
44
        // Add certificates if set.. etc..
45
46
        /** @var Response $response */
47
        $response = $httpHelper->execute();
48
49
        return $response;
50
    }
51
}
52