Skip to content

Commit

Permalink
Services are no longer public, added plugins service locator, introdu…
Browse files Browse the repository at this point in the history
…ced test aliases
  • Loading branch information
mateuszsip committed Jan 28, 2018
1 parent 862bc60 commit 4479ab1
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 26 deletions.
45 changes: 45 additions & 0 deletions src/DependencyInjection/Compiler/PluginLocatorPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);

namespace Prooph\Bundle\EventStore\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ServiceLocator;

final class PluginLocatorPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasParameter('prooph_event_store.stores')) {
return;
}

$stores = $container->getParameter('prooph_event_store.stores');

$globalPlugins = $container->findTaggedServiceIds('prooph_event_store.plugin');
$storePlugins = [];

foreach ($stores as $name => $store) {
$storePlugins[] = $container->findTaggedServiceIds(sprintf('prooph_event_store.%s.plugin', $name));
}

$plugins = array_merge($globalPlugins, ...$storePlugins);

$locatorPlugins = [];

foreach ($plugins as $id => $attributes) {
$locatorPlugins[$id] = new ServiceClosureArgument(new Reference($id));
}

$container
->setDefinition(
'prooph_event_store.plugins_locator',
new Definition(ServiceLocator::class, [$locatorPlugins])
)
->addTag('container.service_locator');
}
}
14 changes: 3 additions & 11 deletions src/DependencyInjection/ProophEventStoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,14 @@ private function loadEventStore(string $name, array $options, ContainerBuilder $
$eventStoreId,
new ChildDefinition('prooph_event_store.store_definition')
)
// TODO: Remove me
->setPublic(true)
->setArguments(
[
$name,
new Reference($options['event_store']),
new Reference('prooph_event_store.action_event_emitter_factory'),
$options['event_emitter'],
$options['wrap_action_event_emitter'],
new Reference('service_container'),
new Reference('prooph_event_store.plugins_locator'),
]
);

Expand All @@ -183,8 +181,6 @@ private function loadEventStore(string $name, array $options, ContainerBuilder $
$repositoryName,
new ChildDefinition('prooph_event_store.repository_definition')
)
// TODO: Remove me
->setPublic(true)
->setArguments(
[
$repositoryClass,
Expand All @@ -206,18 +202,14 @@ private function loadEventStore(string $name, array $options, ContainerBuilder $
->setDefinition(
$metadataEnricherAggregateId,
new ChildDefinition('prooph_event_store.metadata_enricher_aggregate_definition')
)
// TODO: Remove me
->setPublic(true);
);

$metadataEnricherId = sprintf('prooph_event_store.%s.%s', 'metadata_enricher_plugin', $name);

$metadataEnricherDefinition = $container
->setDefinition(
$metadataEnricherId,
new ChildDefinition('prooph_event_store.metadata_enricher_plugin_definition')
)
// TODO: Remove me
->setPublic(true);
);
}
}
2 changes: 1 addition & 1 deletion src/Factory/DefaultEventStoreFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Exception\RuntimeException;
use Prooph\EventStore\Plugin\Plugin;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Container\ContainerInterface;

