mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 22:36:02 +03:00
Preserve backwards compatibility of Ast\Node::toArray(): do shallow conversion by default
This commit is contained in:
parent
835e4e6b2d
commit
848f9c3edf
@ -81,22 +81,26 @@ abstract class Node
|
|||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
$tmp = $this->toArray();
|
$tmp = $this->toArray(true);
|
||||||
return json_encode($tmp);
|
return json_encode($tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param bool $recursive
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function toArray()
|
public function toArray($recursive = false)
|
||||||
{
|
{
|
||||||
$tmp = (array) $this;
|
$tmp = (array) $this;
|
||||||
|
|
||||||
$tmp['loc'] = [
|
$tmp['loc'] = [
|
||||||
'start' => $this->loc->start,
|
'start' => $this->loc->start,
|
||||||
'end' => $this->loc->end
|
'end' => $this->loc->end
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->recursiveToArray($tmp);
|
if ($recursive) {
|
||||||
|
$this->recursiveToArray($tmp);
|
||||||
|
}
|
||||||
|
|
||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
@ -108,7 +112,7 @@ abstract class Node
|
|||||||
{
|
{
|
||||||
if ($object instanceof Node) {
|
if ($object instanceof Node) {
|
||||||
/** @var Node $object */
|
/** @var Node $object */
|
||||||
$object = $object->toArray();
|
$object = $object->toArray(true);
|
||||||
} elseif (is_object($object)) {
|
} elseif (is_object($object)) {
|
||||||
$object = (array) $object;
|
$object = (array) $object;
|
||||||
} elseif (is_array($object)) {
|
} elseif (is_array($object)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user