Skip to content

Commit

Permalink
Merge pull request #10 from formapro/lazy-storages
Browse files Browse the repository at this point in the history
Lazy storages
  • Loading branch information
makasim authored May 14, 2019
2 parents f289629 + 3b3a3e4 commit 26a532e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions DependencyInjection/YadmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ public function load(array $configs, ContainerBuilder $container)

$storages = [];
foreach ($config['models'] as $name => $modelConfig) {
$container->register(sprintf('yadm.%s.collection', $name), Collection::class)
->setFactory([new Reference('yadm.collection_factory'), 'create'])
->addArgument($modelConfig['collection'])
->addArgument($modelConfig['database'])
;

$typesServices = [];
foreach ($modelConfig['types'] as $key => $type) {
switch ($type) {
Expand Down Expand Up @@ -93,14 +87,19 @@ public function load(array $configs, ContainerBuilder $container)
}

$container->register(sprintf('yadm.%s.storage', $name), $modelConfig['storage_class'])
->addArgument(new Reference(sprintf('yadm.%s.collection', $name)))
->addArgument($name)
->addArgument(new Reference('yadm.collection_factory'))
->addArgument(new Reference($hydratorId))
->addArgument(new Reference('yadm.changes_collector'))
->addArgument(null)
->addArgument(new Reference(sprintf('yadm.%s.convert_values', $name)))
->addArgument($storageMetaId ? new Reference($storageMetaId) : null)
;

$container->register(sprintf('yadm.%s.collection', $name), Collection::class)
->setFactory([new Reference(sprintf('yadm.%s.storage', $name)), 'getCollection'])
;

if ($modelConfig['storage_autowire']) {
$container->setAlias($modelConfig['storage_class'], sprintf('yadm.%s.storage', $name))
->setPublic(true)
Expand All @@ -119,7 +118,7 @@ public function load(array $configs, ContainerBuilder $container)
;

$container->getDefinition(sprintf('yadm.%s.storage', $name))
->replaceArgument(3, new Reference(sprintf('yadm.%s.pessimistic_lock', $name)))
->replaceArgument(4, new Reference(sprintf('yadm.%s.pessimistic_lock', $name)))
;
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"require": {
"php": ">=7.1",
"formapro/yadm": "^0.5.3",
"formapro/yadm": "^0.5.5",
"formapro/yadm-migrations": "^0.5"
},
"suggest": {
Expand Down

0 comments on commit 26a532e

Please sign in to comment.