Skip to content

Commit 78d5481

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: 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 45adbd1 + 4508d2f commit 78d5481

File tree

4 files changed

+28
-73
lines changed

4 files changed

+28
-73
lines changed

Loader/YamlFileLoader.php

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

301301
if (isset($service['decorates'])) {
302+
if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
303+
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)));
304+
}
305+
302306
$renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
303307
$priority = isset($service['decoration_priority']) ? $service['decoration_priority'] : 0;
304308
$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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,14 @@ public function testAutowire()
336336

337337
$this->assertTrue($container->getDefinition('bar_service')->isAutowired());
338338
}
339+
340+
/**
341+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
342+
* @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").
343+
*/
344+
public function testDecoratedServicesWithWrongSyntaxThrowsException()
345+
{
346+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
347+
$loader->load('bad_decorates.yml');
348+
}
339349
}

0 commit comments

Comments
 (0)