1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CedricZiel\ShariffBundle\Controller; |
4
|
|
|
|
5
|
|
|
use CedricZiel\ShariffBundle\Model\ShariffConfig; |
6
|
|
|
use CedricZiel\ShariffBundle\Service\ShariffServiceInterface; |
7
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @package CedricZiel\ShariffBundle\Controller |
12
|
|
|
*/ |
13
|
|
|
class ShariffController |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var ShariffServiceInterface |
17
|
|
|
*/ |
18
|
|
|
protected $shariffService; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var ShariffConfig |
22
|
|
|
*/ |
23
|
|
|
protected $config; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* ShariffController constructor. |
27
|
|
|
* |
28
|
|
|
* @param ShariffServiceInterface $shariffService |
29
|
|
|
* @param ShariffConfig $config |
30
|
|
|
*/ |
31
|
|
|
public function __construct(ShariffServiceInterface $shariffService, ShariffConfig $config) |
32
|
|
|
{ |
33
|
|
|
$this->shariffService = $shariffService; |
34
|
|
|
$this->config = $config; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Request $request |
39
|
|
|
* |
40
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
41
|
|
|
*/ |
42
|
|
|
public function getAction(Request $request) |
43
|
|
|
{ |
44
|
|
|
$url = $request->query->get('url'); |
45
|
|
|
$forceProtocol = $this->config->getForceProtocol(); |
46
|
|
|
|
47
|
|
|
if (!is_null($forceProtocol)) { |
48
|
|
|
if ($forceProtocol === "https") { |
49
|
|
|
$url = str_replace('http://', 'https://', $url); |
50
|
|
|
} |
51
|
|
|
if ($forceProtocol === "http") { |
52
|
|
|
$url = str_replace('https://', 'http://', $url); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$result = $this->shariffService->get($url); |
57
|
|
|
|
58
|
|
|
return new JsonResponse($result); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|