class DefaultEventStoreFactory implements EventStoreFactory
{
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/EventStoreFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Prooph\Bundle\EventStore\Factory;

use Prooph\EventStore\EventStore;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Container\ContainerInterface;

interface EventStoreFactory
{
Expand Down
2 changes: 2 additions & 0 deletions src/ProophEventStoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Prooph\Bundle\EventStore;

use Prooph\Bundle\EventStore\DependencyInjection\Compiler\MetadataEnricherPass;
use Prooph\Bundle\EventStore\DependencyInjection\Compiler\PluginLocatorPass;
use Prooph\Bundle\EventStore\DependencyInjection\Compiler\PluginsPass;
use Prooph\Bundle\EventStore\DependencyInjection\Compiler\ProjectorPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -26,5 +27,6 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new PluginsPass());
$container->addCompilerPass(new MetadataEnricherPass());
$container->addCompilerPass(new ProjectorPass());
$container->addCompilerPass(new PluginLocatorPass());
}
}
6 changes: 3 additions & 3 deletions src/Resources/config/event_store.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
</service>
<service id="prooph_event_store.store_factory" class="Prooph\Bundle\EventStore\Factory\DefaultEventStoreFactory" />
<service id="prooph_event_store.plugin_definition" class="Prooph\EventStore\Plugin\Plugin" abstract="true" />
<service id="prooph_event_store.metadata_enricher_plugin_definition" class="Prooph\EventStore\Metadata\MetadataEnricherPlugin" public="true" abstract="true" />
<service id="prooph_event_store.metadata_enricher_aggregate_definition" class="Prooph\EventStore\Metadata\MetadataEnricherAggregate" public="true" abstract="true" />
<service id="prooph_event_store.metadata_enricher_plugin_definition" class="Prooph\EventStore\Metadata\MetadataEnricherPlugin" abstract="true" />
<service id="prooph_event_store.metadata_enricher_aggregate_definition" class="Prooph\EventStore\Metadata\MetadataEnricherAggregate" abstract="true" />
<service id="prooph_event_store.projection_factory" class="Prooph\Bundle\EventStore\ProjectionManagerFactory"/>
<service id="prooph_event_store.projection_definition" class="Prooph\EventStore\Projection\ProjectionManager">
<service id="prooph_event_store.projection_definition" class="Prooph\EventStore\Projection\ProjectionManager" abstract="true">
<factory service="prooph_event_store.projection_factory" method="createProjectionManager" />
</service>
<service id="prooph_event_store.repository_factory" class="Prooph\Bundle\EventStore\RepositoryFactory" />
Expand Down
8 changes: 4 additions & 4 deletions test/BundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function it_creates_an_event_store_with_plugins()
{
$container = $this->loadContainer('event_store', 'plugins');

$eventStore = $container->get('prooph_event_store.main_store');
$eventStore = $container->get('test.prooph_event_store.main_store');
self::assertInstanceOf(EventStore::class, $eventStore);

$plugin = $container->get(BlackHole::class);
Expand All @@ -89,13 +89,13 @@ public function it_creates_an_event_store_with_metadata_enrichers()
{
$container = $this->loadContainer('event_store', 'metadata_enricher');

$eventStore = $container->get('prooph_event_store.main_store');
$eventStore = $container->get('test.prooph_event_store.main_store');
self::assertInstanceOf(EventStore::class, $eventStore);

$metadataEnricherPlugin = $container->get('prooph_event_store.metadata_enricher_plugin.main_store');
$metadataEnricherPlugin = $container->get('test.prooph_event_store.metadata_enricher_plugin.main_store');
self::assertInstanceOf(MetadataEnricherPlugin::class, $metadataEnricherPlugin);

$metadataEnricherAggregate = $container->get('prooph_event_store.metadata_enricher_aggregate.main_store');
$metadataEnricherAggregate = $container->get('test.prooph_event_store.metadata_enricher_aggregate.main_store');
self::assertInstanceOf(MetadataEnricherAggregate::class, $metadataEnricherAggregate);

$plugin = $container->get(DependencyInjection\Fixture\Metadata\BlackHole::class);
Expand Down
12 changes: 6 additions & 6 deletions test/DependencyInjection/AbstractEventStoreExtensionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public function it_creates_an_event_store()
self::assertEquals(EventStore::class, $config->getClass());

/* @var $eventStore EventStore */
$eventStore = $container->get('prooph_event_store.main_store');
$eventStore = $container->get('test.prooph_event_store.main_store');
self::assertInstanceOf(EventStore::class, $eventStore);

$repository = $container->get('todo_list');
$repository = $container->get('test.todo_list');
self::assertInstanceOf(BlackHoleRepository::class, $repository);

$snapshotStore = $container->get('prooph_test.bundle.snapshot_store.in_memory');
$snapshotStore = $container->get('test.prooph_test.bundle.snapshot_store.in_memory');
self::assertInstanceOf(SnapshotStore::class, $snapshotStore);
}

Expand All @@ -68,7 +68,7 @@ public function it_registers_repository_with_short_syntax()
{
$container = $this->loadContainer('event_store');

$repository = $container->get(BlackHoleRepository::class);
$repository = $container->get('test.' . BlackHoleRepository::class);
self::assertInstanceOf(BlackHoleRepository::class, $repository);
}

Expand All @@ -85,10 +85,10 @@ public function it_creates_multiple_event_stores()
self::assertEquals(EventStore::class, $config->getClass());

//* @var $eventStore EventStore */
$eventStore = $container->get('prooph_event_store.' . $name);
$eventStore = $container->get('test.prooph_event_store.' . $name);
self::assertInstanceOf(EventStore::class, $eventStore);

$repository = $container->get($name . '.todo_list');
$repository = $container->get('test.' . $name . '.todo_list');
self::assertInstanceOf(BlackHoleRepository::class, $repository);
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/DependencyInjection/XmlEventStoreExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class XmlEventStoreExtensionTest extends AbstractEventStoreExtensionTestCase
{
protected function loadFromFile(ContainerBuilder $container, $file)
{
$loadXml = new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixture/config/xml'));
$loadXml->load($file.'.xml');

$aliasesLoader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$aliasesLoader->load('test_aliases.yml');
}
}
3 changes: 3 additions & 0 deletions test/DependencyInjection/YamlEventStoreExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ protected function loadFromFile(ContainerBuilder $container, $file)
{
$loadYaml = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixture/config/yml'));
$loadYaml->load($file.'.yml');

$aliasesLoader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$aliasesLoader->load('test_aliases.yml');
}
}
2 changes: 2 additions & 0 deletions test/Resources/config/metadata_enricher.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
services:
'ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Metadata\BlackHole':
class: ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Metadata\BlackHole
public: true
tags:
- { name: 'prooph_event_store.main_store.metadata_enricher' }

'ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Metadata\GlobalBlackHole':
class: ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Metadata\GlobalBlackHole
public: true
tags:
- { name: 'prooph_event_store.metadata_enricher' }
6 changes: 6 additions & 0 deletions test/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
imports:
- { resource: test_aliases.yml }

services:
'ProophTest\Bundle\EventStore\DependencyInjection\Fixture\EventStore\BlackHole':
class: ProophTest\Bundle\EventStore\DependencyInjection\Fixture\EventStore\BlackHole
public: true

'prooph_test.bundle.snapshot_store.in_memory':
class: Prooph\SnapshotStore\InMemorySnapshotStore
public: true

'ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Model\BlackHoleAggregateTranslator':
class: ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Model\BlackHoleAggregateTranslator
public: true
36 changes: 36 additions & 0 deletions test/Resources/config/test_aliases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
services:
test.prooph_event_store.main_store:
alias: prooph_event_store.main_store
public: true

test.prooph_event_store.second_store:
alias: prooph_event_store.second_store
public: true

test.prooph_event_store.metadata_enricher_plugin.main_store:
alias: prooph_event_store.metadata_enricher_plugin.main_store
public: true

test.prooph_event_store.metadata_enricher_aggregate.main_store:
alias: prooph_event_store.metadata_enricher_aggregate.main_store
public: true

test.todo_list:
alias: todo_list
public: true

test.main_store.todo_list:
alias: main_store.todo_list
public: true

test.second_store.todo_list:
alias: second_store.todo_list
public: true

test.ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Model\BlackHoleRepository:
alias: ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Model\BlackHoleRepository
public: true

test.prooph_test.bundle.snapshot_store.in_memory:
alias: prooph_test.bundle.snapshot_store.in_memory
public: true

0 comments on commit 4479ab1

Please sign in to comment.