Skip to content

Commit 7d80f8d

Browse files
Merge branch '3.4' into 4.0
* 3.4: Remove randomness from dumped containers fixed messages to be explicit about the package needed to be installed [FrameworkBundle] Fix recommended composer command (add vendor) [WebProfilerBundle] set the var in the right scope [TwigBundle] fix lowest dep [HttpKernel] Disable CSP header on exception pages Use the default host even if context is empty and fallback to relative URL if empty host Proposing Flex-specific error messages in the controller shortcuts
2 parents 2380cf3 + 4188236 commit 7d80f8d

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

Controller/ControllerTrait.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ protected function file($file, string $fileName = null, string $disposition = Re
153153
protected function addFlash(string $type, string $message)
154154
{
155155
if (!$this->container->has('session')) {
156-
throw new \LogicException('You can not use the addFlash method if sessions are disabled.');
156+
throw new \LogicException('You can not use the addFlash method if sessions are disabled. Enable them in "config/packages/framework.yaml".');
157157
}
158158

159159
$this->container->get('session')->getFlashBag()->add($type, $message);
@@ -169,7 +169,7 @@ protected function addFlash(string $type, string $message)
169169
protected function isGranted($attributes, $subject = null): bool
170170
{
171171
if (!$this->container->has('security.authorization_checker')) {
172-
throw new \LogicException('The SecurityBundle is not registered in your application.');
172+
throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require symfony/security-bundle".');
173173
}
174174

175175
return $this->container->get('security.authorization_checker')->isGranted($attributes, $subject);
@@ -206,7 +206,7 @@ protected function renderView(string $view, array $parameters = array()): string
206206
}
207207

208208
if (!$this->container->has('twig')) {
209-
throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available.');
209+
throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available. Try running "composer require symfony/twig-bundle".');
210210
}
211211

212212
return $this->container->get('twig')->render($view, $parameters);
@@ -224,7 +224,7 @@ protected function render(string $view, array $parameters = array(), Response $r
224224
} elseif ($this->container->has('twig')) {
225225
$content = $this->container->get('twig')->render($view, $parameters);
226226
} else {
227-
throw new \LogicException('You can not use the "render" method if the Templating Component or the Twig Bundle are not available.');
227+
throw new \LogicException('You can not use the "render" method if the Templating Component or the Twig Bundle are not available. Try running "composer require symfony/twig-bundle".');
228228
}
229229

230230
if (null === $response) {
@@ -256,7 +256,7 @@ protected function stream(string $view, array $parameters = array(), StreamedRes
256256
$twig->display($view, $parameters);
257257
};
258258
} else {
259-
throw new \LogicException('You can not use the "stream" method if the Templating Component or the Twig Bundle are not available.');
259+
throw new \LogicException('You can not use the "stream" method if the Templating Component or the Twig Bundle are not available. Try running "composer require symfony/twig-bundle".');
260260
}
261261

262262
if (null === $response) {
@@ -296,7 +296,7 @@ protected function createNotFoundException(string $message = 'Not Found', \Excep
296296
protected function createAccessDeniedException(string $message = 'Access Denied.', \Exception $previous = null): AccessDeniedException
297297
{
298298
if (!class_exists(AccessDeniedException::class)) {
299-
throw new \LogicException('You can not use the "createAccessDeniedException" method if the Security component is not available.');
299+
throw new \LogicException('You can not use the "createAccessDeniedException" method if the Security component is not available. Try running "composer require symfony/security-bundle".');
300300
}
301301

302302
return new AccessDeniedException($message, $previous);
@@ -332,7 +332,7 @@ protected function createFormBuilder($data = null, array $options = array()): Fo
332332
protected function getDoctrine(): ManagerRegistry
333333
{
334334
if (!$this->container->has('doctrine')) {
335-
throw new \LogicException('The DoctrineBundle is not registered in your application.');
335+
throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
336336
}
337337

338338
return $this->container->get('doctrine');
@@ -352,7 +352,7 @@ protected function getDoctrine(): ManagerRegistry
352352
protected function getUser()
353353
{
354354
if (!$this->container->has('security.token_storage')) {
355-
throw new \LogicException('The SecurityBundle is not registered in your application.');
355+
throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require symfony/security-bundle".');
356356
}
357357

358358
if (null === $token = $this->container->get('security.token_storage')->getToken()) {
@@ -378,7 +378,7 @@ protected function getUser()
378378
protected function isCsrfTokenValid(string $id, string $token): bool
379379
{
380380
if (!$this->container->has('security.csrf.token_manager')) {
381-
throw new \LogicException('CSRF protection is not enabled in your application.');
381+
throw new \LogicException('CSRF protection is not enabled in your application. Enable it with the "csrf_protection" key in "config/packages/framework.yaml".');
382382
}
383383

384384
return $this->container->get('security.csrf.token_manager')->isTokenValid(new CsrfToken($id, $token));

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
3737
use Symfony\Component\DependencyInjection\Exception\LogicException;
3838
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
39+
use Symfony\Component\DependencyInjection\Parameter;
3940
use Symfony\Component\DependencyInjection\Reference;
4041
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
4142
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -1137,7 +1138,7 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
11371138
}
11381139

11391140
if (!class_exists('Symfony\Component\Security\Csrf\CsrfToken')) {
1140-
throw new LogicException('CSRF support cannot be enabled as the Security CSRF component is not installed. Try running "composer require security-csrf".');
1141+
throw new LogicException('CSRF support cannot be enabled as the Security CSRF component is not installed. Try running "composer require symfony/security-csrf".');
11411142
}
11421143

11431144
if (!$this->sessionConfigEnabled) {
@@ -1332,7 +1333,7 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
13321333

13331334
private function registerCacheConfiguration(array $config, ContainerBuilder $container)
13341335
{
1335-
$version = substr(str_replace('/', '-', base64_encode(hash('sha256', uniqid(mt_rand(), true), true))), 0, 22);
1336+
$version = new Parameter('container.build_id');
13361337
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version);
13371338
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
13381339
$container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']);

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,9 @@ protected function createContainer(array $data = array())
10231023
'kernel.name' => 'kernel',
10241024
'kernel.root_dir' => __DIR__,
10251025
'kernel.container_class' => 'testContainer',
1026+
'container.build_hash' => 'Abc1234',
1027+
'container.build_id' => hash('crc32', 'Abc123423456789'),
1028+
'container.build_time' => 23456789,
10261029
), $data)));
10271030
}
10281031

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": "^7.1.3",
2020
"ext-xml": "*",
2121
"symfony/cache": "~3.4|~4.0",
22-
"symfony/dependency-injection": "~3.4|~4.0",
22+
"symfony/dependency-injection": "^3.4.3|^4.0.3",
2323
"symfony/config": "~3.4|~4.0",
2424
"symfony/event-dispatcher": "~3.4|~4.0",
2525
"symfony/http-foundation": "~3.4|~4.0",

0 commit comments

Comments
 (0)