class FormatterManager (View source)

Manage a collection of formatters; return one on request.

Properties

protected $formatters

var FormatterInterface[]

protected $arraySimplifiers

var SimplifyToArrayInterface[]

Methods

__construct()

No description

addDefaultFormatters()

No description

addDefaultSimplifiers()

No description

addFormatter(string $key, FormatterInterface $formatter)

Add a formatter

InputOption[]
automaticOptions(FormatterOptions $options, $dataType)

Return a set of InputOption based on the annotations of a command.

string[]
availableFieldsList($availableFields)

Given a list of available fields, return a list of field descriptions.

array
validFormats(mixed $dataType)

Return the identifiers for all valid data types that have been registered.

isValidFormat(FormatterInterface $formatter, $dataType)

No description

isValidDataType(FormatterInterface $formatter, ReflectionClass $dataType)

No description

write(OutputInterface $output, string $format, mixed $structuredOutput, FormatterOptions $options)

Format and write output

validateAndRestructure(FormatterInterface $formatter, $structuredOutput, FormatterOptions $options)

No description

getFormatter(string $format)

Fetch the requested formatter.

hasFormatter($format)

Test to see if the stipulated format exists

mixed
renderData(FormatterInterface $formatter, mixed $originalData, mixed $restructuredData, FormatterOptions $options)

Render the data as necessary (e.g. to select or reorder fields).

mixed
validateData(FormatterInterface $formatter, mixed $structuredOutput, FormatterOptions $options)

Determine if the provided data is compatible with the formatter being used.

simplifyToArray($structuredOutput, FormatterOptions $options)

No description

canSimplifyToArray(ReflectionClass $structuredOutput)

No description

convertData($structuredOutput, FormatterOptions $options)

Convert from one format to another if necessary prior to restructuring.

mixed
restructureData(mixed $structuredOutput, FormatterOptions $options)

Restructure the data as necessary (e.g. to select or reorder fields).

mixed
overrideRestructure(FormatterInterface $formatter, mixed $structuredOutput, FormatterOptions $options)

Allow the formatter access to the raw structured data prior to restructuring. For example, the 'list' formatter may wish to display the row keys when provided table output. If this function returns a result that does not evaluate to 'false', then that result will be used as-is, and restructuring and validation will not occur.

overrideOptions(FormatterInterface $formatter, mixed $structuredOutput, FormatterOptions $options)

Allow the formatter to mess with the configuration options before any transformations et. al. get underway.

Details

__construct()

No description

addDefaultFormatters()

No description

addDefaultSimplifiers()

No description

FormatterManager addFormatter(string $key, FormatterInterface $formatter)

Add a formatter

Parameters

string $key

the identifier of the formatter to add

FormatterInterface $formatter

the class name of the formatter to add

Return Value

FormatterManager

FormatterManager addSimplifier(SimplifyToArrayInterface $simplifier)

Add a simplifier

Parameters

SimplifyToArrayInterface $simplifier

the array simplifier to add

Return Value

FormatterManager

InputOption[] automaticOptions(FormatterOptions $options, $dataType)

Return a set of InputOption based on the annotations of a command.

Parameters

FormatterOptions $options
$dataType

Return Value

InputOption[]

protected string[] availableFieldsList($availableFields)

Given a list of available fields, return a list of field descriptions.

Parameters

$availableFields

Return Value

string[]

array validFormats(mixed $dataType)

Return the identifiers for all valid data types that have been registered.

Parameters

mixed $dataType

\ReflectionObject or other description of the produced data type

Return Value

array

isValidFormat(FormatterInterface $formatter, $dataType)

No description

Parameters

FormatterInterface $formatter
$dataType

isValidDataType(FormatterInterface $formatter, ReflectionClass $dataType)

No description

Parameters

FormatterInterface $formatter
ReflectionClass $dataType

write(OutputInterface $output, string $format, mixed $structuredOutput, FormatterOptions $options)

Format and write output

Parameters

OutputInterface $output

Output stream to write to

string $format

Data format to output in

mixed $structuredOutput

Data to output

FormatterOptions $options

Formatting options

protected validateAndRestructure(FormatterInterface $formatter, $structuredOutput, FormatterOptions $options)

No description

Parameters

FormatterInterface $formatter
$structuredOutput
FormatterOptions $options

FormatterInterface getFormatter(string $format)

Fetch the requested formatter.

Parameters

string $format

Identifier for requested formatter

Return Value

FormatterInterface

hasFormatter($format)

Test to see if the stipulated format exists

Parameters

$format

mixed renderData(FormatterInterface $formatter, mixed $originalData, mixed $restructuredData, FormatterOptions $options)

Render the data as necessary (e.g. to select or reorder fields).

Parameters

FormatterInterface $formatter
mixed $originalData
mixed $restructuredData
FormatterOptions $options

Formatting options

Return Value

mixed

mixed validateData(FormatterInterface $formatter, mixed $structuredOutput, FormatterOptions $options)

Determine if the provided data is compatible with the formatter being used.

Parameters

FormatterInterface $formatter

Formatter being used

mixed $structuredOutput

Data to validate

FormatterOptions $options

Return Value

mixed

protected simplifyToArray($structuredOutput, FormatterOptions $options)

No description

Parameters

$structuredOutput
FormatterOptions $options

protected canSimplifyToArray(ReflectionClass $structuredOutput)

No description

Parameters

ReflectionClass $structuredOutput

convertData($structuredOutput, FormatterOptions $options)

Convert from one format to another if necessary prior to restructuring.

Parameters

$structuredOutput
FormatterOptions $options

mixed restructureData(mixed $structuredOutput, FormatterOptions $options)

Restructure the data as necessary (e.g. to select or reorder fields).

Parameters

mixed $structuredOutput
FormatterOptions $options

Return Value

mixed

mixed overrideRestructure(FormatterInterface $formatter, mixed $structuredOutput, FormatterOptions $options)

Allow the formatter access to the raw structured data prior to restructuring. For example, the 'list' formatter may wish to display the row keys when provided table output. If this function returns a result that does not evaluate to 'false', then that result will be used as-is, and restructuring and validation will not occur.

Parameters

FormatterInterface $formatter
mixed $structuredOutput
FormatterOptions $options

Return Value

mixed

FormatterOptions overrideOptions(FormatterInterface $formatter, mixed $structuredOutput, FormatterOptions $options)

Allow the formatter to mess with the configuration options before any transformations et. al. get underway.

Parameters

FormatterInterface $formatter
mixed $structuredOutput
FormatterOptions $options

Return Value

FormatterOptions