Skip to content

Commit be0e04b

Browse files
Merge branch '5.0'
* 5.0: (21 commits) fix merge CS [FrameworkBundle][ContainerLintCommand] Improve messages when the kernel or the container is not supported [Serializer] Skip uninitialized (PHP 7.4) properties in PropertyNormalizer and ObjectNormalizer stop using deprecated Doctrine persistence classes [Cache] Fix wrong classname in deprecation message Fix regex lookahead syntax in ApplicationTest Fixed syntax in comment [SecurityBundle][FirewallMap] Remove unused property [Messenger][AMQP] Use delivery_mode=2 by default [FrameworkBundle][DependencyInjection] Skip removed ids in the lint container command and its associated pass [SECURITY] Revert "AbstractAuthenticationListener.php error instead info. Rebase of #28462" [FrameworkBundle][Secrets] Hook configured local dotenv file [DI] Improve performance of processDefinition fix redis multi host dsn not recognized fix constructor argument type declaration Fix invalid Windows path normalization [Validator][ConstraintValidator] Safe fail on invalid timezones [DoctrineBridge] Fixed submitting invalid ids when using queries with limit [FrameworkBundle] Add info & example to auto_mapping config ...
2 parents 8c80c5b + 525d7bf commit be0e04b

File tree

39 files changed

+331
-76
lines changed

39 files changed

+331
-76
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ public function getEntities()
5050
*/
5151
public function getEntitiesByIds(string $identifier, array $values)
5252
{
53+
if (null !== $this->queryBuilder->getMaxResults() || null !== $this->queryBuilder->getFirstResult()) {
54+
// an offset or a limit would apply on results including the where clause with submitted id values
55+
// that could make invalid choices valid
56+
$choices = [];
57+
$metadata = $this->queryBuilder->getEntityManager()->getClassMetadata(current($this->queryBuilder->getRootEntities()));
58+
59+
foreach ($this->getEntities() as $entity) {
60+
if (\in_array(current($metadata->getIdentifierValues($entity)), $values, true)) {
61+
$choices[] = $entity;
62+
}
63+
}
64+
65+
return $choices;
66+
}
67+
5368
$qb = clone $this->queryBuilder;
5469
$alias = current($qb->getRootAliases());
5570
$parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier;

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,31 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie
953953
$this->assertNull($field->getData());
954954
}
955955

