Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3d199d

Browse filesBrowse files
committed
Merge branch '5.4' into 6.0
* 5.4: fix SQLSRV throws for method_exists() [HttpKernel] Add basic support for language negotiation [Messenger] Add a middleware to log when transaction has been left open [HttpClient] Add method to set response factory in mock client Move array_merge calls out of loops to improve performance Remove references to DBALException [VarDumper] Fix handling of "new" in initializers on PHP 8.1
2 parents 889de45 + 055b38f commit f3d199d
Copy full SHA for f3d199d

File tree

Expand file treeCollapse file tree

62 files changed

+580
-152
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

62 files changed

+580
-152
lines changed

‎UPGRADE-5.4.md

Copy file name to clipboardExpand all lines: UPGRADE-5.4.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Form
2525
FrameworkBundle
2626
---------------
2727

28+
* Deprecate the `framework.translator.enabled_locales` config option, use `framework.enabled_locales` instead
2829
* Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead
2930
* Deprecate the public `profiler` service to private
3031
* Deprecate `get()`, `has()`, `getDoctrine()`, and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead

‎UPGRADE-6.0.md

Copy file name to clipboardExpand all lines: UPGRADE-6.0.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Form
8989
FrameworkBundle
9090
---------------
9191

92+
* Remove the `framework.translator.enabled_locales` config option, use `framework.enabled_locales` instead
9293
* Remove the `session.storage` alias and `session.storage.*` services, use the `session.storage.factory` alias and `session.storage.factory.*` services instead
9394
* Remove `framework.session.storage_id` configuration option, use the `framework.session.storage_factory_id` configuration option instead
9495
* Remove the `session` service and the `SessionInterface` alias, use the `\Symfony\Component\HttpFoundation\Request::getSession()` or the new `\Symfony\Component\HttpFoundation\RequestStack::getSession()` methods instead

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"doctrine/annotations": "^1.13.1",
126126
"doctrine/collections": "~1.0",
127127
"doctrine/data-fixtures": "^1.1",
128-
"doctrine/dbal": "^2.10|^3.0",
128+
"doctrine/dbal": "^2.13|^3.0",
129129
"doctrine/orm": "^2.7.3",
130130
"guzzlehttp/promises": "^1.4",
131131
"masterminds/html5": "^2.6",
@@ -151,7 +151,7 @@
151151
"ext-psr": "<1.1|>=2",
152152
"async-aws/core": "<1.5",
153153
"doctrine/annotations": "<1.13.1",
154-
"doctrine/dbal": "<2.10",
154+
"doctrine/dbal": "<2.13",
155155
"egulias/email-validator": "~3.0.0",
156156
"masterminds/html5": "<2.6",
157157
"phpdocumentor/reflection-docblock": "<3.2.2",

‎src/Symfony/Bridge/Doctrine/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ CHANGELOG
66

77
* Remove `DoctrineTestHelper` and `TestRepositoryFactory`
88

9+
5.4
10+
---
11+
* Add a middleware to log when transaction has been left open `DoctrineOpenTransactionLoggerMiddleware`
12+
913
5.3
1014
---
1115

+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Bridge\Doctrine\Messenger;
13+
14+
use Doctrine\ORM\EntityManagerInterface;
15+
use Doctrine\Persistence\ManagerRegistry;
16+
use Psr\Log\LoggerInterface;
17+
use Psr\Log\NullLogger;
18+
use Symfony\Component\Messenger\Envelope;
19+
use Symfony\Component\Messenger\Middleware\StackInterface;
20+
21+
/**
22+
* Middleware to log when transaction has been left open.
23+
*
24+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
25+
*/
26+
class DoctrineOpenTransactionLoggerMiddleware extends AbstractDoctrineMiddleware
27+
{
28+
private $logger;
29+
30+
public function __construct(ManagerRegistry $managerRegistry, string $entityManagerName = null, LoggerInterface $logger = null)
31+
{
32+
parent::__construct($managerRegistry, $entityManagerName);
33+
34+
$this->logger = $logger ?? new NullLogger();
35+
}
36+
37+
protected function handleForManager(EntityManagerInterface $entityManager, Envelope $envelope, StackInterface $stack): Envelope
38+
{
39+
try {
40+
return $stack->next()->handle($envelope, $stack);
41+
} finally {
42+
if ($entityManager->getConnection()->isTransactionActive()) {
43+
$this->logger->error('A handler opened a transaction but did not close it.', [
44+
'message' => $envelope->getMessage(),
45+
]);
46+
}
47+
}
48+
}
49+
}

‎src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Messenger;
1313

