CsvFormatter
class CsvFormatter implements FormatterInterface, ValidDataTypesInterface, RenderDataInterface (View source)
Comma-separated value formatters
Display the provided structured data in a comma-separated list. If there are multiple records provided, then they will be printed one per line. The primary data types accepted are RowsOfFields and PropertyList. The later behaves exactly like the former, save for the fact that it contains but a single row. This formmatter can also accept a PHP array; this is also interpreted as a single-row of data with no header.
Traits
Provides a default implementation of isValidDataType.
Methods
Return the list of data types acceptable to this formatter
Return the list of data types acceptable to this formatter
Throw an IncompatibleDataException if the provided data cannot be processed by this formatter. Return the source data if it is valid. The data may be encapsulated or converted if necessary.
Return default values for formatter options
Writes a single a single line of formatted CSV data to the output stream.
Generates a CSV-escaped string from an array of field data.
Details
ReflectionClass[]
validDataTypes()
Return the list of data types acceptable to this formatter
isValidDataType(ReflectionClass $dataType)
Return the list of data types acceptable to this formatter
renderData($originalData, $restructuredData, FormatterOptions $options)
No description
protected
renderEachCell($originalData, $restructuredData, FormatterOptions $options)
No description
mixed
validate(mixed $structuredData)
Throw an IncompatibleDataException if the provided data cannot be processed by this formatter. Return the source data if it is valid. The data may be encapsulated or converted if necessary.
protected array
getDefaultFormatterOptions()
Return default values for formatter options
write(OutputInterface $output, mixed $data, FormatterOptions $options)
No description
protected
writeOneLine(OutputInterface $output, array $data, FormatterOptions $options)
Writes a single a single line of formatted CSV data to the output stream.
protected string|bool
csvEscape(array $data, string $delimiter = ',', string $enclosure = '"', string $escapeChar = "\\")
Generates a CSV-escaped string from an array of field data.