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 Knp\Rad\ResourceResolver\Bundle\ResourceResolverBundle; |
13
|
|
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
15
|
|
|
use Symfony\Bundle\TwigBundle\TwigBundle; |
16
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
19
|
|
|
use Symfony\Component\Routing\Route; |
20
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
21
|
|
|
use SymfonyUtil\Controller\EngineAsArgumentController; |
22
|
|
|
use SymfonyUtil\Controller\TemplatingController; |
23
|
|
|
use SymfonyUtil\Controller\VariadicController; |
24
|
|
|
|
25
|
|
|
class Identity |
26
|
|
|
{ |
27
|
|
|
public function __invoke($a) |
28
|
|
|
{ |
29
|
|
|
dump($a); |
30
|
|
|
|
31
|
|
|
return $a; |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
class AppKernel extends Kernel |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
use MicroKernelTrait; |
38
|
|
|
|
39
|
|
|
public function registerBundles() |
40
|
|
|
{ |
41
|
|
|
return [ |
42
|
|
|
new FrameworkBundle(), |
43
|
|
|
new ResourceResolverBundle(), |
44
|
|
|
new TwigBundle(), |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes) |
49
|
|
|
{ |
50
|
|
|
$routes->add('/', EngineAsArgumentController::class, 'index'); |
51
|
|
|
$routes->add('/argument', EngineAsArgumentController::class, 'argument'); |
52
|
|
|
$routes->add('/constructor', TemplatingController::class, 'constructor'); |
53
|
|
|
$routes->addRoute(new Route('/variadic/request', [ |
54
|
|
|
'_controller' => VariadicController::class, |
55
|
|
|
'_resources' => [ Identity::class, ['request']], |
56
|
|
|
]), |
57
|
|
|
'variadic_request' |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
//Controllers |
64
|
|
|
$c->autowire(EngineAsArgumentController::class) |
65
|
|
|
->setAutoconfigured(true) |
66
|
|
|
->addTag('controller.service_arguments') |
67
|
|
|
->setPublic(true); |
68
|
|
|
|
69
|
|
|
$c->autowire(TemplatingController::class) |
70
|
|
|
->setAutoconfigured(true) |
71
|
|
|
// ->addTag('controller.service_arguments') |
|
|
|
|
72
|
|
|
->setPublic(true); |
73
|
|
|
|
74
|
|
|
$c->autowire(VariadicController::class) |
75
|
|
|
->setAutoconfigured(true) |
76
|
|
|
->setPublic(true); |
77
|
|
|
|
78
|
|
|
// Extensions |
79
|
|
|
$c->loadFromExtension('framework', [ |
80
|
|
|
'secret' => 'NotSecret', // What about use $ uuid -v4 or $ uuidgen |
81
|
|
|
'test' => in_array($this->getEnvironment(), ['test'], true), // test.client service for eg. PHPUnit |
82
|
|
|
'templating' => ['engines' => 'twig'], |
83
|
|
|
]); |
84
|
|
|
$c->loadFromExtension('twig', [ |
85
|
|
|
'debug' => true, |
86
|
|
|
'paths' => ['%kernel.project_dir%/tests/templates'], |
87
|
|
|
]); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This check looks for classes that have been defined more than once.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.