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 | */ |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
11 | |||
12 | namespace Tvi\MonitorBundle\Controller; |
||
13 | |||
14 | use JMS\Serializer\Serializer; |
||
15 | use Symfony\Component\HttpFoundation\Response; |
||
16 | use Tvi\MonitorBundle\Reporter\ReporterManager; |
||
17 | use Tvi\MonitorBundle\Runner\RunnerManager; |
||
18 | |||
19 | /** |
||
0 ignored issues
–
show
|
|||
20 | * @author Vladimir Turnaev <[email protected]> |
||
21 | */ |
||
0 ignored issues
–
show
|
|||
22 | trait TraitApiCommon |
||
23 | { |
||
24 | /** |
||
0 ignored issues
–
show
|
|||
25 | * @var RunnerManager |
||
26 | */ |
||
27 | protected $runnerManager; |
||
28 | |||
29 | /** |
||
0 ignored issues
–
show
|
|||
30 | * @var ReporterManager |
||
31 | */ |
||
32 | protected $reporterManager; |
||
33 | |||
34 | /** |
||
0 ignored issues
–
show
|
|||
35 | * @var Serializer |
||
36 | */ |
||
37 | protected $serializer; |
||
38 | |||
39 | 95 | public function __construct(RunnerManager $runnerManager, ReporterManager $reporterManager, Serializer $serializer) |
|
0 ignored issues
–
show
|
|||
40 | { |
||
41 | 95 | $this->runnerManager = $runnerManager; |
|
42 | 95 | $this->reporterManager = $reporterManager; |
|
43 | 95 | $this->serializer = $serializer; |
|
44 | 95 | } |
|
45 | |||
46 | 95 | protected function creatResponse($data = null, int $status = Response::HTTP_OK, bool $json = false, array $headers = []): Response |
|
0 ignored issues
–
show
|
|||
47 | { |
||
48 | 95 | if ($json && !\is_string($json)) { |
|
49 | 61 | $data = $this->serializer->serialize($data, 'json'); |
|
50 | } |
||
51 | |||
52 | 95 | if ($json) { |
|
53 | 61 | $headers['Content-Type'] = 'application/json'; |
|
54 | } |
||
55 | |||
56 | 95 | return new Response($data, $status, $headers); |
|
57 | } |
||
58 | } |
||
59 |