|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doyo\Behat\Coverage\Bridge\CodeCoverage\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Doyo\Behat\Coverage\Bridge\CodeCoverage\Cache; |
|
6
|
|
|
use Doyo\Behat\Coverage\Bridge\CodeCoverage\Processor; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
|
|
11
|
|
|
class RemoteController |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @return static |
|
15
|
|
|
*/ |
|
16
|
3 |
|
public static function create() |
|
17
|
|
|
{ |
|
18
|
3 |
|
return new static(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return Response |
|
23
|
|
|
*/ |
|
24
|
3 |
|
public function getResponse() |
|
25
|
|
|
{ |
|
26
|
3 |
|
$request = Request::createFromGlobals(); |
|
27
|
3 |
|
$action = $request->get('action').'Action'; |
|
28
|
3 |
|
$callable = [$this,$action]; |
|
29
|
|
|
|
|
30
|
3 |
|
if(!method_exists($this,$action)){ |
|
31
|
2 |
|
$callable = [$this,'notFoundAction']; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
3 |
|
return call_user_func_array($callable,[$request]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param Request $request |
|
39
|
|
|
* @return JsonResponse |
|
40
|
|
|
*/ |
|
41
|
3 |
|
public function notFoundAction() |
|
42
|
|
|
{ |
|
43
|
|
|
$data = [ |
|
44
|
3 |
|
'message' => 'The page you requested is not exists', |
|
45
|
|
|
]; |
|
46
|
3 |
|
return new JsonResponse($data, 404); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
public function unsupportedMethodAction(Request $request, $supportedMethod) |
|
50
|
|
|
{ |
|
51
|
|
|
$data = [ |
|
52
|
1 |
|
'message' => sprintf( |
|
53
|
1 |
|
'action: %s not support method: %s. Supported method: %s', |
|
54
|
1 |
|
$request->get('action'), |
|
55
|
1 |
|
$request->getMethod(), |
|
56
|
|
|
$supportedMethod |
|
57
|
|
|
), |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
1 |
|
return new JsonResponse($data,Response::HTTP_METHOD_NOT_ALLOWED); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
public function initAction(Request $request) |
|
64
|
|
|
{ |
|
65
|
2 |
|
if(!$request->isMethod(Request::METHOD_POST)){ |
|
66
|
|
|
return $this->unsupportedMethodAction($request,'POST'); |
|
67
|
|
|
} |
|
68
|
2 |
|
$session = $request->get('session'); |
|
69
|
2 |
|
$config = $request->getContent(); |
|
70
|
2 |
|
$config = json_decode($config, true); |
|
71
|
|
|
|
|
72
|
2 |
|
$cache = new Cache($session); |
|
73
|
2 |
|
$cache->setFilter($config['filter']); |
|
74
|
2 |
|
$cache->setCodeCoverageOptions($config['codeCoverageOptions']); |
|
75
|
2 |
|
$cache->save(); |
|
76
|
|
|
|
|
77
|
|
|
$data = [ |
|
78
|
2 |
|
'message' => 'coverage session: '.$session.' initialized.' |
|
79
|
|
|
]; |
|
80
|
2 |
|
return new JsonResponse($data,Response::HTTP_ACCEPTED); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|