Merge branch '2.3' into 2.6

* 2.3:
  [Routing][DependencyInjection] Support .yaml extension in YAML loaders
  [DX] improve file loader error for router/other resources in bundle
  [FrameworkBundle] Fix Routing\DelegatingLoader resiliency to fatal errors
  [HttpKernel] Cleanup ExceptionListener
  CS fixes
  [DependencyInjection] Show better error when the Yaml component is not installed
  [2.3] SCA for Components - reference mismatches
  [2.3] Static Code Analysis for Components
  [Translation][fixed test] refresh cache when resources are no longer fresh.
  [Validator] Added missing Simplified Chinese (zh_CN) translations
  [FrameworkBundle] Workaround php -S ignoring auto_prepend_file

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php
	src/Symfony/Component/Config/Exception/FileLoaderLoadException.php
	src/Symfony/Component/Console/Descriptor/TextDescriptor.php
	src/Symfony/Component/Console/Helper/TableHelper.php
	src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php
	src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
	src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
	src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php
	src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php
	src/Symfony/Component/PropertyAccess/PropertyAccessor.php
	src/Symfony/Component/Yaml/Tests/InlineTest.php
This commit is contained in:
Nicolas Grekas 2015-04-18 17:02:51 +02:00
commit 0191aa24bb
44 changed files with 291 additions and 111 deletions

View File

@ -58,7 +58,7 @@ class CodeExtension extends \Twig_Extension
$parts = explode('\\', $class);
$short = array_pop($parts);
return sprintf("<abbr title=\"%s\">%s</abbr>", $class, $short);
return sprintf('<abbr title="%s">%s</abbr>', $class, $short);
}
public function abbrMethod($method)
@ -67,9 +67,9 @@ class CodeExtension extends \Twig_Extension
list($class, $method) = explode('::', $method, 2);
$result = sprintf('%s::%s()', $this->abbrClass($class), $method);
} elseif ('Closure' === $method) {
$result = sprintf("<abbr title=\"%s\">%s</abbr>", $method, $method);
$result = sprintf('<abbr title="%s">%s</abbr>', $method, $method);
} else {
$result = sprintf("<abbr title=\"%s\">%s</abbr>()", $method, $method);
$result = sprintf('<abbr title="%s">%s</abbr>()', $method, $method);
}
return $result;
@ -89,7 +89,7 @@ class CodeExtension extends \Twig_Extension
if ('object' === $item[0]) {
$parts = explode('\\', $item[1]);
$short = array_pop($parts);
$formattedValue = sprintf("<em>object</em>(<abbr title=\"%s\">%s</abbr>)", $item[1], $short);
$formattedValue = sprintf('<em>object</em>(<abbr title="%s">%s</abbr>)', $item[1], $short);
} elseif ('array' === $item[0]) {
$formattedValue = sprintf('<em>array</em>(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
} elseif ('string' === $item[0]) {

View File

@ -21,6 +21,11 @@
* @author: Albert Jessurum <ajessu@gmail.com>
*/
// Workaround https://bugs.php.net/64566
if (ini_get('auto_prepend_file') && !in_array(realpath(ini_get('auto_prepend_file')), get_included_files(), true)) {
require ini_get('auto_prepend_file');
}
if (is_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) {
return false;
}

View File

@ -21,6 +21,11 @@
* @author: Albert Jessurum <ajessu@gmail.com>
*/
// Workaround https://bugs.php.net/64566
if (ini_get('auto_prepend_file') && !in_array(realpath(ini_get('auto_prepend_file')), get_included_files(), true)) {
require ini_get('auto_prepend_file');
}
if (is_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) {
return false;
}

View File

@ -12,10 +12,10 @@
namespace Symfony\Bundle\FrameworkBundle\Routing;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\Config\Exception\FileLoaderLoadException;
use Symfony\Component\Config\Loader\DelegatingLoader as BaseDelegatingLoader;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\RouteCollection;
/**
* DelegatingLoader delegates route loading to other loaders using a loader resolver.
@ -29,6 +29,7 @@ class DelegatingLoader extends BaseDelegatingLoader
{
protected $parser;
protected $logger;
private $loading = false;
/**
* Constructor.
@ -46,16 +47,39 @@ class DelegatingLoader extends BaseDelegatingLoader
}
/**
* Loads a resource.
*
* @param mixed $resource A resource
* @param string $type The resource type
*
* @return RouteCollection A RouteCollection instance
* {@inheritdoc}
*/
public function load($resource, $type = null)
{
$collection = parent::load($resource, $type);
if ($this->loading) {
// This can happen if a fatal error occurs in parent::load().
// Here is the scenario:
// - while routes are being loaded by parent::load() below, a fatal error
// occurs (e.g. parse error in a controller while loading annotations);
// - PHP abruptly empties the stack trace, bypassing all catch blocks;
// it then calls the registered shutdown functions;
// - the ErrorHandler catches the fatal error and re-injects it for rendering
// thanks to HttpKernel->terminateWithException() (that calls handleException());
// - at this stage, if we try to load the routes again, we must prevent
// the fatal error from occurring a second time,
// otherwise the PHP process would be killed immediately;
// - while rendering the exception page, the router can be required
// (by e.g. the web profiler that needs to generate an URL);
// - this handles the case and prevents the second fatal error
// by triggering an exception beforehand.
throw new FileLoaderLoadException($resource);
}
$this->loading = true;
try {
$collection = parent::load($resource, $type);
} catch (\Exception $e) {
$this->loading = false;
throw $e;
}
$this->loading = false;
foreach ($collection->all() as $route) {
if ($controller = $route->getDefault('_controller')) {

View File

@ -55,7 +55,7 @@ class CodeHelper extends Helper
$parts = explode('\\', $class);
$short = array_pop($parts);
return sprintf("<abbr title=\"%s\">%s</abbr>", $class, $short);
return sprintf('<abbr title="%s">%s</abbr>', $class, $short);
}
public function abbrMethod($method)
@ -64,9 +64,9 @@ class CodeHelper extends Helper
list($class, $method) = explode('::', $method, 2);
$result = sprintf('%s::%s()', $this->abbrClass($class), $method);
} elseif ('Closure' === $method) {
$result = sprintf("<abbr title=\"%s\">%s</abbr>", $method, $method);
$result = sprintf('<abbr title="%s">%s</abbr>', $method, $method);
} else {
$result = sprintf("<abbr title=\"%s\">%s</abbr>()", $method, $method);
$result = sprintf('<abbr title="%s">%s</abbr>()', $method, $method);
}
return $result;
@ -86,7 +86,7 @@ class CodeHelper extends Helper
if ('object' === $item[0]) {
$parts = explode('\\', $item[1]);
$short = array_pop($parts);
$formattedValue = sprintf("<em>object</em>(<abbr title=\"%s\">%s</abbr>)", $item[1], $short);
$formattedValue = sprintf('<em>object</em>(<abbr title="%s">%s</abbr>)', $item[1], $short);
} elseif ('array' === $item[0]) {
$formattedValue = sprintf('<em>array</em>(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
} elseif ('string' === $item[0]) {

View File

@ -93,27 +93,27 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
}
// refresh cache again when resource file resources file change
public function testRefreshCacheWhenResourcesAreNoLongerFresh()
{
$resource = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface');
$resource
->expects($this->at(0))
->method('isFresh')
->will($this->returnValue(false))
;
$catalogue = $this->getCatalogue('fr', array('foo' => 'foo fresh'));
$catalogue->addResource($resource);
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
$resource->method('isFresh')->will($this->returnValue(false));
$loader
->expects($this->at(0))
->expects($this->exactly(2))
->method('load')
->will($this->returnValue($catalogue))
;
->will($this->returnValue($this->getCatalogue('fr', array(), array($resource))));
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
// prime the cache
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'debug' => true));
$translator->setLocale('fr');
$this->assertEquals('foo fresh', $translator->trans('foo'));
$translator->trans('foo');
// prime the cache second time
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'debug' => true));
$translator->setLocale('fr');
$translator->trans('foo');
}
public function testTransWithCachingWithInvalidLocale()
@ -126,12 +126,124 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
$translator->trans('foo');
}
protected function getCatalogue($locale, $messages)
public function testGetLocale()
{
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request
->expects($this->once())
->method('getLocale')
->will($this->returnValue('en'))
;
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container
->expects($this->exactly(2))
->method('isScopeActive')
->with('request')
->will($this->onConsecutiveCalls(false, true))
;
$container
->expects($this->once())
->method('has')
->with('request')
->will($this->returnValue(true))
;
$container
->expects($this->once())
->method('get')
->with('request')
->will($this->returnValue($request))
;
$translator = new Translator($container, new MessageSelector());
$this->assertNull($translator->getLocale());
$this->assertSame('en', $translator->getLocale());
}
public function testGetLocaleWithInvalidLocale()
{
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request
->expects($this->once())
->method('getLocale')
->will($this->returnValue('foo bar'))
;
$request
->expects($this->once())
->method('getDefaultLocale')
->will($this->returnValue('en-US'))
;
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container
->expects($this->once())
->method('isScopeActive')
->with('request')
->will($this->returnValue(true))
;
$container
->expects($this->once())
->method('has')
->with('request')
->will($this->returnValue(true))
;
$container
->expects($this->any())
->method('get')
->with('request')
->will($this->returnValue($request))
;
$translator = new Translator($container, new MessageSelector());
$this->assertSame('en-US', $translator->getLocale());
}
public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales()
{
/*
* Because the cache file contains a catalogue including all of its fallback
* catalogues, we must take the active set of fallback locales into
* consideration when loading a catalogue from the cache.
*/
$translator = $this->createTranslator(new ArrayLoader(), array('cache_dir' => $this->tmpDir));
$translator->setLocale('a');
$translator->setFallbackLocales(array('b'));
$translator->addResource('loader', array('foo' => 'foo (a)'), 'a');
$translator->addResource('loader', array('bar' => 'bar (b)'), 'b');
$this->assertEquals('bar (b)', $translator->trans('bar'));
// Remove fallback locale
$translator->setFallbackLocales(array());
$this->assertEquals('bar', $translator->trans('bar'));
// Use a fresh translator with no fallback locales, result should be the same
$translator = $this->createTranslator(new ArrayLoader(), array('cache_dir' => $this->tmpDir));
$translator->setLocale('a');
$translator->addResource('loader', array('foo' => 'foo (a)'), 'a');
$translator->addResource('loader', array('bar' => 'bar (b)'), 'b');
$this->assertEquals('bar', $translator->trans('bar'));
}
protected function getCatalogue($locale, $messages, $resources = array())
{
$catalogue = new MessageCatalogue($locale);
foreach ($messages as $key => $translation) {
$catalogue->set($key, $translation);
}
foreach ($resources as $resource) {
$catalogue->addResource($resource);
}
return $catalogue;
}