14-
use Doctrine\DBAL\DBALException;
15-
use Doctrine\DBAL\Exception;
14+
use Doctrine\DBAL\Exception as DBALException;
1615
use Doctrine\ORM\EntityManagerInterface;
1716
use Symfony\Component\Messenger\Envelope;
1817
use Symfony\Component\Messenger\Middleware\StackInterface;
@@ -40,7 +39,7 @@ private function pingConnection(EntityManagerInterface $entityManager)
4039

4140
try {
4241
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
43-
} catch (DBALException | Exception $e) {
42+
} catch (DBALException $e) {
4443
$connection->close();
4544
$connection->connect();
4645
}
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Bridge\Doctrine\Tests\Messenger;
13+
14+
use Doctrine\DBAL\Connection;
15+
use Doctrine\ORM\EntityManagerInterface;
16+
use Doctrine\Persistence\ManagerRegistry;
17+
use Psr\Log\AbstractLogger;
18+
use Symfony\Bridge\Doctrine\Messenger\DoctrineOpenTransactionLoggerMiddleware;
19+
use Symfony\Component\Messenger\Envelope;
20+
use Symfony\Component\Messenger\Test\Middleware\MiddlewareTestCase;
21+
22+
class DoctrineOpenTransactionLoggerMiddlewareTest extends MiddlewareTestCase
23+
{
24+
private $logger;
25+
private $connection;
26+
private $entityManager;
27+
private $middleware;
28+
29+
protected function setUp(): void
30+
{
31+
$this->logger = new class() extends AbstractLogger {
32+
public $logs = [];
33+
34+
public function log($level, $message, $context = []): void
35+
{
36+
$this->logs[$level][] = $message;
37+
}
38+
};
39+
40+
$this->connection = $this->createMock(Connection::class);
41+
42+
$this->entityManager = $this->createMock(EntityManagerInterface::class);
43+
$this->entityManager->method('getConnection')->willReturn($this->connection);
44+
45+
$managerRegistry = $this->createMock(ManagerRegistry::class);
46+
$managerRegistry->method('getManager')->willReturn($this->entityManager);
47+
48+
$this->middleware = new DoctrineOpenTransactionLoggerMiddleware($managerRegistry, null, $this->logger);
49+
}
50+
51+
public function testMiddlewareWrapsInTransactionAndFlushes()
52+
{
53+
$this->connection->expects($this->exactly(1))
54+
->method('isTransactionActive')
55+
->will($this->onConsecutiveCalls(true, true, false))
56+
;
57+
58+
$this->middleware->handle(new Envelope(new \stdClass()), $this->getStackMock());
59+
60+
$this->assertSame(['error' => ['A handler opened a transaction but did not close it.']], $this->logger->logs);
61+
}
62+
}

‎src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Tests\Messenger;
1313

