Skip to content

Commit 8ec9151

Browse files
committed
Merge branch '3.0'
* 3.0: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by #16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
2 parents 9d54eec + b3d2a2e commit 8ec9151

File tree

4 files changed

+23
-104
lines changed

4 files changed

+23
-104
lines changed

Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ private function parseDefinition($id, $service, $file)
304304
}
305305

306306
if (isset($service['decorates'])) {
307+
if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
308+
throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['decorates'], substr($service['decorates'], 1)));
309+
}
310+
307311
$renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
308312
$priority = isset($service['decoration_priority']) ? $service['decoration_priority'] : 0;
309313
$definition->setDecoratedService($service['decorates'], $renameId, $priority);

README.md

Lines changed: 7 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,14 @@
11
DependencyInjection Component
22
=============================
33

4-
DependencyInjection manages your services via a robust and flexible Dependency
5-
Injection Container.
6-
7-
Here is a simple example that shows how to register services and parameters:
8-
9-
```php
10-
use Symfony\Component\DependencyInjection\ContainerBuilder;
11-
use Symfony\Component\DependencyInjection\Reference;
12-
13-
$sc = new ContainerBuilder();
14-
$sc
15-
->register('foo', '%foo.class%')
16-
->addArgument(new Reference('bar'))
17-
;
18-
$sc->setParameter('foo.class', 'Foo');
19-
20-
$sc->get('foo');
21-
```
22-
23-
Method Calls (Setter Injection):
24-
25-
```php
26-
$sc = new ContainerBuilder();
27-
28-
$sc
29-
->register('bar', '%bar.class%')
30-
->addMethodCall('setFoo', array(new Reference('foo')))
31-
;
32-
$sc->setParameter('bar.class', 'Bar');
33-
34-
$sc->get('bar');
35-
```
36-
37-
Factory Class:
38-
39-
If your service is retrieved by calling a static method:
40-
41-
```php
42-
$sc = new ContainerBuilder();
43-
44-
$sc
45-
->register('bar', '%bar.class%')
46-
->setFactory(array('%bar.class%', 'getInstance'))
47-
->addArgument('Aarrg!!!')
48-
;
49-
$sc->setParameter('bar.class', 'Bar');
50-
51-
$sc->get('bar');
52-
```
53-
54-
File Include:
55-
56-
For some services, especially those that are difficult or impossible to
57-
autoload, you may need the container to include a file before
58-
instantiating your class.
59-
60-
```php
61-
$sc = new ContainerBuilder();
62-
63-
$sc
64-
->register('bar', '%bar.class%')
65-
->setFile('/path/to/file')
66-
->addArgument('Aarrg!!!')
67-
;
68-
$sc->setParameter('bar.class', 'Bar');
69-
70-
$sc->get('bar');
71-
```
4+
The DependencyInjection component allows you to standardize and centralize the
5+
way objects are constructed in your application.
726

737
Resources
748
---------
759

76-
You can run the unit tests with the following command:
77-
78-
$ cd path/to/Symfony/Component/DependencyInjection/
79-
$ composer install
80-
$ phpunit
10+
* [Documentation](https://symfony.com/doc/current/components/dependency_injection/index.html)
11+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
12+
* [Report issues](https://github.com/symfony/symfony/issues) and
13+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
14+
in the [main Symfony repository](https://github.com/symfony/symfony)

Tests/Fixtures/yaml/bad_decorates.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
foo:
3+
class: stdClass
4+
bar:
5+
class: stdClass
6+
decorates: "@foo"
7+
arguments: ["@bar.inner"]

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -315,38 +315,12 @@ public function testAutowire()
315315
}
316316

317317
/**
318-
* @group legacy
319-
*/
320-
public function testServiceDefinitionContainsUnsupportedKeywords()
321-
{
322-
$container = new ContainerBuilder();
323-
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
324-
$loader->load('legacy_invalid_definition.yml');
325-
}
326-
327-
/**
328-
* @group legacy
318+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
319+
* @expectedExceptionMessage The value of the "decorates" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" with "foo").
329320
*/
330-
public function testAliasDefinitionContainsUnsupportedKeywords()
321+
public function testDecoratedServicesWithWrongSyntaxThrowsException()
331322
{
332-
$container = new ContainerBuilder();
333-
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
334-
335-
$deprecations = array();
336-
set_error_handler(function ($type, $msg) use (&$deprecations) {
337-
if (E_USER_DEPRECATED === $type) {
338-
$deprecations[] = $msg;
339-
}
340-
});
341-
342-
$loader->load('legacy_invalid_alias_definition.yml');
343-
344-
$this->assertTrue($container->has('foo'));
345-
346-
$this->assertCount(2, $deprecations);
347-
$this->assertContains('The configuration key "factory" is unsupported for alias definition "foo"', $deprecations[0]);
348-
$this->assertContains('The configuration key "parent" is unsupported for alias definition "foo"', $deprecations[1]);
349-
350-
restore_error_handler();
323+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
324+
$loader->load('bad_decorates.yml');
351325
}
352326
}

0 commit comments

Comments
 (0)