Initial Drupal 11 with DDEV setup
This commit is contained in:
132
vendor/consolidation/output-formatters/src/Formatters/CsvFormatter.php
vendored
Normal file
132
vendor/consolidation/output-formatters/src/Formatters/CsvFormatter.php
vendored
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesInterface;
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesTrait;
|
||||
use Consolidation\OutputFormatters\Transformations\TableTransformation;
|
||||
use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class CsvFormatter implements FormatterInterface, ValidDataTypesInterface, RenderDataInterface
|
||||
{
|
||||
use ValidDataTypesTrait;
|
||||
use RenderTableDataTrait;
|
||||
|
||||
public function validDataTypes()
|
||||
{
|
||||
return
|
||||
[
|
||||
new \ReflectionClass('\Consolidation\OutputFormatters\StructuredData\RowsOfFields'),
|
||||
new \ReflectionClass('\Consolidation\OutputFormatters\StructuredData\PropertyList'),
|
||||
new \ReflectionClass('\ArrayObject'),
|
||||
];
|
||||
}
|
||||
|
||||
public function validate($structuredData)
|
||||
{
|
||||
// If the provided data was of class RowsOfFields
|
||||
// or PropertyList, it will be converted into
|
||||
// a TableTransformation object.
|
||||
if (!is_array($structuredData) && (!$structuredData instanceof TableTransformation)) {
|
||||
throw new IncompatibleDataException(
|
||||
$this,
|
||||
$structuredData,
|
||||
$this->validDataTypes()
|
||||
);
|
||||
}
|
||||
// If the data was provided to us as a single array, then
|
||||
// convert it to a single row.
|
||||
if (is_array($structuredData) && !empty($structuredData)) {
|
||||
$firstRow = reset($structuredData);
|
||||
if (!is_array($firstRow)) {
|
||||
return [$structuredData];
|
||||
}
|
||||
}
|
||||
return $structuredData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return default values for formatter options
|
||||
* @return array
|
||||
*/
|
||||
protected function getDefaultFormatterOptions()
|
||||
{
|
||||
return [
|
||||
FormatterOptions::INCLUDE_FIELD_LABELS => true,
|
||||
FormatterOptions::DELIMITER => ',',
|
||||
FormatterOptions::CSV_ENCLOSURE => '"',
|
||||
FormatterOptions::CSV_ESCAPE_CHAR => "\\",
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
$defaults = $this->getDefaultFormatterOptions();
|
||||
|
||||
$includeFieldLabels = $options->get(FormatterOptions::INCLUDE_FIELD_LABELS, $defaults);
|
||||
if ($includeFieldLabels && ($data instanceof TableTransformation)) {
|
||||
$headers = $data->getHeaders();
|
||||
$this->writeOneLine($output, $headers, $options);
|
||||
}
|
||||
|
||||
foreach ($data as $line) {
|
||||
$this->writeOneLine($output, $line, $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a single a single line of formatted CSV data to the output stream.
|
||||
*
|
||||
* @param OutputInterface $output the output stream to write to.
|
||||
* @param array $data an array of field data to convert to a CSV string.
|
||||
* @param FormatterOptions $options the specified options for this formatter.
|
||||
*/
|
||||
protected function writeOneLine(OutputInterface $output, $data, $options)
|
||||
{
|
||||
$defaults = $this->getDefaultFormatterOptions();
|
||||
$delimiter = $options->get(FormatterOptions::DELIMITER, $defaults);
|
||||
$enclosure = $options->get(FormatterOptions::CSV_ENCLOSURE, $defaults);
|
||||
$escapeChar = $options->get(FormatterOptions::CSV_ESCAPE_CHAR, $defaults);
|
||||
$output->write($this->csvEscape($data, $delimiter, $enclosure, $escapeChar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a CSV-escaped string from an array of field data.
|
||||
*
|
||||
* @param array $data an array of field data to format as a CSV.
|
||||
* @param string $delimiter the delimiter to use between fields.
|
||||
* @param string $enclosure character to use when enclosing complex fields.
|
||||
* @param string $escapeChar character to use when escaping special characters.
|
||||
*
|
||||
* @return string|bool the formatted CSV string, or FALSE if the formatting failed.
|
||||
*/
|
||||
protected function csvEscape($data, $delimiter = ',', $enclosure = '"', $escapeChar = "\\")
|
||||
{
|
||||
$buffer = fopen('php://temp', 'r+');
|
||||
if (version_compare(PHP_VERSION, '5.5.4', '>=')) {
|
||||
fputcsv($buffer, $data, $delimiter, $enclosure, $escapeChar);
|
||||
} else {
|
||||
fputcsv($buffer, $data, $delimiter, $enclosure);
|
||||
}
|
||||
rewind($buffer);
|
||||
$csv = fgets($buffer);
|
||||
fclose($buffer);
|
||||
return $csv;
|
||||
}
|
||||
}
|
||||
10
vendor/consolidation/output-formatters/src/Formatters/FormatterAwareInterface.php
vendored
Normal file
10
vendor/consolidation/output-formatters/src/Formatters/FormatterAwareInterface.php
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
interface FormatterAwareInterface
|
||||
{
|
||||
public function setFormatter(FormatterInterface $formatter);
|
||||
public function getFormatter();
|
||||
public function isHumanReadable();
|
||||
}
|
||||
23
vendor/consolidation/output-formatters/src/Formatters/FormatterAwareTrait.php
vendored
Normal file
23
vendor/consolidation/output-formatters/src/Formatters/FormatterAwareTrait.php
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
trait FormatterAwareTrait
|
||||
{
|
||||
protected $formatter;
|
||||
|
||||
public function setFormatter(FormatterInterface $formatter)
|
||||
{
|
||||
$this->formatter = $formatter;
|
||||
}
|
||||
|
||||
public function getFormatter()
|
||||
{
|
||||
return $this->formatter;
|
||||
}
|
||||
|
||||
public function isHumanReadable()
|
||||
{
|
||||
return $this->formatter && $this->formatter instanceof \Consolidation\OutputFormatters\Formatters\HumanReadableFormat;
|
||||
}
|
||||
}
|
||||
19
vendor/consolidation/output-formatters/src/Formatters/FormatterInterface.php
vendored
Normal file
19
vendor/consolidation/output-formatters/src/Formatters/FormatterInterface.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
interface FormatterInterface
|
||||
{
|
||||
/**
|
||||
* Given structured data, apply appropriate
|
||||
* formatting, and return a printable string.
|
||||
*
|
||||
* @param OutputInterface output stream to write to
|
||||
* @param mixed $data Structured data to format
|
||||
* @param FormatterOptions formating options
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options);
|
||||
}
|
||||
14
vendor/consolidation/output-formatters/src/Formatters/HumanReadableFormat.php
vendored
Normal file
14
vendor/consolidation/output-formatters/src/Formatters/HumanReadableFormat.php
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
/**
|
||||
* Marker interface that indicates that a cell data renderer
|
||||
* (@see Consolidation\OutputFormatters\SturcturedData\RenderCellInterface)
|
||||
* may test for to determine whether it is allowable to add
|
||||
* human-readable formatting into the cell data
|
||||
* (@see Consolidation\OutputFormatters\SturcturedData\NumericCallRenderer).
|
||||
*/
|
||||
interface HumanReadableFormat
|
||||
{
|
||||
}
|
||||
22
vendor/consolidation/output-formatters/src/Formatters/JsonFormatter.php
vendored
Normal file
22
vendor/consolidation/output-formatters/src/Formatters/JsonFormatter.php
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Json formatter
|
||||
*
|
||||
* Convert an array or ArrayObject into Json.
|
||||
*/
|
||||
class JsonFormatter implements FormatterInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
$output->writeln(json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
}
|
||||
60
vendor/consolidation/output-formatters/src/Formatters/ListFormatter.php
vendored
Normal file
60
vendor/consolidation/output-formatters/src/Formatters/ListFormatter.php
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\StructuredData\ListDataInterface;
|
||||
use Consolidation\OutputFormatters\StructuredData\RenderCellInterface;
|
||||
use Consolidation\OutputFormatters\Transformations\OverrideRestructureInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Display the data in a simple list.
|
||||
*
|
||||
* This formatter prints a plain, unadorned list of data,
|
||||
* with each data item appearing on a separate line. If you
|
||||
* wish your list to contain headers, then use the table
|
||||
* formatter, and wrap your data in an PropertyList.
|
||||
*/
|
||||
class ListFormatter implements FormatterInterface, OverrideRestructureInterface, RenderDataInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
$output->writeln(implode("\n", $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function overrideRestructure($structuredOutput, FormatterOptions $options)
|
||||
{
|
||||
// If the structured data implements ListDataInterface,
|
||||
// then we will render whatever data its 'getListData'
|
||||
// method provides.
|
||||
if ($structuredOutput instanceof ListDataInterface) {
|
||||
return $this->renderData($structuredOutput, $structuredOutput->getListData($options), $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function renderData($originalData, $restructuredData, FormatterOptions $options)
|
||||
{
|
||||
if ($originalData instanceof RenderCellInterface) {
|
||||
return $this->renderEachCell($originalData, $restructuredData, $options);
|
||||
}
|
||||
return $restructuredData;
|
||||
}
|
||||
|
||||
protected function renderEachCell($originalData, $restructuredData, FormatterOptions $options)
|
||||
{
|
||||
foreach ($restructuredData as $key => $cellData) {
|
||||
$restructuredData[$key] = $originalData->renderCell($key, $cellData, $options, $restructuredData);
|
||||
}
|
||||
return $restructuredData;
|
||||
}
|
||||
}
|
||||
18
vendor/consolidation/output-formatters/src/Formatters/MetadataFormatterInterface.php
vendored
Normal file
18
vendor/consolidation/output-formatters/src/Formatters/MetadataFormatterInterface.php
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
interface MetadataFormatterInterface
|
||||
{
|
||||
/**
|
||||
* Given some metadata, decide how to display it.
|
||||
*
|
||||
* @param OutputInterface output stream to write to
|
||||
* @param array $metadata associative array containing metadata
|
||||
* @param FormatterOptions formating options
|
||||
*/
|
||||
public function writeMetadata(OutputInterface $output, $metadata, FormatterOptions $options);
|
||||
}
|
||||
54
vendor/consolidation/output-formatters/src/Formatters/MetadataFormatterTrait.php
vendored
Normal file
54
vendor/consolidation/output-formatters/src/Formatters/MetadataFormatterTrait.php
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Consolidation\OutputFormatters\StructuredData\MetadataInterface;
|
||||
|
||||
trait MetadataFormatterTrait
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function writeMetadata(OutputInterface $output, $structuredOutput, FormatterOptions $options)
|
||||
{
|
||||
$template = $options->get(FormatterOptions::METADATA_TEMPLATE);
|
||||
if (!$template) {
|
||||
return;
|
||||
}
|
||||
if (!$structuredOutput instanceof MetadataInterface) {
|
||||
return;
|
||||
}
|
||||
$metadata = $structuredOutput->getMetadata();
|
||||
if (empty($metadata)) {
|
||||
return;
|
||||
}
|
||||
$message = $this->interpolate($template, $metadata);
|
||||
return $output->writeln($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpolates context values into the message placeholders.
|
||||
*
|
||||
* @author PHP Framework Interoperability Group
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function interpolate($message, array $context)
|
||||
{
|
||||
// build a replacement array with braces around the context keys
|
||||
$replace = array();
|
||||
foreach ($context as $key => $val) {
|
||||
if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
|
||||
$replace[sprintf('{%s}', $key)] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// interpolate replacement values into the message and return
|
||||
return strtr($message, $replace);
|
||||
}
|
||||
}
|
||||
41
vendor/consolidation/output-formatters/src/Formatters/NoOutputFormatter.php
vendored
Normal file
41
vendor/consolidation/output-formatters/src/Formatters/NoOutputFormatter.php
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Validate\ValidationInterface;
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesTrait;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* No output formatter
|
||||
*
|
||||
* This formatter never produces any output. It is useful in cases where
|
||||
* a command should not produce any output by default, but may do so if
|
||||
* the user explicitly includes a --format option.
|
||||
*/
|
||||
class NoOutputFormatter implements FormatterInterface, ValidationInterface
|
||||
{
|
||||
/**
|
||||
* All data types are acceptable.
|
||||
*/
|
||||
public function isValidDataType(\ReflectionClass $dataType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate($structuredData)
|
||||
{
|
||||
return $structuredData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
}
|
||||
}
|
||||
22
vendor/consolidation/output-formatters/src/Formatters/PrintRFormatter.php
vendored
Normal file
22
vendor/consolidation/output-formatters/src/Formatters/PrintRFormatter.php
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Print_r formatter
|
||||
*
|
||||
* Run provided date thruogh print_r.
|
||||
*/
|
||||
class PrintRFormatter implements FormatterInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
$output->writeln(print_r($data, true));
|
||||
}
|
||||
}
|
||||
20
vendor/consolidation/output-formatters/src/Formatters/RenderDataInterface.php
vendored
Normal file
20
vendor/consolidation/output-formatters/src/Formatters/RenderDataInterface.php
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
|
||||
interface RenderDataInterface
|
||||
{
|
||||
/**
|
||||
* Convert the contents of the output data just before it
|
||||
* is to be printed, prior to output but after restructuring
|
||||
* and validation.
|
||||
*
|
||||
* @param mixed $originalData
|
||||
* @param mixed $restructuredData
|
||||
* @param FormatterOptions $options Formatting options
|
||||
* @return mixed
|
||||
*/
|
||||
public function renderData($originalData, $restructuredData, FormatterOptions $options);
|
||||
}
|
||||
30
vendor/consolidation/output-formatters/src/Formatters/RenderTableDataTrait.php
vendored
Normal file
30
vendor/consolidation/output-formatters/src/Formatters/RenderTableDataTrait.php
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\StructuredData\RenderCellInterface;
|
||||
|
||||
trait RenderTableDataTrait
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function renderData($originalData, $restructuredData, FormatterOptions $options)
|
||||
{
|
||||
if ($originalData instanceof RenderCellInterface) {
|
||||
return $this->renderEachCell($originalData, $restructuredData, $options);
|
||||
}
|
||||
return $restructuredData;
|
||||
}
|
||||
|
||||
protected function renderEachCell($originalData, $restructuredData, FormatterOptions $options)
|
||||
{
|
||||
foreach ($restructuredData as $id => $row) {
|
||||
foreach ($row as $key => $cellData) {
|
||||
$restructuredData[$id][$key] = $originalData->renderCell($key, $cellData, $options, $row);
|
||||
}
|
||||
}
|
||||
return $restructuredData;
|
||||
}
|
||||
}
|
||||
72
vendor/consolidation/output-formatters/src/Formatters/SectionsFormatter.php
vendored
Normal file
72
vendor/consolidation/output-formatters/src/Formatters/SectionsFormatter.php
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesInterface;
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesTrait;
|
||||
use Consolidation\OutputFormatters\StructuredData\TableDataInterface;
|
||||
use Consolidation\OutputFormatters\Transformations\ReorderFields;
|
||||
use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
|
||||
use Consolidation\OutputFormatters\StructuredData\PropertyList;
|
||||
|
||||
/**
|
||||
* Display sections of data.
|
||||
*
|
||||
* This formatter takes data in the RowsOfFields data type.
|
||||
* Each row represents one section; the data in each section
|
||||
* is rendered in two columns, with the key in the first column
|
||||
* and the value in the second column.
|
||||
*/
|
||||
class SectionsFormatter implements FormatterInterface, ValidDataTypesInterface, RenderDataInterface
|
||||
{
|
||||
use ValidDataTypesTrait;
|
||||
use RenderTableDataTrait;
|
||||
|
||||
public function validDataTypes()
|
||||
{
|
||||
return
|
||||
[
|
||||
new \ReflectionClass('\Consolidation\OutputFormatters\StructuredData\RowsOfFields')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate($structuredData)
|
||||
{
|
||||
// If the provided data was of class RowsOfFields
|
||||
// or PropertyList, it will be converted into
|
||||
// a TableTransformation object by the restructure call.
|
||||
if (!$structuredData instanceof TableDataInterface) {
|
||||
throw new IncompatibleDataException(
|
||||
$this,
|
||||
$structuredData,
|
||||
$this->validDataTypes()
|
||||
);
|
||||
}
|
||||
return $structuredData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $tableTransformer, FormatterOptions $options)
|
||||
{
|
||||
$table = new Table($output);
|
||||
$table->setStyle('compact');
|
||||
foreach ($tableTransformer as $rowid => $row) {
|
||||
$rowLabel = $tableTransformer->getRowLabel($rowid);
|
||||
$output->writeln('');
|
||||
$output->writeln($rowLabel);
|
||||
$sectionData = new PropertyList($row);
|
||||
$sectionOptions = new FormatterOptions([], $options->getOptions());
|
||||
$sectionTableTransformer = $sectionData->restructure($sectionOptions);
|
||||
$table->setRows($sectionTableTransformer->getTableData(true));
|
||||
$table->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
22
vendor/consolidation/output-formatters/src/Formatters/SerializeFormatter.php
vendored
Normal file
22
vendor/consolidation/output-formatters/src/Formatters/SerializeFormatter.php
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Serialize formatter
|
||||
*
|
||||
* Run provided date thruogh serialize.
|
||||
*/
|
||||
class SerializeFormatter implements FormatterInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
$output->writeln(serialize($data));
|
||||
}
|
||||
}
|
||||
96
vendor/consolidation/output-formatters/src/Formatters/StringFormatter.php
vendored
Normal file
96
vendor/consolidation/output-formatters/src/Formatters/StringFormatter.php
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\Options\OverrideOptionsInterface;
|
||||
use Consolidation\OutputFormatters\StructuredData\RestructureInterface;
|
||||
use Consolidation\OutputFormatters\StructuredData\UnstructuredInterface;
|
||||
use Consolidation\OutputFormatters\Transformations\SimplifiedFormatterInterface;
|
||||
use Consolidation\OutputFormatters\Transformations\StringTransformationInterface;
|
||||
use Consolidation\OutputFormatters\Validate\ValidationInterface;
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesTrait;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* String formatter
|
||||
*
|
||||
* This formatter is used as the default action when no
|
||||
* particular formatter is requested. It will print the
|
||||
* provided data only if it is a string; if any other
|
||||
* type is given, then nothing is printed.
|
||||
*/
|
||||
class StringFormatter implements FormatterInterface, ValidationInterface, OverrideOptionsInterface
|
||||
{
|
||||
/**
|
||||
* By default, we assume that we can convert any data type to `string`,
|
||||
* unless it implements UnstructuredInterface, in which case we won't
|
||||
* allow the `string` format unless the data type also implements
|
||||
* StringTransformationInterface.
|
||||
*/
|
||||
public function isValidDataType(\ReflectionClass $dataType)
|
||||
{
|
||||
if ($dataType->implementsInterface('\Consolidation\OutputFormatters\StructuredData\UnstructuredInterface') && !$dataType->implementsInterface('\Consolidation\OutputFormatters\Transformations\StringTransformationInterface')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
if (is_string($data)) {
|
||||
return $output->writeln($data);
|
||||
}
|
||||
return $this->reduceToSigleFieldAndWrite($output, $data, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function overrideOptions($structuredOutput, FormatterOptions $options)
|
||||
{
|
||||
$defaultField = $options->get(FormatterOptions::DEFAULT_STRING_FIELD, [], '');
|
||||
$userFields = $options->get(FormatterOptions::FIELDS, [FormatterOptions::FIELDS => $options->get(FormatterOptions::FIELD)]);
|
||||
$optionsOverride = $options->override([]);
|
||||
if (empty($userFields) && !empty($defaultField)) {
|
||||
$optionsOverride->setOption(FormatterOptions::FIELDS, $defaultField);
|
||||
}
|
||||
return $optionsOverride;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the data provided to a 'string' formatter is a table, then try
|
||||
* to emit it in a simplified form (by default, TSV).
|
||||
*
|
||||
* @param OutputInterface $output
|
||||
* @param mixed $data
|
||||
* @param FormatterOptions $options
|
||||
*/
|
||||
protected function reduceToSigleFieldAndWrite(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
if ($data instanceof StringTransformationInterface) {
|
||||
$simplified = $data->simplifyToString($options);
|
||||
return $output->write($simplified);
|
||||
}
|
||||
|
||||
$alternateFormatter = new TsvFormatter();
|
||||
try {
|
||||
$data = $alternateFormatter->validate($data);
|
||||
$alternateFormatter->write($output, $data, $options);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Always validate any data, though. This format will never
|
||||
* cause an error if it is selected for an incompatible data type; at
|
||||
* worse, it simply does not print any data.
|
||||
*/
|
||||
public function validate($structuredData)
|
||||
{
|
||||
return $structuredData;
|
||||
}
|
||||
}
|
||||
165
vendor/consolidation/output-formatters/src/Formatters/TableFormatter.php
vendored
Normal file
165
vendor/consolidation/output-formatters/src/Formatters/TableFormatter.php
vendored
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableStyle;
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesInterface;
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesTrait;
|
||||
use Consolidation\OutputFormatters\StructuredData\TableDataInterface;
|
||||
use Consolidation\OutputFormatters\Transformations\ReorderFields;
|
||||
use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
|
||||
use Consolidation\OutputFormatters\Transformations\WordWrapper;
|
||||
use Consolidation\OutputFormatters\Formatters\HumanReadableFormat;
|
||||
|
||||
/**
|
||||
* Display a table of data with the Symfony Table class.
|
||||
*
|
||||
* This formatter takes data of either the RowsOfFields or
|
||||
* PropertyList data type. Tables can be rendered with the
|
||||
* rows running either vertically (the normal orientation) or
|
||||
* horizontally. By default, associative lists will be displayed
|
||||
* as two columns, with the key in the first column and the
|
||||
* value in the second column.
|
||||
*/
|
||||
class TableFormatter implements FormatterInterface, ValidDataTypesInterface, RenderDataInterface, MetadataFormatterInterface, HumanReadableFormat
|
||||
{
|
||||
use ValidDataTypesTrait;
|
||||
use RenderTableDataTrait;
|
||||
use MetadataFormatterTrait;
|
||||
|
||||
protected $fieldLabels;
|
||||
protected $defaultFields;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function validDataTypes()
|
||||
{
|
||||
return
|
||||
[
|
||||
new \ReflectionClass('\Consolidation\OutputFormatters\StructuredData\RowsOfFields'),
|
||||
new \ReflectionClass('\Consolidation\OutputFormatters\StructuredData\PropertyList')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate($structuredData)
|
||||
{
|
||||
// If the provided data was of class RowsOfFields
|
||||
// or PropertyList, it will be converted into
|
||||
// a TableTransformation object by the restructure call.
|
||||
if (!$structuredData instanceof TableDataInterface) {
|
||||
throw new IncompatibleDataException(
|
||||
$this,
|
||||
$structuredData,
|
||||
$this->validDataTypes()
|
||||
);
|
||||
}
|
||||
return $structuredData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $tableTransformer, FormatterOptions $options)
|
||||
{
|
||||
$headers = [];
|
||||
$defaults = [
|
||||
FormatterOptions::TABLE_STYLE => 'consolidation',
|
||||
FormatterOptions::INCLUDE_FIELD_LABELS => true,
|
||||
FormatterOptions::TABLE_EMPTY_MESSAGE => false,
|
||||
];
|
||||
|
||||
$table = new Table($output);
|
||||
|
||||
static::addCustomTableStyles($table);
|
||||
|
||||
$table->setStyle($options->get(FormatterOptions::TABLE_STYLE, $defaults));
|
||||
$isList = $tableTransformer->isList();
|
||||
$includeHeaders = $options->get(FormatterOptions::INCLUDE_FIELD_LABELS, $defaults);
|
||||
$listDelimiter = $options->get(FormatterOptions::LIST_DELIMITER, $defaults);
|
||||
$emptyMessage = $options->get(FormatterOptions::TABLE_EMPTY_MESSAGE, $defaults);
|
||||
|
||||
$headers = $tableTransformer->getHeaders();
|
||||
$data = $tableTransformer->getTableData($includeHeaders && $isList);
|
||||
|
||||
// Do not print table headers for an empty table if the
|
||||
// TABLE_EMPTY_MESSAGE has been set.
|
||||
if (empty($data) && ($emptyMessage !== false)) {
|
||||
if (!empty($emptyMessage)) {
|
||||
$output->writeln($emptyMessage);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($listDelimiter) {
|
||||
if (!empty($headers)) {
|
||||
array_splice($headers, 1, 0, ':');
|
||||
}
|
||||
$data = array_map(function ($item) {
|
||||
array_splice($item, 1, 0, ':');
|
||||
return $item;
|
||||
}, $data);
|
||||
}
|
||||
|
||||
if ($includeHeaders && !$isList) {
|
||||
$table->setHeaders($headers);
|
||||
}
|
||||
|
||||
// todo: $output->getFormatter();
|
||||
$data = $this->wrap($headers, $data, $table->getStyle(), $options);
|
||||
$table->setRows($data);
|
||||
$table->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the table data
|
||||
* @param array $data
|
||||
* @param TableStyle $tableStyle
|
||||
* @param FormatterOptions $options
|
||||
* @return array
|
||||
*/
|
||||
protected function wrap($headers, $data, TableStyle $tableStyle, FormatterOptions $options)
|
||||
{
|
||||
$wrapper = new WordWrapper($options->get(FormatterOptions::TERMINAL_WIDTH));
|
||||
$wrapper->setPaddingFromStyle($tableStyle);
|
||||
if (!empty($headers)) {
|
||||
$headerLengths = array_map(function ($item) {
|
||||
return strlen($item);
|
||||
}, $headers);
|
||||
$wrapper->setMinimumWidths($headerLengths);
|
||||
}
|
||||
return $wrapper->wrap($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add our custom table style(s) to the table.
|
||||
*/
|
||||
protected static function addCustomTableStyles($table)
|
||||
{
|
||||
// The 'consolidation' style is the same as the 'symfony-style-guide'
|
||||
// style, except it maintains the colored headers used in 'default'.
|
||||
$consolidationStyle = new TableStyle();
|
||||
|
||||
if (method_exists($consolidationStyle, 'setHorizontalBorderChars')) {
|
||||
$consolidationStyle
|
||||
->setHorizontalBorderChars('-')
|
||||
->setVerticalBorderChars(' ')
|
||||
->setDefaultCrossingChar(' ')
|
||||
;
|
||||
} else {
|
||||
$consolidationStyle
|
||||
->setHorizontalBorderChar('-')
|
||||
->setVerticalBorderChar(' ')
|
||||
->setCrossingChar(' ')
|
||||
;
|
||||
}
|
||||
$table->setStyleDefinition('consolidation', $consolidationStyle);
|
||||
}
|
||||
}
|
||||
41
vendor/consolidation/output-formatters/src/Formatters/TsvFormatter.php
vendored
Normal file
41
vendor/consolidation/output-formatters/src/Formatters/TsvFormatter.php
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesInterface;
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\Transformations\TableTransformation;
|
||||
use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Tab-separated value formatters
|
||||
*
|
||||
* Display the provided structured data in a tab-separated list. Output
|
||||
* escaping is much lighter, since there is no allowance for altering
|
||||
* the delimiter.
|
||||
*/
|
||||
class TsvFormatter extends CsvFormatter
|
||||
{
|
||||
protected function getDefaultFormatterOptions()
|
||||
{
|
||||
return [
|
||||
FormatterOptions::INCLUDE_FIELD_LABELS => false,
|
||||
];
|
||||
}
|
||||
|
||||
protected function writeOneLine(OutputInterface $output, $data, $options)
|
||||
{
|
||||
$output->writeln($this->tsvEscape($data));
|
||||
}
|
||||
|
||||
protected function tsvEscape($data)
|
||||
{
|
||||
return implode("\t", array_map(
|
||||
function ($item) {
|
||||
return str_replace(["\t", "\n"], ['\t', '\n'], $item);
|
||||
},
|
||||
$data
|
||||
));
|
||||
}
|
||||
}
|
||||
51
vendor/consolidation/output-formatters/src/Formatters/VarDumpFormatter.php
vendored
Normal file
51
vendor/consolidation/output-formatters/src/Formatters/VarDumpFormatter.php
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\Validate\ValidationInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
* Var_dump formatter
|
||||
*
|
||||
* Run provided data through Symfony VarDumper component.
|
||||
*/
|
||||
class VarDumpFormatter implements FormatterInterface, ValidationInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
$dumper = new CliDumper();
|
||||
$cloned_data = (new VarCloner())->cloneVar($data);
|
||||
|
||||
if ($output instanceof StreamOutput) {
|
||||
// When stream output is used the dumper is smart enough to
|
||||
// determine whether or not to apply colors to the dump.
|
||||
// @see Symfony\Component\VarDumper\Dumper\CliDumper::supportsColors
|
||||
$dumper->dump($cloned_data, $output->getStream());
|
||||
} else {
|
||||
// @todo Use dumper return value to get output once we stop support
|
||||
// VarDumper v2.
|
||||
$stream = fopen('php://memory', 'r+b');
|
||||
$dumper->dump($cloned_data, $stream);
|
||||
$output->writeln(stream_get_contents($stream, -1, 0));
|
||||
fclose($stream);
|
||||
}
|
||||
}
|
||||
|
||||
public function isValidDataType(\ReflectionClass $dataType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate($structuredData)
|
||||
{
|
||||
return $structuredData;
|
||||
}
|
||||
}
|
||||
33
vendor/consolidation/output-formatters/src/Formatters/VarExportFormatter.php
vendored
Normal file
33
vendor/consolidation/output-formatters/src/Formatters/VarExportFormatter.php
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\Validate\ValidationInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Var_export formatter
|
||||
*
|
||||
* Run provided date thruogh var_export.
|
||||
*/
|
||||
class VarExportFormatter implements FormatterInterface, ValidationInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
$output->writeln(var_export($data, true));
|
||||
}
|
||||
|
||||
public function isValidDataType(\ReflectionClass $dataType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate($structuredData)
|
||||
{
|
||||
return $structuredData;
|
||||
}
|
||||
}
|
||||
79
vendor/consolidation/output-formatters/src/Formatters/XmlFormatter.php
vendored
Normal file
79
vendor/consolidation/output-formatters/src/Formatters/XmlFormatter.php
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableStyle;
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesInterface;
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Consolidation\OutputFormatters\Validate\ValidDataTypesTrait;
|
||||
use Consolidation\OutputFormatters\StructuredData\TableDataInterface;
|
||||
use Consolidation\OutputFormatters\Transformations\ReorderFields;
|
||||
use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
|
||||
use Consolidation\OutputFormatters\StructuredData\Xml\DomDataInterface;
|
||||
|
||||
/**
|
||||
* Display a table of data with the Symfony Table class.
|
||||
*
|
||||
* This formatter takes data of either the RowsOfFields or
|
||||
* PropertyList data type. Tables can be rendered with the
|
||||
* rows running either vertically (the normal orientation) or
|
||||
* horizontally. By default, associative lists will be displayed
|
||||
* as two columns, with the key in the first column and the
|
||||
* value in the second column.
|
||||
*/
|
||||
class XmlFormatter implements FormatterInterface, ValidDataTypesInterface
|
||||
{
|
||||
use ValidDataTypesTrait;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function validDataTypes()
|
||||
{
|
||||
return
|
||||
[
|
||||
new \ReflectionClass('\DOMDocument'),
|
||||
new \ReflectionClass('\ArrayObject'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate($structuredData)
|
||||
{
|
||||
if ($structuredData instanceof \DOMDocument) {
|
||||
return $structuredData;
|
||||
}
|
||||
if ($structuredData instanceof DomDataInterface) {
|
||||
return $structuredData->getDomData();
|
||||
}
|
||||
if ($structuredData instanceof \ArrayObject) {
|
||||
return $structuredData->getArrayCopy();
|
||||
}
|
||||
if (!is_array($structuredData)) {
|
||||
throw new IncompatibleDataException(
|
||||
$this,
|
||||
$structuredData,
|
||||
$this->validDataTypes()
|
||||
);
|
||||
}
|
||||
return $structuredData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $dom, FormatterOptions $options)
|
||||
{
|
||||
if (is_array($dom)) {
|
||||
$schema = $options->getXmlSchema();
|
||||
$dom = $schema->arrayToXML($dom);
|
||||
}
|
||||
$dom->formatOutput = true;
|
||||
$output->writeln($dom->saveXML());
|
||||
}
|
||||
}
|
||||
28
vendor/consolidation/output-formatters/src/Formatters/YamlFormatter.php
vendored
Normal file
28
vendor/consolidation/output-formatters/src/Formatters/YamlFormatter.php
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\OutputFormatters\Formatters;
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Consolidation\OutputFormatters\Options\FormatterOptions;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Yaml formatter
|
||||
*
|
||||
* Convert an array or ArrayObject into Yaml.
|
||||
*/
|
||||
class YamlFormatter implements FormatterInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function write(OutputInterface $output, $data, FormatterOptions $options)
|
||||
{
|
||||
// Set Yaml\Dumper's default indentation for nested nodes/collections to
|
||||
// 2 spaces for consistency with Drupal coding standards.
|
||||
$indent = 2;
|
||||
// The level where you switch to inline YAML is set to PHP_INT_MAX to
|
||||
// ensure this does not occur.
|
||||
$output->writeln(Yaml::dump($data, PHP_INT_MAX, $indent, false, true));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user