Format the output.

@param  array $output
@return iterable
@throws \Exception
487622
public function format(array $output): iterable
    {
        $formatted = [];
        foreach ($output as $row) {
            $formatted[] = $this->createCommit($row);
        }
        return $formatted;
    }
907771
private function parseS3CmdListOutput($output)
    {
        $backups = array();

        if (null === $output) {
            return $backups;
        }

        foreach (explode("\n", $output) as $row) {
            if ('' === $row) {
                continue;
            }

            $backups[] = $this->parseS3CmdListRow($row);
        }

        return $backups;
    }
50884
public function output($output)
    {
        $this->_output = $output;
        $request       = Craft::$app->getRequest();
        $response      = Craft::$app->getResponse();

        if (!$this->isPJAX() || $request->isCpRequest || $request->isLivePreview || $request->isConsoleRequest) {
            return $this->_output;
        }

        $this->filterResponse($this->_output, $request->headers->get('X-PJAX-Container'))
             ->setUriHeader($request, $response)
             ->setVersionHeader($output, $response);

        return $this->_output;
    }
1213564
public function handle($input, $output = null)
    {
        try {
            return $this->run($input, $output);
        }
        catch (Exception $e) {
            $this->manageException($output, $e);

            return 1;
        }
        catch (Throwable $e) {
            $this->manageException($output, new FatalThrowableError($e));

            return 1;
        }
    }
890520
private function getStreamOutput(StreamOutput $output = null)
    {
        if ($output) {
            rewind($output->getStream());
            $this->consoleOutput[] = trim(stream_get_contents($output->getStream()));
            fclose($output->getStream());
        }

        return new StreamOutput(fopen('php://memory', 'w+', false), StreamOutput::VERBOSITY_VERBOSE);
    }
340624
private function handleOutput(string $output): self
    {
        $this->output .= $output;

        if (!self::inTest()) {
            echo $output;
        }

        return $this;
    }
112066
public function getOutputFilename($output)
	{
		// default behaviour / backwards compatibility
		$outputDir = $output;
		$outputFilename = $this->getDefaultOutputFilename();

		// Find out if a .htm(l) filename has been given in the output argument.
		if ($this->endsWith($output, ".htm") || $this->endsWith($output, ".html")) {
			$outputDir = dirname($output);
			$outputFilename = basename($output);
		}

		return $outputDir . DIRECTORY_SEPARATOR . $outputFilename;
	}
1246677
protected function parseOutput(string $output): array
    {
        $lines = explode(PHP_EOL, $output);
        $issues = [];
        $lineNo = 1;
        foreach ($lines as $line) {
            $line = trim($line);
            if ('' === $line) {
                // Go to the next line
                $lineNo++;
                continue;
            }
            switch ($line[0]) {
                case '#':
                    $parts = explode(' ', $line);
                    $word = $parts[1];
                    $issue = new Issue($word);
                    $issue->line = $lineNo;
                    $issue->offset = trim($parts[2]);
                    $issues [] = $issue;
                    break;
                case '&':
                    $parts = explode(':', $line);
                    $parts[0] = explode(' ', $parts[0]);
                    $parts[1] = explode(', ', trim($parts[1]));
                    $word = $parts[0][1];
                    $issue = new Issue($word);
                    $issue->line = $lineNo;
                    $issue->offset = trim($parts[0][3]);
                    $issue->suggestions = $parts[1];
                    $issues [] = $issue;
                    break;
            }
        }

        return $issues;
    }
68460
private function initACL($output)
    {
        $command = $this->getApplication()->find('acl:init');

        $arguments = [
            'command' => 'acl:init',
        ];

        $input = new ArrayInput($arguments);

        return $command->run($input, $output);
    }
227283
public function prepareOutput($output, $strict = false)
    {
        if ($strict && version_compare(PHP_VERSION, '7') < 1) {
            throw new RuntimeException('Strict mode requires PHP 7 or greater.');
        }

        $dir = dirname($output);

        if (!is_dir($dir) && !mkdir($dir, 0777, true)) {
            throw new RuntimeException("Unable to create directory $dir.");
        }

        $handle = fopen($output, 'w');

        if (!$handle) {
            throw new RuntimeException("Unable to open $output for writing.");
        }

        if ($strict) {
            fwrite($handle, "<?php declare(strict_types=1);\n");
        } else {
            fwrite($handle, "<?php\n");
        }

        return $handle;
    }
