class PolyOutput extends Output (View source)

Output that correctly formats for HTML or for the terminal, depending on the output type.

Used for functionality that can be used both via CLI and via the browser.

Traits

A class that can be instantiated or replaced via DI

Constants

LIST_UNORDERED

LIST_ORDERED

FORMAT_HTML

Use this if you want HTML markup in the output

FORMAT_ANSI

Use this for outputing to a terminal, or for plain text output

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
__construct(string $outputFormat, int $verbosity = OutputInterface::VERBOSITY_NORMAL, bool $decorated = false, OutputInterface|null $wrappedOutput = null)

No description

public
void
writeForHtml(string|iterable $messages, bool $newline = false, int $options = OutputInterface::OUTPUT_RAW)

Writes messages to the output - but only if we're using HTML format.

public
void
writeForAnsi(string|iterable $messages, bool $newline = false, int $options = OutputInterface::OUTPUT_NORMAL)

Writes messages to the output - but only if we're using ANSI format.

public
void
startList(string $listType = PolyOutput::LIST_UNORDERED, int $options = OutputInterface::OUTPUT_NORMAL)

Start a list.

public
void
stopList()

Stop a list.

public
void
writeListItem(string|iterable $items, int|null $options = null)

Writes messages formatted as a list.

public
void
setFormatter(OutputFormatterInterface $formatter)

No description

public
void
setOutputFormat(string $outputFormat)

Set whether this will output in HTML or ANSI format.

public
string
getOutputFormat()

Get the format used for output.

public
void
setWrappedOutput(OutputInterface $wrappedOutput)

Set an output to wrap inside this one. Useful for capturing output in a buffer.

protected
void
doWrite(string $message, bool $newline)

No description

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

__construct(string $outputFormat, int $verbosity = OutputInterface::VERBOSITY_NORMAL, bool $decorated = false, OutputInterface|null $wrappedOutput = null)

No description

Parameters

string $outputFormat

The format to use for the output (one of the FORMAT_* constants)

int $verbosity
bool $decorated

Whether to decorate messages (if false, decoration tags will simply be removed)

OutputInterface|null $wrappedOutput

An optional output pipe messages through. Useful for capturing output instead of echoing directly to the client, for example.

void writeForHtml(string|iterable $messages, bool $newline = false, int $options = OutputInterface::OUTPUT_RAW)

Writes messages to the output - but only if we're using HTML format.

Useful for when HTML and ANSI formatted output need to diverge.

Note that this method uses RAW output by default, which allows you to add HTML markup directly into the message. If you're using symfony/console style formatting, set $options to use the OUTPUT_NORMAL constant.

Parameters

string|iterable $messages
bool $newline
int $options

A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL

Return Value

void

void writeForAnsi(string|iterable $messages, bool $newline = false, int $options = OutputInterface::OUTPUT_NORMAL)

Writes messages to the output - but only if we're using ANSI format.

Useful for when HTML and ANSI formatted output need to diverge.

Parameters

string|iterable $messages
bool $newline
int $options

A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL

Return Value

void

void startList(string $listType = PolyOutput::LIST_UNORDERED, int $options = OutputInterface::OUTPUT_NORMAL)

Start a list.

In HTML format this will write the opening <ul> or <ol> tag. In ANSI format this will set up information for rendering list items.

Call writeListItem() to add items to the list, then call stopList() when you're done.

Parameters

string $listType

One of the LIST_* consts, e.g. PolyOutput::LIST_UNORDERED

int $options

A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL

Return Value

void

void stopList()

Stop a list.

In HTML format this will write the closing </ul> or </ol> tag. In ANSI format this will mark the list as closed (useful when nesting lists)

Return Value

void

void writeListItem(string|iterable $items, int|null $options = null)

Writes messages formatted as a list.

Make sure to call startList() before writing list items, and call stopList() when you're done.

Parameters

string|iterable $items
int|null $options

A bitmask of options (one of the OUTPUT or VERBOSITY constants), by default this will inherit the options used to start the list.

Return Value

void

void setFormatter(OutputFormatterInterface $formatter)

No description

Parameters

OutputFormatterInterface $formatter

Return Value

void

void setOutputFormat(string $outputFormat)

Set whether this will output in HTML or ANSI format.

Parameters

string $outputFormat

Return Value

void

Exceptions

InvalidArgumentException

string getOutputFormat()

Get the format used for output.

Return Value

string

void setWrappedOutput(OutputInterface $wrappedOutput)

Set an output to wrap inside this one. Useful for capturing output in a buffer.

Parameters

OutputInterface $wrappedOutput

Return Value

void

protected void doWrite(string $message, bool $newline)

No description

Parameters

string $message
bool $newline

Return Value

void