-
- $this->validateReferences($definition->getArguments());
- $this->validateReferences($definition->getMethodCalls());
- $this->validateReferences($definition->getProperties());
- }
- }
-
- /**
- * Validates an array of References.
- *
- * @param array $arguments An array of Reference objects
- *
- * @throws RuntimeException when there is a reference to an abstract definition.
- */
- private function validateReferences(array $arguments)
- {
- foreach ($arguments as $argument) {
- if (is_array($argument)) {
- $this->validateReferences($argument);
- } elseif ($argument instanceof Reference) {
- $targetDefinition = $this->getDefinition((string) $argument);
-
- if (null !== $targetDefinition && $targetDefinition->isAbstract()) {
- throw new RuntimeException(sprintf(
- 'The definition "%s" has a reference to an abstract definition "%s". '
- .'Abstract definitions cannot be the target of references.',
- $this->currentId,
- $argument
- ));
- }
-
- $this->validateScope($argument, $targetDefinition);
- }
- }
- }
-
- /**
- * Validates the scope of a single Reference.
- *
- * @param Reference $reference
- * @param Definition $definition
- *
- * @throws ScopeWideningInjectionException when the definition references a service of a narrower scope
- * @throws ScopeCrossingInjectionException when the definition references a service of another scope hierarchy
- */
- private function validateScope(Reference $reference, Definition $definition = null)
- {
- if (ContainerInterface::SCOPE_PROTOTYPE === $this->currentScope) {
- return;
- }
-
- if (!$reference->isStrict(false)) {
- return;
- }
-
- if (null === $definition) {
- return;
- }
-
- if ($this->currentScope === $scope = $definition->getScope(false)) {
- return;
- }
-
- $id = (string) $reference;
-
- if (in_array($scope, $this->currentScopeChildren, true)) {
- throw new ScopeWideningInjectionException($this->currentId, $this->currentScope, $id, $scope);
- }
-
- if (!in_array($scope, $this->currentScopeAncestors, true)) {
- throw new ScopeCrossingInjectionException($this->currentId, $this->currentScope, $id, $scope);
- }
- }
-
- /**
- * Returns the Definition given an id.
- *
- * @param string $id Definition identifier
- *
- * @return Definition
- */
- private function getDefinition($id)
- {
- if (!$this->container->hasDefinition($id)) {
- return;