@@ -50,7 +50,7 @@ public function load($resource, $type = null)
5050 $ this ->parseImports ($ xml , $ path );
5151
5252 // parameters
53- $ this ->parseParameters ($ xml );
53+ $ this ->parseParameters ($ xml, $ path );
5454
5555 // extensions
5656 $ this ->loadFromExtensions ($ xml );
@@ -83,11 +83,12 @@ public function supports($resource, $type = null)
8383 * Parses parameters.
8484 *
8585 * @param \DOMDocument $xml
86+ * @param string $file
8687 */
87- private function parseParameters (\DOMDocument $ xml )
88+ private function parseParameters (\DOMDocument $ xml, $ file )
8889 {
8990 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 ));
9192 }
9293 }
9394
@@ -266,8 +267,8 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults =
266267 $ definition ->setDeprecated (true , $ deprecated [0 ]->nodeValue ?: null );
267268 }
268269
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 ));
271272
272273 if ($ factories = $ this ->getChildren ($ service , 'factory ' )) {
273274 $ factory = $ factories [0 ];
@@ -300,7 +301,7 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults =
300301 }
301302
302303 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 ));
304305 }
305306
306307 $ tags = $ this ->getChildren ($ service , 'tag ' );
@@ -434,11 +435,12 @@ private function processAnonymousServices(\DOMDocument $xml, $file)
434435 *
435436 * @param \DOMElement $node
436437 * @param string $name
438+ * @param string $file
437439 * @param bool $lowercase
438440 *
439441 * @return mixed
440442 */
441- private function getArgumentsAsPhp (\DOMElement $ node , $ name , $ lowercase = true , $ isChildDefinition = false )
443+ private function getArgumentsAsPhp (\DOMElement $ node , $ name , $ file , $ lowercase = true , $ isChildDefinition = false )
442444 {
443445 $ arguments = array ();
444446 foreach ($ this ->getChildren ($ node , $ name ) as $ arg ) {
@@ -474,6 +476,9 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true,
474476
475477 switch ($ arg ->getAttribute ('type ' )) {
476478 case 'service ' :
479+ if (!$ arg ->getAttribute ('id ' )) {
480+ throw new InvalidArgumentException (sprintf ('Tag "<%s>" with type="service" is missing an "id" attribute in "%s". ' , $ name , $ file ));
481+ }
477482 if ($ arg ->hasAttribute ('strict ' )) {
478483 @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 );
479484 }
@@ -484,17 +489,23 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true,
484489 $ arguments [$ key ] = new Expression ($ arg ->nodeValue );
485490 break ;
486491 case 'closure-proxy ' :
492+ if (!$ arg ->getAttribute ('id ' )) {
493+ throw new InvalidArgumentException (sprintf ('Tag "<%s>" with type="service" is missing an "id" attribute in "%s". ' , $ name , $ file ));
494+ }
495+ if (!$ arg ->getAttribute ('method ' )) {
496+ throw new InvalidArgumentException (sprintf ('Tag "<%s>" with type="service" is missing a "method" attribute in "%s". ' , $ name , $ file ));
497+ }
487498 $ arguments [$ key ] = new ClosureProxyArgument ($ arg ->getAttribute ('id ' ), $ arg ->getAttribute ('method ' ), $ invalidBehavior );
488499 break ;
489500 case 'collection ' :
490- $ arguments [$ key ] = $ this ->getArgumentsAsPhp ($ arg , $ name , false );
501+ $ arguments [$ key ] = $ this ->getArgumentsAsPhp ($ arg , $ name , $ file , false );
491502 break ;
492503 case 'iterator ' :
493- $ arg = $ this ->getArgumentsAsPhp ($ arg , $ name , false );
504+ $ arg = $ this ->getArgumentsAsPhp ($ arg , $ name , $ file , false );
494505 try {
495506 $ arguments [$ key ] = new IteratorArgument ($ arg );
496507 } 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 ));
498509 }
499510 break ;
500511 case 'string ' :
0 commit comments