View File

@ -93,6 +93,7 @@ class Cookie
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
if ($dateTime === false) {
// this throw will provoke PHP fatal
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $this->expires);
}

View File

@ -58,7 +58,8 @@ class FileLoaderLoadException extends \Exception
if ('@' === $resource[0]) {
$parts = explode(DIRECTORY_SEPARATOR, $resource);
$bundle = substr($parts[0], 1);
$message .= ' '.sprintf('Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
$message .= sprintf(' Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
$message .= sprintf(' If the bundle is registered, make sure the bundle path "%s" is not empty.', $resource);
}
parent::__construct($message, $code, $previous);

View File

@ -103,7 +103,12 @@ abstract class FileLoader extends Loader
}
self::$loading[$resource] = true;
$ret = $loader->load($resource, $type);
try {
$ret = $loader->load($resource, $type);
} catch (\Exception $e) {
unset(self::$loading[$resource]);
throw $e;
}
unset(self::$loading[$resource]);

View File

@ -32,7 +32,8 @@ class FileLoaderLoadExceptionTest extends \PHPUnit_Framework_TestCase
$exception = new FileLoaderLoadException('@resource', 'sourceResource');
$this->assertEquals(
'Cannot import resource "@resource" from "sourceResource". '.
'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class.',
'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class. '.
'If the bundle is registered, make sure the bundle path "@resource" is not empty.',
$exception->getMessage()
);
}
@ -76,7 +77,8 @@ class FileLoaderLoadExceptionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(
'There was a previous error with an ending dot in @resource '.
'(which is loaded in resource "@resource"). '.
'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class.',
'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class. '.
'If the bundle is registered, make sure the bundle path "@resource" is not empty.',
$exception->getMessage()
);
}

