Mercurial > hg > isophonics-drupal-site
comparison vendor/consolidation/output-formatters/src/FormatterManager.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
2 namespace Consolidation\OutputFormatters; | 2 namespace Consolidation\OutputFormatters; |
3 | 3 |
4 use Consolidation\OutputFormatters\Exception\IncompatibleDataException; | 4 use Consolidation\OutputFormatters\Exception\IncompatibleDataException; |
5 use Consolidation\OutputFormatters\Exception\InvalidFormatException; | 5 use Consolidation\OutputFormatters\Exception\InvalidFormatException; |
6 use Consolidation\OutputFormatters\Exception\UnknownFormatException; | 6 use Consolidation\OutputFormatters\Exception\UnknownFormatException; |
7 use Consolidation\OutputFormatters\Formatters\FormatterAwareInterface; | |
7 use Consolidation\OutputFormatters\Formatters\FormatterInterface; | 8 use Consolidation\OutputFormatters\Formatters\FormatterInterface; |
9 use Consolidation\OutputFormatters\Formatters\MetadataFormatterInterface; | |
8 use Consolidation\OutputFormatters\Formatters\RenderDataInterface; | 10 use Consolidation\OutputFormatters\Formatters\RenderDataInterface; |
9 use Consolidation\OutputFormatters\Options\FormatterOptions; | 11 use Consolidation\OutputFormatters\Options\FormatterOptions; |
10 use Consolidation\OutputFormatters\Options\OverrideOptionsInterface; | 12 use Consolidation\OutputFormatters\Options\OverrideOptionsInterface; |
13 use Consolidation\OutputFormatters\StructuredData\MetadataInterface; | |
11 use Consolidation\OutputFormatters\StructuredData\RestructureInterface; | 14 use Consolidation\OutputFormatters\StructuredData\RestructureInterface; |
12 use Consolidation\OutputFormatters\Transformations\DomToArraySimplifier; | 15 use Consolidation\OutputFormatters\Transformations\DomToArraySimplifier; |
13 use Consolidation\OutputFormatters\Transformations\OverrideRestructureInterface; | 16 use Consolidation\OutputFormatters\Transformations\OverrideRestructureInterface; |
14 use Consolidation\OutputFormatters\Transformations\SimplifyToArrayInterface; | 17 use Consolidation\OutputFormatters\Transformations\SimplifyToArrayInterface; |
15 use Consolidation\OutputFormatters\Validate\ValidationInterface; | 18 use Consolidation\OutputFormatters\Validate\ValidationInterface; |
45 'csv' => '\Consolidation\OutputFormatters\Formatters\CsvFormatter', | 48 'csv' => '\Consolidation\OutputFormatters\Formatters\CsvFormatter', |
46 'tsv' => '\Consolidation\OutputFormatters\Formatters\TsvFormatter', | 49 'tsv' => '\Consolidation\OutputFormatters\Formatters\TsvFormatter', |
47 'table' => '\Consolidation\OutputFormatters\Formatters\TableFormatter', | 50 'table' => '\Consolidation\OutputFormatters\Formatters\TableFormatter', |
48 'sections' => '\Consolidation\OutputFormatters\Formatters\SectionsFormatter', | 51 'sections' => '\Consolidation\OutputFormatters\Formatters\SectionsFormatter', |
49 ]; | 52 ]; |
53 if (class_exists('Symfony\Component\VarDumper\Dumper\CliDumper')) { | |
54 $defaultFormatters['var_dump'] = '\Consolidation\OutputFormatters\Formatters\VarDumpFormatter'; | |
55 } | |
50 foreach ($defaultFormatters as $id => $formatterClassname) { | 56 foreach ($defaultFormatters as $id => $formatterClassname) { |
51 $formatter = new $formatterClassname; | 57 $formatter = new $formatterClassname; |
52 $this->addFormatter($id, $formatter); | 58 $this->addFormatter($id, $formatter); |
53 } | 59 } |
54 $this->addFormatter('', $this->formatters['string']); | 60 $this->addFormatter('', $this->formatters['string']); |
200 $formatter = $this->getFormatter((string)$format); | 206 $formatter = $this->getFormatter((string)$format); |
201 if (!is_string($structuredOutput) && !$this->isValidFormat($formatter, $structuredOutput)) { | 207 if (!is_string($structuredOutput) && !$this->isValidFormat($formatter, $structuredOutput)) { |
202 $validFormats = $this->validFormats($structuredOutput); | 208 $validFormats = $this->validFormats($structuredOutput); |
203 throw new InvalidFormatException((string)$format, $structuredOutput, $validFormats); | 209 throw new InvalidFormatException((string)$format, $structuredOutput, $validFormats); |
204 } | 210 } |
211 if ($structuredOutput instanceof FormatterAwareInterface) { | |
212 $structuredOutput->setFormatter($formatter); | |
213 } | |
205 // Give the formatter a chance to override the options | 214 // Give the formatter a chance to override the options |
206 $options = $this->overrideOptions($formatter, $structuredOutput, $options); | 215 $options = $this->overrideOptions($formatter, $structuredOutput, $options); |
207 $structuredOutput = $this->validateAndRestructure($formatter, $structuredOutput, $options); | 216 $restructuredOutput = $this->validateAndRestructure($formatter, $structuredOutput, $options); |
208 $formatter->write($output, $structuredOutput, $options); | 217 if ($formatter instanceof MetadataFormatterInterface) { |
218 $formatter->writeMetadata($output, $structuredOutput, $options); | |
219 } | |
220 $formatter->write($output, $restructuredOutput, $options); | |
209 } | 221 } |
210 | 222 |
211 protected function validateAndRestructure(FormatterInterface $formatter, $structuredOutput, FormatterOptions $options) | 223 protected function validateAndRestructure(FormatterInterface $formatter, $structuredOutput, FormatterOptions $options) |
212 { | 224 { |
213 // Give the formatter a chance to do something with the | 225 // Give the formatter a chance to do something with the |