Performs the check for circular references and returns the referenced object.

@param $requiredClass
@param $dataTypeName

@throws BuildException

@return mixed
336085
public function getCheckedRef($requiredClass, $dataTypeName)
    {
        if (!$this->checked) {
            // should be in stack
            $stk = [];
            $stk[] = $this;
            $this->dieOnCircularReference($stk, $this->getProject());
        }

        $o = $this->ref->getReferencedObject($this->getProject());
        if (!($o instanceof $requiredClass)) {
            throw new BuildException($this->ref->getRefId() . " doesn't denote a " . $dataTypeName);
        } else {
            return $o;
        }
    }
44963
public function lookup($id, $required = true) {
		if ($id instanceof \ReflectionClass) {
			$id = $id->getName();
		}
		
		// @todo check $required
		switch ($id) {
			case Request::class:
				try {
					return $this->getHttpContext()->getRequest();
				} catch (HttpContextNotAvailableException $e) {
					if (!$required) return null;
					throw new MagicObjectUnavailableException('Request not available.', 0, $e); 
				}
				return $this->request;
			case Response::class:
				try {
					return $this->getHttpContext()->getResponse();
				} catch (HttpContextNotAvailableException $e) {
					if (!$required) return null;
					throw new MagicObjectUnavailableException('Response not available.', 0, $e); 
				}
			case Session::class:
				try {
					return $this->getHttpContext()->getSession();
				} catch (HttpContextNotAvailableException $e) {
					if (!$required) return null;
					throw new MagicObjectUnavailableException('Session not available.', 0, $e);
				}
			case HttpContext::class:
				try {
					return $this->getHttpContext();
				} catch (HttpContextNotAvailableException $e) {
					if (!$required) return null;
					throw new MagicObjectUnavailableException('HttpContext not available.', 0, $e);
				}
			case N2nContext::class:
				return $this;
			case LookupManager::class:
				return $this->getLookupManager();
			case N2nLocale::class:
				return $this->getN2nLocale();
			case EntityManager::class:
				return $this->lookup(PdoPool::class)->getEntityManagerFactory()->getExtended();
			case EntityManagerFactory::class:
				return $this->lookup(PdoPool::class)->getEntityManagerFactory();
			case TransactionManager::class:
				return $this->transactionManager;
			case VarStore::class:
				return $this->varStore;
			case AppCache::class:
				return $this->appCache;
			case AppConfig::class:
				return $this->appConfig;
			case GeneralConfig::class:
				return $this->appConfig->general();
			case WebConfig::class:
				return $this->appConfig->web();
			case MailConfig::class:
				return $this->appConfig->mail();
			case IoConfig::class:
				return $this->appConfig->io();
			case FilesConfig::class:
				return $this->appConfig->files();
			case ErrorConfig::class:
				return $this->appConfig->error();
			case DbConfig::class:
				return $this->appConfig->db();
			case OrmConfig::class:
				return $this->appConfig->orm();
			case N2nLocaleConfig::class:
				return $this->appConfig->locale();
			default:
				try {
					return $this->getLookupManager()->lookup($id);
				} catch (LookupFailedException $e) {
					throw new MagicObjectUnavailableException('Could not lookup object with name: ' . $id, 0, $e);
				}
		}
	}
887760
public function get($name, $paramsOverride = array())
    {
        $key             = $this->makeKey($name);
        $descriptor      = $this->describe($name);
        $reflectionClass = $descriptor->getReflectionClass();
        $class           = $reflectionClass->getName();

        if (in_array($class, $this->queue)) {
            $parent = end($this->queue);

            throw new CircularReferenceException("Circular dependency found for class '$class' in class '$parent'. Please use a setter method to resolve this.");
        }

        array_push($this->queue, $class);

        $params = $descriptor->getParams();

        if (!empty($paramsOverride)) {
            $paramsKeys     = array_map(array($descriptor, 'resolveParamName'), array_keys($paramsOverride));
            $paramsOverride = array_combine($paramsKeys, $paramsOverride);
            $params         = array_replace($params, $paramsOverride);
        }

        $args = $this->resolveParams($params);

        array_pop($this->queue);

        if ($descriptor->isShared() && isset($this->instances[$key])) {
            return $this->instances[$key];
        }

        if ($descriptor->isCloneable() && isset($this->instances[$key])) {
            return clone $this->instances[$key];
        }

        if (!$reflectionClass->isInstantiable()) {
            throw new RuntimeException("Class '$class' is is not instantiable");
        }

        $this->instances[$key] = null;

        if (empty($args)) {
            $instance = $reflectionClass->newInstance();
        }
        else {
            $instance = $reflectionClass->newInstanceArgs($args);
        }

        $this->instances[$key] = $instance;

        $this->executeActions($descriptor->getActions(), $this->instances[$key]);

        return $instance;
    }
1071361
public function createClassConstant(string $className, string $constantName): ClassConstFetch
    {
        $classNameNode = in_array($className, ['static', 'parent', 'self'], true) ? new Name(
            $className
        ) : new FullyQualified($className);

        $classConstFetchNode = $this->builderFactory->classConstFetch($classNameNode, $constantName);
        $classConstFetchNode->class->setAttribute(AttributeKey::RESOLVED_NAME, $classNameNode);

        return $classConstFetchNode;
    }
359147
Object _getDataService(T session, Class cls) throws DataServiceException {
		String dataServiceClassName = cls.getName();
		DataService dataServiceAnno = (DataService) cls.getAnnotation(DataService.class);
		IDataServiceResolver resolver = getResolver(dataServiceAnno.resolver());
		Scope scope = resolver.getScope(cls);
		Object dataService = null;
		Map<String, Object> sessionBeans = getSessionBeans(session);
		logger.debug("{} : scope : {}", dataServiceClassName, scope);
		if (scope.equals(Scope.SESSION)) {
			dataService = sessionBeans.get(dataServiceClassName);
			logger.debug("{} : scope : session is in session : {}", dataServiceClassName, (dataService != null));
		}
		if (dataService == null) {
			dataService = resolver.resolveDataService(cls);
			if (scope.equals(Scope.SESSION)) {
				logger.debug("Store {} scope session in session", dataServiceClassName);
				sessionBeans.put(dataServiceClassName, dataService);
			}
		}
		return dataService;
	}
833303
public function addAttribute($attributeName, $attributeType)
    {
        if (empty($attributeName) || empty($attributeType)) {
            throw new \InvalidArgumentException(sprintf('Attribute name "%s" and/or attribute type "%s" is invalid for Struct "%s"', $attributeName, $attributeType, $this->getName()), __LINE__);
        }
        if ($this->attributes->getStructAttributeByName($attributeName) === null) {
            $structAttribute = new StructAttribute($this->getGenerator(), $attributeName, $attributeType, $this);
            $this->attributes->add($structAttribute);
        }
        return $this;
    }
616987
public function getEntityBuilder($className = null, ClassMetadata $classMetadata = null)
    {
        $builder = new Entity\Builder($this->getMapper(), $this->getFieldManager());

        if ($className !== null) {
            $builder->setClass($className);
        }

        if ($classMetadata !== null) {
            $builder->setClassMetadata($classMetadata);
        }

        return $builder;
    }
1363461
protected function checkTraitDependencies($traitName)
    {
        if(isset($this->traitsDependencies[$traitName])) {
            $reflection = new \ReflectionClass($this);
            foreach($this->traitsDependencies[$traitName] as $requiredTrait) {
                $propertyName = 'has' . $requiredTrait;
                if(!$reflection->hasProperty($propertyName) || !$this->$propertyName) {
                    throw new \Exception(sprintf('Class %s uses %s trait but %s required trait is not used', $this->buildClassName($this->name), $traitName, $requiredTrait));
                }
            }
        }
    }
724371
protected function register($className, $type, $requiredBaseClass) {
        // check if the class is available for TYPO3 before registering the driver
        if (!class_exists($className)) {
            throw new \InvalidArgumentException('Class ' . $className . ' does not exist.', 1462883324);
        }

        if (!is_subclass_of($className, $requiredBaseClass)) {
            throw new \InvalidArgumentException('Parser ' . $className . ' needs to extend the ' . $requiredBaseClass . '.', 1462883325);
        }

        $this->classMap[$type] = $className;
    }
1182313
public function build(): CollectClassNamesRequest
	{
		$instance = new CollectClassNamesRequest();
		if ($this->styleSheetId === null) {
			throw new BuilderException('Property [styleSheetId] is required.');
		}
		$instance->styleSheetId = $this->styleSheetId;
		return $instance;
	}
13325
public function build(): RemoveBindingRequest
	{
		$instance = new RemoveBindingRequest();
		if ($this->name === null) {
			throw new BuilderException('Property [name] is required.');
		}
		$instance->name = $this->name;
		return $instance;
	}
