class FormatterOptions (View source)

FormatterOptions holds information that affects the way a formatter renders its output.

There are three places where a formatter might get options from:

  1. Configuration associated with the command that produced the output. This is passed in to FormatterManager::write() along with the data to format. It might originally come from annotations on the command, or it might come from another source. Examples include the field labels for a table, or the default list of fields to display.

  2. Options specified by the user, e.g. by commandline options.

  3. Default values associated with the formatter itself.

This class caches configuration from sources (1) and (2), and expects to be provided the defaults, (3), whenever a value is requested.

Constants

FORMAT

DEFAULT_FORMAT

TABLE_STYLE

TABLE_EMPTY_MESSAGE

LIST_ORIENTATION

FIELDS

FIELD

INCLUDE_FIELD_LABELS

ROW_LABELS

FIELD_LABELS

DEFAULT_FIELDS

DEFAULT_TABLE_FIELDS

DEFAULT_STRING_FIELD

DELIMITER

CSV_ENCLOSURE

CSV_ESCAPE_CHAR

LIST_DELIMITER

TERMINAL_WIDTH

METADATA_TEMPLATE

HUMAN_READABLE

Properties

protected $configurationData

var array

protected $options

var array

protected $input

var InputInterface

Methods

__construct(array $configurationData = [], array $options = [])

Create a new FormatterOptions with the configuration data and the user-specified options for this request.

override(array $configurationData)

Create a new FormatterOptions object with new configuration data (provided), and the same options data as this instance.

setTableStyle($style)

No description

setDelimiter($delimiter)

No description

setCsvEnclosure($enclosure)

No description

setCsvEscapeChar($escapeChar)

No description

setListDelimiter($listDelimiter)

No description

setIncludeFieldLables($includFieldLables)

No description

setListOrientation($listOrientation)

No description

setRowLabels($rowLabels)

No description

setDefaultFields($fields)

No description

setFieldLabels($fieldLabels)

No description

setTableEmptyMessage($emptyMessage)

No description

setTableDefaultFields($defaultTableFields)

No description

setDefaultStringField($defaultStringField)

No description

setWidth($width)

No description

setHumanReadable($isHumanReadable = true)

No description

mixed
get(string $key, array $defaults = [], mixed $default = false)

Get a formatter option

mixed
fields(array $defaults = [], mixed $default = false)

Get the fields based on the selections made by the user and the available annotation data. The fields are reported as the user selected them, and therefore may be either the field machine name, or its corresponding human-readable label.

fieldsContain($fieldName)

Returns 'true' iff the fields selected by the user (or the default fields, if none explicitly selected) contain the specified field name.

fieldAlias($fieldName)

No description

getXmlSchema()

Return the XmlSchema to use with --format=xml for data types that support that. This is used when an array needs to be converted into xml.

string
getFormat(array $defaults = [])

Determine the format that was requested by the caller.

mixed
fetch(string $key, array $defaults = [], mixed $default = false)

Look up a key, and return its raw value.

array
defaultsForKey(string $key, array $defaults, $default = false)

Reduce provided defaults to the single item identified by '$key', if it exists, or an empty array otherwise.

array
fetchRawValues(array $defaults = [])

Look up all of the items associated with the provided defaults.

mixed
parse(string $key, mixed $value)

Given the raw value for a specific key, do any type conversion (e.g. from a textual list to an array) needed for the data.

array
parsePropertyList(string $value)

Convert from a textual list to an array

string
getOptionFormat(string $key)

Given a specific key, return the class method name of the parsing method for data stored under this key.

setConfigurationData(array $configurationData)

Change the configuration data for this formatter options object.

setConfigurationValue(string $key, mixed $value)

Change one configuration value for this formatter option.

setConfigurationDefault(string $key, mixed $value)

Change one configuration value for this formatter option, but only if it does not already have a value set.

array
getConfigurationData()

Return a reference to the configuration data for this object.

setOptions(array $options)

Set all of the options that were specified by the user for this request.

setOption(string $key, mixed $value)

Change one option value specified by the user for this request.

array
getOptions()

Return a reference to the user-specified options for this request.

setInput(InputInterface $input)

Provide a Symfony Console InputInterface containing the user-specified options for this request.

array
getInputOptions(array $defaults)

Return all of the options from the provided $defaults array that exist in our InputInterface object.

Details

__construct(array $configurationData = [], array $options = [])

Create a new FormatterOptions with the configuration data and the user-specified options for this request.

Parameters

array $configurationData
array $options

See also

FormatterOptions::setInput

FormatterOptions override(array $configurationData)

Create a new FormatterOptions object with new configuration data (provided), and the same options data as this instance.

