From 6549360dac38da2d57f4d4bcb7e9aa62051f9523 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 2 Nov 2012 18:13:08 +0100 Subject: [PATCH] Add ArrayIO helper to capture output --- src/Composer/IO/ArrayIO.php | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Composer/IO/ArrayIO.php diff --git a/src/Composer/IO/ArrayIO.php b/src/Composer/IO/ArrayIO.php new file mode 100644 index 000000000..8ca737ab8 --- /dev/null +++ b/src/Composer/IO/ArrayIO.php @@ -0,0 +1,46 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\IO; + +use Symfony\Component\Console\Output\StreamOutput; +use Symfony\Component\Console\Input\StringInput; +use Symfony\Component\Console\Helper\HelperSet; + +/** + * The Input/Output helper. + * + * @author Jordi Boggiano + */ +class ArrayIO extends ConsoleIO +{ + /** + * @param string $input + * @param int $verbosity + */ + public function __construct($input = '', $verbosity = null) + { + $input = new StringInput($input); + $input->setInteractive(false); + + // TODO pass a custom output formatter for html tags + $output = new StreamOutput(fopen('php://memory', 'rw'), $verbosity === null ? StreamOutput::VERBOSITY_NORMAL : $verbosity, false); + + parent::__construct($input, $output, new HelperSet(array())); + } + + public function getOutput() + { + fseek($this->output->getStream(), 0); + return stream_get_contents($this->output->getStream()); + } +}