8000 Merge branch '2.7' into 2.8 · symfony/symfony@2f4cdb9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f4cdb9

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: backport GlobTest from 2.7 branch [FrameworkBundle] Remove unused code in test [2.3] Fixed an undefined variable in Glob::toRegex simplified a test fix container cache key generation [Form] fix option name in changelog [Translation] Add resources from fallback locale [DependencyInjection] enforce tags to have a name [YAML] Refine the return value of Yaml::parse()
2 parents 6232b23 + bb20503 commit 2f4cdb9

File tree

15 files changed

+114
-10
lines changed

15 files changed

+114
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ protected function createContainer(array $data = array())
513513

514514
protected function createContainerFromFile($file, $data = array())
515515
{
516-
$cacheKey = md5($file.serialize($data));
516+
$cacheKey = md5(get_class($this).$file.serialize($data));
517517
if (isset(self::$containerCache[$cacheKey])) {
518518
return self::$containerCache[$cacheKey];
519519
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function loadFromFile(ContainerBuilder $container, $file)
2828
*/
2929
public function testAssetsCannotHavePathAndUrl()
3030
{
31-
$container = $this->createContainerFromClosure(function ($container) {
31+
$this->createContainerFromClosure(function ($container) {
3232
$container->loadFromExtension('framework', array(
3333
'assets' => array(
3434
'base_urls' => 'http://cdn.example.com',
@@ -43,7 +43,7 @@ public function testAssetsCannotHavePathAndUrl()
4343
*/
4444
public function testAssetPackageCannotHavePathAndUrl()
4545
{
46-
$container = $this->createContainerFromClosure(function ($container) {
46+
$this->createContainerFromClosure(function ($container) {
4747
$container->loadFromExtension('framework', array(
4848
'assets' => array(
4949
'packages' => array(

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ private function parseDefinition(\DOMElement $service, $file)
249249
$parameters[$name] = XmlUtils::phpize($node->nodeValue);
250250
}
251251

252+
if ('' === $tag->getAttribute('name')) {
253+
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', (string) $service->getAttribute('id'), $file));
254+
}
255+
252256
$definition->addTag($tag->getAttribute('name'), $parameters);
253257
}
254258

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ private function parseDefinition($id, $service, $file)
281281
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
282282
}
283283

284+
if (!is_string($tag['name']) || '' === $tag['name']) {
285+
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
286+
}
287+
284288
$name = $tag['name'];
285289
unset($tag['name']);
286290

src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
</xsd:complexType>
109109

110110
<xsd:complexType name="tag">
111-
<xsd:attribute name="name" type="xsd:string" />
111+
<xsd:attribute name="name" type="xsd:string" use="required" />
112112
<xsd:anyAttribute namespace="##any" processContents="lax" />
113113
</xsd:complexType>
114114

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="foo" class="BarClass">
8+
<tag name="" foo="bar" />
9+
</service>
10+
</services>
11+
</container>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="foo" class="BarClass">
8+
<tag foo="bar" />
9+
</service>
10+
</services>
11+
</container>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
foo_service:
3+
class: FooClass
4+
tags:
5+
# tag name is an empty string
6+
- { name: '', foo: bar }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
foo_service:
3+
class: FooClass
4+
tags:
5+
# tag name is not a string
6+
- { name: [], foo: bar }

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\DependencyInjection\ContainerInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1617
use Symfony\Component\DependencyInjection\Reference;
1718
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1819
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
@@ -270,6 +271,27 @@ public function testParsesTags()
270271
}
271272
}
272273

274+
/**
275+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
276+
*/
277+
public function testParseTagsWithoutNameThrowsException()
278+
{
279+
$container = new ContainerBuilder();
280+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
281+
$loader->load('tag_without_name.xml');
282+
}
283+
284+
/**
285+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
286+
* @expectedExceptionMessageRegExp /The tag name for service ".+" in .* must be a non-empty string/
287+
*/
288+
public function testParseTagWithEmptyNameThrowsException()
289+
{
290+
$container = new ContainerBuilder();
291+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
292+
$loader->load('tag_with_empty_name.xml');
293+
}
294+
273295
public function testConvertDomElementToArray()
274296
{
275297
$doc = new \DOMDocument('1.0');

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,26 @@ public function testTypesNotArray()
289289
$loader->load('bad_types1.yml');
290290
}
291291

292+
/**
293+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
294+
* @expectedExceptionMessageRegExp /The tag name for service ".+" in .+ must be a non-empty string/
295+
*/
296+
public function testTagWithEmptyNameThrowsException()
297+
{
298+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
299+
$loader->load('tag_name_empty_string.yml');
300+
}
301+
302+
/**
303+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
304+
* @expectedExceptionMessageREgExp /The tag name for service "\.+" must be a non-empty string/
305+
*/
306+
public function testTagWithNonStringNameThrowsException()
307+
{
308+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
309+
$loader->load('tag_name_no_string.yml');
310+
}
311+
292312
/**
293313
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
294314
*/

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ CHANGELOG
7373

7474
* moved CSRF implementation to the new Security CSRF sub-component
7575
* deprecated CsrfProviderInterface and its implementations
76-
* deprecated options "csrf_provider" and "intention" in favor of the new options "csrf_token_generator" and "csrf_token_id"
76+
* deprecated options "csrf_provider" and "intention" in favor of the new options "csrf_token_manager" and "csrf_token_id"
7777

7878
2.3.0
7979
-----

src/Symfony/Component/Translation/Tests/TranslatorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,26 @@ public function testWhenAResourceHasNoRegisteredLoader()
273273
$translator->trans('foo');
274274
}
275275

276+
public function testFallbackCatalogueResources()
277+
{
278+
$translator = new Translator('en_GB', new MessageSelector());
279+
$translator->addLoader('yml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
280+
$translator->addResource('yml', __DIR__.'/fixtures/empty.yml', 'en_GB');
281+
$translator->addResource('yml', __DIR__.'/fixtures/resources.yml', 'en');
282+
283+
// force catalogue loading
284+
$this->assertEquals('bar', $translator->trans('foo', array()));
285+
286+
$resources = $translator->getCatalogue('en')->getResources();
287+
$this->assertCount(1, $resources);
288+
$this->assertContains( __DIR__.'/fixtures/resources.yml', $resources);
289+
290+
$resources = $translator->getCatalogue('en_GB')->getResources();
291+
$this->assertCount(2, $resources);
292+
$this->assertContains( __DIR__.'/fixtures/empty.yml', $resources);
293+
$this->assertContains( __DIR__.'/fixtures/resources.yml', $resources);
294+
}
295+
276296
/**
277297
* @dataProvider getTransTests
278298
*/

src/Symfony/Component/Translation/Translator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ private function loadFallbackCatalogues($locale)
428428
}
429429

430430
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
431+
foreach ($this->catalogues[$fallback]->getResources() as $resource) {
432+
$fallbackCatalogue->addResource($resource);
433+
}
431434
$current->addFallbackCatalogue($fallbackCatalogue);
432435
$current = $fallbackCatalogue;
433436
}

src/Symfony/Component/Yaml/Yaml.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
class Yaml
2222
{
2323
/**
24-
* Parses YAML into a PHP array.
25-
*
26-
* The parse method, when supplied with a YAML stream (string or file),
27-
* will do its best to convert YAML in a file into a PHP array.
24+
* Parses YAML into a PHP value.
2825
*
2926
* Usage:
3027
* <code>
@@ -43,7 +40,7 @@ class Yaml
4340
* @param bool $objectSupport True if object support is enabled, false otherwise
4441
* @param bool $objectForMap True if maps should return a stdClass instead of array()
4542
*
46-
* @return array The YAML converted to a PHP array
43+
* @return mixed The YAML converted to a PHP value
4744
*
4845
* @throws ParseException If the YAML is not valid
4946
*/

0 commit comments

Comments
 (0)
0