Parameters

array $configurationData

Return Value

FormatterOptions

setTableStyle($style)

No description

Parameters

$style

setDelimiter($delimiter)

No description

Parameters

$delimiter

setCsvEnclosure($enclosure)

No description

Parameters

$enclosure

setCsvEscapeChar($escapeChar)

No description

Parameters

$escapeChar

setListDelimiter($listDelimiter)

No description

Parameters

$listDelimiter

setIncludeFieldLables($includFieldLables)

No description

Parameters

$includFieldLables

setListOrientation($listOrientation)

No description

Parameters

$listOrientation

setRowLabels($rowLabels)

No description

Parameters

$rowLabels

setDefaultFields($fields)

No description

Parameters

$fields

setFieldLabels($fieldLabels)

No description

Parameters

$fieldLabels

setTableEmptyMessage($emptyMessage)

No description

Parameters

$emptyMessage

setTableDefaultFields($defaultTableFields)

No description

Parameters

$defaultTableFields

setDefaultStringField($defaultStringField)

No description

Parameters

$defaultStringField

setWidth($width)

No description

Parameters

$width

setHumanReadable($isHumanReadable = true)

No description

Parameters

$isHumanReadable

mixed get(string $key, array $defaults = [], mixed $default = false)

Get a formatter option

Parameters

string $key
array $defaults
mixed $default

Return Value

mixed

mixed fields(array $defaults = [], mixed $default = false)

Get the fields based on the selections made by the user and the available annotation data. The fields are reported as the user selected them, and therefore may be either the field machine name, or its corresponding human-readable label.

Parameters

array $defaults
mixed $default

Return Value

mixed

fieldsContain($fieldName)

Returns 'true' iff the fields selected by the user (or the default fields, if none explicitly selected) contain the specified field name.

Note that the provided field name may be either the machine name for the field, or the human-readable field label.

Parameters

$fieldName

protected fieldAlias($fieldName)

No description

Parameters

$fieldName

XmlSchema getXmlSchema()

Return the XmlSchema to use with --format=xml for data types that support that. This is used when an array needs to be converted into xml.

Return Value

XmlSchema

string getFormat(array $defaults = [])

Determine the format that was requested by the caller.

Parameters

array $defaults

Return Value

string

protected mixed fetch(string $key, array $defaults = [], mixed $default = false)

Look up a key, and return its raw value.

Parameters

string $key
array $defaults
mixed $default

Return Value

mixed

protected array defaultsForKey(string $key, array $defaults, $default = false)

Reduce provided defaults to the single item identified by '$key', if it exists, or an empty array otherwise.

Parameters

string $key
array $defaults
$default

Return Value

array

protected array fetchRawValues(array $defaults = [])

Look up all of the items associated with the provided defaults.

Parameters

array $defaults

Return Value

array

protected mixed parse(string $key, mixed $value)

Given the raw value for a specific key, do any type conversion (e.g. from a textual list to an array) needed for the data.

Parameters

string $key
mixed $value

Return Value

mixed

array parsePropertyList(string $value)

Convert from a textual list to an array

Parameters

string $value

Return Value

array

protected string getOptionFormat(string $key)

Given a specific key, return the class method name of the parsing method for data stored under this key.

Parameters

string $key

Return Value

string

FormatterOptions setConfigurationData(array $configurationData)

Change the configuration data for this formatter options object.

Parameters

array $configurationData

Return Value

FormatterOptions

protected FormatterOptions setConfigurationValue(string $key, mixed $value)

Change one configuration value for this formatter option.

Parameters

string $key
mixed $value

Return Value

FormatterOptions

FormatterOptions setConfigurationDefault(string $key, mixed $value)

Change one configuration value for this formatter option, but only if it does not already have a value set.

Parameters

string $key
mixed $value

Return Value

FormatterOptions

array getConfigurationData()

Return a reference to the configuration data for this object.

Return Value

array

FormatterOptions setOptions(array $options)

Set all of the options that were specified by the user for this request.

Parameters

array $options

Return Value

FormatterOptions

FormatterOptions setOption(string $key, mixed $value)

Change one option value specified by the user for this request.

Parameters

string $key
mixed $value

Return Value

FormatterOptions

array getOptions()

Return a reference to the user-specified options for this request.

Return Value

array

FormatterOptions setInput(InputInterface $input)

Provide a Symfony Console InputInterface containing the user-specified options for this request.

Parameters

InputInterface $input

Return Value

FormatterOptions

array getInputOptions(array $defaults)

Return all of the options from the provided $defaults array that exist in our InputInterface object.

Parameters

array $defaults

Return Value

array