|
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
|
|
|
namespace Tests\FrameworkTwig; |
|
13
|
|
|
|
|
14
|
|
|
use Knp\Rad\ResourceResolver\Bundle\ResourceResolverBundle; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
|
17
|
|
|
use Symfony\Bundle\TwigBundle\TwigBundle; |
|
18
|
|
|
use Symfony\Bundle\WebServerBundle\WebServerBundle; |
|
19
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
21
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
22
|
|
|
use Symfony\Component\Routing\Route; |
|
23
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
|
24
|
|
|
use SymfonyUtil\Controller\EngineAsArgumentController; |
|
25
|
|
|
use SymfonyUtil\Controller\TemplatingController; |
|
26
|
|
|
use SymfonyUtil\Controller\VariadicController; |
|
27
|
|
|
|
|
28
|
|
|
class Identity |
|
29
|
|
|
{ |
|
30
|
|
|
public function __invoke($a) |
|
31
|
|
|
{ |
|
32
|
|
|
dump($a); |
|
33
|
|
|
|
|
34
|
|
|
return $a; |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
class AppKernel extends Kernel |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
use MicroKernelTrait; |
|
41
|
|
|
|
|
42
|
|
|
public function registerBundles() |
|
43
|
|
|
{ |
|
44
|
|
|
return [ |
|
45
|
|
|
new FrameworkBundle(), |
|
46
|
|
|
new ResourceResolverBundle(), |
|
47
|
|
|
new TwigBundle(), |
|
48
|
|
|
new WebServerBundle() |
|
49
|
|
|
]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes) |
|
53
|
|
|
{ |
|
54
|
|
|
$routes->add('/', EngineAsArgumentController::class, 'index'); |
|
55
|
|
|
$routes->add('/argument', EngineAsArgumentController::class, 'argument'); |
|
56
|
|
|
$routes->add('/constructor', TemplatingController::class, 'constructor'); |
|
57
|
|
|
$routes->addRoute(new Route('/variadic/request', [ |
|
58
|
|
|
'_controller' => VariadicController::class, |
|
59
|
|
|
'_resources' => ['\Identity', ['request']], |
|
60
|
|
|
]), |
|
61
|
|
|
'variadic_request' |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
//Controllers |
|
68
|
|
|
$c->autowire(EngineAsArgumentController::class) |
|
69
|
|
|
->setAutoconfigured(true) |
|
70
|
|
|
->addTag('controller.service_arguments') |
|
71
|
|
|
->setPublic(true); |
|
72
|
|
|
|
|
73
|
|
|
$c->autowire(TemplatingController::class) |
|
74
|
|
|
->setAutoconfigured(true) |
|
75
|
|
|
// ->addTag('controller.service_arguments') |
|
|
|
|
|
|
76
|
|
|
->setPublic(true); |
|
77
|
|
|
|
|
78
|
|
|
$c->autowire(VariadicController::class) |
|
79
|
|
|
->setAutoconfigured(true) |
|
80
|
|
|
->setPublic(true); |
|
81
|
|
|
|
|
82
|
|
|
$c->autowire('\Identity') |
|
83
|
|
|
->setAutoconfigured(true) |
|
84
|
|
|
->setPublic(true); |
|
85
|
|
|
|
|
86
|
|
|
// Extensions |
|
87
|
|
|
$c->loadFromExtension('framework', [ |
|
88
|
|
|
'secret' => 'NotSecret', // What about use $ uuid -v4 or $ uuidgen |
|
89
|
|
|
'test' => in_array($this->getEnvironment(), ['test'], true), // test.client service for eg. PHPUnit |
|
90
|
|
|
'templating' => ['engines' => 'twig'], |
|
91
|
|
|
]); |
|
92
|
|
|
$c->loadFromExtension('twig', [ |
|
93
|
|
|
'debug' => true, |
|
94
|
|
|
'paths' => ['%kernel.project_dir%/tests/templates'], |
|
95
|
|
|
]); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.