mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-09-06 05:25:33 +01:00
Start using Symfony Components
This commit is contained in:
parent
b61178b9b0
commit
bc3dae9c48
9 changed files with 131 additions and 13 deletions
46
src/Console/Command/GenerateCommand.php
Normal file
46
src/Console/Command/GenerateCommand.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\GmailFilterBuilder\Console\Command;
|
||||
|
||||
use Opdavies\GmailFilterBuilder\Builder;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class GenerateCommand extends Command
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configure()
|
||||
{
|
||||
$this
|
||||
->setName('generate')
|
||||
->setDefinition([
|
||||
new InputArgument('input-file', InputArgument::OPTIONAL, 'The name of the PHP file containing your filters.', 'filters.php'),
|
||||
new InputArgument('output-file', InputArgument::OPTIONAL, 'The name of the XML file to generate.', 'filters.xml')
|
||||
])
|
||||
->setDescription('Generates XML for Gmail filters.')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$inputFile = $input->getArgument('input-file');
|
||||
$outputFile = $input->getArgument('output-file');
|
||||
|
||||
if (file_exists(__DIR__.'/../../../../'.$inputFile)) {
|
||||
$filters = require(__DIR__.'/../../../../'.$inputFile);
|
||||
} elseif (file_exists(__DIR__.'/../../../'.$inputFile)) {
|
||||
$filters = require(__DIR__.'/../../../'.$inputFile);
|
||||
} else {
|
||||
throw new \Exception('No filters.php file found.');
|
||||
}
|
||||
|
||||
echo new Builder($filters);
|
||||
}
|
||||
}
|
22
src/Container/CommandCompilerClass.php
Normal file
22
src/Container/CommandCompilerClass.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\GmailFilterBuilder\Container;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class CommandCompilerClass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container) {
|
||||
$definition = $container->findDefinition('app.cli');
|
||||
$taggedServices = $container->findTaggedServiceIds('ConsoleCommand');
|
||||
|
||||
foreach ($taggedServices as $id => $tags) {
|
||||
$definition->addMethodCall('add', [new Reference($id)]);
|
||||
}
|
||||
}
|
||||
}
|
24
src/Container/Container.php
Normal file
24
src/Container/Container.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\GmailFilterBuilder\Container;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
|
||||
class Container
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->containerBuilder = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($this->containerBuilder, new FileLocator(__DIR__.'/../../config'));
|
||||
$loader->load('services.yml');
|
||||
$this->containerBuilder->addCompilerPass(new CommandCompilerClass());
|
||||
$this->containerBuilder->compile();
|
||||
}
|
||||
|
||||
public function get($className)
|
||||
{
|
||||
return $this->containerBuilder->get($className);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue