8000 Merge branch '3.1' into 3.2 · symfony/symfony@a28c522 · GitHub
[go: up one dir, main page]

Skip to content

Commit a28c522

Browse files
Merge branch '3.1' into 3.2
* 3.1: (28 commits) Fix merge [Validator] add class name to the cache key [Serializer] Remove AbstractObjectNormalizer::isAttributeToNormalize Throw less misleading exception when property access not found [Twig] Fix deprecations with Twig 1.29 Fixed typo [FrameworkBundle] Removed the kernel.debug parameter from the cache pool namespace seed Fix email address fix the docblock in regard to the role argument Don't use the "app" global variable in the profiler [VarDumper] fix tests when xdebug is enabled Fix merge FIXED NON EXISTING TYPE DECLARATION [Cache] Fix dumping SplDoublyLinkedList iter mode [Console] fixed PHP7 Errors when not using Dispatcher Regression test for missing controller arguments (3.1) Regression test for missing controller arguments fix a test checking for a value [Form][DX] FileType "multiple" fixes fixed CS ...
2 parents f5058ac + 59d0444 commit a28c522

File tree

50 files changed

+507
-92
lines changed

Some content is hidden

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

50 files changed

+507
-92
lines changed

UPGRADE-3.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ Serializer
111111
deprecated and will not be supported in Symfony 4.0. You should use the
112112
`CacheClassMetadataFactory` class instead.
113113

114+
* The `AbstractObjectNormalizer::isAttributeToNormalize()` method has been removed
115+
because it was initially added by mistake, has never been used and is not tested
116+
nor documented.
117+
114118
Translation
115119
-----------
116120

src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public function getExtractData()
7272
}
7373

7474
/**
75-
* @expectedException \Twig_Error
76-
* @expectedExceptionMessageRegExp /Unclosed "block" in ".*extractor(\/|\\)syntax_error\.twig" at line 1/
75+
* @expectedException \Twig_Error
7776
* @dataProvider resourcesWithSyntaxErrorsProvider
7877
*/
7978
public function testExtractSyntaxError($resources)
@@ -82,7 +81,19 @@ public function testExtractSyntaxError($resources)
8281
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
8382

8483
$extractor = new TwigExtractor($twig);
85-
$extractor->extract($resources, new MessageCatalogue('en'));
84+
85+
try {
86+
$extractor->extract($resources, new MessageCatalogue('en'));
87+
} catch (\Twig_Error $e) {
88+
if (method_exists($e, 'getSourceContext')) {
89+
$this->assertSame(dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', DIRECTORY_SEPARATOR), $e->getFile());
90+
$this->assertSame(1, $e->getLine());
91+
$this->assertSame('Unclosed "block".', $e->getMessage());
92+
} else {
93+
$this->expectExceptionMessageRegExp('/Unclosed "block" in ".*extractor(\\/|\\\\)syntax_error\\.twig" at line 1/');
94+
}
95+
throw $e;
96+
}
8697
}
8798

8899
/**

src/Symfony/Bridge/Twig/Translation/TwigExtractor.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ public function extract($resource, MessageCatalogue $catalogue)
6161
try {
6262
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
6363
} catch (\Twig_Error $e) {
64-
if ($file instanceof SplFileInfo) {
65-
$e->setTemplateName($file->getRelativePathname());
66-
} elseif ($file instanceof \SplFileInfo) {
67-
$e->setTemplateName($file->getRealPath() ?: $file->getPathname());
64+
if ($file instanceof \SplFileInfo) {
65+
$path = $file->getRealPath() ?: $file->getPathname();
66+
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
67+
if (method_exists($e, 'setSourceContext')) {
68+
$e->setSourceContext(new \Twig_Source('', $name, $path));
69+
} else {
70+
$e->setTemplateName($name);
71+
}
6872
}
6973

7074
throw $e;

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function process(ContainerBuilder $container)
3434
} else {
3535
$seed = '_'.$container->getParameter('kernel.root_dir');
3636
}
37-
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment').'.'.$container->getParameter('kernel.debug');
37+
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment');
3838

3939
$aliases = $container->getAliases();
4040
$attributes = array(

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testNamespaceArgumentIsReplaced()
4545

4646
$this->cachePoolPass->process($container);
4747

48-
$this->assertSame('C42Pcl9VBJ', $cachePool->getArgument(0));
48+
$this->assertSame('D07rhFx97S', $cachePool->getArgument(0));
4949
}
5050

5151
public function testArgsAreReplaced()
@@ -69,7 +69,7 @@ public function testArgsAreReplaced()
6969

7070
$this->assertInstanceOf(Reference::class, $cachePool->getArgument(0));
7171
$this->assertSame('foobar', (string) $cachePool->getArgument(0));
72-
$this->assertSame('KO3xHaFEZU', $cachePool->getArgument(1));
72+
$this->assertSame('itantF+pIq', $cachePool->getArgument(1));
7373
$this->assertSame(3, $cachePool->getArgument(2));
7474
}
7575

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\Config\Resource\ClassExistenceResource;
15+
use Symfony\Component\DependencyInjection\Alias;
1516
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Reference;
@@ -74,7 +75,7 @@ public function process(ContainerBuilder $container)
7475
$loader->addTag('twig.loader');
7576
$loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls());
7677

77-
$container->setDefinition('twig.loader.filesystem', $loader);
78+
$container->setAlias('twig.loader.filesystem', new Alias('twig.loader.native_filesystem', false));
7879
}
7980

8081
if ($container->has('assets.packages')) {

src/Symfony/Bundle/TwigBundle/TwigEngine.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ public function render($name, array $parameters = array())
5252
if ($name instanceof TemplateReference) {
5353
try {
5454
// try to get the real name of the template where the error occurred
55-
$e->setTemplateName(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateName()))));
55+
$name = $e->getTemplateName();
56+
$path = (string) $this->locator->locate($this->parser->parse($name));
57+
if (method_exists($e, 'setSourceContext')) {
58+
$e->setSourceContext(new \Twig_Source('', $name, $path));
59+
} else {
60+
$e->setTemplateName($path);
61+
}
5662
} catch (\Exception $e2) {
5763
}
5864
}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/exception.css.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
padding-bottom: 2px;
1010
}
1111
.sf-reset .traces li {
12-
ccolor: #222;
12+
color: #222;
1313
font-size: 14px;
1414
padding: 5px 0;
1515
list-style-type: decimal;

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{%- else -%}
4040
{{ redirect_route }}
4141
{%- endif %}
42-
(<a href="{{ path('_profiler', { token: redirect.token }) }}">{{ redirect.token }}</a>)
42+
(<a href="{{ path('_profiler', { token: redirect.token, panel: request.query.get('panel', 'request') }) }}">{{ redirect.token }}</a>)
4343
</dd>
4444
</dl>
4545
{%- endif %}
@@ -113,9 +113,11 @@
113113
<ul id="menu-profiler">
114114
{% for name, template in templates %}
115115
{% set menu -%}
116-
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
117-
{{- block('menu', template) -}}
118-
{% endwith %}
116+
{% if block('menu', template) is defined %}
117+
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
118+
{{- block('menu', template) -}}
119+
{% endwith %}
120+
{% endif %}
119121
{%- endset %}
120122
{% if menu is not empty %}
121123
<li class="{{ name }} {{ name == panel ? 'selected' : '' }}">

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,13 @@
375375
border-color: #777;
376376
border-radius: 0;
377377
margin: 6px 0 12px 0;
378-
width: 200px;
379378
}
380379
.sf-toolbar-block-dump pre.sf-dump:last-child {
381380
margin-bottom: 0;
382381
}
382+
.sf-toolbar-block-dump .sf-toolbar-info-piece {
383+
display: block;
384+
}
383385
.sf-toolbar-block-dump .sf-toolbar-info-piece .sf-toolbar-file-line {
384386
color: #AAA;
385387
margin-left: 4px;

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313

1414
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset clear-fix" data-no-turbolink>
1515
{% for name, template in templates %}
16-
{% with {
17-
collector: profile.getcollector(name),
18-
profiler_url: profiler_url,
19-
token: profile.token,
20-
name: name,
21-
profiler_markup_version: profiler_markup_version,
22-
csp_script_nonce: csp_script_nonce,
23-
csp_style_nonce: csp_style_nonce
24-
} %}
25-
{{ block('toolbar', template) }}
26-
{% endwith %}
16+
{% if block('toolbar', template) is defined %}
17+
{% with {
18+
collector: profile.getcollector(name),
19+
profiler_url: profiler_url,
20+
token: profile.token,
21+
name: name,
22+
profiler_markup_version: profiler_markup_version,
23+
csp_script_nonce: csp_script_nonce,
24+
csp_style_nonce: csp_style_nonce
25+
} %}
26+
{{ block('toolbar', template) }}
27+
{% endwith %}
28+
{% endif %}
2729
{% endfor %}
2830

2931
{% if 'normal' != position %}

src/Symfony/Component/Console/Application.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
826826
}
827827

828828
if (null === $this->dispatcher) {
829-
return $command->run($input, $output);
829+
try {
830+
return $command->run($input, $output);
831+
} catch (\Exception $e) {
832+
throw $e;
833+
} catch (\Throwable $e) {
834+
throw new FatalThrowableError($e);
835+
}
830836
}
831837

832838
// bind before the console.command event, so the listeners have access to input options/arguments

src/Symfony/Component/Console/Descriptor/TextDescriptor.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ protected function describeInputArgument(InputArgument $argument, array $options
3838
}
3939

4040
$totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName());
41-
$spacingWidth = $totalWidth - strlen($argument->getName()) + 2;
41+
$spacingWidth = $totalWidth - strlen($argument->getName());
4242

43-
$this->writeText(sprintf(' <info>%s</info>%s%s%s',
43+
$this->writeText(sprintf(' <info>%s</info> %s%s%s',
4444
$argument->getName(),
4545
str_repeat(' ', $spacingWidth),
46-
// + 17 = 2 spaces + <info> + </info> + 2 spaces
47-
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $argument->getDescription()),
46+
// + 4 = 2 spaces before <info>, 2 spaces after </info>
47+
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $argument->getDescription()),
4848
$default
4949
), $options);
5050
}
@@ -75,13 +75,13 @@ protected function describeInputOption(InputOption $option, array $options = arr
7575
sprintf('--%s%s', $option->getName(), $value)
7676
);
7777

78-
$spacingWidth = $totalWidth - strlen($synopsis) + 2;
78+
$spacingWidth = $totalWidth - strlen($synopsis);
7979

80-
$this->writeText(sprintf(' <info>%s</info>%s%s%s%s',
80+
$this->writeText(sprintf(' <info>%s</info> %s%s%s%s',
8181
$synopsis,
8282
str_repeat(' ', $spacingWidth),
83-
// + 17 = 2 spaces + <info> + </info> + 2 spaces
84-
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $option->getDescription()),
83+
// + 4 = 2 spaces before <info>, 2 spaces after </info>
84+
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $option->getDescription()),
8585
$default,
8686
$option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
8787
), $options);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,24 @@ public function testRunDispatchesAllEventsWithException()
944944
$this->assertContains('before.foo.caught.after.', $tester->getDisplay());
945945
}
946946

947+
public function testRunWithError()
948+
{
949+
$this->setExpectedException('Exception', 'dymerr');
950+
951+
$application = new Application();
952+
$application->setAutoExit(false);
953+
$application->setCatchExceptions(false);
954+
955+
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
956+
$output->write('dym.');
957+
958+
throw new \Error('dymerr');
959+
});
960+
961+
$tester = new ApplicationTester($application);
962+
$tester->run(array('command' => 'dym'));
963+
}
964+
947965
/**
948966
* @expectedException \LogicException
949967
* @expectedExceptionMessage caught
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<info>argument_name</info> multiline
2-
argument description
2+
argument description
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<info>-o, --option_name=OPTION_NAME</info> multiline
2-
option description
2+
option description

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@ private function checkOutEdges(array $edges)
6060
$id = $node->getId();
6161

6262
if (empty($this->checkedNodes[$id])) {
63-
$searchKey = array_search($id, $this->currentPath);
64-
$this->currentPath[] = $id;
6563

66-
if (false !== $searchKey) {
67-
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
68-
}
64+
// don't check circular dependencies for lazy services
65+
if (!$node->getValue() || !$node->getValue()->isLazy()) {
66+
$searchKey = array_search($id, $this->currentPath);
67+
$this->currentPath[] = $id;
68+
69+
if (false !== $searchKey) {
70+
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
71+
}
6972

70-
$this->checkOutEdges($node->getOutEdges());
73+
$this->checkOutEdges($node->getOutEdges());
74+
}
7175

7276
$this->checkedNodes[$id] = true;
7377
array_pop($this->currentPath);

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,13 @@ private function hasReference($id, array $arguments, $deep = false, array &$visi
13101310
$visited[$argumentId] = true;
13111311

13121312
$service = $this->container->getDefinition($argumentId);
1313+
1314+
// if the proxy manager is enabled, disable searching for references in lazy services,
1315+
// as these services will be instantiated lazily and don't have direct related references.
1316+
if ($service->isLazy() && !$this->getProxyDumper() instanceof NullDumper) {
1317+
continue;
1318+
}
1319+
13131320
$arguments = array_merge($service->getMethodCalls(), $service->getArguments(), $service->getProperties());
13141321

13151322
if ($this->hasReference($id, $arguments, $deep, $visited)) {

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,22 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
346346
$arg->setAttribute('key', $arg->getAttribute('name'));
347347
}
348348

349-
if (!$arg->hasAttribute('key')) {
350-
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
351-
} else {
352-
$key = $arg->getAttribute('key');
353-
}
354-
355-
// parameter keys are case insensitive
356-
if ('parameter' == $name && $lowercase) {
357-
$key = strtolower($key);
358-
}
359-
360349
// this is used by DefinitionDecorator to overwrite a specific
361350
// argument of the parent definition
362351
if ($arg->hasAttribute('index')) {
363352
$key = 'index_'.$arg->getAttribute('index');
353+
} elseif (!$arg->hasAttribute('key')) {
354+
// Append an empty argument, then fetch its key to overwrite it later
355+
$arguments[] = null;
356+
$keys = array_keys($arguments);
357+
$key = array_pop($keys);
358+
} else {
359+
$key = $arg->getAttribute('key');
360+
361+
// parameter keys are case insensitive
362+
if ('parameter' == $name && $lowercase) {
363+
$key = strtolower($key);
364+
}
364365
}
365366

366367
switch ($arg->getAttribute('type')) {

0 commit comments

Comments
 (0)
0