-
-
Notifications
You must be signed in to change notification settings - Fork 848
/
AppKernel.php
156 lines (137 loc) · 5.06 KB
/
AppKernel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\User as UserDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\User;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\TestBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
use FOS\UserBundle\FOSUserBundle;
use Nelmio\ApiDocBundle\NelmioApiDocBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\MercureBundle\MercureBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* AppKernel for tests.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class AppKernel extends Kernel
{
use MicroKernelTrait;
public function __construct(string $environment, bool $debug)
{
parent::__construct($environment, $debug);
// patch for behat/symfony2-extension not supporting %env(APP_ENV)%
$this->environment = $_SERVER['APP_ENV'] ?? $environment;
}
public function registerBundles(): array
{
$bundles = [
new FrameworkBundle(),
new TwigBundle(),
new DoctrineBundle(),
new MercureBundle(),
new ApiPlatformBundle(),
new SecurityBundle(),
new FOSUserBundle(),
new WebProfilerBundle(),
];
if (class_exists(DoctrineMongoDBBundle::class)) {
$bundles[] = new DoctrineMongoDBBundle();
}
if ('elasticsearch' !== $this->getEnvironment()) {
$bundles[] = new TestBundle();
}
if ($_SERVER['LEGACY'] ?? true) {
$bundles[] = new NelmioApiDocBundle();
}
return $bundles;
}
public function getProjectDir()
{
return __DIR__;
}
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$routes->import("config/routing_{$this->getEnvironment()}.yml");
if ($_SERVER['LEGACY'] ?? true) {
$routes->import('@NelmioApiDocBundle/Resources/config/routing.yml', '/nelmioapidoc');
}
}
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
$c->setParameter('kernel.project_dir', __DIR__);
$loader->load(__DIR__."/config/config_{$this->getEnvironment()}.yml");
$securityConfig = [
'encoders' => [
User::class => 'bcrypt',
UserDocument::class => 'bcrypt',
// Don't use plaintext in production!
UserInterface::class => 'plaintext',
],
'providers' => [
'chain_provider' => [
'chain' => [
'providers' => ['in_memory', 'fos_userbundle'],
],
],
'in_memory' => [
'memory' => [
'users' => [
'dunglas' => ['password' => 'kevin', 'roles' => 'ROLE_USER'],
'admin' => ['password' => 'kitten', 'roles' => 'ROLE_ADMIN'],
],
],
],
'fos_userbundle' => ['id' => 'fos_user.user_provider.username_email'],
],
'firewalls' => [
'dev' => [
'pattern' => '^/(_(profiler|wdt|error)|css|images|js)/',
'security' => false,
],
'default' => [
'provider' => 'chain_provider',
'http_basic' => null,
'anonymous' => null,
],
],
'access_control' => [
['path' => '^/', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'],
],
];
$c->loadFromExtension('security', $securityConfig);
if ($_SERVER['LEGACY'] ?? true) {
$c->loadFromExtension('nelmio_api_doc', [
'sandbox' => [
'accept_type' => 'application/json',
'body_format' => [
'formats' => ['json'],
'default_format' => 'json',
],
'request_format' => [
'formats' => ['json' => 'application/json'],
],
],
]);
$c->loadFromExtension('api_platform', ['enable_nelmio_api_doc' => true]);
}
}
}