Commit e9e4869
committed
feature #17132 [DependencyInjection] Properly ignore invalid reference arguments in collection arguments (ogizanagi)
This PR was merged into the 3.1-dev branch.
Discussion
----------
[DependencyInjection] Properly ignore invalid reference arguments in collection arguments
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
With this new feature, the following configuration:
```xml
<service id="baz" class="Baz"/>
<service id="foo" class="Foo">
<argument type="collection">
<argument type="service" id="bar" on-invalid="ignore" />
<argument type="service" id="baz" />
<argument type="service" id="moo" on-invalid="null" />
</argument>
<argument type="service" id="bar" on-invalid="ignore" />
<argument type="service" id="baz" />
<argument type="service" id="moo" on-invalid="null" />
<call method="foo">
<argument type="service" id="bar" on-invalid="ignore" />
</call>
<call method="fooCollection">
<argument type="collection">
<argument type="service" id="bar" on-invalid="ignore" />
<argument type="service" id="baz" />
<argument type="service" id="moo" on-invalid="null" />
</argument>
</call>
</service>
```
will result into the following `Definition`:
```php
Definition {#64 ▼
-class: "Foo"
// […]
-calls: array:1 [▼
0 => array:2 [▼
0 => "fooCollection"
1 => array:1 [▼
0 => array:2 [▼
0 => Reference {#59 ▼
-id: "baz"
-invalidBehavior: 1
}
1 => null
]
]
]
]
// […]
#arguments: array:4 [▼
0 => array:2 [▼
0 => Reference {#63 ▼
-id: "baz"
-invalidBehavior: 1
}
1 => null
]
1 => null
2 => Reference {#56 ▼
-id: "baz"
-invalidBehavior: 1
}
3 => null
]
}
```
Invalid references are ignored instead of replaced by `null` when they are part of a collection argument.
If the collection argument is part of a method call and contains an invalid reference, the method call is kept, but the invalid reference removed.
The behavior stays the same as before for non-collection arguments.
:christmas_tree:
Commits
-------
cfc4879 [DependencyInjection] Properly ignore invalid reference arguments in collection arguments2 files changed
Lines changed: 62 additions & 4 deletions
File tree
- src/Symfony/Component/DependencyInjection
- Compiler
- Tests/Compiler
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
| 80 | + | |
80 | 81 | | |
| 82 | + | |
| 83 | + | |
81 | 84 | | |
82 | 85 | | |
83 | | - | |
| 86 | + | |
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
| |||
91 | 94 | | |
92 | 95 | | |
93 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
94 | 101 | | |
95 | 102 | | |
96 | 103 | | |
| |||
100 | 107 | | |
101 | 108 | | |
102 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
103 | 115 | | |
104 | 116 | | |
105 | 117 | | |
Lines changed: 48 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
33 | | - | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
37 | 83 | | |
38 | 84 | | |
39 | 85 | | |
| |||
0 commit comments