41 lines
880 B
PHP
41 lines
880 B
PHP
|
<?php
|
||
|
|
||
|
namespace Questionnaire\Parser;
|
||
|
|
||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||
|
use Symfony\Component\Console\Output\StreamOutput;
|
||
|
|
||
|
abstract class Parser implements ParserInterface
|
||
|
{
|
||
|
/**
|
||
|
* @var OutputInterface
|
||
|
*/
|
||
|
protected $output;
|
||
|
|
||
|
public function stream(OutputInterface $output)
|
||
|
{
|
||
|
$this->output = $output;
|
||
|
$this->doStream();
|
||
|
$this->output = null;
|
||
|
}
|
||
|
|
||
|
public function capture()
|
||
|
{
|
||
|
$output = fopen('php://temp', 'w+b');
|
||
|
$this->stream(new StreamOutput($output));
|
||
|
rewind($output);
|
||
|
$data = stream_get_contents($output);
|
||
|
fclose($output);
|
||
|
return $data;
|
||
|
}
|
||
|
|
||
|
public function save($file)
|
||
|
{
|
||
|
$output = fopen($file, 'wb');
|
||
|
$this->stream(new StreamOutput($output));
|
||
|
fclose($file);
|
||
|
}
|
||
|
|
||
|
abstract protected function doStream();
|
||
|
}
|