956+
public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifierWithLimit()
957+
{
958+
$entity1 = new SingleIntIdEntity(1, 'Foo');
959+
$entity2 = new SingleIntIdEntity(2, 'Bar');
960+
$entity3 = new SingleIntIdEntity(3, 'Baz');
961+
962+
$this->persist([$entity1, $entity2, $entity3]);
963+
964+
$repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS);
965+
966+
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
967+
'em' => 'default',
968+
'class' => self::SINGLE_IDENT_CLASS,
969+
'query_builder' => $repository->createQueryBuilder('e')
970+
->where('e.id IN (1, 2, 3)')
971+
->setMaxResults(1),
972+
'choice_label' => 'name',
973+
]);
974+
975+
$field->submit('3');
976+
977+
$this->assertFalse($field->isSynchronized());
978+
$this->assertNull($field->getData());
979+
}
980+
956981
public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleAssocIdentifier()
957982
{
958983
$innerEntity1 = new SingleIntIdNoToStringEntity(1, 'InFoo');

src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
use Symfony\Component\Config\ConfigCache;
1515
use Symfony\Component\Config\FileLocator;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Exception\RuntimeException;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Style\SymfonyStyle;
1921
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
2022
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
23+
use Symfony\Component\DependencyInjection\Container;
2124
use Symfony\Component\DependencyInjection\ContainerBuilder;
2225
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2326
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
27+
use Symfony\Component\HttpKernel\Kernel;
2428

2529
final class ContainerLintCommand extends Command
2630
{
@@ -47,13 +51,18 @@ protected function configure()
4751
*/
4852
protected function execute(InputInterface $input, OutputInterface $output): int
4953
{
50-
$container = $this->getContainerBuilder();
54+
$io = new SymfonyStyle($input, $output);
55+
$errorIo = $io->getErrorStyle();
5156

52-
$container->setParameter('container.build_hash', 'lint_container');
53-
$container->setParameter('container.build_time', time());
54-
$container->setParameter('container.build_id', 'lint_container');
57+
try {
58+
$container = $this->getContainerBuilder();
59+
} catch (RuntimeException $e) {
60+
$errorIo->error($e->getMessage());
61+
62+
return 2;
63+
}
5564

56-
$container->addCompilerPass(new CheckTypeDeclarationsPass(true), PassConfig::TYPE_AFTER_REMOVING, -100);
65+
$container->setParameter('container.build_time', time());
5766

5867
$container->compile();
5968

@@ -67,22 +76,44 @@ private function getContainerBuilder(): ContainerBuilder
6776
}
6877

6978
$kernel = $this->getApplication()->getKernel();
79+
$kernelContainer = $kernel->getContainer();
80+
81+
if (!$kernel->isDebug() || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) {
82+
if (!$kernel instanceof Kernel) {
83+
throw new RuntimeException(sprintf('This command does not support the application kernel: "%s" does not extend "%s".', \get_class($kernel), Kernel::class));
84+
}
7085

71-
if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
7286
$buildContainer = \Closure::bind(function (): ContainerBuilder {
7387
$this->initializeBundles();
7488

7589
return $this->buildContainer();
7690
}, $kernel, \get_class($kernel));
7791
$container = $buildContainer();
92+
93+
$skippedIds = [];
7894
} else {
79-
(new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
95+
if (!$kernelContainer instanceof Container) {
96+
throw new RuntimeException(sprintf('This command does not support the application container: "%s" does not extend "%s".', \get_class($kernelContainer), Container::class));
97+
}
98+
99+
(new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernelContainer->getParameter('debug.container.dump'));
80100

81101
$refl = new \ReflectionProperty($parameterBag, 'resolved');
82102
$refl->setAccessible(true);
83103
$refl->setValue($parameterBag, true);
104+
105+
$passConfig = $container->getCompilerPassConfig();
106+
$passConfig->setRemovingPasses([]);
107+
$passConfig->setAfterRemovingPasses([]);
108+
109+
$skippedIds = $kernelContainer->getRemovedIds();
84110
}
85111

112+
$container->setParameter('container.build_hash', 'lint_container');
113+
$container->setParameter('container.build_id', 'lint_container');
114+
115+
$container->addCompilerPass(new CheckTypeDeclarationsPass(true, $skippedIds), PassConfig::TYPE_AFTER_REMOVING, -100);
116+
86117
return $this->containerBuilder = $container;
87118
}
88119
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function addSecretsSection(ArrayNodeDefinition $rootNode)
130130
->canBeDisabled()
131131
->children()
132132
->scalarNode('vault_directory')->defaultValue('%kernel.project_dir%/config/secrets/%kernel.environment%')->cannotBeEmpty()->end()
133-
->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.local')->end()
133+
->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.%kernel.environment%.local')->end()
134134
->scalarNode('decryption_env_var')->defaultValue('base64:default::SYMFONY_DECRYPTION_SECRET')->end()
135135
->end()
136136
->end()
@@ -724,6 +724,11 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
724724
->end()
725725
->end()
726726
->arrayNode('auto_mapping')
727+
->info('A collection of namespaces for which auto-mapping will be enabled.')
728+
->example([
729+
'App\\Entity\\' => [],
730+
'App\\WithSpecificLoaders\\' => ['validator.property_info_loader'],
731+
])
727732
->useAttributeAsKey('namespace')
728733
->normalizeKeys(false)
729734
->beforeNormalization()

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,9 @@ private function registerSecretsConfiguration(array $config, ContainerBuilder $c
13531353

13541354
$container->getDefinition('secrets.vault')->replaceArgument(0, $config['vault_directory']);
13551355

1356-
if (!$config['local_dotenv_file']) {
1356+
if ($config['local_dotenv_file']) {
1357+
$container->getDefinition('secrets.local_vault')->replaceArgument(0, $config['local_dotenv_file']);
1358+
} else {
13571359
$container->removeDefinition('secrets.local_vault');
13581360
}
13591361

src/Symfony/Bundle/FrameworkBundle/Resources/config/secrets.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<services>
88
<service id="secrets.vault" class="Symfony\Bundle\FrameworkBundle\Secrets\SodiumVault">
99
<tag name="container.env_var_loader" />
10-
<argument>%kernel.project_dir%/config/secrets/%kernel.environment%</argument>
11-
<argument>%env(base64:default::SYMFONY_DECRYPTION_SECRET)%</argument>
10+
<argument />
11+
<argument />
1212
</service>
1313

1414
<service id="secrets.local_vault" class="Symfony\Bundle\FrameworkBundle\Secrets\DotenvVault">
15-
<argument>%kernel.project_dir%/.env.local</argument>
15+
<argument />
1616
</service>
1717
</services>
1818
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
504504
'secrets' => [
505505
'enabled' => true,
506506
'vault_directory' => '%kernel.project_dir%/config/secrets/%kernel.environment%',
507-
'local_dotenv_file' => '%kernel.project_dir%/.env.local',
507+
'local_dotenv_file' => '%kernel.project_dir%/.env.%kernel.environment%.local',
508508
'decryption_env_var' => 'base64:default::SYMFONY_DECRYPTION_SECRET',
509509
],
510510
];

src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ class FirewallMap implements FirewallMapInterface
2626
{
2727
private $container;
2828
private $map;
29-
private $contexts;
3029

3130
public function __construct(ContainerInterface $container, iterable $map)
3231
{
3332
$this->container = $container;
3433
$this->map = $map;
35-
$this->contexts = new \SplObjectStorage();
3634
}
3735

3836
public function getListeners(Request $request)

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ public function testFindAlternativeCommands()
616616
$this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
617617
$this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"');
618618
$this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"');
619-
$this->assertNotRegExp('/foo:bar(?>!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');
619+
$this->assertNotRegExp('/foo:bar(?!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');
620620
}
621621
}
622622

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,30 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
4242
private const SCALAR_TYPES = ['int', 'float', 'bool', 'string'];
4343

4444
private $autoload;
45+
private $skippedIds;
4546

4647
private $expressionLanguage;
4748

4849
/**
49-
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
50-
* Defaults to false to save loading code during compilation.
50+
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
51+
* Defaults to false to save loading code during compilation.
52+
* @param array $skippedIds An array indexed by the service ids to skip
5153
*/
52-
public function __construct(bool $autoload = false)
54+
public function __construct(bool $autoload = false, array $skippedIds = [])
5355
{
5456
$this->autoload = $autoload;
57+
$this->skippedIds = $skippedIds;
5558
}
5659

5760
/**
5861
* {@inheritdoc}
5962
*/
6063
protected function processValue($value, $isRoot = false)
6164
{
65+
if (isset($this->skippedIds[$this->currentId])) {
66+
return $value;
67+
}
68+
6269
if (!$value instanceof Definition || $value->hasErrors()) {
6370
return parent::processValue($value, $isRoot);
6471
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy