Automattic\WooCommerce\Vendor\GraphQL\Utils
AST::valueFromASTUntyped
Produces a PHP value given a Automattic\WooCommerce\Vendor\GraphQL Value AST.
Unlike valueFromAST(), no type is provided. The resulting PHP value will reflect the provided Automattic\WooCommerce\Vendor\GraphQL value AST.
| Automattic\WooCommerce\Vendor\GraphQL Value | PHP Value |
|---|---|
| Input Object | Assoc Array |
| List | Array |
| Boolean | Boolean |
| String | String |
| Int / Float | Int / Float |
| Enum | Mixed |
| Null | null |
Method of the class: AST{}
No Hooks.
Returns
mixed.
Usage
$result = AST::valueFromASTUntyped( $valueNode, ?array $variables );
- $valueNode(Node) (required)
- .
- ?array $variables
- .
Default:null
AST::valueFromASTUntyped() AST::valueFromASTUntyped code WC 11.0.1
public static function valueFromASTUntyped(Node $valueNode, ?array $variables = null)
{
switch (true) {
case $valueNode instanceof NullValueNode:
return null;
case $valueNode instanceof IntValueNode:
return (int) $valueNode->value;
case $valueNode instanceof FloatValueNode:
return (float) $valueNode->value;
case $valueNode instanceof StringValueNode:
case $valueNode instanceof EnumValueNode:
case $valueNode instanceof BooleanValueNode:
return $valueNode->value;
case $valueNode instanceof ListValueNode:
$values = [];
foreach ($valueNode->values as $node) {
$values[] = self::valueFromASTUntyped($node, $variables);
}
return $values;
case $valueNode instanceof ObjectValueNode:
$values = [];
foreach ($valueNode->fields as $field) {
$values[$field->name->value] = self::valueFromASTUntyped($field->value, $variables);
}
return $values;
case $valueNode instanceof VariableNode:
$variableName = $valueNode->name->value;
return ($variables ?? []) !== [] && isset($variables[$variableName])
? $variables[$variableName]
: null;
}
throw new Error("Unexpected value kind: {$valueNode->kind}");
}