mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-03-13 05:26:57 +00:00
Dump file, add output
This commit is contained in:
parent
99caed2737
commit
9410609588
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue