Skip to content

Commit

Permalink
Merge branch '3.1' into 3.2
Browse files Browse the repository at this point in the history
* 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
  ...
  • Loading branch information
nicolas-grekas committed Dec 8, 2016
2 parents f5058ac + 59d0444 commit a28c522
Show file tree
Hide file tree
Showing 50 changed files with 507 additions and 92 deletions.
4 changes: 4 additions & 0 deletions UPGRADE-3.1.md
Expand Up @@ -111,6 +111,10 @@ Serializer
deprecated and will not be supported in Symfony 4.0. You should use the
`CacheClassMetadataFactory` class instead.

* The `AbstractObjectNormalizer::isAttributeToNormalize()` method has been removed
because it was initially added by mistake, has never been used and is not tested
nor documented.

Translation
-----------

Expand Down
17 changes: 14 additions & 3 deletions src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php
Expand Up @@ -72,8 +72,7 @@ public function getExtractData()
}

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

$extractor = new TwigExtractor($twig);
$extractor->extract($resources, new MessageCatalogue('en'));

try {
$extractor->extract($resources, new MessageCatalogue('en'));
} catch (\Twig_Error $e) {
if (method_exists($e, 'getSourceContext')) {
$this->assertSame(dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', DIRECTORY_SEPARATOR), $e->getFile());
$this->assertSame(1, $e->getLine());
$this->assertSame('Unclosed "block".', $e->getMessage());
} else {
$this->expectExceptionMessageRegExp('/Unclosed "block" in ".*extractor(\\/|\\\\)syntax_error\\.twig" at line 1/');
}
throw $e;
}
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/Symfony/Bridge/Twig/Translation/TwigExtractor.php
Expand Up @@ -61,10 +61,14 @@ public function extract($resource, MessageCatalogue $catalogue)
try {
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
} catch (\Twig_Error $e) {
if ($file instanceof SplFileInfo) {
$e->setTemplateName($file->getRelativePathname());
} elseif ($file instanceof \SplFileInfo) {
$e->setTemplateName($file->getRealPath() ?: $file->getPathname());
if ($file instanceof \SplFileInfo) {
$path = $file->getRealPath() ?: $file->getPathname();
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
if (method_exists($e, 'setSourceContext')) {
$e->setSourceContext(new \Twig_Source('', $name, $path));
} else {
$e->setTemplateName($name);
}
}

throw $e;
Expand Down
Expand Up @@ -34,7 +34,7 @@ public function process(ContainerBuilder $container)
} else {
$seed = '_'.$container->getParameter('kernel.root_dir');
}
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment').'.'.$container->getParameter('kernel.debug');
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment');

$aliases = $container->getAliases();
$attributes = array(
Expand Down
Expand Up @@ -45,7 +45,7 @@ public function testNamespaceArgumentIsReplaced()

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

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

public function testArgsAreReplaced()
Expand All @@ -69,7 +69,7 @@ public function testArgsAreReplaced()

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

Expand Down
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;

use Symfony\Component\Config\Resource\ClassExistenceResource;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -74,7 +75,7 @@ public function process(ContainerBuilder $container)
$loader->addTag('twig.loader');
$loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls());

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

if ($container->has('assets.packages')) {
Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Bundle/TwigBundle/TwigEngine.php
Expand Up @@ -52,7 +52,13 @@ public function render($name, array $parameters = array())
if ($name instanceof TemplateReference) {
try {
// try to get the real name of the template where the error occurred
$e->setTemplateName(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateName()))));
$name = $e->getTemplateName();
$path = (string) $this->locator->locate($this->parser->parse($name));
if (method_exists($e, 'setSourceContext')) {
$e->setSourceContext(new \Twig_Source('', $name, $path));
} else {
$e->setTemplateName($path);
}
} catch (\Exception $e2) {
}
}
Expand Down
Expand Up @@ -9,7 +9,7 @@
padding-bottom: 2px;
}
.sf-reset .traces li {
ccolor: #222;
color: #222;
font-size: 14px;
padding: 5px 0;
list-style-type: decimal;
Expand Down
Expand Up @@ -39,7 +39,7 @@
{%- else -%}
{{ redirect_route }}
{%- endif %}
(<a href="{{ path('_profiler', { token: redirect.token }) }}">{{ redirect.token }}</a>)
(<a href="{{ path('_profiler', { token: redirect.token, panel: request.query.get('panel', 'request') }) }}">{{ redirect.token }}</a>)
</dd>
</dl>
{%- endif %}
Expand Down Expand Up @@ -113,9 +113,11 @@
<ul id="menu-profiler">
{% for name, template in templates %}
{% set menu -%}
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
{{- block('menu', template) -}}
{% endwith %}
{% if block('menu', template) is defined %}
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
{{- block('menu', template) -}}
{% endwith %}
{% endif %}
{%- endset %}
{% if menu is not empty %}
<li class="{{ name }} {{ name == panel ? 'selected' : '' }}">
Expand Down
Expand Up @@ -375,11 +375,13 @@
border-color: #777;
border-radius: 0;
margin: 6px 0 12px 0;
width: 200px;
}
.sf-toolbar-block-dump pre.sf-dump:last-child {
margin-bottom: 0;
}
.sf-toolbar-block-dump .sf-toolbar-info-piece {
display: block;
}
.sf-toolbar-block-dump .sf-toolbar-info-piece .sf-toolbar-file-line {
color: #AAA;
margin-left: 4px;
Expand Down
Expand Up @@ -13,17 +13,19 @@

<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset clear-fix" data-no-turbolink>
{% for name, template in templates %}
{% with {
collector: profile.getcollector(name),
profiler_url: profiler_url,
token: profile.token,
name: name,
profiler_markup_version: profiler_markup_version,
csp_script_nonce: csp_script_nonce,
csp_style_nonce: csp_style_nonce
} %}
{{ block('toolbar', template) }}
{% endwith %}
{% if block('toolbar', template) is defined %}
{% with {
collector: profile.getcollector(name),
profiler_url: profiler_url,
token: profile.token,
name: name,
profiler_markup_version: profiler_markup_version,
csp_script_nonce: csp_script_nonce,
csp_style_nonce: csp_style_nonce
} %}
{{ block('toolbar', template) }}
{% endwith %}
{% endif %}
{% endfor %}

{% if 'normal' != position %}
Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -826,7 +826,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
}

