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\Bundle\TwigBundle\TwigBundle; |
17
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
20
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
21
|
|
|
use Symfony\Component\Templating\EngineInterface; |
22
|
|
|
use Symfony\Component\Templating\TemplateNameParser; |
23
|
|
|
use Symfony\Component\Templating\TemplateNameParserInterface; |
24
|
|
|
use SymfonyUtil\Controller\EngineAsArgumentController; |
25
|
|
|
|
26
|
|
|
// use Twig_Environment; |
|
|
|
|
27
|
|
|
// use Twig_Loader_Array; |
28
|
|
|
|
29
|
|
|
class ComponentKernel extends Kernel |
30
|
|
|
{ |
31
|
|
|
use MicroKernelTrait; |
32
|
|
|
|
33
|
|
|
public function registerBundles() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
new FrameworkBundle(), |
37
|
|
|
// new TwigBundle(), |
|
|
|
|
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes) |
42
|
|
|
{ |
43
|
|
|
$routes->add('/', EngineAsArgumentController::class, 'index'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
// https://symfony.com/doc/current/service_container.html |
49
|
|
|
$c->autowire(TemplateNameParser::class) |
50
|
|
|
->setAutoconfigured(true) |
51
|
|
|
->setPublic(false); |
52
|
|
|
$c->setAlias(TemplateNameParserInterface::class, TemplateNameParser::class); |
53
|
|
|
|
54
|
|
|
$c->autowire(Twig_Loader_Array::class, Twig_Loader_Array::class) |
55
|
|
|
->setArgument('$templates', ['index.html.twig' => 'Hello Component!']) |
56
|
|
|
->setAutoconfigured(true) |
57
|
|
|
->setPublic(false); |
58
|
|
|
$c->setAlias(Twig_LoaderInterface::class, Twig_Loader_Array::class); |
59
|
|
|
|
60
|
|
|
$c->autowire(Twig_Environment::class, Twig_Environment::class) |
61
|
|
|
->setAutoconfigured(true) |
62
|
|
|
->setPublic(false); |
63
|
|
|
$c->setAlias(Twig\Environment::class, Twig_Environment::class); |
64
|
|
|
|
65
|
|
|
$c->autowire(TwigEngine::class) |
66
|
|
|
->setAutoconfigured(true) |
67
|
|
|
->setShared(true) // not needed: default |
68
|
|
|
->setPublic(false); |
69
|
|
|
$c->setAlias(EngineInterface::class, TwigEngine::class); |
70
|
|
|
|
71
|
|
|
if (in_array($this->getEnvironment(), ['test'], true)) { |
72
|
|
|
$c->autowire('test.client', Client::class) |
73
|
|
|
->setAutoconfigured(false) |
74
|
|
|
->setShared(false) |
75
|
|
|
->setPublic(true); // |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
//Controllers |
79
|
|
|
$c->autowire(EngineAsArgumentController::class) |
80
|
|
|
->setAutoconfigured(true) |
81
|
|
|
->addTag('controller.service_arguments') |
82
|
|
|
->setPublic(false); |
83
|
|
|
|
84
|
|
|
// Extensions |
85
|
|
|
$c->loadFromExtension('framework', [ |
86
|
|
|
'secret' => 'NotSecret', // What about use $ uuid -v4 or $ uuidgen |
87
|
|
|
'test' => in_array($this->getEnvironment(), ['test'], true), // test.client service for eg. PHPUnit |
88
|
|
|
// 'templating' => ['engines' => 'twig'], |
|
|
|
|
89
|
|
|
]); |
90
|
|
|
// $c->loadFromExtension('twig', [ |
|
|
|
|
91
|
|
|
// 'debug' => true, |
|
|
|
|
92
|
|
|
// 'paths' => ['%kernel.project_dir%/tests/templates'], |
|
|
|
|
93
|
|
|
// ]); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// Information for Service "test.client" |
98
|
|
|
// ===================================== |
99
|
|
|
|
100
|
|
|
// ---------------- --------------------------------------- |
101
|
|
|
// Option Value |
102
|
|
|
// ---------------- --------------------------------------- |
103
|
|
|
// Service ID test.client |
104
|
|
|
// Class Symfony\Bundle\FrameworkBundle\Client |
105
|
|
|
// Tags - |
106
|
|
|
// Public yes |
107
|
|
|
// Synthetic no |
108
|
|
|
// Lazy no |
109
|
|
|
// Shared no |
110
|
|
|
// Abstract no |
111
|
|
|
// Autowired no |
112
|
|
|
// Autoconfigured no |
113
|
|
|
// ---------------- --------------------------------------- |
114
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.