92 lines
1.7 KiB
PHP
Raw Normal View History

2015-07-15 23:05:46 +06:00
<?php
namespace GraphQL\Language\AST;
use GraphQL\Utils;
abstract class Node
{
/**
type Node = Name
2015-07-15 23:05:46 +06:00
| Document
| OperationDefinition
| VariableDefinition
| Variable
| SelectionSet
| Field
| Argument
| FragmentSpread
| InlineFragment
| FragmentDefinition
| IntValue
| FloatValue
| StringValue
| BooleanValue
| EnumValue
| ListValue
2015-07-15 23:05:46 +06:00
| ObjectValue
| ObjectField
| Directive
| ListType
| NonNullType
*/
public $kind;
/**
* @var Location
*/
public $loc;
/**
* @param array $vars
*/
public function __construct(array $vars)
{
Utils::assign($this, $vars);
}
2016-04-24 17:35:14 +06:00
/**
* @return $this
*/
2015-07-15 23:05:46 +06:00
public function cloneDeep()
{
return $this->cloneValue($this);
2015-07-15 23:05:46 +06:00
}
/**
* @param $value
* @return array|Node
*/
private function cloneValue($value)
2015-07-15 23:05:46 +06:00
{
if (is_array($value)) {
$cloned = [];
foreach ($value as $key => $arrValue) {
$cloned[$key] = $this->cloneValue($arrValue);
2015-07-15 23:05:46 +06:00
}
} else if ($value instanceof Node) {
$cloned = clone $value;
foreach (get_object_vars($cloned) as $prop => $propValue) {
$cloned->{$prop} = $this->cloneValue($propValue);
2015-07-15 23:05:46 +06:00
}
} else {
$cloned = $value;
}
return $cloned;
}
/**
* @return string
*/
public function __toString()
{
$tmp = (array) $this;
$tmp['loc'] = [
'start' => $this->loc->start,
'end' => $this->loc->end
];
return json_encode($tmp);
2015-07-15 23:05:46 +06:00
}
}