Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.

Commit

Permalink
Provide API for the extension
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Nov 2, 2016
1 parent 1a95a1f commit 5ef349d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
15 changes: 13 additions & 2 deletions src/CrossContainerProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
24 changes: 17 additions & 7 deletions src/ServiceContainer/CrossContainerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down

0 comments on commit 5ef349d

Please sign in to comment.