35597
private function createType($typeClass)
    {
        if ($typeClass !== DataTableType::class && !is_subclass_of($typeClass, DataTableType::class)) {
            throw new \InvalidArgumentException("Class '$typeClass' must extends DataTableType class.");
        }

        if ($this->container->has($typeClass)) {
            return $this->container->get($typeClass);
        } else {
            return new $typeClass();
        }
    }
52975
public static function parse($typeName)
    {
        $normalize = array("int" => self::INTEGER_NAME, 
            "bool" => self::BOOLEAN_NAME, 
            "double" => self::FLOAT_NAME,
            "real" => self::FLOAT_NAME,
            "long" => self::INTEGER_NAME);

        if (isset($normalize[$typeName]))
            $typeName = $normalize[$typeName];

        if (self::$cachedTypes === null)
        {
            self::$cachedTypes = array(
                self::INTEGER_NAME => new PrimitiveType(self::INTEGER_NAME),
                self::FLOAT_NAME => new PrimitiveType(self::FLOAT_NAME),
                self::STRING_NAME => new PrimitiveType(self::STRING_NAME),
                self::BOOLEAN_NAME => new PrimitiveType(self::BOOLEAN_NAME),
                self::MIXED_NAME => new PrimitiveType(self::MIXED_NAME),
                self::RESOURCE_NAME => new PrimitiveType(self::RESOURCE_NAME),
                self::OBJECT_NAME => new PrimitiveType(self::OBJECT_NAME),
                self::NULL_NAME => new PrimitiveType(self::NULL_NAME),
                self::CALLABLE_NAME => new PrimitiveType(self::CALLABLE_NAME));
        }

        if (isset(self::$cachedTypes[$typeName]))
            return self::$cachedTypes[$typeName];

        return null;
    }
312346
public function getDataType(string $dataTypeHandle)
    {
        if (!isset($this->dataTypes[$dataTypeHandle])) {
            Schematic::error('DataType '.$dataTypeHandle.' is not registered');

            return null;
        }

        $dataTypeClass = $this->dataTypes[$dataTypeHandle];
        if (!class_exists($dataTypeClass)) {
            Schematic::error('Class '.$dataTypeClass.' does not exist');

            return null;
        }

        $dataType = new $dataTypeClass();
        if (!$dataType instanceof DataTypeInterface) {
            Schematic::error($dataTypeClass.' does not implement DataTypeInterface');

            return null;
        }

        return $dataType;
    }
94992
public function get($dependencyClassname, $guaranteeNew = false)
    {
        if (!class_exists($dependencyClassname) && !($this->container->has($dependencyClassname) && !$guaranteeNew)) {
            throw new ClassDoesNotExistException($dependencyClassname);
        }

        $dependency = $this->getDependency($dependencyClassname, $guaranteeNew);
        $this->container->set($dependencyClassname, $dependency);
        return $dependency;
    }
847519
public static TypeSerializer<?> getValidationSerializerClassInstance(Class<?> dataType, boolean isCql3Enabled)
    {
        resetMapperForCQL3(isCql3Enabled);
        TypeSerializer<?> validation_class;
        validation_class = validationSerializerClassMapper.get(dataType);
        if (validation_class == null)
        {
            if (dataType.isEnum())
            {
                validation_class = UTF8Serializer.instance;
            }
            else
            {
                validation_class = BytesSerializer.instance;
            }
        }
        resetMapperForThrift(isCql3Enabled);
        return validation_class;
    }
827827
protected function createConfiguration($dataType)
    {
        if (!isset($this->generatedPropertyMappingConfigurations[$dataType])) {
            $propertyMappingConfiguration = new PropertyMappingConfiguration();
            $propertyMappingConfiguration->allowAllProperties();

            $parsedType = [
                'elementType' => null,
                'type' => $dataType
            ];
            // Special handling for "reference(s)", should be deprecated and normlized to array<NodeInterface>
            if ($dataType !== 'references' && $dataType !== 'reference') {
                $parsedType = TypeHandling::parseType($dataType);
            }

            if ($this->setTypeConverterForType($propertyMappingConfiguration, $dataType) === false) {
                $this->setTypeConverterForType($propertyMappingConfiguration, $parsedType['type']);
            }

            $elementConfiguration = $propertyMappingConfiguration->forProperty('*');
            $this->setTypeConverterForType($elementConfiguration, $parsedType['elementType']);

            $this->generatedPropertyMappingConfigurations[$dataType] = $propertyMappingConfiguration;
        }

        return $this->generatedPropertyMappingConfigurations[$dataType];
    }