WooCommerce Code Reference

Printer
in package

Prints AST to string. Capable of printing Automattic\WooCommerce\Vendor\GraphQL queries and Type definition language.

Useful for pretty-printing queries or printing back AST for logging, documentation, etc.

Usage example:

$query = 'query myQuery {someField}';
$ast = Automattic\WooCommerce\Vendor\GraphQL\Language\Parser::parse($query);
$printed = Automattic\WooCommerce\Vendor\GraphQL\Language\Printer::doPrint($ast);
Tags
see
PrinterTest

Table of Contents

doPrint()  : string
Converts the AST of a Automattic\WooCommerce\Vendor\GraphQL node to a string.
addDescription()  : string
indent()  : string
join()  : string
p()  : string
printList()  : string
printListBlock()  : string
Print each item on its own line, wrapped in an indented "{ }" block.
wrap()  : string
If maybeString is not null or empty, then wrap with start and end, otherwise print an empty string.

Methods

doPrint()

Converts the AST of a Automattic\WooCommerce\Vendor\GraphQL node to a string.

public static doPrint(Node $ast) : string

Handles both executable definitions and schema definitions.

Parameters
$ast : Node
Tags
throws
JsonException
Return values
string

join()

protected static join(array<string|int, string|null> $parts[, string $separator = '' ]) : string
Parameters
$parts : array<string|int, string|null>
$separator : string = ''
Return values
string

printList()

protected static printList(NodeList<string|int, TNode$list[, string $separator = '' ]) : string
Parameters
$list : NodeList<string|int, TNode>
$separator : string = ''
Tags
template

TNode of Node

throws
JsonException
Return values
string

printListBlock()

Print each item on its own line, wrapped in an indented "{ }" block.

protected static printListBlock(NodeList<string|int, TNode$list) : string
Parameters
$list : NodeList<string|int, TNode>
Tags
template

TNode of Node

throws
JsonException
Return values
string

wrap()

If maybeString is not null or empty, then wrap with start and end, otherwise print an empty string.

protected static wrap(string $start, string|null $maybeString[, string $end = '' ]) : string
Parameters
$start : string
$maybeString : string|null
$end : string = ''
Return values
string