if (null === $this->dispatcher) {
return $command->run($input, $output);
try {
return $command->run($input, $output);
} catch (\Exception $e) {
throw $e;
} catch (\Throwable $e) {
throw new FatalThrowableError($e);
}
}

// bind before the console.command event, so the listeners have access to input options/arguments
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Expand Up @@ -38,13 +38,13 @@ protected function describeInputArgument(InputArgument $argument, array $options
}

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

$this->writeText(sprintf(' <info>%s</info>%s%s%s',
$this->writeText(sprintf(' <info>%s</info> %s%s%s',
$argument->getName(),
str_repeat(' ', $spacingWidth),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $argument->getDescription()),
// + 4 = 2 spaces before <info>, 2 spaces after </info>
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $argument->getDescription()),
$default
), $options);
}
Expand Down Expand Up @@ -75,13 +75,13 @@ protected function describeInputOption(InputOption $option, array $options = arr
sprintf('--%s%s', $option->getName(), $value)
);

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

$this->writeText(sprintf(' <info>%s</info>%s%s%s%s',
$this->writeText(sprintf(' <info>%s</info> %s%s%s%s',
$synopsis,
str_repeat(' ', $spacingWidth),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $option->getDescription()),
// + 4 = 2 spaces before <info>, 2 spaces after </info>
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $option->getDescription()),
$default,
$option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
), $options);
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -944,6 +944,24 @@ public function testRunDispatchesAllEventsWithException()
$this->assertContains('before.foo.caught.after.', $tester->getDisplay());
}

public function testRunWithError()
{
$this->setExpectedException('Exception', 'dymerr');

$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);

$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
$output->write('dym.');

throw new \Error('dymerr');
});

$tester = new ApplicationTester($application);
$tester->run(array('command' => 'dym'));
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage caught
Expand Down
@@ -1,2 +1,2 @@
<info>argument_name</info> multiline
argument description
argument description
@@ -1,2 +1,2 @@
<info>-o, --option_name=OPTION_NAME</info> multiline
option description
option description
Expand Up @@ -60,14 +60,18 @@ private function checkOutEdges(array $edges)
$id = $node->getId();

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

if (false !== $searchKey) {
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
}
// don't check circular dependencies for lazy services
if (!$node->getValue() || !$node->getValue()->isLazy()) {
$searchKey = array_search($id, $this->currentPath);
$this->currentPath[] = $id;

if (false !== $searchKey) {
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
}

$this->checkOutEdges($node->getOutEdges());
$this->checkOutEdges($node->getOutEdges());
}

$this->checkedNodes[$id] = true;
array_pop($this->currentPath);
Expand Down
Expand Up @@ -1310,6 +1310,13 @@ private function hasReference($id, array $arguments, $deep = false, array &$visi
$visited[$argumentId] = true;

$service = $this->container->getDefinition($argumentId);

// if the proxy manager is enabled, disable searching for references in lazy services,
// as these services will be instantiated lazily and don't have direct related references.
if ($service->isLazy() && !$this->getProxyDumper() instanceof NullDumper) {
continue;
}

$arguments = array_merge($service->getMethodCalls(), $service->getArguments(), $service->getProperties());

if ($this->hasReference($id, $arguments, $deep, $visited)) {
Expand Down
23 changes: 12 additions & 11 deletions src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
Expand Up @@ -346,21 +346,22 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
$arg->setAttribute('key', $arg->getAttribute('name'));
}

if (!$arg->hasAttribute('key')) {
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
} else {
$key = $arg->getAttribute('key');
}

// parameter keys are case insensitive
if ('parameter' == $name && $lowercase) {
$key = strtolower($key);
}

// this is used by DefinitionDecorator to overwrite a specific
// argument of the parent definition
if ($arg->hasAttribute('index')) {
$key = 'index_'.$arg->getAttribute('index');
} elseif (!$arg->hasAttribute('key')) {
// Append an empty argument, then fetch its key to overwrite it later
$arguments[] = null;
$keys = array_keys($arguments);
$key = array_pop($keys);
} else {
$key = $arg->getAttribute('key');

// parameter keys are case insensitive
if ('parameter' == $name && $lowercase) {
$key = strtolower($key);
}
}

switch ($arg->getAttribute('type')) {
Expand Down

0 comments on commit a28c522

Please sign in to comment.