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 ApiCommonTrait |
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
|
60 |
|
public function __construct(RunnerManager $runnerManager, ReporterManager $reporterManager, Serializer $serializer) |
|
|
|
|
40
|
|
|
{ |
41
|
60 |
|
$this->runnerManager = $runnerManager; |
42
|
60 |
|
$this->reporterManager = $reporterManager; |
43
|
60 |
|
$this->serializer = $serializer; |
44
|
60 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
|
|
|
|
47
|
|
|
* return array [$ids, $checks, $groups, $tags]. |
|
|
|
|
48
|
|
|
*/ |
|
|
|
|
49
|
34 |
|
protected function getFilterParams(Request $request): array |
50
|
|
|
{ |
51
|
34 |
|
$id = $request->get('id', []); |
52
|
34 |
|
if (\is_scalar($id)) { |
53
|
4 |
|
$id = $id ? [$id] : []; |
54
|
|
|
} |
55
|
|
|
|
56
|
34 |
|
$ids = !\is_array($id) ? [$id] : $id; |
57
|
|
|
|
58
|
34 |
|
$checks = $request->get('check', []); |
59
|
34 |
|
if (\is_scalar($checks)) { |
60
|
3 |
|
$checks = $checks ? [$checks] : []; |
61
|
|
|
} |
62
|
34 |
|
$checks = !\is_array($checks) ? [$checks] : $checks; |
63
|
|
|
|
64
|
34 |
|
$groups = $request->get('group', []); |
65
|
34 |
|
if (\is_scalar($groups)) { |
66
|
8 |
|
$groups = $groups ? [$groups] : []; |
67
|
|
|
} |
68
|
34 |
|
$groups = !\is_array($groups) ? [$groups] : $groups; |
69
|
|
|
|
70
|
34 |
|
$tags = $request->get('tag', []); |
71
|
34 |
|
if (\is_scalar($tags)) { |
72
|
4 |
|
$tags = $tags ? [$tags] : []; |
73
|
|
|
} |
74
|
34 |
|
$tags = !\is_array($tags) ? [$tags] : $tags; |
75
|
|
|
|
76
|
34 |
|
return [$ids, $checks, $groups, $tags]; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|