1414
use Doctrine\DBAL\Connection;
15-
use Doctrine\DBAL\DBALException;
16-
use Doctrine\DBAL\Exception;
15+
use Doctrine\DBAL\Exception as DBALException;
1716
use Doctrine\ORM\EntityManagerInterface;
1817
use Doctrine\Persistence\ManagerRegistry;
1918
use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware;
@@ -50,7 +49,7 @@ public function testMiddlewarePingOk()
5049
{
5150
$this->connection->expects($this->once())
5251
->method('getDatabasePlatform')
53-
->will($this->throwException(class_exists(Exception::class) ? new Exception() : new DBALException()));
52+
->will($this->throwException(new DBALException()));
5453

5554
$this->connection->expects($this->once())
5655
->method('close')
@@ -69,7 +68,7 @@ public function testMiddlewarePingResetEntityManager()
6968
{
7069
$this->connection->expects($this->once())
7170
->method('getDatabasePlatform')
72-
->will($this->throwException(class_exists(Exception::class) ? new Exception() : new DBALException()));
71+
->will($this->throwException(new DBALException()));
7372

7473
$this->entityManager->expects($this->once())
7574
->method('isOpen')

‎src/Symfony/Bridge/Doctrine/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/composer.json
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
"doctrine/annotations": "^1.10.4",
4747
"doctrine/collections": "~1.0",
4848
"doctrine/data-fixtures": "^1.1",
49-
"doctrine/dbal": "^2.10|^3.0",
50-
"doctrine/orm": "^2.7.3"
49+
"doctrine/dbal": "^2.13|^3.0",
50+
"doctrine/orm": "^2.7.3",
51+
"psr/log": "^1|^2|^3"
5152
},
5253
"conflict": {
53-
"doctrine/dbal": "<2.10",
54+
"doctrine/dbal": "<2.13",
5455
"doctrine/orm": "<2.7.3",
5556
"phpunit/phpunit": "<5.4.3",
5657
"symfony/dependency-injection": "<5.4",

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ CHANGELOG
2424
5.4
2525
---
2626

27+
* Add `set_locale_from_accept_language` config option to automatically set the request locale based on the `Accept-Language`
28+
HTTP request header and the `framework.enabled_locales` config option
29+
* Add `set_content_language_from_locale` config option to automatically set the `Content-Language` HTTP response header based on the Request locale
30+
* Deprecate the `framework.translator.enabled_locales`, use `framework.enabled_locales` instead
2731
* Add autowiring alias for `HttpCache\StoreInterface`
2832
* Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead
2933
* Deprecate the public `profiler` service to private

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+20-8Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function getConfigTreeBuilder(): TreeBuilder
7373
return $v;
7474
})
7575
->end()
76+
->fixXmlConfig('enabled_locale')
7677
->children()
7778
->scalarNode('secret')->end()
7879
->scalarNode('http_method_override')
@@ -82,6 +83,18 @@ public function getConfigTreeBuilder(): TreeBuilder
8283
->scalarNode('ide')->defaultNull()->end()
8384
->booleanNode('test')->end()
8485
->scalarNode('default_locale')->defaultValue('en')->end()
86+
->booleanNode('set_locale_from_accept_language')
87+
->info('Whether to use the Accept-Language HTTP header to set the Request locale (only when the "_locale" request attribute is not passed).')
88+
->defaultFalse()
89+
->end()
90+
->booleanNode('set_content_language_from_locale')
91+
->info('Whether to set the Content-Language HTTP header on the Response using the Request locale.')
92+
->defaultFalse()
93+
->end()
94+
->arrayNode('enabled_locales')
95+
->info('Defines the possible locales for the application. This list is used for generating translations files, but also to restrict which locales are allowed when it is set from Accept-Language header (using "set_locale_from_accept_language").')
96+
->prototype('scalar')->end()
97+
->end()
8598
->arrayNode('trusted_hosts')
8699
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
87100
->prototype('scalar')->end()
@@ -792,6 +805,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode, callable $e
792805
->prototype('scalar')->end()
793806
->end()
794807
->arrayNode('enabled_locales')
808+
->setDeprecated('symfony/framework-bundle', '5.3', 'Option "%node%" at "%path%" is deprecated, set the "framework.enabled_locales" option instead.')
795809
->prototype('scalar')->end()
796810
->defaultValue([])
797811
->end()
@@ -826,7 +840,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode, callable $e
826840
->arrayNode('locales')
827841
->prototype('scalar')->end()
828842
->defaultValue([])
829-
->info('If not set, all locales listed under framework.translator.enabled_locales are used.')
843+
->info('If not set, all locales listed under framework.enabled_locales are used.')
830844
->end()
831845
->end()
832846
->end()
@@ -1240,15 +1254,13 @@ private function addLockSection(ArrayNodeDefinition $rootNode, callable $enableI
12401254
->then(function ($v) {
12411255
$resources = [];
12421256
foreach ($v as $resource) {
1243-
$resources = array_merge_recursive(
1244-
$resources,
1245-
\is_array($resource) && isset($resource['name'])
1246-
? [$resource['name'] => $resource['value']]
1247-
: ['default' => $resource]
1248-
);
1257+
$resources[] = \is_array($resource) && isset($resource['name'])
1258+
? [$resource['name'] => $resource['value']]
1259+
: ['default' => $resource]
1260+
;
12491261
}
12501262

1251-
return $resources;
1263+
return array_merge_recursive([], ...$resources);
12521264
})
12531265
->end()
12541266
->prototype('array')

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+15-5Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ public function load(array $configs, ContainerBuilder $container)
274274
}
275275
}
276276

