function PrettyPrinterAbstract::__construct
Creates a pretty printer instance using the given options.
Supported options:
- PhpVersion $phpVersion: The PHP version to target (default to PHP 7.4). This option controls compatibility of the generated code with older PHP versions in cases where a simple stylistic choice exists (e.g. array() vs []). It is safe to pretty-print an AST for a newer PHP version while specifying an older target (but the result will of course not be compatible with the older version in that case).
- string $newline: The newline style to use. Should be "\n" (default) or "\r\n".
- string $indent: The indentation to use. Should either be all spaces or a single tab. Defaults to four spaces (" ").
- bool $shortArraySyntax: Whether to use [] instead of array() as the default array syntax, if the node does not specify a format. Defaults to whether the phpVersion support short array syntax.
Parameters
array{: phpVersion?: PhpVersion, newline?: string, indent?: string, shortArraySyntax?: bool } $options Dictionary of formatting options
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinterAbstract.php, line 192
Class
Namespace
PhpParserCode
public function __construct(array $options = []) {
$this->phpVersion = $options['phpVersion'] ?? PhpVersion::fromComponents(7, 4);
$this->newline = $options['newline'] ?? "\n";
if ($this->newline !== "\n" && $this->newline != "\r\n") {
throw new \LogicException('Option "newline" must be one of "\\n" or "\\r\\n"');
}
$this->shortArraySyntax = $options['shortArraySyntax'] ?? $this->phpVersion
->supportsShortArraySyntax();
$this->docStringEndToken = $this->phpVersion
->supportsFlexibleHeredoc() ? null : '_DOC_STRING_END_' . mt_rand();
$this->indent = $indent = $options['indent'] ?? ' ';
if ($indent === "\t") {
$this->useTabs = true;
$this->indentWidth = $this->tabWidth;
}
elseif ($indent === \str_repeat(' ', \strlen($indent))) {
$this->useTabs = false;
$this->indentWidth = \strlen($indent);
}
else {
throw new \LogicException('Option "indent" must either be all spaces or a single tab');
}
}