From 5ef349d854f028350f2a136849cb82173c72b4d4 Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Wed, 2 Nov 2016 16:28:44 +0100 Subject: [PATCH] Provide API for the extension --- src/CrossContainerProcessor.php | 15 ++++++++++-- .../CrossContainerExtension.php | 24 +++++++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/CrossContainerProcessor.php b/src/CrossContainerProcessor.php index 8bcb26e..b3bebb6 100644 --- a/src/CrossContainerProcessor.php +++ b/src/CrossContainerProcessor.php @@ -26,9 +26,20 @@ final class CrossContainerProcessor implements CompilerPassInterface /** * @param ContainerAccessor[] $containerAccessors */ - public function __construct(array $containerAccessors) + public function __construct(array $containerAccessors = []) { - $this->containerAccessors = $containerAccessors; + foreach ($containerAccessors as $containerIdentifier => $containerAccessor) { + $this->addContainerAccessor($containerIdentifier, $containerAccessor); + } + } + + /** + * @param string $containerIdentifier + * @param ContainerAccessor $containerAccessor + */ + public function addContainerAccessor($containerIdentifier, ContainerAccessor $containerAccessor) + { + $this->containerAccessors[$containerIdentifier] = $containerAccessor; } /** diff --git a/src/ServiceContainer/CrossContainerExtension.php b/src/ServiceContainer/CrossContainerExtension.php index 596e22f..796a588 100644 --- a/src/ServiceContainer/CrossContainerExtension.php +++ b/src/ServiceContainer/CrossContainerExtension.php @@ -15,23 +15,33 @@ use Behat\Testwork\ServiceContainer\ExtensionManager; use FriendsOfBehat\CrossContainerExtension\ContainerAccessor; use FriendsOfBehat\CrossContainerExtension\ContainerBasedContainerAccessor; +use FriendsOfBehat\CrossContainerExtension\CrossContainerProcessor; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** + * @api + */ final class CrossContainerExtension implements Extension { /** - * @var ContainerAccessor[] + * @var CrossContainerProcessor */ - private $containers = []; + private $crossContainerProcessor; + + public function __construct() + { + $this->crossContainerProcessor = new CrossContainerProcessor(); + } /** - * @param string $containerIdentifier - * @param ContainerAccessor $containerAccessor + * @api + * + * @return CrossContainerProcessor */ - public function addContainer($containerIdentifier, ContainerAccessor $containerAccessor) + public function getCrossContainerProcessor() { - $this->containers[$containerIdentifier] = $containerAccessor; + return $this->crossContainerProcessor; } /** @@ -69,7 +79,7 @@ public function configure(ArrayNodeDefinition $builder) */ public function load(ContainerBuilder $container, array $config) { - $this->containers['behat'] = new ContainerBasedContainerAccessor($container); + $this->crossContainerProcessor->addContainerAccessor('behat', new ContainerBasedContainerAccessor($container)); } /**