1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the `tvi/monitor-bundle` project. |
5
|
|
|
* |
6
|
|
|
* (c) https://github.com/turnaev/monitor-bundle/graphs/contributors |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Tvi\MonitorBundle\Controller; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
use JMS\Serializer\Serializer; |
16
|
|
|
use Tvi\MonitorBundle\Reporter\ReporterManager; |
17
|
|
|
use Tvi\MonitorBundle\Runner\RunnerManager; |
18
|
|
|
|
19
|
|
|
/** |
|
|
|
|
20
|
|
|
* @author Vladimir Turnaev <[email protected]> |
21
|
|
|
*/ |
|
|
|
|
22
|
|
|
trait ApiInitTrait |
23
|
|
|
{ |
24
|
|
|
/** |
|
|
|
|
25
|
|
|
* @var RunnerManager |
26
|
|
|
*/ |
27
|
|
|
protected $runnerManager; |
28
|
|
|
|
29
|
|
|
/** |
|
|
|
|
30
|
|
|
* @var ReporterManager |
31
|
|
|
*/ |
32
|
|
|
protected $reporterManager; |
33
|
|
|
|
34
|
|
|
/** |
|
|
|
|
35
|
|
|
* @var Serializer |
36
|
|
|
*/ |
37
|
|
|
protected $serializer; |
38
|
|
|
|
39
|
51 |
|
public function __construct(RunnerManager $runnerManager, ReporterManager $reporterManager, Serializer $serializer) |
|
|
|
|
40
|
|
|
{ |
41
|
51 |
|
$this->runnerManager = $runnerManager; |
42
|
51 |
|
$this->reporterManager = $reporterManager; |
43
|
51 |
|
$this->serializer = $serializer; |
44
|
51 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
|
|
|
|
47
|
|
|
* return array [$checks, $groups, $tags]. |
|
|
|
|
48
|
|
|
*/ |
|
|
|
|
49
|
28 |
|
protected function getFilterParams(Request $request): array |
50
|
|
|
{ |
51
|
28 |
|
$checks = $request->get('check', []); |
52
|
28 |
|
if (\is_scalar($checks)) { |
53
|
3 |
|
$checks = $checks ? [$checks] : []; |
54
|
|
|
} |
55
|
28 |
|
$checks = !\is_array($checks) ? [$checks] : $checks; |
56
|
|
|
|
57
|
28 |
|
$groups = $request->get('group', []); |
58
|
28 |
|
if (\is_scalar($groups)) { |
59
|
8 |
|
$groups = $groups ? [$groups] : []; |
60
|
|
|
} |
61
|
28 |
|
$groups = !\is_array($groups) ? [$groups] : $groups; |
62
|
|
|
|
63
|
28 |
|
$tags = $request->get('tag', []); |
64
|
28 |
|
if (\is_scalar($tags)) { |
65
|
4 |
|
$tags = $tags ? [$tags] : []; |
66
|
|
|
} |
67
|
28 |
|
$tags = !\is_array($tags) ? [$tags] : $tags; |
68
|
|
|
|
69
|
28 |
|
return [$checks, $groups, $tags]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
|
|
|
|
73
|
|
|
* return array. |
|
|
|
|
74
|
|
|
*/ |
|
|
|
|
75
|
|
|
protected function getFilterIds(Request $request): array |
76
|
|
|
{ |
77
|
|
|
$id = $request->get('id', []); |
78
|
|
|
if (\is_scalar($id)) { |
79
|
|
|
$id = $id ? [$id] : []; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return !\is_array($id) ? [$id] : $id; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|