277+
$container->getDefinition('locale_listener')->replaceArgument(3, $config['set_locale_from_accept_language']);
278+
$container->getDefinition('response_listener')->replaceArgument(1, $config['set_content_language_from_locale']);
279+
277280
// If the slugger is used but the String component is not available, we should throw an error
278281
if (!ContainerBuilder::willBeAvailable('symfony/string', SluggerInterface::class, ['symfony/framework-bundle'])) {
279282
$container->register('slugger', 'stdClass')
@@ -296,6 +299,7 @@ public function load(array $configs, ContainerBuilder $container)
296299
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
297300
$container->setParameter('kernel.trusted_hosts', $config['trusted_hosts']);
298301
$container->setParameter('kernel.default_locale', $config['default_locale']);
302+
$container->setParameter('kernel.enabled_locales', $config['enabled_locales']);
299303
$container->setParameter('kernel.error_controller', $config['error_controller']);
300304

301305
if (($config['trusted_proxies'] ?? false) && ($config['trusted_headers'] ?? false)) {
@@ -417,11 +421,13 @@ public function load(array $configs, ContainerBuilder $container)
417421
$this->registerEsiConfiguration($config['esi'], $container, $loader);
418422
$this->registerSsiConfiguration($config['ssi'], $container, $loader);
419423
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
420-
$this->registerTranslatorConfiguration($config['translator'], $container, $loader, $config['default_locale']);
424+
$this->registerTranslatorConfiguration($config['translator'], $container, $loader, $config['default_locale'], $config['enabled_locales']);
421425
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
422426
$this->registerWorkflowConfiguration($config['workflows'], $container, $loader);
423427
$this->registerDebugConfiguration($config['php_errors'], $container, $loader);
424-
$this->registerRouterConfiguration($config['router'], $container, $loader, $config['translator']['enabled_locales'] ?? []);
428+
// @deprecated since Symfony 5.4, in 6.0 change to:
429+
// $this->registerRouterConfiguration($config['router'], $container, $loader, $config['enabled_locales']);
430+
$this->registerRouterConfiguration($config['router'], $container, $loader, $config['translator']['enabled_locales'] ?: $config['enabled_locales']);
425431
$this->registerAnnotationsConfiguration($config['annotations'], $container, $loader);
426432
$this->registerPropertyAccessConfiguration($config['property_access'], $container, $loader);
427433
$this->registerSecretsConfiguration($config['secrets'], $container, $loader);
@@ -1187,7 +1193,7 @@ private function createVersion(ContainerBuilder $container, ?string $version, ?s
11871193
return new Reference('assets.empty_version_strategy');
11881194
}
11891195

1190-
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader, string $defaultLocale)
1196+
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader, string $defaultLocale, array $enabledLocales)
11911197
{
11921198
if (!$this->isConfigEnabled($container, $config)) {
11931199
$container->removeDefinition('console.command.translation_debug');
@@ -1211,7 +1217,9 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
12111217
$defaultOptions['cache_dir'] = $config['cache_dir'];
12121218
$translator->setArgument(4, $defaultOptions);
12131219

1214-
$translator->setArgument(5, $config['enabled_locales']);
1220+
// @deprecated since Symfony 5.4, in 6.0 change to:
1221+
// $translator->setArgument(5, $enabledLocales);
1222+
$translator->setArgument(5, $config['enabled_locales'] ?: $enabledLocales);
12151223

12161224
$container->setParameter('translator.logging', $config['logging']);
12171225
$container->setParameter('translator.default_path', $config['default_path']);
@@ -1344,7 +1352,9 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
13441352
return;
13451353
}
13461354

1347-
$locales = $config['enabled_locales'] ?? [];
1355+
// @deprecated since Symfony 5.4, in 6.0 change to:
1356+
// $locales = $enabledLocales;
1357+
$locales = $config['enabled_locales'] ?: $enabledLocales;
13481358

13491359
foreach ($config['providers'] as $provider) {
13501360
if ($provider['locales']) {

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@
3838
<xsd:element name="rate-limiter" type="rate_limiter" minOccurs="0" maxOccurs="1" />
3939
<xsd:element name="uid" type="uid" minOccurs="0" maxOccurs="1" />
4040
<xsd:element name="notifier" type="notifier" minOccurs="0" maxOccurs="1" />
41+
<xsd:element name="enabled-locale" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
4142
</xsd:choice>
4243

4344
<xsd:attribute name="http-method-override" type="xsd:boolean" />
4445
<xsd:attribute name="ide" type="xsd:string" />
4546
<xsd:attribute name="secret" type="xsd:string" />
4647
<xsd:attribute name="default-locale" type="xsd:string" />
48+
<xsd:attribute name="set_locale_from_accept_language" type="xsd:boolean" />
49+
<xsd:attribute name="set_content_language_from_locale" type="xsd:boolean" />
4750
<xsd:attribute name="test" type="xsd:boolean" />
4851
<xsd:attribute name="error-controller" type="xsd:string" />
4952
<xsd:attribute name="trusted-hosts" type="xsd:string" />

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/web.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/web.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
->set('response_listener', ResponseListener::class)
7070
->args([
7171
param('kernel.charset'),
72+
abstract_arg('The "set_content_language_from_locale" config value'),
73+
param('kernel.enabled_locales'),
7274
])
7375
->tag('kernel.event_subscriber')
7476

@@ -80,6 +82,8 @@
8082
service('request_stack'),
8183
param('kernel.default_locale'),
8284
service('router')->ignoreOnInvalid(),
85+
abstract_arg('The "set_locale_from_accept_language" config value'),
86+
param('kernel.enabled_locales'),
8387
])
8488
->tag('kernel.event_subscriber')
8589

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.