AbstractMagisController::getSubscribedServices()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace pjpawel\Magis\MagisBundle\Controller;
4
5
use pjpawel\Magis\ViewDispatcherService;
6
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7
use Symfony\Component\HttpFoundation\Response;
8
9
/**
10
 * @codeCoverageIgnore
11
 *
12
 * @author Paweł Podgórski <[email protected]>
13
 */
14
class AbstractMagisController extends AbstractController
15
{
16
17
    /**
18
     * @param string $view
19
     * @param array<string,mixed> $parameters
20
     * @param Response|null $response
21
     * @return Response
22
     * @throws \Psr\Container\ContainerExceptionInterface
23
     * @throws \Psr\Container\NotFoundExceptionInterface
24
     */
25
    protected function renderPhpView(string $view, array $parameters = [], Response $response = null): Response
26
    {
27
        /** @var ViewDispatcherService $magis */
28
        $magis = $this->container->get('magis');
29
        $content = $magis->render($view, $parameters);
30
31
        if (null === $response) {
32
            $response = new Response();
33
        }
34
35
        $response->setContent($content);
36
        return $response;
37
    }
38
39
    public static function getSubscribedServices(): array
40
    {
41
        return array_merge(
42
            parent::getSubscribedServices(),
43
            [
44
                'magis' => ViewDispatcherService::class
45
            ]
46
        );
47
    }
48
49
50
}