Merge branch '2.7' into 2.8

* 2.7:
  [Yaml] throw a ParseException on invalid data type
  [TwigBridge] type-dependent path discovery
  Resources as string have the same problem
  Introduce failing test case when a SplFileInfo object is passed to the extract() method in the TwigExtractor.
  #15331 add infos about deprecated classes to UPGRADE-3.0
  [Asset] removed unused private property.
  [Security] removed useless else condition in SwitchUserListener class.
  [travis] Tests deps=low with PHP 5.6
  [Console] Fix console output with closed stdout
This commit is contained in:
Fabien Potencier 2015-07-26 11:09:29 +02:00
commit 96e211d2da
9 changed files with 74 additions and 15 deletions

View File

@ -13,7 +13,6 @@ matrix:
- php: 5.3 - php: 5.3
- php: 5.4 - php: 5.4
- php: 5.5 - php: 5.5
- php: 5.6
- php: 5.6 - php: 5.6
env: deps=low env: deps=low
- php: 5.6 - php: 5.6

View File

@ -299,6 +299,17 @@ UPGRADE FROM 2.x to 3.0
```php ```php
echo $form->getErrors(true, false); echo $form->getErrors(true, false);
``` ```
* The `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList`.
* The `Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\LazyChoiceList`.
* The `Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList`.
* The `Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList`.
### FrameworkBundle ### FrameworkBundle

View File

@ -73,15 +73,28 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase
/** /**
* @expectedException \Twig_Error * @expectedException \Twig_Error
* @expectedExceptionMessageRegExp /Unclosed "block" in "extractor(\/|\\)syntax_error\.twig" at line 1/ * @expectedExceptionMessageRegExp /Unclosed "block" in ".*extractor(\/|\\)syntax_error\.twig" at line 1/
* @dataProvider resourcesWithSyntaxErrorsProvider
*/ */
public function testExtractSyntaxError() public function testExtractSyntaxError($resources)
{ {
$twig = new \Twig_Environment(new \Twig_Loader_Array(array())); $twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface'))); $twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
$extractor = new TwigExtractor($twig); $extractor = new TwigExtractor($twig);
$extractor->extract(__DIR__.'/../Fixtures', new MessageCatalogue('en')); $extractor->extract($resources, new MessageCatalogue('en'));
}
/**
* @return array
*/
public function resourcesWithSyntaxErrorsProvider()
{
return array(
array(__DIR__.'/../Fixtures'),
array(__DIR__.'/../Fixtures/extractor/syntax_error.twig'),
array(new \SplFileInfo(__DIR__.'/../Fixtures/extractor/syntax_error.twig')),
);
} }
/** /**

View File

@ -12,6 +12,7 @@
namespace Symfony\Bridge\Twig\Translation; namespace Symfony\Bridge\Twig\Translation;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Translation\Extractor\AbstractFileExtractor; use Symfony\Component\Translation\Extractor\AbstractFileExtractor;
use Symfony\Component\Translation\Extractor\ExtractorInterface; use Symfony\Component\Translation\Extractor\ExtractorInterface;
use Symfony\Component\Translation\MessageCatalogue; use Symfony\Component\Translation\MessageCatalogue;
@ -60,7 +61,11 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
try { try {
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue); $this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
} catch (\Twig_Error $e) { } catch (\Twig_Error $e) {
$e->setTemplateFile($file->getRelativePathname()); if ($file instanceof SplFileInfo) {
$e->setTemplateFile($file->getRelativePathname());
} elseif ($file instanceof \SplFileInfo) {
$e->setTemplateFile($file->getRealPath());
}
throw $e; throw $e;
} }

View File

@ -36,7 +36,6 @@ use Symfony\Component\Asset\Exception\LogicException;
class UrlPackage extends Package class UrlPackage extends Package
{ {
private $baseUrls = array(); private $baseUrls = array();
private $sslUrls;
private $sslPackage; private $sslPackage;
/** /**
@ -62,7 +61,7 @@ class UrlPackage extends Package
$sslUrls = $this->getSslUrls($baseUrls); $sslUrls = $this->getSslUrls($baseUrls);
if ($sslUrls && $baseUrls !== $sslUrls) { if ($sslUrls && $baseUrls !== $sslUrls) {
$this->sslPackage = new UrlPackage($sslUrls, $versionStrategy); $this->sslPackage = new self($sslUrls, $versionStrategy);
} }
} }

View File

@ -46,12 +46,9 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
*/ */
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null) public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
{ {
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output'; parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter); $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());
$this->stderr = new StreamOutput(fopen($errorStream, 'w'), $verbosity, $decorated, $this->getFormatter());
} }
/** /**
@ -129,4 +126,24 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
{ {
return 'OS400' === php_uname('s'); return 'OS400' === php_uname('s');
} }
/**
* @return resource
*/
private function openOutputStream()
{
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
}
/**
* @return resource
*/
private function openErrorStream()
{
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
return fopen($errorStream, 'w');
}
} }

View File

@ -115,9 +115,9 @@ class SwitchUserListener implements ListenerInterface
if (false !== $originalToken) { if (false !== $originalToken) {
if ($token->getUsername() === $request->get($this->usernameParameter)) { if ($token->getUsername() === $request->get($this->usernameParameter)) {
return $token; return $token;
} else {
throw new \LogicException(sprintf('You are already switched to "%s" user.', $token->getUsername()));
} }
throw new \LogicException(sprintf('You are already switched to "%s" user.', $token->getUsername()));
} }
if (false === $this->accessDecisionManager->decide($token, array($this->role))) { if (false === $this->accessDecisionManager->decide($token, array($this->role))) {

View File

@ -234,7 +234,7 @@ class Parser
} }
// 1-liner optionally followed by newline(s) // 1-liner optionally followed by newline(s)
if ($this->lines[0] === trim($value)) { if (is_string($value) && $this->lines[0] === trim($value)) {
try { try {
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs); $value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
} catch (ParseException $e) { } catch (ParseException $e) {

View File

@ -551,6 +551,21 @@ EOF
); );
} }
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage missing colon
*/
public function testScalarInSequence()
{
Yaml::parse(<<<EOF
foo:
- bar
"missing colon"
foo: bar
EOF
);
}
/** /**
* > It is an error for two equal keys to appear in the same mapping node. * > It is an error for two equal keys to appear in the same mapping node.
* > In such a case the YAML processor may continue, ignoring the second * > In such a case the YAML processor may continue, ignoring the second