8000 Merge branch '6.4' into feature/assetmapper-outdated · symfony/symfony@3c0a1b9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c0a1b9

Browse files
Merge branch '6.4' into feature/assetmapper-outdated
# Conflicts: # src/Symfony/Bundle/FrameworkBundle/Resources/config/asset_mapper.php # src/Symfony/Component/AssetMapper/Command/ImportMapAuditCommand.php # src/Symfony/Component/AssetMapper/ImportMap/ImportMapAuditor.php # src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapAuditorTest.php
2 parents 74257e3 + 8b420d4 commit 3c0a1b9

File tree

23 files changed

+244
-79
lines changed

23 files changed

+244
-79
lines changed

src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ private function findViaExpression(ObjectManager $manager, Request $request, Map
199199
}
200200

201201
$repository = $manager->getRepository($options->class);
202-
$variables = array_merge($request->attributes->all(), ['repository' => $repository]);
202+
$variables = array_merge($request->attributes->all(), [
203+
'repository' => $repository,
204+
'request' => $request,
205+
]);
203206

204207
try {
205208
return $this->expressionLanguage->evaluate($options->expr, $variables);

src/Symfony/Bridge/Doctrine/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Deprecate not constructing `DoctrineDataCollector` with an instance of `DebugDataHolder`
99
* Deprecate `DoctrineDataCollector::addLogger()`, use a `DebugDataHolder` instead
1010
* Deprecate `ContainerAwareLoader`, use dependency injection in your fixtures instead
11+
* Always pass the `Request` object to `EntityValueResolver`'s expression
1112

1213
6.3
1314
---

src/Symfony/Bridge/Doctrine/Tests/ArgumentResolver/EntityValueResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ public function testExpressionMapsToArgument()
334334
->method('evaluate')
335335
->with('repository.findOneByCustomMethod(id)', [
336336
'repository' => $repository,
337+
'request' => $request,
337338
'id' => 5,
338339
])
339340
->willReturn($object = new \stdClass());

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTestCase.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,31 @@ public function testSingleChoiceWithPreferred()
576576
);
577577
}
578578

579+
public function testSingleChoiceWithPreferredIsNotDuplicated()
580+
{
581+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
582+
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
583+
'preferred_choices' => ['&b'],
584+
'duplicate_preferred_choices' => false,
585+
'multiple' => false,
586+
'expanded' => false,
587+
]);
588+
589+
$this->assertWidgetMatchesXpath($form->createView(), ['separator' => '-- sep --', 'attr' => ['class' => 'my&class']],
590+
'/select
591+
[@name="name"]
592+
[@class="my&class form-control"]
593+
[not(@required)]
594+
[
595+
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
596+
/following-sibling::option[@disabled="disabled"][not(@selected)][.="-- sep --"]
597+
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
598+
]
599+
[count(./option)=3]
600+
'
601+
);
602+
}
603+
579604
public function testSingleChoiceWithSelectedPreferred()
580605
{
581606
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap5LayoutTestCase.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,31 @@ public function testSingleChoiceWithPreferred()
584584
);
585585
}
586586

