Skip to content

Commit

Permalink
Merge branch '2.3' into 2.4
Browse files Browse the repository at this point in the history
* 2.3:
  [Debug] ErrorHandler: remove $GLOBALS from context in PHP5.3 fix symfony#10292
  Allow File instance to be passed to BinaryFileResponse
  Add upgrade instructions for the LoggerInterface
  fixed CS
  Removed strict check when found variables inside a translation
  • Loading branch information
fabpot committed Apr 28, 2014
2 parents e210082 + 48f26f7 commit b1c4ece
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 deletions.
20 changes: 20 additions & 0 deletions UPGRADE-2.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,23 @@
extended with an optional `$context` array. This was necessary to allow for
more complex use-cases that require context information during the
(de)normalization and en-/decoding steps.
### HttpKernel
* The `Symfony\Component\HttpKernel\Log\LoggerInterface` now extends `Psr\Log\LoggerInterface`.
So if you have implemented your own logger, you need to implement these methods:
* `emergency`
* `critical`
* `error`
* `warning`
* `log`
#### Deprecations:
* The following Logger methods are deprecated and will be removed in 3.0. You should use the new PSR-3 methods:
* `emerg()` -> `emergency()`
* `crit()` -> `critical()`
* `err()` -> `error()`
* `warn()` -> `warning()`
8 changes: 5 additions & 3 deletions src/Symfony/Bridge/Twig/Node/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function compile(\Twig_Compiler $compiler)
$defaults = $this->getNode('vars');
$vars = null;
}
list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults);
list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);

$method = null === $this->getNode('count') ? 'trans' : 'transChoice';

Expand Down Expand Up @@ -83,7 +83,7 @@ public function compile(\Twig_Compiler $compiler)
$compiler->raw(");\n");
}

protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false)
{
if ($body instanceof \Twig_Node_Expression_Constant) {
$msg = $body->getAttribute('value');
Expand All @@ -98,7 +98,9 @@ protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expressio
foreach ($matches[1] as $var) {
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
if (!$vars->hasElement($key)) {
$vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
$varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
$vars->addElement($varExpr, $key);
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Twig\Tests\Node;

use Symfony\Bridge\Twig\Node\TransNode;

/**
* @author Asmir Mustafic <[email protected]>
*/
class TransNodeTest extends \PHPUnit_Framework_TestCase
{
public function testCompileStrict()
{
$body = new \Twig_Node_Text('trans %var%', 0);
$vars = new \Twig_Node_Expression_Name('foo', 0);
$node = new TransNode($body, null, null, $vars);

$env = new \Twig_Environment(null, array('strict_variables' => true));
$compiler = new \Twig_Compiler($env);

$this->assertEquals(
sprintf(
'echo $this->env->getExtension(\'translator\')->getTranslator()->trans("trans %%var%%", array_merge(array("%%var%%" => %s), %s), "messages");',
$this->getVariableGetterWithoutStrictCheck('var'),
$this->getVariableGetterWithStrictCheck('foo')
),
trim($compiler->compile($node)->getSource())
);
}
protected function getVariableGetterWithoutStrictCheck($name)
{
if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}

return sprintf('$this->getContext($context, "%s", true)', $name);
}

protected function getVariableGetterWithStrictCheck($name)
{
if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
}

return sprintf('$this->getContext($context, "%s")', $name);
}
}
4 changes: 4 additions & 0 deletions src/Symfony/Component/Debug/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ function ($row) {
require __DIR__.'/Exception/ContextErrorException.php';
}

if (PHP_VERSION_ID < 50400 && isset($context['GLOBALS'])) {
unset($context['GLOBALS']);
}

$exception = new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context);

// Exceptions thrown from error handlers are sometimes not caught by the exception
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public static function create($file = null, $status = 200, $headers = array(), $
*/
public function setFile($file, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
{
$file = new File((string) $file);
if (!$file instanceof File) {
$file = new File((string) $file);
}

if (!$file->isReadable()) {
throw new FileException('File must be readable.');
Expand Down

0 comments on commit b1c4ece

Please sign in to comment.