AppKernel::configureContainer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 45

Duplication

Lines 4
Ratio 8.89 %

Importance

Changes 0
Metric Value
dl 4
loc 45
rs 9.2
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Symfony-Util package.
5
 *
6
 * (c) Jean-Bernard Addor
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
use Symfony\Bridge\Twig\TwigEngine;
13
use Symfony\Bundle\FrameworkBundle\Client;
14
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
15
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
16
use Symfony\Component\Config\Loader\LoaderInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\HttpKernel\Kernel;
19
use Symfony\Component\Routing\RouteCollectionBuilder;
20
use Symfony\Component\Templating\EngineInterface;
21
use Symfony\Component\Templating\TemplateNameParser;
22
use Symfony\Component\Templating\TemplateNameParserInterface;
23
use SymfonyUtil\Controller\EngineAsArgumentController;
24
use SymfonyUtil\Controller\TemplatingController;
25
26
// use Twig_Environment;
27
// use Twig_Loader_Array;
28
29
class AppKernel extends Kernel
30
{
31
    use MicroKernelTrait;
32
33
    public function registerBundles()
34
    {
35
        return [
36
            new FrameworkBundle(),
37
        ];
38
    }
39
40
    protected function configureRoutes(RouteCollectionBuilder $routes)
41
    {
42
        $routes->add('/', EngineAsArgumentController::class, 'index');
43
        $routes->add('/argument', EngineAsArgumentController::class, 'argument');
44
        $routes->add('/constructor', TemplatingController::class, 'constructor');
45
    }
46
47
    protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $loader is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        // https://symfony.com/doc/current/service_container.html
50
        $c->autowire(TemplateNameParser::class)
51
            ->setAutoconfigured(true)
52
            ->setPublic(false);
53
        $c->setAlias(TemplateNameParserInterface::class, TemplateNameParser::class);
54
55
        $c->autowire(Twig_Loader_Array::class, Twig_Loader_Array::class)
56
            ->setArgument('$templates', ['index.html.twig' => 'Hello Component!'])
57
            ->setAutoconfigured(true)
58
            ->setPublic(false);
59
        $c->setAlias(Twig_LoaderInterface::class, Twig_Loader_Array::class);
60
61
        $c->autowire(Twig_Environment::class, Twig_Environment::class)
62
            ->setAutoconfigured(true)
63
            ->setPublic(false);
64
        $c->setAlias(Twig\Environment::class, Twig_Environment::class);
65
66
        $c->autowire(TwigEngine::class)
67
            ->setAutoconfigured(true)
68
            ->setPublic(false);
69
        $c->setAlias(EngineInterface::class, TwigEngine::class);
70
71 View Code Duplication
        if (in_array($this->getEnvironment(), ['test'], true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
            $c->autowire('test.client', Client::class)
73
                ->setPublic(true); // Public needed!
74
        }
75
76
        //Controllers
77
        $c->autowire(EngineAsArgumentController::class)
78
            ->setAutoconfigured(true)
79
            ->addTag('controller.service_arguments')
80
            ->setPublic(true);
81
82
        $c->autowire(TemplatingController::class)
83
            ->setAutoconfigured(true)
84
            // ->addTag('controller.service_arguments')
85
            ->setPublic(true);
86
87
        // Extensions
88
        $c->loadFromExtension('framework', [
89
            'secret' => 'NotSecret', // What about use $ uuid -v4  or $ uuidgen
90
        ]);
91
    }
92
}
93
94
// Information for Service "test.client"
95
// =====================================
96
97
//  ---------------- ---------------------------------------
98
//   Option           Value
99
//  ---------------- ---------------------------------------
100
//   Service ID       test.client
101
//   Class            Symfony\Bundle\FrameworkBundle\Client
102
//   Tags             -
103
//   Public           yes
104
//   Synthetic        no
105
//   Lazy             no
106
//   Shared           no
107
//   Abstract         no
108
//   Autowired        no
109
//   Autoconfigured   no
110
//  ---------------- ---------------------------------------
111