final class Formatter
Public API: explicitly declared with @visibility public.

Formats SQL with the dialect, release, and lexical settings of a supplied parser.

Compact canonicalizes optional syntax and keywords; other styles preserve tokens. Output is parsed again to verify the selected style's preservation contract.

Formatting a querydoctest
$formatter = new \SqlFormatter\Facade\Formatter(new \SqlParser\Sqlite\SqliteParser());
    $formatter->format('SELECT id,name FROM users') // => "SELECT\n    id,\n    name\nFROM\n    users"
Selecting compact outputdoctest
$formatter = new \SqlFormatter\Facade\Formatter(new \SqlParser\MySql\MySqlParser(), new \SqlFormatter\Core\FormatOptions(\SqlFormatter\Core\Style::Compact));
    $formatter->format("SELECT  id, name\nFROM users") // => 'SELECT id,name FROM users'

Methods§

public function __construct(
    SqlParser $parser,
    FormatOptions $options = new \SqlFormatter\Core\FormatOptions(),
    ?Dialect $dialect = null,
)

Selects built-in formatting rules or accepts caller-supplied rules.

Parameters

$parserSqlParser
$optionsFormatOptions
$dialect?Dialect
Calls 3

Private surface 1§

Implementation details, listed for orientation only.

private Formatter $formatter

Test cases 23§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 10
Other tests reaching this symbol 13