View File

@ -146,9 +146,11 @@ class ApplicationDescription
}
ksort($namespacedCommands);
foreach ($namespacedCommands as &$commands) {
ksort($commands);
foreach ($namespacedCommands as &$commandsSet) {
ksort($commandsSet);
}
// unset reference to keep scope clear
unset($commandsSet);
return $namespacedCommands;
}

View File

@ -189,7 +189,7 @@ class TextDescriptor extends Descriptor
$width = $this->getColumnWidth($description->getCommands());
if ($describedNamespace) {
$this->writeText(sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace), $options);
$this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
} else {
$this->writeText('<comment>Available commands:</comment>', $options);
}

View File

@ -74,7 +74,7 @@ class DialogHelper extends InputAwareHelper
if (empty($choices[$value])) {
throw new \InvalidArgumentException(sprintf($errorMessage, $value));
}
array_push($multiselectChoices, $value);
$multiselectChoices[] = $value;
}
if ($multiselect) {

View File

@ -179,7 +179,7 @@ class Table
reset($this->rows);
foreach ($row as $key => $cellValue) {
if (!strstr($cellValue, "\n")) {
if (false === strpos($cellValue, "\n")) {
continue;
}

View File

@ -28,7 +28,7 @@ class OutputFormatterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo<bar', $formatter->format('foo\\<bar'));
$this->assertEquals('<info>some info</info>', $formatter->format('\\<info>some info\\</info>'));
$this->assertEquals("\\<info>some info\\</info>", OutputFormatter::escape('<info>some info</info>'));
$this->assertEquals('\\<info>some info\\</info>', OutputFormatter::escape('<info>some info</info>'));
$this->assertEquals(
"\033[33mSymfony\\Component\\Console does work very well!\033[39m",
@ -162,7 +162,7 @@ class OutputFormatterTest extends \PHPUnit_Framework_TestCase
public function testFormatLongString()
{
$formatter = new OutputFormatter(true);
$long = str_repeat("\\", 14000);
$long = str_repeat('\\', 14000);
$this->assertEquals("\033[37;41msome error\033[39;49m".$long, $formatter->format('<error>some error</error>'.$long));
}

View File

@ -100,7 +100,7 @@ class TokenStream
throw new InternalErrorException('Unexpected token stream end.');
}
return $this->tokens[$this->cursor ++];
return $this->tokens[$this->cursor++];
}
/**

View File

@ -371,7 +371,7 @@ EOF;
{
$parts = explode('\\', $class);
return sprintf("<abbr title=\"%s\">%s</abbr>", $class, array_pop($parts));
return sprintf('<abbr title="%s">%s</abbr>', $class, array_pop($parts));
}
private function formatPath($path, $line)

View File

@ -39,7 +39,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
$this->compiler = $container->getCompiler();
$this->formatter = $this->compiler->getLoggingFormatter();
foreach (array_keys($container->getDefinitions()) as $id) {
foreach ($container->getDefinitions() as $id => $definition) {
// yes, we are specifically fetching the definition from the
// container to ensure we are not operating on stale data
$definition = $container->getDefinition($id);

View File

@ -307,7 +307,7 @@ class Container implements IntrospectableContainerInterface
}
$alternatives = array();
foreach (array_keys($this->services) as $key) {
foreach ($this->services as $key => $associatedService) {
$lev = levenshtein($id, $key);
if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
$alternatives[] = $key;

View File

@ -560,7 +560,7 @@ class PhpDumper extends Dumper
if ($definition->isSynthetic()) {
$return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
} elseif ($class = $definition->getClass()) {
$return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : "\\".$class, $class);
$return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\'.$class, $class);
} elseif ($definition->getFactory()) {
$factory = $definition->getFactory();
if (is_string($factory)) {
@ -1340,7 +1340,7 @@ EOF;
}
}
return sprintf("new \\%s(%s)", substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
return sprintf('new \\%s(%s)', substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
} elseif ($value instanceof Variable) {
return '$'.$value;
} elseif ($value instanceof Reference) {

View File

@ -18,7 +18,6 @@ use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\ExpressionLanguage\Expression;
/**
@ -32,20 +31,6 @@ class YamlDumper extends Dumper
{
private $dumper;
/**
* Constructor.
*
* @param ContainerBuilder $container The service container to dump
*
* @api
*/
public function __construct(ContainerBuilder $container)
{
parent::__construct($container);
$this->dumper = new YmlDumper();
}
/**
* Dumps the service container as an YAML string.
*
@ -57,6 +42,14 @@ class YamlDumper extends Dumper
*/
public function dump(array $options = array())
{
if (!class_exists('Symfony\Component\Yaml\Dumper')) {
throw new RuntimeException('Unable to dump the container as the Symfony Yaml Component is not installed.');
}
if (null === $this->dumper) {
$this->dumper = new YmlDumper();
}
return $this->addParameters()."\n".$this->addServices();
}

View File

@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Yaml\Parser as YamlParser;
use Symfony\Component\ExpressionLanguage\Expression;
@ -74,7 +75,7 @@ class YamlFileLoader extends FileLoader
*/
public function supports($resource, $type = null)
{
return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION);
return is_string($resource) && in_array(pathinfo($resource, PATHINFO_EXTENSION), array('yml', 'yaml'), true);
}
/**
@ -288,6 +289,10 @@ class YamlFileLoader extends FileLoader
*/
protected function loadFile($file)
{
if (!class_exists('Symfony\Component\Yaml\Parser')) {
throw new RuntimeException('Unable to load YAML config files as the Symfony Yaml Component is not installed.');
}
if (!stream_is_local($file)) {
throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
}
@ -323,7 +328,7 @@ class YamlFileLoader extends FileLoader
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid. It should contain an array. Check your YAML syntax.', $file));
}
foreach (array_keys($content) as $namespace) {
foreach ($content as $namespace => $data) {
if (in_array($namespace, array('imports', 'parameters', 'services'))) {
continue;
}

View File

@ -96,7 +96,7 @@ class ParameterBag implements ParameterBagInterface
}
$alternatives = array();
foreach (array_keys($this->parameters) as $key) {
foreach ($this->parameters as $key => $parameterValue) {
$lev = levenshtein($name, $key);
if ($lev <= strlen($name) / 3 || false !== strpos($key, $name)) {
$alternatives[] = $key;

View File

@ -65,21 +65,21 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
{
$container = include self::$fixturesPath.'/containers/container11.php';
$dumper = new XmlDumper($container);
$this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>
<container xmlns=\"http://symfony.com/schema/dic/services\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd\">
$this->assertEquals('<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id=\"foo\" class=\"FooClass\">
<argument type=\"service\">
<service class=\"BarClass\">
<argument type=\"service\">
<service class=\"BazClass\"/>
<service id="foo" class="FooClass">
<argument type="service">
<service class="BarClass">
<argument type="service">
<service class="BazClass"/>
</argument>
</service>
</argument>
</service>
</services>
</container>
", $dumper->dump());
', $dumper->dump());
}
public function testDumpEntities()

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\DependencyInjection\Tests\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\Config\FileLocator;

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
@ -206,6 +205,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator());
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
}

View File

@ -163,7 +163,7 @@ class Link
if ('..' === $segment) {
array_pop($output);
} elseif ('.' !== $segment) {
array_push($output, $segment);
$output[] = $segment;
}
}

View File

@ -121,7 +121,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
public function getListeners($eventName = null)
{
if (null === $eventName) {
foreach (array_keys($this->listenerIds) as $serviceEventName) {
foreach ($this->listenerIds as $serviceEventName => $args) {
$this->lazyLoad($serviceEventName);
}
} else {

View File

@ -68,7 +68,7 @@ class EventDispatcher implements EventDispatcherInterface
return $this->sorted[$eventName];
}
foreach (array_keys($this->listeners) as $eventName) {
foreach ($this->listeners as $eventName => $eventListeners) {
if (!isset($this->sorted[$eventName])) {
$this->sortListeners($eventName);
}

View File

@ -51,7 +51,7 @@ abstract class IteratorTestCase extends \PHPUnit_Framework_TestCase
foreach ($expected as $subarray) {
$temp = array();
while (count($values) && count($temp) < count($subarray)) {
array_push($temp, array_shift($values));
$temp[] = array_shift($values);
}
sort($temp);
sort($subarray);

View File

@ -40,11 +40,11 @@ abstract class BaseDateTimeTransformer implements DataTransformerInterface
*/
public function __construct($inputTimezone = null, $outputTimezone = null)
{
if (!is_string($inputTimezone) && null !== $inputTimezone) {
if (null !== $inputTimezone && !is_string($inputTimezone)) {
throw new UnexpectedTypeException($inputTimezone, 'string');
}
if (!is_string($outputTimezone) && null !== $outputTimezone) {
if (null !== $outputTimezone && !is_string($outputTimezone)) {
throw new UnexpectedTypeException($outputTimezone, 'string');
}

View File

@ -99,6 +99,8 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
// remove leading zeros
$entry = (string) (int) $entry;
}
// unset reference to keep scope clear
unset($entry);
}
return $result;

View File

@ -74,7 +74,7 @@ class MergeCollectionListener implements EventSubscriberInterface
}
// If we are not allowed to change anything, return immediately
if ((!$this->allowAdd && !$this->allowDelete) || $data === $dataToMergeInto) {
if ($data === $dataToMergeInto || (!$this->allowAdd && !$this->allowDelete)) {
$event->setData($dataToMergeInto);
return;

View File

@ -1580,8 +1580,8 @@ class Request
$languages = AcceptHeader::fromString($this->headers->get('Accept-Language'))->all();
$this->languages = array();
foreach (array_keys($languages) as $lang) {
if (strstr($lang, '-')) {
foreach ($languages as $lang => $acceptHeaderItem) {
if (false !== strpos($lang, '-')) {
$codes = explode('-', $lang);
if ('i' === $codes[0]) {
// Language not listed in ISO 639 that are not variants

View File

@ -43,6 +43,7 @@ class NamespacedAttributeBag extends AttributeBag
*/
public function has($name)
{
// reference mismatch: if fixed, re-introduced in array_key_exists; keep as it is
$attributes = $this->resolveAttributePath($name);
$name = $this->resolveKey($name);
@ -58,6 +59,7 @@ class NamespacedAttributeBag extends AttributeBag
*/
public function get($name, $default = null)
{
// reference mismatch: if fixed, re-introduced in array_key_exists; keep as it is
$attributes = $this->resolveAttributePath($name);
$name = $this->resolveKey($name);

View File

@ -39,14 +39,6 @@ class ExceptionListener implements EventSubscriberInterface
public function onKernelException(GetResponseForExceptionEvent $event)
{
static $handling;
if (true === $handling) {
return false;
}
$handling = true;
$exception = $event->getException();
$request = $event->getRequest();
@ -55,13 +47,10 @@ class ExceptionListener implements EventSubscriberInterface
$request = $this->duplicateRequest($exception, $request);
try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
} catch (\Exception $e) {
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);
// set handling to false otherwise it wont be able to handle further more
$handling = false;
$wrapper = $e;
while ($prev = $wrapper->getPrevious()) {
@ -78,8 +67,6 @@ class ExceptionListener implements EventSubscriberInterface
}
$event->setResponse($response);
$handling = false;
}
public static function getSubscribedEvents()

View File

@ -92,7 +92,7 @@ class PropertyAccessor implements PropertyAccessorInterface
return;
}
$value = & $objectOrArray;
$value = &$objectOrArray;
}
}
@ -456,8 +456,10 @@ class PropertyAccessor implements PropertyAccessorInterface
// see https://github.com/symfony/symfony/issues/4670
$itemsToAdd = is_object($collection) ? iterator_to_array($collection) : $collection;
$itemToRemove = array();
$propertyValue = $this->readProperty($object, $property);
$propertyValue = &$this->readProperty($object, $property);
$previousValue = $propertyValue[self::VALUE];
// remove reference to avoid modifications
unset($propertyValue);
if (is_array($previousValue) || $previousValue instanceof \Traversable) {
foreach ($previousValue as $previousItem) {

View File

@ -104,7 +104,7 @@ class YamlFileLoader extends FileLoader
*/
public function supports($resource, $type = null)
{
return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'yaml' === $type);
return is_string($resource) && in_array(pathinfo($resource, PATHINFO_EXTENSION), array('yml', 'yaml'), true) && (!$type || 'yaml' === $type);
}
/**

View File

@ -22,9 +22,11 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
$this->assertTrue($loader->supports('foo.yml', 'yaml'), '->supports() checks the resource type if specified');
$this->assertTrue($loader->supports('foo.yaml', 'yaml'), '->supports() checks the resource type if specified');
$this->assertFalse($loader->supports('foo.yml', 'foo'), '->supports() checks the resource type if specified');
}

View File

@ -161,7 +161,7 @@ class DigestData
public function getUsername()
{
return strtr($this->elements['username'], array("\\\"" => "\"", "\\\\" => "\\"));
return strtr($this->elements['username'], array('\\"' => '"', '\\\\' => '\\'));
}
public function validateAndDecode($entryPointKey, $expectedRealm)

View File

@ -278,6 +278,38 @@
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
<target>该值不应与 {{ compared_value_type }} {{ compared_value }} 相同。</target>
</trans-unit>
<trans-unit id="73">
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
<target>图片宽高比太大 ({{ ratio }})。允许的最大宽高比为 {{ max_ratio }}。</target>
</trans-unit>
<trans-unit id="74">
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
<target>图片宽高比太小 ({{ ratio }})。允许的最大宽高比为 {{ min_ratio }}。</target>
</trans-unit>
<trans-unit id="75">
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
<target>图片是方形的 ({{ width }}x{{ height }}px)。不允许使用方形的图片。</target>
</trans-unit>
<trans-unit id="76">
<source>The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.</source>
<target>图片是横向的 ({{ width }}x{{ height }}px)。不允许使用横向的图片。</target>
</trans-unit>
<trans-unit id="77">
<source>The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.</source>
<target>图片是纵向的 ({{ width }}x{{ height }}px)。不允许使用纵向的图片。</target>
</trans-unit>
<trans-unit id="78">
<source>An empty file is not allowed.</source>
<target>不允许使用空文件。</target>
</trans-unit>
<trans-unit id="79">
<source>The host could not be resolved.</source>
<target>主机名无法解析。</target>
</trans-unit>
<trans-unit id="80">
<source>This value does not match the expected {{ charset }} charset.</source>
<target>该值不符合 {{ charset }} 编码。</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -33,11 +33,11 @@ class Escaper
"\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f",
"\xc2\x85", "\xc2\xa0", "\xe2\x80\xa8", "\xe2\x80\xa9",);
private static $escaped = array('\\\\', '\\"', '\\\\', '\\"',
"\\0", "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a",
"\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\x0e", "\\x0f",
"\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17",
"\\x18", "\\x19", "\\x1a", "\\e", "\\x1c", "\\x1d", "\\x1e", "\\x1f",
"\\N", "\\_", "\\L", "\\P",);
'\\0', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\a',
'\\b', '\\t', '\\n', '\\v', '\\f', '\\r', '\\x0e', '\\x0f',
'\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17',
'\\x18', '\\x19', '\\x1a', '\\e', '\\x1c', '\\x1d', '\\x1e', '\\x1f',
'\\N', '\\_', '\\L', '\\P',);
/**
* Determines if a PHP value would require double quoting in YAML.

View File

@ -222,8 +222,8 @@ class InlineTest extends \PHPUnit_Framework_TestCase
array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
array('{foo: \'bar\', bar: \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', array('foo\'' => 'bar', "bar\"" => 'foo: bar')),
array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', array('foo: ' => 'bar', "bar: " => 'foo: bar')),
array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', array('foo\'' => 'bar', 'bar"' => 'foo: bar')),
array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', array('foo: ' => 'bar', 'bar: ' => 'foo: bar')),
// nested sequences and mappings
array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),