PolyOutput
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
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
No description
Writes messages to the output - but only if we're using HTML format.
Writes messages to the output - but only if we're using ANSI format.
Start a list.
Writes messages formatted as a list.
Set whether this will output in HTML or ANSI format.
Set an output to wrap inside this one. Useful for capturing output in a buffer.
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();
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).
__construct(string $outputFormat, int $verbosity = OutputInterface::VERBOSITY_NORMAL, bool $decorated = false, OutputInterface|null $wrappedOutput = null)
No description
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.
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.
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.
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)
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.
void
setFormatter(OutputFormatterInterface $formatter)
No description
void
setOutputFormat(string $outputFormat)
Set whether this will output in HTML or ANSI format.
string
getOutputFormat()
Get the format used for output.
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