361952
protected function writeLong(OutputInterface $output, array $result = null)
    {
        if ($result === null) {
            return;
        }

        $table = $this->getTable($output);

        foreach ($result as $label => $items) {
            $output->writeln('');
            $output->writeln(\sprintf('<strong>%s:</strong>', $label));

            $table->setRows([]);
            foreach ($items as $item) {
                $table->addRow([$this->formatItemName($item), $item['value']]);
            }

            if ($table instanceof TableHelper) {
                $table->render($output);
            } else {
                $table->render();
            }
        }
    }
65352
public function output( $output ) {
		$response = $this->response();
		$response = $response->withBody( Psr7\stream_for( $output ) );
		return $response;
	}
1120056
public function format(array $input)
    {
        $output = $this->formatString;

        foreach ($input as $key => $value)
        {
            if (!isset($this->map[$key])) {
                continue;
            }

            if (is_array($value)) {
                $value = implode('\n\t', $value);
            }
            $output = str_replace($this->map[$key], $value, $output);
        }

        return $output;
    }
119821
public static function normalizeOutputsStruct(array $outputs) {
        $result = [];

        foreach ($outputs as $k => $v) {
            if (is_numeric($k)) {
                if (!is_array($v)) {
                    throw new \InvalidArgumentException("outputs should be [address => value, ] or [[address, value], ] or [['address' => address, 'value' => value], ]");
                }

                if (isset($v['address']) && isset($v['value'])) {
                    $address = $v['address'];
                    $value = $v['value'];
                } elseif (count($v) == 2 && isset($v[0]) && isset($v[1])) {
                    $address = $v[0];
                    $value = $v[1];
                } else {
                    throw new \InvalidArgumentException("outputs should be [address => value, ] or [[address, value], ] or [['address' => address, 'value' => value], ]");
                }
            } else {
                $address = $k;
                $value = $v;
            }

            $result[] = ['address' => $address, 'value' => $value];
        }

        return $result;
    }
331523
public static function removeComments($output)
    {
        $lines  = explode("\n", $output);
        $output = "";
        // try to keep mem. use down
        $linecount  = count($lines);
        $in_comment = false;
        for ($i=0; $i<$linecount; $i++) {
            if (preg_match("/^\/\*/", $lines[$i])) {
                $in_comment = true;
            }
            if (!$in_comment) {
                $output .= $lines[$i] . "\n";
            }
            if (preg_match("/\*\/$/", $lines[$i])) {
                $in_comment = false;
            }
        }
        unset($lines);
        return $output;
    }
332617
protected function updateOutput(OutputInterface $output, array $lines = [])
    {
        foreach ($lines as $line) {
            $status = $line["status"] == "ok" ? "<fg=green>✓</fg=green>" : "<fg=red>✗</fg=red>";

            switch ($line['operation']) {
            case "creating":
                $operation = sprintf("<fg=green>%s</fg=green>", ucwords($line['operation']));
                break;
            case "overwriting":
                $operation = sprintf("<fg=cyan>%s</fg=cyan>", ucwords($line['operation']));
                break;
            case "deleting":
                $operation = sprintf("<fg=red>%s</fg=red>", ucwords($line['operation']));
                break;
            default:
                $operation = ucwords($line['operation']);
            }

            $output->writeln(
                sprintf(
                    " %s  %s file <fg=yellow>'%s'</fg=yellow>.",
                    $status,
                    $operation,
                    $line['file']
                )
            );
        }

        return $this;
    }
1306342
private function formatThrowableObjects(array $array)
    {
        array_walk_recursive($array, function (&$value) {
            if ($value instanceof \Throwable) {
                try {
                    $value = serialize($value);
                } catch (\Throwable $throwable) {
                    $value = $this->formatThrowable($value);
                }
            }
        });

        return $array;
    }