Skip to content

Commit a57d479

Browse files
Merge branch '4.4' into feat-switch
2 parents 3d77e4f + 6253369 commit a57d479

File tree

94 files changed

+1380
-900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1380
-900
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
`DebugCommand::__construct()` method, swap the variables position.
1010
* the `LintCommand` lints all the templates stored in all configured Twig paths if none argument is provided
1111
* deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit.
12+
* added `--show-deprecations` option to the `lint:twig` command
1213
* added support for Bootstrap4 switches, use `switch-custom` as `label_attr` in a `CheckboxType`
1314

1415
4.3.0

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function configure()
5050
$this
5151
->setDescription('Lints a template and outputs encountered errors')
5252
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
53+
->addOption('show-deprecations', null, InputOption::VALUE_NONE, 'Show deprecations as errors')
5354
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
5455
->setHelp(<<<'EOF'
5556
The <info>%command.name%</info> command lints a template and outputs to STDOUT
@@ -77,6 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7778
{
7879
$io = new SymfonyStyle($input, $output);
7980
$filenames = $input->getArgument('filename');
81+
$showDeprecations = $input->getOption('show-deprecations');
8082

8183
if (['-'] === $filenames) {
8284
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
@@ -104,7 +106,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
104106
}
105107
}
106108

107-
$filesInfo = $this->getFilesInfo($filenames);
109+
if ($showDeprecations) {
110+
$prevErrorHandler = set_error_handler(static function ($level, $message, $file, $line) use (&$prevErrorHandler) {
111+
if (E_USER_DEPRECATED === $level) {
112+
$templateLine = 0;
113+
if (preg_match('/ at line (\d+) /', $message, $matches)) {
114+
$templateLine = $matches[1];
115+
}
116+
117+
throw new Error($message, $templateLine);
118+
}
119+
120+
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
121+
});
122+
}
123+
124+
try {
125+
$filesInfo = $this->getFilesInfo($filenames);
126+
} finally {
127+
if ($showDeprecations) {
128+
restore_error_handler();
129+
}
130+
}
108131

109132
return $this->display($input, $output, $io, $filesInfo);
110133
}

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Symfony\Component\Console\Output\OutputInterface;
2121
use Symfony\Component\Console\Style\SymfonyStyle;
2222
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
23-
use Symfony\Component\ErrorHandler\Exception\FatalThrowableError;
23+
use Symfony\Component\ErrorHandler\Exception\ErrorException;
2424
use Symfony\Component\HttpKernel\Bundle\Bundle;
2525
use Symfony\Component\HttpKernel\Kernel;
2626
use Symfony\Component\HttpKernel\KernelInterface;
@@ -208,7 +208,7 @@ private function renderRegistrationErrors(InputInterface $input, OutputInterface
208208

209209
foreach ($this->registrationErrors as $error) {
210210
if (!$error instanceof \Exception) {
211-
$error = new FatalThrowableError($error);
211+
$error = new ErrorException($error);
212212
}
213213

214214
$this->doRenderException($error, $output);

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,25 @@ protected function sortTaggedServicesByPriority(array $services): array
286286
return array_keys($maxPriority);
287287
}
288288

289+
protected function sortTagsByPriority(array $tags): array
290+
{
291+
$sortedTags = [];
292+
foreach ($tags as $tagName => $tag) {
293+
$sortedTags[$tagName] = $this->sortByPriority($tag);
294+
}
295+
296+
return $sortedTags;
297+
}
298+
299+
protected function sortByPriority(array $tag): array
300+
{
301+
usort($tag, function ($a, $b) {
302+
return ($b['priority'] ?? 0) <=> ($a['priority'] ?? 0);
303+
});
304+
305+
return $tag;
306+
}
307+
289308
/**
290309
* Gets class description from a docblock.
291310
*/

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private function getContainerDefinitionData(Definition $definition, bool $omitTa
270270

271271
if (!$omitTags) {
272272
$data['tags'] = [];
273-
foreach ($definition->getTags() as $tagName => $tagData) {
273+
foreach ($this->sortTagsByPriority($definition->getTags()) as $tagName => $tagData) {
274274
foreach ($tagData as $parameters) {
275275
$data['tags'][] = ['name' => $tagName, 'parameters' => $parameters];
276276
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
233233
}
234234

235235
if (!(isset($options['omit_tags']) && $options['omit_tags'])) {
236-
foreach ($definition->getTags() as $tagName => $tagData) {
236+
foreach ($this->sortTagsByPriority($definition->getTags()) as $tagName => $tagData) {
237237
foreach ($tagData as $parameters) {
238238
$output .= "\n".'- Tag: `'.$tagName.'`';
239239
foreach ($parameters as $name => $value) {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
238238
$styledServiceId = $rawOutput ? $serviceId : sprintf('<fg=cyan>%s</fg=cyan>', OutputFormatter::escape($serviceId));
239239
if ($definition instanceof Definition) {
240240
if ($showTag) {
241-
foreach ($definition->getTag($showTag) as $key => $tag) {
241+
foreach ($this->sortByPriority($definition->getTag($showTag)) as $key => $tag) {
242242
$tagValues = [];
243243
foreach ($tagsNames as $tagName) {
244244
$tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : '';

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private function getContainerDefinitionDocument(Definition $definition, string $
371371
}
372372

373373
if (!$omitTags) {
374-
if ($tags = $definition->getTags()) {
374+
if ($tags = $this->sortTagsByPriority($definition->getTags())) {
375375
$serviceXML->appendChild($tagsXML = $dom->createElement('tags'));
376376
foreach ($tags as $tagName => $tagData) {
377377
foreach ($tagData as $parameters) {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_priority_tag.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
{
1515
"name": "tag1",
1616
"parameters": {
17-
"attr1": "val1",
18-
"attr2": "val2",
19-
"priority": 0
17+
"attr3": "val3",
18+
"priority": 40
2019
}
2120
},
2221
{
2322
"name": "tag1",
2423
"parameters": {
25-
"attr3": "val3",
26-
"priority": 40
24+
"attr1": "val1",
25+
"attr2": "val2",
26+
"priority": 0
2727
}
2828
}
2929
]
@@ -87,4 +87,4 @@
8787
},
8888
"aliases": [],
8989
"services": []
90-
}
90+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_priority_tag.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Definitions
1515
- Autowired: no
1616
- Autoconfigured: no
1717
- File: `/path/to/file`
18+
- Tag: `tag1`
19+
- Attr3: val3
20+
- Priority: 40
1821
- Tag: `tag1`
1922
- Attr1: val1
2023
- Attr2: val2
2124
- Priority: 0
22-
- Tag: `tag1`
23-
- Attr3: val3
24-
- Priority: 40
2525

2626
### definition_1
2727

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