@@ -50,7 +50,7 @@ public function load($resource, $type = null)
50
50
$ this ->parseImports ($ xml , $ path );
51
51
52
52
// parameters
53
- $ this ->parseParameters ($ xml );
53
+ $ this ->parseParameters ($ xml, $ path );
54
54
55
55
// extensions
56
56
$ this ->loadFromExtensions ($ xml );
@@ -83,11 +83,12 @@ public function supports($resource, $type = null)
83
83
* Parses parameters.
84
84
*
85
85
* @param \DOMDocument $xml
86
+ * @param string $file
86
87
*/
87
- private function parseParameters (\DOMDocument $ xml )
88
+ private function parseParameters (\DOMDocument $ xml, $ file )
88
89
{
89
90
if ($ parameters = $ this ->getChildren ($ xml ->documentElement , 'parameters ' )) {
90
- $ this ->container ->getParameterBag ()->add ($ this ->getArgumentsAsPhp ($ parameters [0 ], 'parameter ' ));
91
+ $ this ->container ->getParameterBag ()->add ($ this ->getArgumentsAsPhp ($ parameters [0 ], 'parameter ' , $ file ));
91
92
}
92
93
}
93
94
@@ -266,8 +267,8 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults =
266
267
$ definition ->setDeprecated (true , $ deprecated [0 ]->nodeValue ?: null );
267
268
}
268
269
269
- $ definition ->setArguments ($ this ->getArgumentsAsPhp ($ service , 'argument ' , false , $ definition instanceof ChildDefinition));
270
- $ definition ->setProperties ($ this ->getArgumentsAsPhp ($ service , 'property ' ));
270
+ $ definition ->setArguments ($ this ->getArgumentsAsPhp ($ service , 'argument ' , $ file , false , $ definition instanceof ChildDefinition));
271
+ $ definition ->setProperties ($ this ->getArgumentsAsPhp ($ service , 'property ' , $ file ));
271
272
272
273
if ($ factories = $ this ->getChildren ($ service , 'factory ' )) {
273
274
$ factory = $ factories [0 ];
@@ -300,7 +301,7 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults =
300
301
}
301
302
302
303
foreach ($ this ->getChildren ($ service , 'call ' ) as $ call ) {
303
- $ definition ->addMethodCall ($ call ->getAttribute ('method ' ), $ this ->getArgumentsAsPhp ($ call , 'argument ' ));
304
+ $ definition ->addMethodCall ($ call ->getAttribute ('method ' ), $ this ->getArgumentsAsPhp ($ call , 'argument ' , $ file ));
304
305
}
305
306
306
307
$ tags = $ this ->getChildren ($ service , 'tag ' );
@@ -434,11 +435,12 @@ private function processAnonymousServices(\DOMDocument $xml, $file)
434
435
*
435
436
* @param \DOMElement $node
436
437
* @param string $name
438
+ * @param string $file
437
439
* @param bool $lowercase
438
440
*
439
441
* @return mixed
440
442
*/
441
- private function getArgumentsAsPhp (\DOMElement $ node , $ name , $ lowercase = true , $ isChildDefinition = false )
443
+ private function getArgumentsAsPhp (\DOMElement $ node , $ name , $ file , $ lowercase = true , $ isChildDefinition = false )
442
444
{
443
445
$ arguments = array ();
444
446
foreach ($ this ->getChildren ($ node , $ name ) as $ arg ) {
@@ -474,6 +476,9 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true,
474
476
475
477
switch ($ arg ->getAttribute ('type ' )) {
476
478
case 'service ' :
479
+ if (!$ arg ->getAttribute ('id ' )) {
480
+ throw new InvalidArgumentException (sprintf ('Tag "<%s>" with type="service" has no or empty "id" attribute in "%s". ' , $ name , $ file ));
481
+ }
477
482
if ($ arg ->hasAttribute ('strict ' )) {
478
483
@trigger_error (sprintf ('The "strict" attribute used when referencing the "%s" service is deprecated since version 3.3 and will be removed in 4.0. ' , $ arg ->getAttribute ('id ' )), E_USER_DEPRECATED );
479
484
}
@@ -484,17 +489,23 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true,
484
489
$ arguments [$ key ] = new Expression ($ arg ->nodeValue );
485
490
break ;
486
491
case 'closure-proxy ' :
492
+ if (!$ arg ->getAttribute ('id ' )) {
493
+ throw new InvalidArgumentException (sprintf ('Tag "<%s>" with type="closure-proxy" has no or empty "id" attribute in "%s". ' , $ name , $ file ));
494
+ }
495
+ if (!$ arg ->getAttribute ('method ' )) {
496
+ throw new InvalidArgumentException (sprintf ('Tag "<%s>" with type="closure-proxy" has no or empty "method" attribute in "%s". ' , $ name , $ file ));
497
+ }
487
498
$ arguments [$ key ] = new ClosureProxyArgument ($ arg ->getAttribute ('id ' ), $ arg ->getAttribute ('method ' ), $ invalidBehavior );
488
499
break ;
489
500
case 'collection ' :
490
- $ arguments [$ key ] = $ this ->getArgumentsAsPhp ($ arg , $ name , false );
501
+ $ arguments [$ key ] = $ this ->getArgumentsAsPhp ($ arg , $ name , $ file , false );
491
502
break ;
492
503
case 'iterator ' :
493
- $ arg = $ this ->getArgumentsAsPhp ($ arg , $ name , false );
504
+ $ arg = $ this ->getArgumentsAsPhp ($ arg , $ name , $ file , false );
494
505
try {
495
506
$ arguments [$ key ] = new IteratorArgument ($ arg );
496
507
} catch (InvalidArgumentException $ e ) {
497
- throw new InvalidArgumentException (sprintf ('Tag "<%s>" with type="iterator" only accepts collections of type="service" references. ' , $ name ));
508
+ throw new InvalidArgumentException (sprintf ('Tag "<%s>" with type="iterator" only accepts collections of type="service" references in "%s" . ' , $ name, $ file ));
498
509
}
499
510
break ;
500
511
case 'string ' :
0 commit comments