587+
public function testSingleChoiceWithPreferredIsNotDuplicated()
588+
{
589+
$form = $this->factory->createNamed('name', ChoiceType::class, '&a', [
590+
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
591+
'preferred_choices' => ['&b'],
592+
'duplicate_preferred_choices' => false,
593+
'multiple' => false,
594+
'expanded' => false,
595+
]);
596+
597+
$this->assertWidgetMatchesXpath($form->createView(), ['separator' => '-- sep --', 'attr' => ['class' => 'my&class']],
598+
'/select
599+
[@name="name"]
600+
[@class="my&class form-select"]
601+
[not(@required)]
602+
[
603+
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
604+
/following-sibling::option[@disabled="disabled"][not(@selected)][.="-- sep --"]
605+
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
606+
]
607+
[count(./option)=3]
608+
'
609+
);
610+
}
611+
587612
public function testSingleChoiceWithSelectedPreferred()
588613
{
589614
$form = $this->factory->createNamed('name', ChoiceType::class, '&a', [

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"symfony/asset-mapper": "^6.3|^7.0",
2929
"symfony/dependency-injection": "^5.4|^6.0|^7.0",
3030
"symfony/finder": "^5.4|^6.0|^7.0",
31-
"symfony/form": "^6.3|^7.0",
31+
"symfony/form": "^6.4|^7.0",
3232
"symfony/html-sanitizer": "^6.1|^7.0",
3333
"symfony/http-foundation": "^5.4|^6.0|^7.0",
3434
"symfony/http-kernel": "^6.4|^7.0",

src/Symfony/Bundle/FrameworkBundle/Resources/config/asset_mapper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use Symfony\Component\AssetMapper\AssetMapperInterface;
1818
use Symfony\Component\AssetMapper\AssetMapperRepository;
1919
use Symfony\Component\AssetMapper\Command\AssetMapperCompileCommand;
20-
use Symfony\Component\AssetMapper\Command\ImportMapAuditCommand;
2120
use Symfony\Component\AssetMapper\Command\DebugAssetMapperCommand;
21+
use Symfony\Component\AssetMapper\Command\ImportMapAuditCommand;
2222
use Symfony\Component\AssetMapper\Command\ImportMapInstallCommand;
2323
use Symfony\Component\AssetMapper\Command\ImportMapOutdatedCommand;
2424
use Symfony\Component\AssetMapper\Command\ImportMapRemoveCommand;
@@ -203,6 +203,7 @@
203203
service('asset_mapper.importmap.resolver'),
204204
service('http_client'),
205205
])
206+
206207
->set('asset_mapper.importmap.update_checker', ImportMapUpdateChecker::class)
207208
->args([
208209
service('asset_mapper.importmap.config_reader'),

src/Symfony/Component/AssetMapper/Command/ImportMapAuditCommand.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ private function displayTxt(array $audit): int
7272
$rows = [];
7373

7474
$packagesWithoutVersion = [];
75-
$vulnerabilitiesCount = array_map(fn() => 0, self::SEVERITY_COLORS);
75+
$vulnerabilitiesCount = array_map(fn () => 0, self::SEVERITY_COLORS);
7676
foreach ($audit as $packageAudit) {
7777
if (!$packageAudit->version) {
7878
$packagesWithoutVersion[] = $packageAudit->package;
7979
}
80-
foreach($packageAudit->vulnerabilities as $vulnerability) {
80+
foreach ($packageAudit->vulnerabilities as $vulnerability) {
8181
$rows[] = [
8282
sprintf('<fg=%s>%s</>', self::SEVERITY_COLORS[$vulnerability->severity] ?? 'default', ucfirst($vulnerability->severity)),
8383
$vulnerability->summary,
@@ -89,16 +89,16 @@ private function displayTxt(array $audit): int
8989
++$vulnerabilitiesCount[$vulnerability->severity];
9090
}
9191
}
92-
$packagesCount = count($audit);
93-
$packagesWithoutVersionCount = count($packagesWithoutVersion);
92+
$packagesCount = \count($audit);
93+
$packagesWithoutVersionCount = \count($packagesWithoutVersion);
9494

95-
if ([] === $rows && 0 === $packagesWithoutVersionCount) {
95+
if (!$rows && !$packagesWithoutVersionCount) {
9696
$this->io->info('No vulnerabilities found.');
9797

9898
return self::SUCCESS;
9999
}
100100

101-
if ([] !== $rows) {
101+
if ($rows) {
102102
$table = $this->io->createTable();
103103
$table->setHeaders([
104104
'Severity',
@@ -131,10 +131,10 @@ private function displayTxt(array $audit): int
131131
$vulnerabilityCount = 0;
132132
$vulnerabilitySummary = [];
133133
foreach ($vulnerabilitiesCount as $severity => $count) {
134-
if (0 === $count) {
134+
if (!$count) {
135135
continue;
136136
}
137-
$vulnerabilitySummary[] = sprintf( '%d %s', $count, ucfirst($severity));
137+
$vulnerabilitySummary[] = sprintf('%d %s', $count, ucfirst($severity));
138138
$vulnerabilityCount += $count;
139139
}
140140
$this->io->text(sprintf('%d vulnerabilit%s found: %s',
@@ -149,7 +149,7 @@ private function displayTxt(array $audit): int
149149

150150
private function displayJson(array $audit): int
151151
{
152-
$vulnerabilitiesCount = array_map(fn() => 0, self::SEVERITY_COLORS);
152+
$vulnerabilitiesCount = array_map(fn () => 0, self::SEVERITY_COLORS);
153153

154154
$json = [
155155
'packages' => [],

src/Symfony/Component/AssetMapper/ImportMap/ImportMapAuditor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function audit(): array
3737
{
3838
$entries = $this->configReader->getEntries();
3939

40-
if ([] === $entries) {
40+
if (!$entries) {
4141
return [];
4242
}
4343

@@ -67,15 +67,15 @@ public function audit(): array
6767
]);
6868

6969
if (200 !== $response->getStatusCode()) {
70-
throw new RuntimeException(sprintf('Error %d auditing packages. Response: %s', $response->getStatusCode(), $response->getContent(false)));
70+
throw new RuntimeException(sprintf('Error %d auditing packages. Response:'.$response->getContent(false), $response->getStatusCode()));
7171
}
7272

7373
foreach ($response->toArray() as $advisory) {
7474
foreach ($advisory['vulnerabilities'] ?? [] as $vulnerability) {
7575
if (
7676
null === $vulnerability['package']
7777
|| 'npm' !== $vulnerability['package']['ecosystem']
78-
|| !array_key_exists($package = $vulnerability['package']['name'], $installed)
78+
|| !\array_key_exists($package = $vulnerability['package']['name'], $installed)
7979
) {
8080
continue;
8181
}
@@ -105,7 +105,7 @@ private function versionMatches(string $version, string $ranges): bool
105105
{
106106
foreach (explode(',', $ranges) as $rangeString) {
107107
$range = explode(' ', trim($rangeString));
108-
if (1 === count($range)) {
108+
if (1 === \count($range)) {
109109
$range = ['=', $range[0]];
110110
}
111111

src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapAuditorTest.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
use Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader;
1818
use Symfony\Component\AssetMapper\ImportMap\ImportMapEntries;
1919
use Symfony\Component\AssetMapper\ImportMap\ImportMapEntry;
20-
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
2120
use Symfony\Component\AssetMapper\ImportMap\ImportMapPackageAudit;
2221
use Symfony\Component\AssetMapper\ImportMap\ImportMapPackageAuditVulnerability;
23-
use Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolver;
2422
use Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolverInterface;
2523
use Symfony\Component\HttpClient\MockHttpClient;
2624
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -45,26 +43,26 @@ public function testAudit()
4543
{
4644
$this->httpClient->setResponseFactory(new MockResponse(json_encode([
4745
[
48-
"ghsa_id" => "GHSA-abcd-1234-efgh",
49-
"cve_id" => "CVE-2050-00000",
50-
"url" => "https =>//api.github.com/repos/repo/a-package/security-advisories/GHSA-abcd-1234-efgh",
51-
"summary" => "A short summary of the advisory.",
52-
"severity" 48DA => "critical",
53-
"vulnerabilities" => [
46+
'ghsa_id' => 'GHSA-abcd-1234-efgh',
47+
'cve_id' => 'CVE-2050-00000',
48+
'url' => 'https =>//api.github.com/repos/repo/a-package/security-advisories/GHSA-abcd-1234-efgh',
49+
'summary' => 'A short summary of the advisory.',
50+
'severity' => 'critical',
51+
'vulnerabilities' => [
5452
[
55-
"package" => ["ecosystem" => "pip", "name" => "json5"],
56-
"vulnerable_version_range" => ">= 1.0.0, < 1.0.1",
57-
"first_patched_version" => "1.0.1",
53+
'package' => ['ecosystem' => 'pip', 'name' => 'json5'],
54+
'vulnerable_version_range' => '>= 1.0.0, < 1.0.1',
55+
'first_patched_version' => '1.0.1',
5856
],
5957
[
60-
"package" => ["ecosystem" => "npm", "name" => "json5"],
61-
"vulnerable_version_range" => ">= 1.0.0, < 1.0.1",
62-
"first_patched_version" => "1.0.1",
58+
'package' => ['ecosystem' => 'npm', 'name' => 'json5'],
59+
'vulnerable_version_range' => '>= 1.0.0, < 1.0.1',
60+
'first_patched_version' => '1.0.1',
6361
],
6462
[
65-
"package" => ["ecosystem" => "npm", "name" => "another-package"],
66-
"vulnerable_version_range" => ">= 1.0.0, < 1.0.1",
67-
"first_patched_version" => "1.0.2",
63+
'package' => ['ecosystem' => 'npm', 'name' => 'another-package'],
64+
'vulnerable_version_range' => '>= 1.0.0, < 1.0.1',
65+
'first_patched_version' => '1.0.2',
6866
],
6967
],
7068
],
@@ -111,16 +109,16 @@ public function testAuditWithVersionRange(bool $expectMatch, string $version, ?s
111109
{
112110
$this->httpClient->setResponseFactory(new MockResponse(json_encode([
113111
[
114-
"ghsa_id" => "GHSA-abcd-1234-efgh",
115-
"cve_id" => "CVE-2050-00000",
116-
"url" => "https =>//api.github.com/repos/repo/a-package/security-advisories/GHSA-abcd-1234-efgh",
117-
"summary" => "A short summary of the advisory.",
118-
"severity" => "critical",
119-
"vulnerabilities" => [
112+
'ghsa_id' => 'GHSA-abcd-1234-efgh',
113+
'cve_id' => 'CVE-2050-00000',
114+
'url' => 'https =>//api.github.com/repos/repo/a-package/security-advisories/GHSA-abcd-1234-efgh',
115+
'summary' => 'A short summary of the advisory.',
116+
'severity' => 'critical',
117+
'vulnerabilities' => [
120118
[
121-
"package" => ["ecosystem" => "npm", "name" => "json5"],
122-
"vulnerable_version_range" => $versionRange,
123-
"first_patched_version" => "1.0.1",
119+
'package' => ['ecosystem' => 'npm', 'name' => 'json5'],
120+
'vulnerable_version_range' => $versionRange,
121+
'first_patched_version' => '1.0.1',
124122
],
125123
],
126124
],
@@ -135,7 +133,7 @@ public function testAuditWithVersionRange(bool $expectMatch, string $version, ?s
135133

136134
$audit = $this->importMapAuditor->audit();
137135

138-
$this->assertSame($expectMatch, 0 < count($audit[0]->vulnerabilities));
136+
$this->assertSame($expectMatch, 0 < \count($audit[0]->vulnerabilities));
139137
}
140138

141139
public function provideAuditWithVersionRange(): iterable

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ CHANGELOG
88
`model_timezone` option in `DateType`, `DateTimeType`, and `TimeType`
99
* Deprecate `PostSetDataEvent::setData()`, use `PreSetDataEvent::setData()` instead
1010
* Deprecate `PostSubmitEvent::setData()`, use `PreSubmitDataEvent::setData()` or `SubmitDataEvent::setData()` instead
11+
* Add `duplicate_preferred_choices` option in `ChoiceType`
12+
* Add `$duplicatePreferredChoices` parameter to `ChoiceListFactoryInterface::createView()`
1113

1214
6.3
1315
---

src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,12 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, mixed $value
145145
return $this->lists[$hash];
146146
}
147147

148-
public function createView(ChoiceListInterface $list, mixed $preferredChoices = null, mixed $label = null, mixed $index = null, mixed $groupBy = null, mixed $attr = null, mixed $labelTranslationParameters = []): ChoiceListView
148+
/**
149+
* @param bool $duplicatePreferredChoices
150+
*/
151+
public function createView(ChoiceListInterface $list, mixed $preferredChoices = null, mixed $label = null, mixed $index = null, mixed $groupBy = null, mixed $attr = null, mixed $labelTranslationParameters = []/* , bool $duplicatePreferredChoices = true */): ChoiceListView
149152
{
153+
$duplicatePreferredChoices = \func_num_args() > 7 ? func_get_arg(7) : true;
150154
$cache = true;
151155

152156
if ($preferredChoices instanceof Cache\PreferredChoice) {
@@ -193,11 +197,12 @@ public function createView(ChoiceListInterface $list, mixed $preferredChoices =
193197
$index,
194198
$groupBy,
195199
$attr,
196-
$labelTranslationParameters
200+
$labelTranslationParameters,
201+
$duplicatePreferredChoices,
197202
);
198203
}
199204

200-
$hash = self::generateHash([$list, $preferredChoices, $label, $index, $groupBy, $attr, $labelTranslationParameters]);
205+
$hash = self::generateHash([$list, $preferredChoices, $label, $index, $groupBy, $attr, $labelTranslationParameters, $duplicatePreferredChoices]);
201206

202207
if (!isset($this->views[$hash])) {
203208
$this->views[$hash] = $this->decoratedFactory->createView(
@@ -207,7 +212,8 @@ public function createView(ChoiceListInterface $list, mixed $preferredChoices =
207212
$index,
208213
$groupBy,
209214
$attr,
210-
$labelTranslationParameters
215+
$labelTranslationParameters,
216+
$duplicatePreferredChoices,
211217
);
212218
}
213219

src/Symfony/Component/Form/ChoiceList/Factory/ChoiceListFactoryInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, callable $va
7777
* pass false to discard the label
7878
* @param array|callable|null $attr The callable generating the HTML attributes
7979
* @param array|callable $labelTranslationParameters The parameters used to translate the choice labels
80+
* @param bool $duplicatePreferredChoices Whether the preferred choices should be duplicated
81+
* on top of the list and in their original position
82+
* or only in the top of the list
8083
*/
81-
public function createView(ChoiceListInterface $list, array|callable $preferredChoices = null, callable|false $label = null, callable $index = null, callable $groupBy = null, array|callable $attr = null, array|callable $labelTranslationParameters = []): ChoiceListView;
84+
public function createView(ChoiceListInterface $list, array|callable $preferredChoices = null, callable|false $label = null, callable $index = null, callable $groupBy = null, array|callable $attr = null, array|callable $labelTranslationParameters = []/* , bool $duplicatePreferredChoices = true */): ChoiceListView;
8285
}

0 commit comments

Comments
 (0)
0