Skip to content

Commit

Permalink
Rename executors to targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Kévin Gomez committed Jan 27, 2017
1 parent dfd598c commit a40f373
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/OperatorsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function process(ContainerBuilder $container)
{
foreach ($container->findTaggedServiceIds('rulerz.operator') as $id => $attributesSet) {
foreach ($attributesSet as $attributes) {
$executor = $container->getDefinition($attributes['executor']);
$executor = $container->getDefinition($attributes['compilation_target']);

if (!empty($attributes['inline']) && $attributes['inline']) {
$executor->addMethodCall('defineInlineOperator', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;

class ExecutorsPass implements CompilerPassInterface
class TargetsPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
Expand Down
8 changes: 4 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getConfigTreeBuilder()

$this->addCacheConfig($rootNode);
$this->addDebugConfig($rootNode);
$this->addExecutorsConfig($rootNode);
$this->addTargetsConfig($rootNode);

return $treeBuilder;
}
Expand All @@ -40,14 +40,14 @@ private function addDebugConfig(ArrayNodeDefinition $rootNode)
return $rootNode;
}

private function addExecutorsConfig(ArrayNodeDefinition $rootNode)
private function addTargetsConfig(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('executors')
->arrayNode('targets')
->addDefaultsIfNotSet()
->children()
->booleanNode('array')->defaultTrue()->end()
->booleanNode('native')->defaultTrue()->end()
->booleanNode('doctrine')->defaultFalse()->end()
->booleanNode('doctrine_dbal')->defaultFalse()->end()
->booleanNode('eloquent')->defaultFalse()->end()
Expand Down
12 changes: 6 additions & 6 deletions DependencyInjection/KPhoenRulerZExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class KPhoenRulerZExtension extends Extension
{
private $supportedExecutors = ['array', 'doctrine', 'eloquent', 'pomm', 'elastica', 'elasticsearch'];
private $supportedTargets = ['native', 'doctrine', 'eloquent', 'pomm', 'elastica', 'elasticsearch'];

public function load(array $configs, ContainerBuilder $container)
{
Expand All @@ -24,7 +24,7 @@ public function load(array $configs, ContainerBuilder $container)
}

$this->configureCache($container, $config);
$this->configureExecutors($loader, $config);
$this->configureTargets($loader, $config);
}

private function configureCache(ContainerBuilder $container, array $config)
Expand All @@ -37,11 +37,11 @@ private function configureCache(ContainerBuilder $container, array $config)
}
}

private function configureExecutors(YamlFileLoader $loader, array $config)
private function configureTargets(YamlFileLoader $loader, array $config)
{
foreach ($this->supportedExecutors as $executor) {
if ($config['executors'][$executor]) {
$loader->load(sprintf('executors/%s.yml', $executor));
foreach ($this->supportedTargets as $target) {
if ($config['targets'][$target]) {
$loader->load(sprintf('targets/%s.yml', $target));
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions KPhoenRulerZBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

use KPhoen\RulerZBundle\DependencyInjection\Compiler\ExecutorsPass;
use KPhoen\RulerZBundle\DependencyInjection\Compiler\OperatorsPass;
use KPhoen\RulerZBundle\DependencyInjection\Compiler;

class KPhoenRulerZBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new ExecutorsPass());
$container->addCompilerPass(new OperatorsPass());
$container->addCompilerPass(new Compiler\TargetsPass());
$container->addCompilerPass(new Compiler\OperatorsPass());
}

/**
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ services:
operator.array.like:
class: RulerZ\Operator\ArrayExecutor\Like
tags:
- { name: rulerz.operator, executor: rulerz.executor.array, operator: like }
- { name: rulerz.operator, compilation_target: rulerz.compilation_target.native, operator: like }
```
In addition to the `rulerz.operator` parameter, two other values are needed:
* `executor`: the executor service we want to register the operator into ;
* `operator`: the name that will be given to the operator.
In addition to the `rulerz.operator` tag, two other values are needed:
* `compilation_target`: the compilation target we want to register the operator for ;
* `operator`: the name that will be given to the operator in rules.

**Important**: Operators registered as classes must implement the `__invoke`
magic method as RulerZ expects custom operators to be defined as callable.
Expand Down Expand Up @@ -96,7 +96,8 @@ kphoen_rulerz:
cache: %kernel.cache_dir%/rulerz
debug: %kernel.debug%
executors:
targets:
native: false
doctrine: false
doctrine_dbal: false
eloquent: false
Expand All @@ -105,8 +106,8 @@ kphoen_rulerz:
elasticsearch: false
```

The `executors` section allows you to enable only the executors needed by your
application.
The `targets` section allows you to enable only the compilation targets needed
by your application.

Licence
-------
Expand Down
6 changes: 0 additions & 6 deletions Resources/config/executors/doctrine_dbal.yml

This file was deleted.

6 changes: 0 additions & 6 deletions Resources/config/executors/elastica.yml

This file was deleted.

6 changes: 0 additions & 6 deletions Resources/config/executors/elasticsearch.yml

This file was deleted.

6 changes: 0 additions & 6 deletions Resources/config/executors/eloquent.yml

This file was deleted.

6 changes: 0 additions & 6 deletions Resources/config/executors/pomm.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
rulerz.executor.doctrine:
rulerz.compilation_target.doctrine:
class: RulerZ\Target\DoctrineORM\DoctrineORM
public: false
tags:
Expand Down
6 changes: 6 additions & 0 deletions Resources/config/targets/doctrine_dbal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
rulerz.compilation_target.doctrine_dbal:
class: RulerZ\Target\DoctrineDBAL\DoctrineDBAL
public: false
tags:
- { name: rulerz.compilation_target }
6 changes: 6 additions & 0 deletions Resources/config/targets/elastica.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
rulerz.compilation_target.elastica:
class: RulerZ\Target\Elasticsa\Elastica
public: false
tags:
- { name: rulerz.compilation_target }
6 changes: 6 additions & 0 deletions Resources/config/targets/elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
rulerz.compilation_target.elasticsearch:
class: RulerZ\Target\Elasticsearch\Elasticsearch
public: false
tags:
- { name: rulerz.compilation_target }
6 changes: 6 additions & 0 deletions Resources/config/targets/eloquent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
rulerz.compilation_target.eloquent:
class: RulerZ\Target\Eloquent\Eloquent
public: false
tags:
- { name: rulerz.compilation_target }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
rulerz.target.native:
rulerz.compilation_target.native:
class: RulerZ\Target\Native\Native
public: false
tags:
Expand Down
6 changes: 6 additions & 0 deletions Resources/config/targets/pomm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
rulerz.compilation_target.pomm:
class: RulerZ\Target\Pomm\Pomm
public: false
tags:
- { name: rulerz.compilation_target }
14 changes: 7 additions & 7 deletions Tests/DependencyInjection/KPhoenRulerZExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ public function testItThrowsIfTheCacheDirectoryCanNotBeCreated()
$this->load();
}

public function testItLoadsExecutorsDefinedInTheConfig()
public function testItLoadsTargetsDefinedInTheConfig()
{
$this->load([
'executors' => [
'targets' => [
'pomm' => null,
'doctrine' => null,
],
]);

$this->assertContainerBuilderHasService('rulerz.executor.pomm');
$this->assertContainerBuilderHasService('rulerz.executor.doctrine');
$this->assertContainerBuilderNotHasService('rulerz.executor.elastica');
$this->assertContainerBuilderHasService('rulerz.compilation_target.pomm');
$this->assertContainerBuilderHasService('rulerz.compilation_target.doctrine');
$this->assertContainerBuilderNotHasService('rulerz.compilation_target.elastica');
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testUnknownExecutorsCantBeLoaded()
public function testUnknownTargetsCantBeLoaded()
{
$this->load([
'executors' => [
'targets' => [
'unknown' => null,
],
]);
Expand Down

0 comments on commit a40f373

Please sign in to comment.