Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
+74
-59
@@ -1,55 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Language\AST;
|
||||
|
||||
use GraphQL\Error\InvariantViolation;
|
||||
use GraphQL\Utils\Utils;
|
||||
use function count;
|
||||
use function get_object_vars;
|
||||
use function is_array;
|
||||
use function is_scalar;
|
||||
use function json_encode;
|
||||
|
||||
/**
|
||||
* type Node = NameNode
|
||||
* | DocumentNode
|
||||
* | OperationDefinitionNode
|
||||
* | VariableDefinitionNode
|
||||
* | VariableNode
|
||||
* | SelectionSetNode
|
||||
* | FieldNode
|
||||
* | ArgumentNode
|
||||
* | FragmentSpreadNode
|
||||
* | InlineFragmentNode
|
||||
* | FragmentDefinitionNode
|
||||
* | IntValueNode
|
||||
* | FloatValueNode
|
||||
* | StringValueNode
|
||||
* | BooleanValueNode
|
||||
* | EnumValueNode
|
||||
* | ListValueNode
|
||||
* | ObjectValueNode
|
||||
* | ObjectFieldNode
|
||||
* | DirectiveNode
|
||||
* | ListTypeNode
|
||||
* | NonNullTypeNode
|
||||
*/
|
||||
abstract class Node
|
||||
{
|
||||
/**
|
||||
type Node = NameNode
|
||||
| DocumentNode
|
||||
| OperationDefinitionNode
|
||||
| VariableDefinitionNode
|
||||
| VariableNode
|
||||
| SelectionSetNode
|
||||
| FieldNode
|
||||
| ArgumentNode
|
||||
| FragmentSpreadNode
|
||||
| InlineFragmentNode
|
||||
| FragmentDefinitionNode
|
||||
| IntValueNode
|
||||
| FloatValueNode
|
||||
| StringValueNode
|
||||
| BooleanValueNode
|
||||
| EnumValueNode
|
||||
| ListValueNode
|
||||
| ObjectValueNode
|
||||
| ObjectFieldNode
|
||||
| DirectiveNode
|
||||
| ListTypeNode
|
||||
| NonNullTypeNode
|
||||
*/
|
||||
/** @var Location|null */
|
||||
public $loc;
|
||||
|
||||
/** @var string */
|
||||
public $kind;
|
||||
|
||||
/**
|
||||
* @var Location
|
||||
*/
|
||||
public $loc;
|
||||
|
||||
/**
|
||||
* @param array $vars
|
||||
* @param (NameNode|NodeList|SelectionSetNode|Location|string|int|bool|float|null)[] $vars
|
||||
*/
|
||||
public function __construct(array $vars)
|
||||
{
|
||||
if (!empty($vars)) {
|
||||
Utils::assign($this, $vars);
|
||||
if (count($vars) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Utils::assign($this, $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function cloneDeep()
|
||||
{
|
||||
@@ -57,8 +64,9 @@ abstract class Node
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return array|Node
|
||||
* @param string|NodeList|Location|Node|(Node|NodeList|Location)[] $value
|
||||
*
|
||||
* @return string|NodeList|Location|Node
|
||||
*/
|
||||
private function cloneValue($value)
|
||||
{
|
||||
@@ -67,7 +75,7 @@ abstract class Node
|
||||
foreach ($value as $key => $arrValue) {
|
||||
$cloned[$key] = $this->cloneValue($arrValue);
|
||||
}
|
||||
} else if ($value instanceof Node) {
|
||||
} elseif ($value instanceof self) {
|
||||
$cloned = clone $value;
|
||||
foreach (get_object_vars($cloned) as $prop => $propValue) {
|
||||
$cloned->{$prop} = $this->cloneValue($propValue);
|
||||
@@ -79,61 +87,67 @@ abstract class Node
|
||||
return $cloned;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
$tmp = $this->toArray(true);
|
||||
return json_encode($tmp);
|
||||
|
||||
return (string) json_encode($tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $recursive
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function toArray($recursive = false)
|
||||
public function toArray(bool $recursive = false) : array
|
||||
{
|
||||
if ($recursive) {
|
||||
return $this->recursiveToArray($this);
|
||||
} else {
|
||||
$tmp = (array) $this;
|
||||
}
|
||||
|
||||
$tmp = (array) $this;
|
||||
|
||||
if ($this->loc !== null) {
|
||||
$tmp['loc'] = [
|
||||
'start' => $this->loc->start,
|
||||
'end' => $this->loc->end
|
||||
'end' => $this->loc->end,
|
||||
];
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node $node
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function recursiveToArray(Node $node)
|
||||
{
|
||||
$result = [
|
||||
'kind' => $node->kind,
|
||||
'loc' => [
|
||||
'start' => $node->loc->start,
|
||||
'end' => $node->loc->end
|
||||
]
|
||||
];
|
||||
|
||||
if ($node->loc !== null) {
|
||||
$result['loc'] = [
|
||||
'start' => $node->loc->start,
|
||||
'end' => $node->loc->end,
|
||||
];
|
||||
}
|
||||
|
||||
foreach (get_object_vars($node) as $prop => $propValue) {
|
||||
if (isset($result[$prop]))
|
||||
if (isset($result[$prop])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($propValue === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($propValue) || $propValue instanceof NodeList) {
|
||||
$tmp = [];
|
||||
foreach ($propValue as $tmp1) {
|
||||
$tmp[] = $tmp1 instanceof Node ? $this->recursiveToArray($tmp1) : (array) $tmp1;
|
||||
}
|
||||
} else if ($propValue instanceof Node) {
|
||||
} elseif ($propValue instanceof Node) {
|
||||
$tmp = $this->recursiveToArray($propValue);
|
||||
} else if (is_scalar($propValue) || null === $propValue) {
|
||||
} elseif (is_scalar($propValue) || $propValue === null) {
|
||||
$tmp = $propValue;
|
||||
} else {
|
||||
$tmp = null;
|
||||
@@ -141,6 +155,7 @@ abstract class Node
|
||||
|
||||
$result[$prop] = $tmp;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user