Parses an externally provided literal value (hardcoded in GraphQL query) to use as an input

@param \GraphQL\Language\AST\Node $valueNode
@param null|array $variables

@return EntityID
170204
public function parseLiteral($valueNode, array $variables = null): EntityID
    {
        $value = (string) parent::parseLiteral($valueNode);

        return $this->createEntityID($value);
    }
77254
protected function getValuesFromWidget($varValue)
    {
        $model    = $this->getTagMetaModel();
        $alias    = $this->getAliasColumn();
        $valueIds = [];

        if ($model->hasAttribute($alias)) {
            $attribute = $model->getAttribute($alias);
            // It is an attribute, we may search for it.
            foreach ($varValue as $value) {
                if ($attribute instanceof ITranslated) {
                    $ids = $attribute->searchForInLanguages(
                        $value,
                        [$model->getActiveLanguage(), $model->getFallbackLanguage()]
                    );
                } else {
                    $ids = $attribute->searchFor($value);
                }
                // If all match, return all.
                if (null === $ids) {
                    $valueIds = $model->getIdsFromFilter($model->getEmptyFilter(), $alias);
                    break;
                }
                if ($ids) {
                    $valueIds = \array_merge($valueIds, $ids);
                }
            }
        } else {
            // Must be a system column then.
            // Translate the alias values to the item ids.
            $result = $this
                ->getConnection()
                ->createQueryBuilder()
                ->select('id')
                ->from($this->getTagSource())
                ->where($alias . ' IN (:values)')
                ->setParameter('values', $varValue, Connection::PARAM_STR_ARRAY)
                ->orderBy('FIELD(' . $alias . ',:values)')
                ->execute();

            $valueIds = $result->fetchAll(\PDO::FETCH_COLUMN);

            if (empty($valueIds)) {
                throw new \RuntimeException('Could not translate value ' . \var_export($varValue, true));
            }
        }

        return $this->getValuesById(
            $valueIds,
            [$this->getIdColumn(), $this->getAliasColumn(), $this->getValueColumn()]
        );
    }
1367520
protected function loadEntityValues($valueClass, array $entitiesById)
    {
        foreach ($this->getValues($valueClass, $entitiesById) as $valueEntity) {
            $data = $valueEntity->getData();

            $refl = new \ReflectionClass($data);
            $valuesProperty = $refl->getProperty('values');
            $valuesProperty->setAccessible(true);
            $dataValues = $valuesProperty->getValue($data);
            if ($dataValues instanceof PersistentCollection) {
                $dataValues->setInitialized(true);
                $dataValues->add($valueEntity);
            } else {
                throw new \UnexpectedValueException('Data.values is not an instance of PersistentCollection');
            }
        }
    }
954872
public function set(string $variableName = null, $variableValue = null): Session
    {
        if ($variableName === null) {
            throw new BadMethodCallException('Variable name must be specified');
        }
        if ($variableName === '_MFREG_') {
            throw new InvalidArgumentException('_MFREG_ variable name is not allowed');
        }
        $_SESSION[$variableName] = \base64_encode(\serialize($variableValue));
        $this->variables[$variableName] = \base64_encode(\serialize($variableValue));

        return static::$instance;
    }
1036128
private function BindExpr( $vars )
	{
		/**
		 * @var XPath2RunningContext $runningContext
		 */
		$runningContext = new XPath2RunningContext();

		/**
		 * @var ReferenceLink[] $variables
		 */
		$variables = null;
		$variableValues = null;
		if ( ! is_null( $vars ) && ! empty( $vars ) )
		{
			/**
			 * @var array[ReferenceLink] $variables
			 */
			$variables = array(); // new ReferenceLink[$vars.Count];
			$variableValues = array(); // new object[$vars.Count];
			// $array = $vars; // new KeyValuePair<QName, object>[$vars.Count];
			$array = array();
			foreach ( $vars as $key => $value )
			{
				$variables[] = $runningContext->NameBinder->PushVar( $key );
				$variableValues[] = $value;
			}
		}

		$this->context->RunningContext = $runningContext;
		$this->context->availableCollections = isset( $vars['availableCollections'] ) ? $vars['availableCollections'] : array();
		$this->context->defaultCollection = isset( $vars['defaultCollection'] ) ? $vars['defaultCollection'] : null;

		$this->exprTree->Bind();

		/**
		 * @var object[] $datapool
		 */
		$dataPool = array(); // new object[ $runningContext->NameBinder->getLength() ];
		if ( ! is_null( $variables ) )
		{
			for ( $k = 0; $k < count( $variables ); $k++ )
			{
				$variables[ $k ]->Set( $dataPool, $this->PrepareValue( $variableValues[ $k ] ) );
			}
		}
		return $dataPool;
	}
448616
private function normalizeValue($value)
    {
        if ($value instanceof NodeInterface) {
            $value = IDEncoder::encode($value);
        } elseif (\is_object($value)) {
            if (method_exists($value, '__toString')) {
                $value = (string) $value;
            } else {
                $value = null;
            }
        }

        return $value;
    }
446583
protected function setNodeKey(NodeValue $nodeValue): void
    {
        if ($nodeValue->getCacheKey()) {
            return;
        }

        $fields = data_get($nodeValue->getTypeDefinition(), 'fields', []);
        $nodeKey = (new Collection($fields))->reduce(function (?string $key, FieldDefinitionNode $field): ?string {
            if ($key) {
                return $key;
            }

            $hasCacheKey = (new Collection($field->directives))
                ->contains(function (DirectiveNode $directive): bool {
                    return $directive->name->value === 'cacheKey';
                });

            return $hasCacheKey
                ? $field->name->value
                : $key;
        });

        if (! $nodeKey) {
            $nodeKey = (new Collection($fields))->reduce(function (?string $key, FieldDefinitionNode $field): ?string {
                if ($key) {
                    return $key;
                }

                $typeName = ASTHelper::getUnderlyingTypeName($field);

                return $typeName === 'ID'
                    ? $field->name->value
                    : $key;
            });
        }

        if (! $nodeKey && $nodeValue->getTypeDefinitionName() !== 'Query') {
            throw new DirectiveException(
                "No @cacheKey or ID field defined on {$nodeValue->getTypeDefinitionName()}"
            );
        }

        $nodeValue->setCacheKey($nodeKey);
    }
1285907
public function getValue( $variableSet, $evaluationResult, $log )
	{
		$aspect = $variableSet->aspectModel == 'dimensional'
			? ( $this->occ == 'segment' ? ASPECT_NON_XDT_SEGMENT : ASPECT_NON_XDT_SCENARIO )
			: ( $this->occ == 'segment' ? ASPECT_COMPLETE_SEGMENT : ASPECT_COMPLETE_SCENARIO );

		$sourceFact = $variableSet->getSourceFact( $this->source, $evaluationResult, $aspect, $log );
		if ( ! $sourceFact ) return null;
		$contextRef = FactValues::getContextRef( $sourceFact );
		if ( ! $contextRef ) return null;
		$context = $variableSet->xbrlInstance->getContext( $contextRef );
		// $component = isset( $context['entity'][ $this->occ ]['member'] )
		// 	? $context['entity'][ $this->occ ]['member']
		// 	: array();
		$components = array();
		if ( ! $this->select ) return $components;

		$componentNodes = $this->evaluateXPath( $variableSet, "{$this->select}", array( $this->getSourceName() => $sourceFact ) );

		foreach ( $componentNodes as $node )
		{
			if ( ( $this->occ == 'scenario' || $this->occ == 'segment' ) &&
				 $node->getNamespaceURI() == \XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XBRLDI] )
			{
				$log->formula_validation( "OCC XPath", "The result of the XPath query is not consistent with ",
					array(
						'occ' => $this->occ,
						'xpath' => $this->select,
						'error' => 'xbrlfe:badSubsequentOCCValue'
					)
				);
			}
			$components[] = array( 'name' => $node->getName(), 'member' => '' );
		}

		return $components;
	}
957079
public function getContextConfigValue($varName, $defaultValue = null)
    {
        if ($this->type == InternalBaseBlock::INJECTOR_VAR) {
            return $this->context->getVarValue($varName, $defaultValue);
        }
        
        if ($this->type == InternalBaseBlock::INJECTOR_CFG) {
            return $this->context->getCfgValue($varName, $defaultValue);
        }
            
        throw new InvalidConfigException("The type '{$this->type}' is not supported.");
    }
989605
public static function getValueByNodes(array $data, array $nodes, $default = null)
    {
        $temp = $data;

        foreach ($nodes as $name) {
            if (isset($temp[$name])) {
                $temp = $temp[$name];
            } else {
                $temp = $default;
                break;
            }
        }

        return $temp;
    }
1305946
protected static function coerceValueAST(TypeInterface $type, $ast, $variables = NULL)
    {
        if ($type instanceof NonNullModifier) {
            // Note: we're not checking that the result of coerceValueAST is non-null.
            // We're assuming that this query has been validated and the value used
            // here is of the correct type.
            return self::coerceValueAST($type->getWrappedType(), $ast, $variables);
        }

        if (!$ast) {
            return NULL;
        }

        if ($ast::KIND === Node::KIND_VARIABLE) {
            $variableName = $ast->get('name')->get('value');

            if (!isset($variables, $variables[$variableName])) {
                return NULL;
            }

            // Note: we're not doing any checking that this variable is correct. We're
            // assuming that this query has been validated and the variable usage here
            // is of the correct type.
            return $variables[$variableName];
        }

        if ($type instanceof ListModifier) {
            $itemType = $type->getWrappedType();

            if ($ast::KIND === Node::KIND_ARRAY_VALUE) {
                $tmp = [];
                foreach ($ast->get('values') as $itemAST) {
                    $tmp[] = self::coerceValueAST($itemType, $itemAST, $variables);
                }

                return $tmp;
            } else {
                return [self::coerceValueAST($itemType, $ast, $variables)];
            }
        }

        if ($type instanceof InputObjectType) {
            $fields = $type->getFields();

            if ($ast::KIND !== Node::KIND_OBJECT_VALUE) {
                return NULL;
            }

            $asts = array_reduce($ast->get('fields'), function ($carry, $field) {
                $carry[$field->get('name')->get('value')] = $field;
                return $carry;
            }, []);

            $object = [];
            foreach ($fields as $name => $item) {
                $field = $asts[$name];
                $fieldValue = self::coerceValueAST($item->getType(), $field ? $field->get('value') : NULL, $variables);
                $object[$name] = $fieldValue === NULL ? $item->getDefaultValue() : $fieldValue;
            }

            return $object;
        }

        if ($type instanceof ScalarType || $type instanceof EnumType) {
            $coerced = $type->coerceLiteral($ast);

            if (isset($coerced)) {
                return $coerced;
            }
        }

        return NULL;
    }
492292
private function parsePhpValue($key, $value, array &$result)
    {
        $node =& $result;
        $keyBuffer = '';

        for ($i = 0, $t = strlen($key); $i < $t; $i++) {
            switch ($key[$i]) {
                case '[':
                    if ($keyBuffer) {
                        $this->prepareNode($node, $keyBuffer);
                        $node =& $node[$keyBuffer];
                        $keyBuffer = '';
                    }
                    break;
                case ']':
                    $k = $this->cleanKey($node, $keyBuffer);
                    $this->prepareNode($node, $k);
                    $node =& $node[$k];
                    $keyBuffer = '';
                    break;
                default:
                    $keyBuffer .= $key[$i];
                    break;
            }
        }

        if (isset($node)) {
            $this->duplicates = true;
            $node[] = $value;
        } else {
            $node = $value;
        }
    }
1092771
public function convert(NodeType $nodeType, $propertyName, $rawValue, Context $context)
    {
        $propertyType = $nodeType->getPropertyType($propertyName);

        switch ($propertyType) {
            case 'string':
                return $rawValue;

            case 'reference':
                return $this->convertReference($rawValue, $context);

            case 'references':
                return $this->convertReferences($rawValue, $context);

            case 'DateTime':
                return $this->convertDateTime($rawValue);

            case 'integer':
                return $this->convertInteger($rawValue);

            case 'boolean':
                return $this->convertBoolean($rawValue);

            case 'array':
                return $this->convertArray($rawValue);

            default:
                $innerType = $propertyType;
                if ($propertyType !== null) {
                    try {
                        $parsedType = TypeHandling::parseType($propertyType);
                        $innerType = $parsedType['elementType'] ?: $parsedType['type'];
                    } catch (InvalidTypeException $exception) {
                    }
                }

                if ((is_string($rawValue) || is_array($rawValue)) && $this->objectManager->isRegistered($innerType) && $rawValue !== '') {
                    $propertyMappingConfiguration = new MvcPropertyMappingConfiguration();
                    $propertyMappingConfiguration->allowOverrideTargetType();
                    $propertyMappingConfiguration->allowAllProperties();
                    $propertyMappingConfiguration->skipUnknownProperties();
                    $propertyMappingConfiguration->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, true);
                    $propertyMappingConfiguration->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true);

                    return $this->propertyMapper->convert($rawValue, $propertyType, $propertyMappingConfiguration);
                } else {
                    return $rawValue;
                }
        }
    }
337862
public function wrap($value, $prefixAlias = false)
    {
        // We will only wrap the value unless it has parentheses
        // in it which is the case where we're matching a node by id, or an *
        // and last whether this is a pre-formatted key.
        if (preg_match('/[(|)]/', $value) || $value == '*' || strpos($value, '.') !== false) return $value;

        // In the case where the developer specifies the properties and not returning
        // everything, we need to check whether the primaryKey is meant to be returned
        // since Neo4j's way of evaluating returned properties for the Node id is
        // different: id(n) instead of n.id

        if ($value == 'id')
        {
            return 'id(' . $this->query->modelAsNode() . ')';
        }
        return $this->query->modelAsNode() . '.' . $value;
    }
788461
public function EvaluateWithVars( $provider, $vars )
	{
		/**
		 * @var object $res
		 */
		$res = $this->exprTree->Execute( $provider, $this->BindExpr( $vars ) );

		if ( $res instanceof DocumentOrderNodeIterator )
		{
			/**
			 * @var DocumentOrderNodeIterator $doni
			 */
			$doni = $res;
			if ( ( $x = $doni->getCount() ) )
			{
				$list = $doni->ToList();
				if ( $list[0] instanceof XPath2Item )
				{
					/**
					 *
					 * @var XPath2Item $item
					 */
					$item = $list[0];
					$value = $item->getTypedValue();
				}
			}
		}
		else if ( $res instanceof XPath2Item )
		{
			/**
			 * @var XPath2Item $item
			 */
			$item = $res;
			$this->resultType = $item->getXPath2ResultType();
			return  $item;
		}
		else if ( $res instanceof XPathItem )
		{
			/**
			 * @var XPathItem $item
			 */
			$item = $res;
			if ( ! $item->getIsNode() )
			{
				$res = $item->getTypedValue();
			}
		}
		else if ( $res instanceof ValueProxy )
		{
			/**
			 * @var ValueProxy $proxy
			 */
			$proxy = $res;
			$res = $proxy->getValue();
			// $res = $proxy->ToDouble( $provider );
		}

		$this->resultType = CoreFuncs::GetXPath2ResultTypeFromValue( $res );

		return $res instanceof Long
			? $res->getValue()
			: ( $res instanceof Integer
				? $res->ToInt( $provider )
				: $res );

		// if ( $res instanceof ValueProxy )
		return $res instanceof ValueProxy
			? $res->getValue()
			: $res;
	}
1073947
private function convertValuesToIds($varValue): array
    {
        $aliasColumn = $this->getAliasColumn();
        $alias       = [];
        foreach ($varValue as $valueId => $value) {
            if (array_key_exists($aliasColumn, $value)) {
                $alias[$valueId] = $value[$aliasColumn];
                continue;
            }
            if (array_key_exists(self::TAGS_RAW, $value) && array_key_exists($aliasColumn, $value[self::TAGS_RAW])) {
                $alias[$valueId] = $value[self::TAGS_RAW][$aliasColumn];
            }
        }

        return $alias;
    }
535397
public function parse($propertyValue)
    {
        $return = $this->cloneValue($propertyValue);
        $return = $this->createInstanceOfTypeFromValue($return);
        $return = $this->runFilters($return);
        $this->validate($return);

        return $return;
    }