data = $data; } /** * @param ReflectionClass|null $class */ public function has(?ReflectionClass $class, ReflectionParameter $param): bool { if ($this->getInternal($class, $param) === null) { return false; } return true; } /** * @param ReflectionClass|null $class */ public function get(?ReflectionClass $class, ReflectionParameter $param): Binding { if (!$this->has($class, $param)) { throw new LogicException("BindingContainer: Can't get not existing binding."); } /** @var Binding */ return $this->getInternal($class, $param); } /** * @param ReflectionClass|null $class */ private function getInternal(?ReflectionClass $class, ReflectionParameter $param): ?Binding { $className = null; $key = null; if ($class) { $className = $class->getName(); $key = '$' . $param->getName(); } if ($className && $key && $this->data->hasContext($className, $key)) { return $this->data->getContext($className, $key); } $dependencyClassName = null; $type = $param->getType(); if ( $type && $type instanceof ReflectionNamedType && !$type->isBuiltin() ) { $dependencyClassName = $type->getName(); } $key = null; $keyWithParamName = null; if ($dependencyClassName) { $key = $dependencyClassName; $keyWithParamName = $key . ' $' . $param->getName(); } if ($keyWithParamName) { if ($className && $this->data->hasContext($className, $keyWithParamName)) { return $this->data->getContext($className, $keyWithParamName); } if ($this->data->hasGlobal($keyWithParamName)) { return $this->data->getGlobal($keyWithParamName); } } if ($key) { if ($className && $this->data->hasContext($className, $key)) { return $this->data->getContext($className, $key); } if ($this->data->hasGlobal($key)) { return $this->data->getGlobal($key); } } return null; } }