Skip to content

Commit

Permalink
Add ability to define a hydrator class.
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Mar 20, 2017
1 parent e7fac04 commit 1e129ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Makasim\Yadm\Bundle\DependencyInjection;

use Makasim\Yadm\Hydrator;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -24,6 +25,7 @@ public function getConfigTreeBuilder()
->scalarNode('collection')->isRequired()->cannotBeEmpty()->end()
->scalarNode('database')->isRequired()->cannotBeEmpty()->end()
->scalarNode('hydrator')->defaultValue(false)->end()
->scalarNode('hydrator_class')->defaultValue(Hydrator::class)->cannotBeEmpty()->end()
->booleanNode('pessimistic_lock')->defaultFalse()->end()
->scalarNode('repository')->end()
->end()
Expand Down
6 changes: 5 additions & 1 deletion DependencyInjection/YadmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ public function load(array $configs, ContainerBuilder $container)
if (false == $hydratorId = $modelConfig['hydrator']) {
$hydratorId = sprintf('yadm.%s.hydrator', $name);

$container->register($hydratorId, Hydrator::class)->addArgument($modelConfig['class']);
$hydratorClass = $modelConfig['hydrator_class'];

$container->register($hydratorId, $hydratorClass)->addArgument($modelConfig['class']);
}



$container->register(sprintf('yadm.%s.storage', $name), Storage::class)
->addArgument(new Reference(sprintf('yadm.%s.collection', $name)))
->addArgument(new Reference($hydratorId))
Expand Down

0 comments on commit 1e129ad

Please sign in to comment.