Dump file, add output

This commit is contained in:
Oliver Davies 2018-01-11 00:48:02 +00:00
parent 99caed2737
commit 9410609588
3 changed files with 25 additions and 4 deletions

View file

@ -3,6 +3,9 @@ services:
class: Symfony\Component\Console\Application
autowire: true
app.builder:
class: Opdavies\GmailFilterBuilder\Service\Builder
app.generate.command:
class: Opdavies\GmailFilterBuilder\Console\Command\GenerateCommand
autowire: true

View file

@ -7,6 +7,7 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class GenerateCommand extends Command
{
@ -43,6 +44,10 @@ class GenerateCommand extends Command
throw new \Exception('No filters.php file found.');
}
echo new Builder($filters);
// TOOD: Check return code.
new Builder($filters, $outputFile);
$io = new SymfonyStyle($input, $output);
$io->success(sprintf('%s file generated.', $outputFile));
}
}

View file

@ -3,17 +3,28 @@
namespace Opdavies\GmailFilterBuilder\Service;
use Opdavies\GmailFilterBuilder\Filter;
use Symfony\Component\Filesystem\Filesystem;
class Builder
{
private $filesystem;
/**
* @var array
*/
private $filters = [];
public function __construct(array $filters)
{
/**
* @var
*/
private $outputFile;
public function __construct(array $filters, $outputFile = 'filters.xml') {
$this->filesystem = new Filesystem();
$this->filters = $filters;
$this->outputFile = $outputFile;
$this->build();
}
public function __toString()
@ -35,7 +46,9 @@ class Builder
return $this->buildEntry($items);
})->implode(PHP_EOL);
return collect([$prefix, $xml, $suffix])->implode(PHP_EOL);
$content = collect([$prefix, $xml, $suffix])->implode(PHP_EOL);
$this->filesystem->dumpFile($this->outputFile, $content);
}
/**