Validates the scope of a single Reference.
Reference $reference:
Definition $definition:
ScopeWideningInjectionException when the definition references a service of a narrower scope
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()) {
return;
}
if (null === $definition) {
return;
}
if ($this->currentScope === ($scope = $definition
->getScope())) {
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);
}
}