Merge branch '2.3' into 2.7
* 2.3: fix container cache key generation [Translation] Add resources from fallback locale [DependencyInjection] enforce tags to have a name [YAML] Refine the return value of Yaml::parse()
This commit is contained in:
commit
9d8232bf25
@ -472,7 +472,7 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
|
|
||||||
protected function createContainerFromFile($file, $data = array())
|
protected function createContainerFromFile($file, $data = array())
|
||||||
{
|
{
|
||||||
$cacheKey = md5($file.serialize($data));
|
$cacheKey = md5(get_class($this).$file.serialize($data));
|
||||||
if (isset(self::$containerCache[$cacheKey])) {
|
if (isset(self::$containerCache[$cacheKey])) {
|
||||||
return self::$containerCache[$cacheKey];
|
return self::$containerCache[$cacheKey];
|
||||||
}
|
}
|
||||||
|
@ -231,6 +231,10 @@ class XmlFileLoader extends FileLoader
|
|||||||
$parameters[$name] = XmlUtils::phpize($node->nodeValue);
|
$parameters[$name] = XmlUtils::phpize($node->nodeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('' === $tag->getAttribute('name')) {
|
||||||
|
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', (string) $service->getAttribute('id'), $file));
|
||||||
|
}
|
||||||
|
|
||||||
$definition->addTag($tag->getAttribute('name'), $parameters);
|
$definition->addTag($tag->getAttribute('name'), $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +270,10 @@ class YamlFileLoader extends FileLoader
|
|||||||
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
|
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_string($tag['name']) || '' === $tag['name']) {
|
||||||
|
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
|
||||||
|
}
|
||||||
|
|
||||||
$name = $tag['name'];
|
$name = $tag['name'];
|
||||||
unset($tag['name']);
|
unset($tag['name']);
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@
|
|||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="tag">
|
<xsd:complexType name="tag">
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
<xsd:anyAttribute namespace="##any" processContents="lax" />
|
<xsd:anyAttribute namespace="##any" processContents="lax" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<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="BarClass">
|
||||||
|
<tag name="" foo="bar" />
|
||||||
|
</service>
|
||||||
|
</services>
|
||||||
|
</container>
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<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="BarClass">
|
||||||
|
<tag foo="bar" />
|
||||||
|
</service>
|
||||||
|
</services>
|
||||||
|
</container>
|
@ -0,0 +1,6 @@
|
|||||||
|
services:
|
||||||
|
foo_service:
|
||||||
|
class: FooClass
|
||||||
|
tags:
|
||||||
|
# tag name is an empty string
|
||||||
|
- { name: '', foo: bar }
|
@ -0,0 +1,6 @@
|
|||||||
|
services:
|
||||||
|
foo_service:
|
||||||
|
class: FooClass
|
||||||
|
tags:
|
||||||
|
# tag name is not a string
|
||||||
|
- { name: [], foo: bar }
|
@ -13,6 +13,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader;
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||||
@ -268,6 +269,27 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testParseTagsWithoutNameThrowsException()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||||
|
$loader->load('tag_without_name.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||||
|
* @expectedExceptionMessageRegExp /The tag name for service ".+" in .* must be a non-empty string/
|
||||||
|
*/
|
||||||
|
public function testParseTagWithEmptyNameThrowsException()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||||
|
$loader->load('tag_with_empty_name.xml');
|
||||||
|
}
|
||||||
|
|
||||||
public function testConvertDomElementToArray()
|
public function testConvertDomElementToArray()
|
||||||
{
|
{
|
||||||
$doc = new \DOMDocument('1.0');
|
$doc = new \DOMDocument('1.0');
|
||||||
|
@ -277,4 +277,24 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(array(true), $definition->getArguments());
|
$this->assertEquals(array(true), $definition->getArguments());
|
||||||
$this->assertEquals(array('manager' => array(array('alias' => 'user'))), $definition->getTags());
|
$this->assertEquals(array('manager' => array(array('alias' => 'user'))), $definition->getTags());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||||
|
* @expectedExceptionMessageRegExp /The tag name for service ".+" in .+ must be a non-empty string/
|
||||||
|
*/
|
||||||
|
public function testTagWithEmptyNameThrowsException()
|
||||||
|
{
|
||||||
|
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
||||||
|
$loader->load('tag_name_empty_string.yml');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||||
|
* @expectedExceptionMessageREgExp /The tag name for service "\.+" must be a non-empty string/
|
||||||
|
*/
|
||||||
|
public function testTagWithNonStringNameThrowsException()
|
||||||
|
{
|
||||||
|
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
||||||
|
$loader->load('tag_name_no_string.yml');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,6 +273,30 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$translator->trans('foo');
|
$translator->trans('foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFallbackCatalogueResources()
|
||||||
|
{
|
||||||
|
$translator = new Translator('en_GB', new MessageSelector());
|
||||||
|
$translator->addLoader('yml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
|
||||||
|
$translator->addResource('yml', __DIR__.'/fixtures/empty.yml', 'en_GB');
|
||||||
|
$translator->addResource('yml', __DIR__.'/fixtures/resources.yml', 'en');
|
||||||
|
|
||||||
|
// force catalogue loading
|
||||||
|
$this->assertEquals('bar', $translator->trans('foo', array()));
|
||||||
|
|
||||||
|
$cataloguesProperty = new \ReflectionProperty($translator, 'catalogues');
|
||||||
|
$cataloguesProperty->setAccessible(true);
|
||||||
|
$catalogues = $cataloguesProperty->getValue($translator);
|
||||||
|
|
||||||
|
$resources = $catalogues['en']->getResources();
|
||||||
|
$this->assertCount(1, $resources);
|
||||||
|
$this->assertContains( __DIR__.'/fixtures/resources.yml', $resources);
|
||||||
|
|
||||||
|
$resources = $catalogues['en_GB']->getResources();
|
||||||
|
$this->assertCount(2, $resources);
|
||||||
|
$this->assertContains( __DIR__.'/fixtures/empty.yml', $resources);
|
||||||
|
$this->assertContains( __DIR__.'/fixtures/resources.yml', $resources);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getTransTests
|
* @dataProvider getTransTests
|
||||||
*/
|
*/
|
||||||
|
@ -424,6 +424,9 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
|
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
|
||||||
|
foreach ($this->catalogues[$fallback]->getResources() as $resource) {
|
||||||
|
$fallbackCatalogue->addResource($resource);
|
||||||
|
}
|
||||||
$current->addFallbackCatalogue($fallbackCatalogue);
|
$current->addFallbackCatalogue($fallbackCatalogue);
|
||||||
$current = $fallbackCatalogue;
|
$current = $fallbackCatalogue;
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,7 @@ use Symfony\Component\Yaml\Exception\ParseException;
|
|||||||
class Yaml
|
class Yaml
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Parses YAML into a PHP array.
|
* Parses YAML into a PHP value.
|
||||||
*
|
|
||||||
* The parse method, when supplied with a YAML stream (string or file),
|
|
||||||
* will do its best to convert YAML in a file into a PHP array.
|
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* <code>
|
* <code>
|
||||||
@ -43,7 +40,7 @@ class Yaml
|
|||||||
* @param bool $objectSupport True if object support is enabled, false otherwise
|
* @param bool $objectSupport True if object support is enabled, false otherwise
|
||||||
* @param bool $objectForMap True if maps should return a stdClass instead of array()
|
* @param bool $objectForMap True if maps should return a stdClass instead of array()
|
||||||
*
|
*
|
||||||
* @return array The YAML converted to a PHP array
|
* @return mixed The YAML converted to a PHP value
|
||||||
*
|
*
|
||||||
* @throws ParseException If the YAML is not valid
|
* @throws ParseException If the YAML is not valid
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user