mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-18 05:13:13 +03:00
Fix CS in src/Language
This commit is contained in:
parent
bfebcd7bee
commit
a95d2ad140
@ -15,7 +15,7 @@ class EnumTypeDefinitionNode extends Node implements TypeDefinitionNode
|
|||||||
/** @var DirectiveNode[] */
|
/** @var DirectiveNode[] */
|
||||||
public $directives;
|
public $directives;
|
||||||
|
|
||||||
/** @var EnumValueDefinitionNode[]|null|NodeList */
|
/** @var EnumValueDefinitionNode[]|NodeList|null */
|
||||||
public $values;
|
public $values;
|
||||||
|
|
||||||
/** @var StringValueNode|null */
|
/** @var StringValueNode|null */
|
||||||
|
@ -51,6 +51,7 @@ class Location
|
|||||||
/**
|
/**
|
||||||
* @param int $start
|
* @param int $start
|
||||||
* @param int $end
|
* @param int $end
|
||||||
|
*
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function create($start, $end)
|
public static function create($start, $end)
|
||||||
|
@ -61,6 +61,7 @@ abstract class Node
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|NodeList|Location|Node|(Node|NodeList|Location)[] $value
|
* @param string|NodeList|Location|Node|(Node|NodeList|Location)[] $value
|
||||||
|
*
|
||||||
* @return string|NodeList|Location|Node
|
* @return string|NodeList|Location|Node
|
||||||
*/
|
*/
|
||||||
private function cloneValue($value)
|
private function cloneValue($value)
|
||||||
@ -94,6 +95,7 @@ abstract class Node
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $recursive
|
* @param bool $recursive
|
||||||
|
*
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
public function toArray($recursive = false)
|
public function toArray($recursive = false)
|
||||||
|
@ -4,19 +4,24 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Language\AST;
|
namespace GraphQL\Language\AST;
|
||||||
|
|
||||||
|
use ArrayAccess;
|
||||||
|
use Countable;
|
||||||
|
use Generator;
|
||||||
use GraphQL\Utils\AST;
|
use GraphQL\Utils\AST;
|
||||||
|
use IteratorAggregate;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
use function array_splice;
|
use function array_splice;
|
||||||
use function count;
|
use function count;
|
||||||
use function is_array;
|
use function is_array;
|
||||||
|
|
||||||
class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable
|
class NodeList implements ArrayAccess, IteratorAggregate, Countable
|
||||||
{
|
{
|
||||||
/** @var Node[]|mixed[] */
|
/** @var Node[]|mixed[] */
|
||||||
private $nodes;
|
private $nodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node[]|mixed[] $nodes
|
* @param Node[]|mixed[] $nodes
|
||||||
|
*
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function create(array $nodes)
|
public static function create(array $nodes)
|
||||||
@ -25,7 +30,6 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param Node[]|mixed[] $nodes
|
* @param Node[]|mixed[] $nodes
|
||||||
*/
|
*/
|
||||||
public function __construct(array $nodes)
|
public function __construct(array $nodes)
|
||||||
@ -35,6 +39,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $offset
|
* @param mixed $offset
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function offsetExists($offset)
|
public function offsetExists($offset)
|
||||||
@ -44,6 +49,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $offset
|
* @param mixed $offset
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function offsetGet($offset)
|
public function offsetGet($offset)
|
||||||
@ -81,6 +87,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable
|
|||||||
* @param int $offset
|
* @param int $offset
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @param mixed $replacement
|
* @param mixed $replacement
|
||||||
|
*
|
||||||
* @return NodeList
|
* @return NodeList
|
||||||
*/
|
*/
|
||||||
public function splice($offset, $length, $replacement = null)
|
public function splice($offset, $length, $replacement = null)
|
||||||
@ -90,6 +97,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param NodeList|Node[] $list
|
* @param NodeList|Node[] $list
|
||||||
|
*
|
||||||
* @return NodeList
|
* @return NodeList
|
||||||
*/
|
*/
|
||||||
public function merge($list)
|
public function merge($list)
|
||||||
@ -101,7 +109,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Generator
|
* @return Generator
|
||||||
*/
|
*/
|
||||||
public function getIterator()
|
public function getIterator()
|
||||||
{
|
{
|
||||||
|
@ -55,6 +55,7 @@ class DirectiveLocation
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has($name)
|
public static function has($name)
|
||||||
|
@ -92,10 +92,8 @@ class Lexer
|
|||||||
*/
|
*/
|
||||||
public function advance()
|
public function advance()
|
||||||
{
|
{
|
||||||
$this->lastToken = $this->token;
|
$this->lastToken = $this->token;
|
||||||
$token = $this->token = $this->lookahead();
|
return $this->token = $this->lookahead();
|
||||||
|
|
||||||
return $token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lookahead()
|
public function lookahead()
|
||||||
@ -112,6 +110,7 @@ class Lexer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Token
|
* @return Token
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function readToken(Token $prev)
|
private function readToken(Token $prev)
|
||||||
@ -129,7 +128,7 @@ class Lexer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read next char and advance string cursor:
|
// Read next char and advance string cursor:
|
||||||
list (, $code, $bytes) = $this->readChar(true);
|
[, $code, $bytes] = $this->readChar(true);
|
||||||
|
|
||||||
// SourceCharacter
|
// SourceCharacter
|
||||||
if ($code < 0x0020 && $code !== 0x0009 && $code !== 0x000A && $code !== 0x000D) {
|
if ($code < 0x0020 && $code !== 0x0009 && $code !== 0x000A && $code !== 0x000D) {
|
||||||
@ -156,8 +155,8 @@ class Lexer
|
|||||||
case 41: // )
|
case 41: // )
|
||||||
return new Token(Token::PAREN_R, $position, $position + 1, $line, $col, $prev);
|
return new Token(Token::PAREN_R, $position, $position + 1, $line, $col, $prev);
|
||||||
case 46: // .
|
case 46: // .
|
||||||
list (, $charCode1) = $this->readChar(true);
|
[, $charCode1] = $this->readChar(true);
|
||||||
list (, $charCode2) = $this->readChar(true);
|
[, $charCode2] = $this->readChar(true);
|
||||||
|
|
||||||
if ($charCode1 === 46 && $charCode2 === 46) {
|
if ($charCode1 === 46 && $charCode2 === 46) {
|
||||||
return new Token(Token::SPREAD, $position, $position + 3, $line, $col, $prev);
|
return new Token(Token::SPREAD, $position, $position + 3, $line, $col, $prev);
|
||||||
@ -254,8 +253,8 @@ class Lexer
|
|||||||
->readNumber($line, $col, $prev);
|
->readNumber($line, $col, $prev);
|
||||||
// "
|
// "
|
||||||
case 34:
|
case 34:
|
||||||
list(, $nextCode) = $this->readChar();
|
[, $nextCode] = $this->readChar();
|
||||||
list(, $nextNextCode) = $this->moveStringCursor(1, 1)->readChar();
|
[, $nextNextCode] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
|
|
||||||
if ($nextCode === 34 && $nextNextCode === 34) {
|
if ($nextCode === 34 && $nextNextCode === 34) {
|
||||||
return $this->moveStringCursor(-2, (-1 * $bytes) - 1)
|
return $this->moveStringCursor(-2, (-1 * $bytes) - 1)
|
||||||
@ -284,13 +283,14 @@ class Lexer
|
|||||||
*
|
*
|
||||||
* @param int $line
|
* @param int $line
|
||||||
* @param int $col
|
* @param int $col
|
||||||
|
*
|
||||||
* @return Token
|
* @return Token
|
||||||
*/
|
*/
|
||||||
private function readName($line, $col, Token $prev)
|
private function readName($line, $col, Token $prev)
|
||||||
{
|
{
|
||||||
$value = '';
|
$value = '';
|
||||||
$start = $this->position;
|
$start = $this->position;
|
||||||
list ($char, $code) = $this->readChar();
|
[$char, $code] = $this->readChar();
|
||||||
|
|
||||||
while ($code && (
|
while ($code && (
|
||||||
$code === 95 || // _
|
$code === 95 || // _
|
||||||
@ -298,8 +298,8 @@ class Lexer
|
|||||||
$code >= 65 && $code <= 90 || // A-Z
|
$code >= 65 && $code <= 90 || // A-Z
|
||||||
$code >= 97 && $code <= 122 // a-z
|
$code >= 97 && $code <= 122 // a-z
|
||||||
)) {
|
)) {
|
||||||
$value .= $char;
|
$value .= $char;
|
||||||
list ($char, $code) = $this->moveStringCursor(1, 1)->readChar();
|
[$char, $code] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Token(
|
return new Token(
|
||||||
@ -322,26 +322,28 @@ class Lexer
|
|||||||
*
|
*
|
||||||
* @param int $line
|
* @param int $line
|
||||||
* @param int $col
|
* @param int $col
|
||||||
|
*
|
||||||
* @return Token
|
* @return Token
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function readNumber($line, $col, Token $prev)
|
private function readNumber($line, $col, Token $prev)
|
||||||
{
|
{
|
||||||
$value = '';
|
$value = '';
|
||||||
$start = $this->position;
|
$start = $this->position;
|
||||||
list ($char, $code) = $this->readChar();
|
[$char, $code] = $this->readChar();
|
||||||
|
|
||||||
$isFloat = false;
|
$isFloat = false;
|
||||||
|
|
||||||
if ($code === 45) { // -
|
if ($code === 45) { // -
|
||||||
$value .= $char;
|
$value .= $char;
|
||||||
list ($char, $code) = $this->moveStringCursor(1, 1)->readChar();
|
[$char, $code] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
// guard against leading zero's
|
// guard against leading zero's
|
||||||
if ($code === 48) { // 0
|
if ($code === 48) { // 0
|
||||||
$value .= $char;
|
$value .= $char;
|
||||||
list ($char, $code) = $this->moveStringCursor(1, 1)->readChar();
|
[$char, $code] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
|
|
||||||
if ($code >= 48 && $code <= 57) {
|
if ($code >= 48 && $code <= 57) {
|
||||||
throw new SyntaxError(
|
throw new SyntaxError(
|
||||||
@ -351,23 +353,23 @@ class Lexer
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$value .= $this->readDigits();
|
$value .= $this->readDigits();
|
||||||
list ($char, $code) = $this->readChar();
|
[$char, $code] = $this->readChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($code === 46) { // .
|
if ($code === 46) { // .
|
||||||
$isFloat = true;
|
$isFloat = true;
|
||||||
$this->moveStringCursor(1, 1);
|
$this->moveStringCursor(1, 1);
|
||||||
|
|
||||||
$value .= $char;
|
$value .= $char;
|
||||||
$value .= $this->readDigits();
|
$value .= $this->readDigits();
|
||||||
list ($char, $code) = $this->readChar();
|
[$char, $code] = $this->readChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($code === 69 || $code === 101) { // E e
|
if ($code === 69 || $code === 101) { // E e
|
||||||
$isFloat = true;
|
$isFloat = true;
|
||||||
$value .= $char;
|
$value .= $char;
|
||||||
list ($char, $code) = $this->moveStringCursor(1, 1)->readChar();
|
[$char, $code] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
|
|
||||||
if ($code === 43 || $code === 45) { // + -
|
if ($code === 43 || $code === 45) { // + -
|
||||||
$value .= $char;
|
$value .= $char;
|
||||||
@ -392,14 +394,14 @@ class Lexer
|
|||||||
*/
|
*/
|
||||||
private function readDigits()
|
private function readDigits()
|
||||||
{
|
{
|
||||||
list ($char, $code) = $this->readChar();
|
[$char, $code] = $this->readChar();
|
||||||
|
|
||||||
if ($code >= 48 && $code <= 57) { // 0 - 9
|
if ($code >= 48 && $code <= 57) { // 0 - 9
|
||||||
$value = '';
|
$value = '';
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$value .= $char;
|
$value .= $char;
|
||||||
list ($char, $code) = $this->moveStringCursor(1, 1)->readChar();
|
[$char, $code] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
} while ($code >= 48 && $code <= 57); // 0 - 9
|
} while ($code >= 48 && $code <= 57); // 0 - 9
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
@ -419,7 +421,9 @@ class Lexer
|
|||||||
/**
|
/**
|
||||||
* @param int $line
|
* @param int $line
|
||||||
* @param int $col
|
* @param int $col
|
||||||
|
*
|
||||||
* @return Token
|
* @return Token
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function readString($line, $col, Token $prev)
|
private function readString($line, $col, Token $prev)
|
||||||
@ -458,8 +462,8 @@ class Lexer
|
|||||||
$this->moveStringCursor(1, $bytes);
|
$this->moveStringCursor(1, $bytes);
|
||||||
|
|
||||||
if ($code === 92) { // \
|
if ($code === 92) { // \
|
||||||
$value .= $chunk;
|
$value .= $chunk;
|
||||||
list (, $code) = $this->readChar(true);
|
[, $code] = $this->readChar(true);
|
||||||
|
|
||||||
switch ($code) {
|
switch ($code) {
|
||||||
case 34:
|
case 34:
|
||||||
@ -487,8 +491,8 @@ class Lexer
|
|||||||
$value .= "\t";
|
$value .= "\t";
|
||||||
break;
|
break;
|
||||||
case 117:
|
case 117:
|
||||||
$position = $this->position;
|
$position = $this->position;
|
||||||
list ($hex) = $this->readChars(4, true);
|
[$hex] = $this->readChars(4, true);
|
||||||
if (! preg_match('/[0-9a-fA-F]{4}/', $hex)) {
|
if (! preg_match('/[0-9a-fA-F]{4}/', $hex)) {
|
||||||
throw new SyntaxError(
|
throw new SyntaxError(
|
||||||
$this->source,
|
$this->source,
|
||||||
@ -512,7 +516,7 @@ class Lexer
|
|||||||
$chunk .= $char;
|
$chunk .= $char;
|
||||||
}
|
}
|
||||||
|
|
||||||
list ($char, $code, $bytes) = $this->readChar();
|
[$char, $code, $bytes] = $this->readChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new SyntaxError(
|
throw new SyntaxError(
|
||||||
@ -532,7 +536,7 @@ class Lexer
|
|||||||
$start = $this->position;
|
$start = $this->position;
|
||||||
|
|
||||||
// Skip leading quotes and read first string char:
|
// Skip leading quotes and read first string char:
|
||||||
list ($char, $code, $bytes) = $this->moveStringCursor(3, 3)->readChar();
|
[$char, $code, $bytes] = $this->moveStringCursor(3, 3)->readChar();
|
||||||
|
|
||||||
$chunk = '';
|
$chunk = '';
|
||||||
$value = '';
|
$value = '';
|
||||||
@ -541,8 +545,8 @@ class Lexer
|
|||||||
// Closing Triple-Quote (""")
|
// Closing Triple-Quote (""")
|
||||||
if ($code === 34) {
|
if ($code === 34) {
|
||||||
// Move 2 quotes
|
// Move 2 quotes
|
||||||
list(, $nextCode) = $this->moveStringCursor(1, 1)->readChar();
|
[, $nextCode] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
list(, $nextNextCode) = $this->moveStringCursor(1, 1)->readChar();
|
[, $nextNextCode] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
|
|
||||||
if ($nextCode === 34 && $nextNextCode === 34) {
|
if ($nextCode === 34 && $nextNextCode === 34) {
|
||||||
$value .= $chunk;
|
$value .= $chunk;
|
||||||
@ -567,9 +571,9 @@ class Lexer
|
|||||||
$this->assertValidBlockStringCharacterCode($code, $this->position);
|
$this->assertValidBlockStringCharacterCode($code, $this->position);
|
||||||
$this->moveStringCursor(1, $bytes);
|
$this->moveStringCursor(1, $bytes);
|
||||||
|
|
||||||
list(, $nextCode) = $this->readChar();
|
[, $nextCode] = $this->readChar();
|
||||||
list(, $nextNextCode) = $this->moveStringCursor(1, 1)->readChar();
|
[, $nextNextCode] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
list(, $nextNextNextCode) = $this->moveStringCursor(1, 1)->readChar();
|
[, $nextNextNextCode] = $this->moveStringCursor(1, 1)->readChar();
|
||||||
|
|
||||||
// Escape Triple-Quote (\""")
|
// Escape Triple-Quote (\""")
|
||||||
if ($code === 92 &&
|
if ($code === 92 &&
|
||||||
@ -585,7 +589,7 @@ class Lexer
|
|||||||
$chunk .= $char;
|
$chunk .= $char;
|
||||||
}
|
}
|
||||||
|
|
||||||
list ($char, $code, $bytes) = $this->readChar();
|
[$char, $code, $bytes] = $this->readChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new SyntaxError(
|
throw new SyntaxError(
|
||||||
@ -626,7 +630,7 @@ class Lexer
|
|||||||
private function positionAfterWhitespace()
|
private function positionAfterWhitespace()
|
||||||
{
|
{
|
||||||
while ($this->position < $this->source->length) {
|
while ($this->position < $this->source->length) {
|
||||||
list(, $code, $bytes) = $this->readChar();
|
[, $code, $bytes] = $this->readChar();
|
||||||
|
|
||||||
// Skip whitespace
|
// Skip whitespace
|
||||||
// tab | space | comma | BOM
|
// tab | space | comma | BOM
|
||||||
@ -637,7 +641,7 @@ class Lexer
|
|||||||
$this->line++;
|
$this->line++;
|
||||||
$this->lineStart = $this->position;
|
$this->lineStart = $this->position;
|
||||||
} elseif ($code === 13) { // carriage return
|
} elseif ($code === 13) { // carriage return
|
||||||
list(, $nextCode, $nextBytes) = $this->moveStringCursor(1, $bytes)->readChar();
|
[, $nextCode, $nextBytes] = $this->moveStringCursor(1, $bytes)->readChar();
|
||||||
|
|
||||||
if ($nextCode === 10) { // lf after cr
|
if ($nextCode === 10) { // lf after cr
|
||||||
$this->moveStringCursor(1, $nextBytes);
|
$this->moveStringCursor(1, $nextBytes);
|
||||||
@ -657,6 +661,7 @@ class Lexer
|
|||||||
*
|
*
|
||||||
* @param int $line
|
* @param int $line
|
||||||
* @param int $col
|
* @param int $col
|
||||||
|
*
|
||||||
* @return Token
|
* @return Token
|
||||||
*/
|
*/
|
||||||
private function readComment($line, $col, Token $prev)
|
private function readComment($line, $col, Token $prev)
|
||||||
@ -666,8 +671,8 @@ class Lexer
|
|||||||
$bytes = 1;
|
$bytes = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
list ($char, $code, $bytes) = $this->moveStringCursor(1, $bytes)->readChar();
|
[$char, $code, $bytes] = $this->moveStringCursor(1, $bytes)->readChar();
|
||||||
$value .= $char;
|
$value .= $char;
|
||||||
} while ($code &&
|
} while ($code &&
|
||||||
// SourceCharacter but not LineTerminator
|
// SourceCharacter but not LineTerminator
|
||||||
($code > 0x001F || $code === 0x0009)
|
($code > 0x001F || $code === 0x0009)
|
||||||
@ -689,6 +694,7 @@ class Lexer
|
|||||||
*
|
*
|
||||||
* @param bool $advance
|
* @param bool $advance
|
||||||
* @param int $byteStreamPosition
|
* @param int $byteStreamPosition
|
||||||
|
*
|
||||||
* @return (string|int)[]
|
* @return (string|int)[]
|
||||||
*/
|
*/
|
||||||
private function readChar($advance = false, $byteStreamPosition = null)
|
private function readChar($advance = false, $byteStreamPosition = null)
|
||||||
@ -736,6 +742,7 @@ class Lexer
|
|||||||
* @param int $charCount
|
* @param int $charCount
|
||||||
* @param bool $advance
|
* @param bool $advance
|
||||||
* @param null $byteStreamPosition
|
* @param null $byteStreamPosition
|
||||||
|
*
|
||||||
* @return (string|int)[]
|
* @return (string|int)[]
|
||||||
*/
|
*/
|
||||||
private function readChars($charCount, $advance = false, $byteStreamPosition = null)
|
private function readChars($charCount, $advance = false, $byteStreamPosition = null)
|
||||||
@ -745,10 +752,10 @@ class Lexer
|
|||||||
$byteOffset = $byteStreamPosition ?: $this->byteStreamPosition;
|
$byteOffset = $byteStreamPosition ?: $this->byteStreamPosition;
|
||||||
|
|
||||||
for ($i = 0; $i < $charCount; $i++) {
|
for ($i = 0; $i < $charCount; $i++) {
|
||||||
list ($char, $code, $bytes) = $this->readChar(false, $byteOffset);
|
[$char, $code, $bytes] = $this->readChar(false, $byteOffset);
|
||||||
$totalBytes += $bytes;
|
$totalBytes += $bytes;
|
||||||
$byteOffset += $bytes;
|
$byteOffset += $bytes;
|
||||||
$result .= $char;
|
$result .= $char;
|
||||||
}
|
}
|
||||||
if ($advance) {
|
if ($advance) {
|
||||||
$this->moveStringCursor($charCount, $totalBytes);
|
$this->moveStringCursor($charCount, $totalBytes);
|
||||||
@ -762,6 +769,7 @@ class Lexer
|
|||||||
*
|
*
|
||||||
* @param int $positionOffset
|
* @param int $positionOffset
|
||||||
* @param int $byteStreamOffset
|
* @param int $byteStreamOffset
|
||||||
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
private function moveStringCursor($positionOffset, $byteStreamOffset)
|
private function moveStringCursor($positionOffset, $byteStreamOffset)
|
||||||
|
@ -102,11 +102,14 @@ class Parser
|
|||||||
* Note: this feature is experimental and may change or be removed in the
|
* Note: this feature is experimental and may change or be removed in the
|
||||||
* future.)
|
* future.)
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param Source|string $source
|
* @param Source|string $source
|
||||||
* @param bool[] $options
|
* @param bool[] $options
|
||||||
|
*
|
||||||
* @return DocumentNode
|
* @return DocumentNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function parse($source, array $options = [])
|
public static function parse($source, array $options = [])
|
||||||
{
|
{
|
||||||
@ -126,10 +129,12 @@ class Parser
|
|||||||
*
|
*
|
||||||
* Consider providing the results to the utility function: `GraphQL\Utils\AST::valueFromAST()`.
|
* Consider providing the results to the utility function: `GraphQL\Utils\AST::valueFromAST()`.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param Source|string $source
|
* @param Source|string $source
|
||||||
* @param bool[] $options
|
* @param bool[] $options
|
||||||
|
*
|
||||||
* @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|ListValueNode|ObjectValueNode|StringValueNode|VariableNode
|
* @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|ListValueNode|ObjectValueNode|StringValueNode|VariableNode
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function parseValue($source, array $options = [])
|
public static function parseValue($source, array $options = [])
|
||||||
{
|
{
|
||||||
@ -152,10 +157,12 @@ class Parser
|
|||||||
*
|
*
|
||||||
* Consider providing the results to the utility function: `GraphQL\Utils\AST::typeFromAST()`.
|
* Consider providing the results to the utility function: `GraphQL\Utils\AST::typeFromAST()`.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param Source|string $source
|
* @param Source|string $source
|
||||||
* @param bool[] $options
|
* @param bool[] $options
|
||||||
|
*
|
||||||
* @return ListTypeNode|NameNode|NonNullTypeNode
|
* @return ListTypeNode|NameNode|NonNullTypeNode
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function parseType($source, array $options = [])
|
public static function parseType($source, array $options = [])
|
||||||
{
|
{
|
||||||
@ -172,7 +179,6 @@ class Parser
|
|||||||
private $lexer;
|
private $lexer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param bool[] $options
|
* @param bool[] $options
|
||||||
*/
|
*/
|
||||||
public function __construct(Source $source, array $options = [])
|
public function __construct(Source $source, array $options = [])
|
||||||
@ -199,6 +205,7 @@ class Parser
|
|||||||
* Determines if the next token is of a given kind
|
* Determines if the next token is of a given kind
|
||||||
*
|
*
|
||||||
* @param string $kind
|
* @param string $kind
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function peek($kind)
|
private function peek($kind)
|
||||||
@ -211,6 +218,7 @@ class Parser
|
|||||||
* the parser. Otherwise, do not change the parser state and return false.
|
* the parser. Otherwise, do not change the parser state and return false.
|
||||||
*
|
*
|
||||||
* @param string $kind
|
* @param string $kind
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function skip($kind)
|
private function skip($kind)
|
||||||
@ -227,8 +235,11 @@ class Parser
|
|||||||
/**
|
/**
|
||||||
* If the next token is of the given kind, return that token after advancing
|
* If the next token is of the given kind, return that token after advancing
|
||||||
* the parser. Otherwise, do not change the parser state and return false.
|
* the parser. Otherwise, do not change the parser state and return false.
|
||||||
|
*
|
||||||
* @param string $kind
|
* @param string $kind
|
||||||
|
*
|
||||||
* @return Token
|
* @return Token
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function expect($kind)
|
private function expect($kind)
|
||||||
@ -254,7 +265,9 @@ class Parser
|
|||||||
* false.
|
* false.
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
*
|
||||||
* @return Token
|
* @return Token
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function expectKeyword($value)
|
private function expectKeyword($value)
|
||||||
@ -292,7 +305,9 @@ class Parser
|
|||||||
* @param string $openKind
|
* @param string $openKind
|
||||||
* @param callable $parseFn
|
* @param callable $parseFn
|
||||||
* @param string $closeKind
|
* @param string $closeKind
|
||||||
|
*
|
||||||
* @return NodeList
|
* @return NodeList
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function any($openKind, $parseFn, $closeKind)
|
private function any($openKind, $parseFn, $closeKind)
|
||||||
@ -316,7 +331,9 @@ class Parser
|
|||||||
* @param string $openKind
|
* @param string $openKind
|
||||||
* @param callable $parseFn
|
* @param callable $parseFn
|
||||||
* @param string $closeKind
|
* @param string $closeKind
|
||||||
|
*
|
||||||
* @return NodeList
|
* @return NodeList
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function many($openKind, $parseFn, $closeKind)
|
private function many($openKind, $parseFn, $closeKind)
|
||||||
@ -335,6 +352,7 @@ class Parser
|
|||||||
* Converts a name lex token into a name parse node.
|
* Converts a name lex token into a name parse node.
|
||||||
*
|
*
|
||||||
* @return NameNode
|
* @return NameNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseName()
|
private function parseName()
|
||||||
@ -351,6 +369,7 @@ class Parser
|
|||||||
* Implements the parsing rules in the Document section.
|
* Implements the parsing rules in the Document section.
|
||||||
*
|
*
|
||||||
* @return DocumentNode
|
* @return DocumentNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseDocument()
|
private function parseDocument()
|
||||||
@ -371,6 +390,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ExecutableDefinitionNode|TypeSystemDefinitionNode
|
* @return ExecutableDefinitionNode|TypeSystemDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseDefinition()
|
private function parseDefinition()
|
||||||
@ -408,6 +428,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ExecutableDefinitionNode
|
* @return ExecutableDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseExecutableDefinition()
|
private function parseExecutableDefinition()
|
||||||
@ -433,6 +454,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return OperationDefinitionNode
|
* @return OperationDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseOperationDefinition()
|
private function parseOperationDefinition()
|
||||||
@ -468,6 +490,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseOperationType()
|
private function parseOperationType()
|
||||||
@ -503,6 +526,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return VariableDefinitionNode
|
* @return VariableDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseVariableDefinition()
|
private function parseVariableDefinition()
|
||||||
@ -524,6 +548,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return VariableNode
|
* @return VariableNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseVariable()
|
private function parseVariable()
|
||||||
@ -575,6 +600,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return FieldNode
|
* @return FieldNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseField()
|
private function parseField()
|
||||||
@ -602,7 +628,9 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $isConst
|
* @param bool $isConst
|
||||||
|
*
|
||||||
* @return ArgumentNode[]|NodeList
|
* @return ArgumentNode[]|NodeList
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseArguments($isConst)
|
private function parseArguments($isConst)
|
||||||
@ -622,6 +650,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ArgumentNode
|
* @return ArgumentNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseArgument()
|
private function parseArgument()
|
||||||
@ -641,6 +670,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ArgumentNode
|
* @return ArgumentNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseConstArgument()
|
private function parseConstArgument()
|
||||||
@ -662,6 +692,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return FragmentSpreadNode|InlineFragmentNode
|
* @return FragmentSpreadNode|InlineFragmentNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseFragment()
|
private function parseFragment()
|
||||||
@ -693,6 +724,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return FragmentDefinitionNode
|
* @return FragmentDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseFragmentDefinition()
|
private function parseFragmentDefinition()
|
||||||
@ -724,6 +756,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return NameNode
|
* @return NameNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseFragmentName()
|
private function parseFragmentName()
|
||||||
@ -756,7 +789,9 @@ class Parser
|
|||||||
* EnumValue : Name but not `true`, `false` or `null`
|
* EnumValue : Name but not `true`, `false` or `null`
|
||||||
*
|
*
|
||||||
* @param bool $isConst
|
* @param bool $isConst
|
||||||
|
*
|
||||||
* @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|StringValueNode|VariableNode|ListValueNode|ObjectValueNode|NullValueNode
|
* @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|StringValueNode|VariableNode|ListValueNode|ObjectValueNode|NullValueNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseValueLiteral($isConst)
|
private function parseValueLiteral($isConst)
|
||||||
@ -834,6 +869,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|StringValueNode|VariableNode
|
* @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|StringValueNode|VariableNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseConstValue()
|
private function parseConstValue()
|
||||||
@ -851,6 +887,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $isConst
|
* @param bool $isConst
|
||||||
|
*
|
||||||
* @return ListValueNode
|
* @return ListValueNode
|
||||||
*/
|
*/
|
||||||
private function parseArray($isConst)
|
private function parseArray($isConst)
|
||||||
@ -872,6 +909,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $isConst
|
* @param bool $isConst
|
||||||
|
*
|
||||||
* @return ObjectValueNode
|
* @return ObjectValueNode
|
||||||
*/
|
*/
|
||||||
private function parseObject($isConst)
|
private function parseObject($isConst)
|
||||||
@ -891,6 +929,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $isConst
|
* @param bool $isConst
|
||||||
|
*
|
||||||
* @return ObjectFieldNode
|
* @return ObjectFieldNode
|
||||||
*/
|
*/
|
||||||
private function parseObjectField($isConst)
|
private function parseObjectField($isConst)
|
||||||
@ -911,7 +950,9 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $isConst
|
* @param bool $isConst
|
||||||
|
*
|
||||||
* @return DirectiveNode[]|NodeList
|
* @return DirectiveNode[]|NodeList
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseDirectives($isConst)
|
private function parseDirectives($isConst)
|
||||||
@ -926,7 +967,9 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $isConst
|
* @param bool $isConst
|
||||||
|
*
|
||||||
* @return DirectiveNode
|
* @return DirectiveNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseDirective($isConst)
|
private function parseDirective($isConst)
|
||||||
@ -947,6 +990,7 @@ class Parser
|
|||||||
* Handles the Type: TypeName, ListType, and NonNullType parsing rules.
|
* Handles the Type: TypeName, ListType, and NonNullType parsing rules.
|
||||||
*
|
*
|
||||||
* @return ListTypeNode|NameNode|NonNullTypeNode
|
* @return ListTypeNode|NameNode|NonNullTypeNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseTypeReference()
|
private function parseTypeReference()
|
||||||
@ -1001,6 +1045,7 @@ class Parser
|
|||||||
* - InputObjectTypeDefinition
|
* - InputObjectTypeDefinition
|
||||||
*
|
*
|
||||||
* @return TypeSystemDefinitionNode
|
* @return TypeSystemDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseTypeSystemDefinition()
|
private function parseTypeSystemDefinition()
|
||||||
@ -1056,6 +1101,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return SchemaDefinitionNode
|
* @return SchemaDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseSchemaDefinition()
|
private function parseSchemaDefinition()
|
||||||
@ -1081,6 +1127,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return OperationTypeDefinitionNode
|
* @return OperationTypeDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseOperationTypeDefinition()
|
private function parseOperationTypeDefinition()
|
||||||
@ -1099,6 +1146,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ScalarTypeDefinitionNode
|
* @return ScalarTypeDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseScalarTypeDefinition()
|
private function parseScalarTypeDefinition()
|
||||||
@ -1119,6 +1167,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ObjectTypeDefinitionNode
|
* @return ObjectTypeDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseObjectTypeDefinition()
|
private function parseObjectTypeDefinition()
|
||||||
@ -1168,6 +1217,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return FieldDefinitionNode[]|NodeList
|
* @return FieldDefinitionNode[]|NodeList
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseFieldsDefinition()
|
private function parseFieldsDefinition()
|
||||||
@ -1196,6 +1246,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return FieldDefinitionNode
|
* @return FieldDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseFieldDefinition()
|
private function parseFieldDefinition()
|
||||||
@ -1220,6 +1271,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return InputValueDefinitionNode[]|NodeList
|
* @return InputValueDefinitionNode[]|NodeList
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseArgumentDefs()
|
private function parseArgumentDefs()
|
||||||
@ -1239,6 +1291,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return InputValueDefinitionNode
|
* @return InputValueDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseInputValueDef()
|
private function parseInputValueDef()
|
||||||
@ -1266,6 +1319,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return InterfaceTypeDefinitionNode
|
* @return InterfaceTypeDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseInterfaceTypeDefinition()
|
private function parseInterfaceTypeDefinition()
|
||||||
@ -1291,6 +1345,7 @@ class Parser
|
|||||||
* - Description? union Name Directives[Const]? UnionMemberTypes?
|
* - Description? union Name Directives[Const]? UnionMemberTypes?
|
||||||
*
|
*
|
||||||
* @return UnionTypeDefinitionNode
|
* @return UnionTypeDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseUnionTypeDefinition()
|
private function parseUnionTypeDefinition()
|
||||||
@ -1334,6 +1389,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return EnumTypeDefinitionNode
|
* @return EnumTypeDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseEnumTypeDefinition()
|
private function parseEnumTypeDefinition()
|
||||||
@ -1356,6 +1412,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return EnumValueDefinitionNode[]|NodeList
|
* @return EnumValueDefinitionNode[]|NodeList
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseEnumValuesDefinition()
|
private function parseEnumValuesDefinition()
|
||||||
@ -1373,6 +1430,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return EnumValueDefinitionNode
|
* @return EnumValueDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseEnumValueDefinition()
|
private function parseEnumValueDefinition()
|
||||||
@ -1392,6 +1450,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return InputObjectTypeDefinitionNode
|
* @return InputObjectTypeDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseInputObjectTypeDefinition()
|
private function parseInputObjectTypeDefinition()
|
||||||
@ -1414,6 +1473,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return InputValueDefinitionNode[]|NodeList
|
* @return InputValueDefinitionNode[]|NodeList
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseInputFieldsDefinition()
|
private function parseInputFieldsDefinition()
|
||||||
@ -1439,6 +1499,7 @@ class Parser
|
|||||||
* - InputObjectTypeDefinition
|
* - InputObjectTypeDefinition
|
||||||
*
|
*
|
||||||
* @return TypeExtensionNode
|
* @return TypeExtensionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseTypeExtension()
|
private function parseTypeExtension()
|
||||||
@ -1469,6 +1530,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return SchemaTypeExtensionNode
|
* @return SchemaTypeExtensionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseSchemaTypeExtension()
|
private function parseSchemaTypeExtension()
|
||||||
@ -1496,6 +1558,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ScalarTypeExtensionNode
|
* @return ScalarTypeExtensionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseScalarTypeExtension()
|
private function parseScalarTypeExtension()
|
||||||
@ -1518,6 +1581,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ObjectTypeExtensionNode
|
* @return ObjectTypeExtensionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseObjectTypeExtension()
|
private function parseObjectTypeExtension()
|
||||||
@ -1548,6 +1612,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return InterfaceTypeExtensionNode
|
* @return InterfaceTypeExtensionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseInterfaceTypeExtension()
|
private function parseInterfaceTypeExtension()
|
||||||
@ -1578,6 +1643,7 @@ class Parser
|
|||||||
* - extend union Name Directives[Const]
|
* - extend union Name Directives[Const]
|
||||||
*
|
*
|
||||||
* @return UnionTypeExtensionNode
|
* @return UnionTypeExtensionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseUnionTypeExtension()
|
private function parseUnionTypeExtension()
|
||||||
@ -1604,6 +1670,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return EnumTypeExtensionNode
|
* @return EnumTypeExtensionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseEnumTypeExtension()
|
private function parseEnumTypeExtension()
|
||||||
@ -1630,6 +1697,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return InputObjectTypeExtensionNode
|
* @return InputObjectTypeExtensionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseInputObjectTypeExtension()
|
private function parseInputObjectTypeExtension()
|
||||||
@ -1659,6 +1727,7 @@ class Parser
|
|||||||
* - directive @ Name ArgumentsDefinition? on DirectiveLocations
|
* - directive @ Name ArgumentsDefinition? on DirectiveLocations
|
||||||
*
|
*
|
||||||
* @return DirectiveDefinitionNode
|
* @return DirectiveDefinitionNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseDirectiveDefinition()
|
private function parseDirectiveDefinition()
|
||||||
@ -1683,6 +1752,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return NameNode[]
|
* @return NameNode[]
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseDirectiveLocations()
|
private function parseDirectiveLocations()
|
||||||
@ -1699,6 +1769,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return NameNode
|
* @return NameNode
|
||||||
|
*
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
private function parseDirectiveLocation()
|
private function parseDirectiveLocation()
|
||||||
|
@ -73,9 +73,11 @@ class Printer
|
|||||||
/**
|
/**
|
||||||
* Prints AST to string. Capable of printing GraphQL queries and Type definition language.
|
* Prints AST to string. Capable of printing GraphQL queries and Type definition language.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param Node $ast
|
* @param Node $ast
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function doPrint($ast)
|
public static function doPrint($ast)
|
||||||
{
|
{
|
||||||
@ -95,11 +97,11 @@ class Printer
|
|||||||
$ast,
|
$ast,
|
||||||
[
|
[
|
||||||
'leave' => [
|
'leave' => [
|
||||||
NodeKind::NAME => function (Node $node) {
|
NodeKind::NAME => static function (Node $node) {
|
||||||
return '' . $node->value;
|
return '' . $node->value;
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::VARIABLE => function ($node) {
|
NodeKind::VARIABLE => static function ($node) {
|
||||||
return '$' . $node->name;
|
return '$' . $node->name;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -143,7 +145,7 @@ class Printer
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::ARGUMENT => function (ArgumentNode $node) {
|
NodeKind::ARGUMENT => static function (ArgumentNode $node) {
|
||||||
return $node->name . ': ' . $node->value;
|
return $node->name . ': ' . $node->value;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -172,11 +174,11 @@ class Printer
|
|||||||
. $node->selectionSet;
|
. $node->selectionSet;
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::INT => function (IntValueNode $node) {
|
NodeKind::INT => static function (IntValueNode $node) {
|
||||||
return $node->value;
|
return $node->value;
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::FLOAT => function (FloatValueNode $node) {
|
NodeKind::FLOAT => static function (FloatValueNode $node) {
|
||||||
return $node->value;
|
return $node->value;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -188,15 +190,15 @@ class Printer
|
|||||||
return json_encode($node->value);
|
return json_encode($node->value);
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::BOOLEAN => function (BooleanValueNode $node) {
|
NodeKind::BOOLEAN => static function (BooleanValueNode $node) {
|
||||||
return $node->value ? 'true' : 'false';
|
return $node->value ? 'true' : 'false';
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::NULL => function (NullValueNode $node) {
|
NodeKind::NULL => static function (NullValueNode $node) {
|
||||||
return 'null';
|
return 'null';
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::ENUM => function (EnumValueNode $node) {
|
NodeKind::ENUM => static function (EnumValueNode $node) {
|
||||||
return $node->value;
|
return $node->value;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -208,7 +210,7 @@ class Printer
|
|||||||
return '{' . $this->join($node->fields, ', ') . '}';
|
return '{' . $this->join($node->fields, ', ') . '}';
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::OBJECT_FIELD => function (ObjectFieldNode $node) {
|
NodeKind::OBJECT_FIELD => static function (ObjectFieldNode $node) {
|
||||||
return $node->name . ': ' . $node->value;
|
return $node->name . ': ' . $node->value;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -216,15 +218,15 @@ class Printer
|
|||||||
return '@' . $node->name . $this->wrap('(', $this->join($node->arguments, ', '), ')');
|
return '@' . $node->name . $this->wrap('(', $this->join($node->arguments, ', '), ')');
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::NAMED_TYPE => function (NamedTypeNode $node) {
|
NodeKind::NAMED_TYPE => static function (NamedTypeNode $node) {
|
||||||
return $node->name;
|
return $node->name;
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::LIST_TYPE => function (ListTypeNode $node) {
|
NodeKind::LIST_TYPE => static function (ListTypeNode $node) {
|
||||||
return '[' . $node->type . ']';
|
return '[' . $node->type . ']';
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::NON_NULL_TYPE => function (NonNullTypeNode $node) {
|
NodeKind::NON_NULL_TYPE => static function (NonNullTypeNode $node) {
|
||||||
return $node->type . '!';
|
return $node->type . '!';
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -239,7 +241,7 @@ class Printer
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::OPERATION_TYPE_DEFINITION => function (OperationTypeDefinitionNode $def) {
|
NodeKind::OPERATION_TYPE_DEFINITION => static function (OperationTypeDefinitionNode $def) {
|
||||||
return $def->operation . ': ' . $def->type;
|
return $def->operation . ': ' . $def->type;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -432,7 +434,7 @@ class Printer
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addDescription(\Closure $cb)
|
public function addDescription(callable $cb)
|
||||||
{
|
{
|
||||||
return function ($node) use ($cb) {
|
return function ($node) use ($cb) {
|
||||||
return $this->join([$node->description, $cb($node)], "\n");
|
return $this->join([$node->description, $cb($node)], "\n");
|
||||||
@ -454,7 +456,7 @@ class Printer
|
|||||||
*/
|
*/
|
||||||
public function block($array)
|
public function block($array)
|
||||||
{
|
{
|
||||||
return ($array && $this->length($array))
|
return $array && $this->length($array)
|
||||||
? "{\n" . $this->indent($this->join($array, "\n")) . "\n}"
|
? "{\n" . $this->indent($this->join($array, "\n")) . "\n}"
|
||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
@ -481,7 +483,7 @@ class Printer
|
|||||||
$separator,
|
$separator,
|
||||||
Utils::filter(
|
Utils::filter(
|
||||||
$maybeArray,
|
$maybeArray,
|
||||||
function ($x) {
|
static function ($x) {
|
||||||
return (bool) $x;
|
return (bool) $x;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -498,7 +500,7 @@ class Printer
|
|||||||
{
|
{
|
||||||
$escaped = str_replace('"""', '\\"""', $value);
|
$escaped = str_replace('"""', '\\"""', $value);
|
||||||
|
|
||||||
return (($value[0] === ' ' || $value[0] === "\t") && strpos($value, "\n") === false)
|
return ($value[0] === ' ' || $value[0] === "\t") && strpos($value, "\n") === false
|
||||||
? ('"""' . preg_replace('/"$/', "\"\n", $escaped) . '"""')
|
? ('"""' . preg_replace('/"$/', "\"\n", $escaped) . '"""')
|
||||||
: ('"""' . "\n" . ($isDescription ? $escaped : $this->indent($escaped)) . "\n" . '"""');
|
: ('"""' . "\n" . ($isDescription ? $escaped : $this->indent($escaped)) . "\n" . '"""');
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,6 @@ class Source
|
|||||||
public $locationOffset;
|
public $locationOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
*
|
|
||||||
* A representation of source input to GraphQL.
|
* A representation of source input to GraphQL.
|
||||||
* `name` and `locationOffset` are optional. They are useful for clients who
|
* `name` and `locationOffset` are optional. They are useful for clients who
|
||||||
* store GraphQL documents in source files; for example, if the GraphQL input
|
* store GraphQL documents in source files; for example, if the GraphQL input
|
||||||
@ -63,6 +61,7 @@ class Source
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $position
|
* @param int $position
|
||||||
|
*
|
||||||
* @return SourceLocation
|
* @return SourceLocation
|
||||||
*/
|
*/
|
||||||
public function getLocation($position)
|
public function getLocation($position)
|
||||||
|
@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Language;
|
namespace GraphQL\Language;
|
||||||
|
|
||||||
class SourceLocation implements \JsonSerializable
|
use JsonSerializable;
|
||||||
|
|
||||||
|
class SourceLocation implements JsonSerializable
|
||||||
{
|
{
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public $line;
|
public $line;
|
||||||
|
@ -85,7 +85,6 @@ class Token
|
|||||||
public $next;
|
public $next;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param string $kind
|
* @param string $kind
|
||||||
* @param int $start
|
* @param int $start
|
||||||
* @param int $end
|
* @param int $end
|
||||||
|
@ -5,10 +5,12 @@ declare(strict_types=1);
|
|||||||
namespace GraphQL\Language;
|
namespace GraphQL\Language;
|
||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
|
use Exception;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
use GraphQL\Language\AST\NodeKind;
|
use GraphQL\Language\AST\NodeKind;
|
||||||
use GraphQL\Language\AST\NodeList;
|
use GraphQL\Language\AST\NodeList;
|
||||||
use GraphQL\Utils\TypeInfo;
|
use GraphQL\Utils\TypeInfo;
|
||||||
|
use SplFixedArray;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use function array_pop;
|
use function array_pop;
|
||||||
use function array_splice;
|
use function array_splice;
|
||||||
@ -172,12 +174,15 @@ class Visitor
|
|||||||
/**
|
/**
|
||||||
* Visit the AST (see class description for details)
|
* Visit the AST (see class description for details)
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param Node|ArrayObject|stdClass $root
|
* @param Node|ArrayObject|stdClass $root
|
||||||
* @param callable[] $visitor
|
* @param callable[] $visitor
|
||||||
* @param mixed[]|null $keyMap
|
* @param mixed[]|null $keyMap
|
||||||
|
*
|
||||||
* @return Node|mixed
|
* @return Node|mixed
|
||||||
* @throws \Exception
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function visit($root, $visitor, $keyMap = null)
|
public static function visit($root, $visitor, $keyMap = null)
|
||||||
{
|
{
|
||||||
@ -247,7 +252,7 @@ class Visitor
|
|||||||
$stack = $stack['prev'];
|
$stack = $stack['prev'];
|
||||||
} else {
|
} else {
|
||||||
$key = $parent ? ($inArray ? $index : $keys[$index]) : $UNDEFINED;
|
$key = $parent ? ($inArray ? $index : $keys[$index]) : $UNDEFINED;
|
||||||
$node = $parent ? (($parent instanceof NodeList || is_array($parent)) ? $parent[$key] : $parent->{$key}) : $newRoot;
|
$node = $parent ? ($parent instanceof NodeList || is_array($parent) ? $parent[$key] : $parent->{$key}) : $newRoot;
|
||||||
if ($node === null || $node === $UNDEFINED) {
|
if ($node === null || $node === $UNDEFINED) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -259,7 +264,7 @@ class Visitor
|
|||||||
$result = null;
|
$result = null;
|
||||||
if (! $node instanceof NodeList && ! is_array($node)) {
|
if (! $node instanceof NodeList && ! is_array($node)) {
|
||||||
if (! ($node instanceof Node)) {
|
if (! ($node instanceof Node)) {
|
||||||
throw new \Exception('Invalid AST Node: ' . json_encode($node));
|
throw new Exception('Invalid AST Node: ' . json_encode($node));
|
||||||
}
|
}
|
||||||
|
|
||||||
$visitFn = self::getVisitFn($visitor, $node->kind, $isLeaving);
|
$visitFn = self::getVisitFn($visitor, $node->kind, $isLeaving);
|
||||||
@ -333,8 +338,9 @@ class Visitor
|
|||||||
/**
|
/**
|
||||||
* Returns marker for visitor break
|
* Returns marker for visitor break
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @return VisitorOperation
|
* @return VisitorOperation
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function stop()
|
public static function stop()
|
||||||
{
|
{
|
||||||
@ -347,8 +353,9 @@ class Visitor
|
|||||||
/**
|
/**
|
||||||
* Returns marker for skipping current node
|
* Returns marker for skipping current node
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @return VisitorOperation
|
* @return VisitorOperation
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function skipNode()
|
public static function skipNode()
|
||||||
{
|
{
|
||||||
@ -361,8 +368,9 @@ class Visitor
|
|||||||
/**
|
/**
|
||||||
* Returns marker for removing a node
|
* Returns marker for removing a node
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @return VisitorOperation
|
* @return VisitorOperation
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function removeNode()
|
public static function removeNode()
|
||||||
{
|
{
|
||||||
@ -374,15 +382,16 @@ class Visitor
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param callable[][] $visitors
|
* @param callable[][] $visitors
|
||||||
|
*
|
||||||
* @return callable[][]
|
* @return callable[][]
|
||||||
*/
|
*/
|
||||||
public static function visitInParallel($visitors)
|
public static function visitInParallel($visitors)
|
||||||
{
|
{
|
||||||
$visitorsCount = count($visitors);
|
$visitorsCount = count($visitors);
|
||||||
$skipping = new \SplFixedArray($visitorsCount);
|
$skipping = new SplFixedArray($visitorsCount);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'enter' => function (Node $node) use ($visitors, $skipping, $visitorsCount) {
|
'enter' => static function (Node $node) use ($visitors, $skipping, $visitorsCount) {
|
||||||
for ($i = 0; $i < $visitorsCount; $i++) {
|
for ($i = 0; $i < $visitorsCount; $i++) {
|
||||||
if (! empty($skipping[$i])) {
|
if (! empty($skipping[$i])) {
|
||||||
continue;
|
continue;
|
||||||
@ -413,7 +422,7 @@ class Visitor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'leave' => function (Node $node) use ($visitors, $skipping, $visitorsCount) {
|
'leave' => static function (Node $node) use ($visitors, $skipping, $visitorsCount) {
|
||||||
for ($i = 0; $i < $visitorsCount; $i++) {
|
for ($i = 0; $i < $visitorsCount; $i++) {
|
||||||
if (empty($skipping[$i])) {
|
if (empty($skipping[$i])) {
|
||||||
$fn = self::getVisitFn(
|
$fn = self::getVisitFn(
|
||||||
@ -449,7 +458,7 @@ class Visitor
|
|||||||
public static function visitWithTypeInfo(TypeInfo $typeInfo, $visitor)
|
public static function visitWithTypeInfo(TypeInfo $typeInfo, $visitor)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'enter' => function (Node $node) use ($typeInfo, $visitor) {
|
'enter' => static function (Node $node) use ($typeInfo, $visitor) {
|
||||||
$typeInfo->enter($node);
|
$typeInfo->enter($node);
|
||||||
$fn = self::getVisitFn($visitor, $node->kind, false);
|
$fn = self::getVisitFn($visitor, $node->kind, false);
|
||||||
|
|
||||||
@ -467,7 +476,7 @@ class Visitor
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
'leave' => function (Node $node) use ($typeInfo, $visitor) {
|
'leave' => static function (Node $node) use ($typeInfo, $visitor) {
|
||||||
$fn = self::getVisitFn($visitor, $node->kind, true);
|
$fn = self::getVisitFn($visitor, $node->kind, true);
|
||||||
$result = $fn ? call_user_func_array($fn, func_get_args()) : null;
|
$result = $fn ? call_user_func_array($fn, func_get_args()) : null;
|
||||||
$typeInfo->leave($node);
|
$typeInfo->leave($node);
|
||||||
@ -481,6 +490,7 @@ class Visitor
|
|||||||
* @param callable[]|null $visitor
|
* @param callable[]|null $visitor
|
||||||
* @param string $kind
|
* @param string $kind
|
||||||
* @param bool $isLeaving
|
* @param bool $isLeaving
|
||||||
|
*
|
||||||
* @return callable|null
|
* @return callable|null
|
||||||
*/
|
*/
|
||||||
public static function getVisitFn($visitor, $kind, $isLeaving)
|
public static function getVisitFn($visitor, $kind, $isLeaving)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user