X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=inline;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FHelperContainer%2FServiceContainer%2FHelperContainerExtension.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FHelperContainer%2FServiceContainer%2FHelperContainerExtension.php;h=1d5100f5cdcfc273f92968c6bc0b23bdd2544a24;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hp=0000000000000000000000000000000000000000;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68;p=yaffs-website diff --git a/vendor/behat/behat/src/Behat/Behat/HelperContainer/ServiceContainer/HelperContainerExtension.php b/vendor/behat/behat/src/Behat/Behat/HelperContainer/ServiceContainer/HelperContainerExtension.php new file mode 100644 index 000000000..1d5100f5c --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/HelperContainer/ServiceContainer/HelperContainerExtension.php @@ -0,0 +1,123 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\HelperContainer\ServiceContainer; + +use Behat\Behat\Context\ServiceContainer\ContextExtension; +use Behat\Behat\HelperContainer\Exception\WrongServicesConfigurationException; +use Behat\Testwork\Call\ServiceContainer\CallExtension; +use Behat\Testwork\ServiceContainer\Extension; +use Behat\Testwork\ServiceContainer\ExtensionManager; +use Behat\Testwork\ServiceContainer\ServiceProcessor; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; + +/** + * Behat helper container extension. + * + * Extends Behat with helper containers support. + * + * @author Konstantin Kudryashov + */ +final class HelperContainerExtension implements Extension +{ + /* + * Available extension points + */ + const HELPER_CONTAINER_TAG = 'helper_container.container'; + + /** + * @var ServiceProcessor + */ + private $processor; + + /** + * Initializes compiler pass. + * + * @param null|ServiceProcessor $processor + */ + public function __construct(ServiceProcessor $processor = null) + { + $this->processor = $processor ? : new ServiceProcessor(); + } + + /** + * {@inheritdoc} + */ + public function getConfigKey() + { + return 'helper_container'; + } + + /** + * {@inheritdoc} + */ + public function initialize(ExtensionManager $extensionManager) + { + } + + /** + * {@inheritdoc} + */ + public function configure(ArrayNodeDefinition $builder) + { + } + + /** + * {@inheritdoc} + */ + public function load(ContainerBuilder $container, array $config) + { + $definition = new Definition('Behat\Behat\HelperContainer\Argument\ServicesResolverFactory', array($container)); + $definition->addTag(ContextExtension::SUITE_SCOPED_RESOLVER_FACTORY_TAG, array('priority' => 0)); + $container->setDefinition(ContextExtension::SUITE_SCOPED_RESOLVER_FACTORY_TAG . '.helper_container', $definition); + + $definition = new Definition('Behat\Behat\HelperContainer\Call\Filter\ServicesResolver'); + $definition->addTag(CallExtension::CALL_FILTER_TAG, array('priority' => 0)); + $container->setDefinition(CallExtension::CALL_FILTER_TAG . '.helper_container', $definition); + } + + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + $references = $this->processor->findAndSortTaggedServices($container, self::HELPER_CONTAINER_TAG); + + foreach ($references as $reference) { + if ($this->isDefinitionShared($container->getDefinition((string) $reference))) { + throw new WrongServicesConfigurationException(sprintf( + 'Container services must not be configured as shared, but `@%s` is.', $reference + )); + } + } + } + + /** + * Checks if provided definition is shared. + * + * @param Definition $definition + * + * @return bool + * + * @todo Remove after upgrading to Symfony 2.8+ + */ + private function isDefinitionShared(Definition $definition) + { + if (method_exists($definition, 'isShared')) { + return $definition->isShared(); + } else if (method_exists($definition, 'getScope')) { + return $definition->getScope() !== ContainerBuilder::SCOPE_PROTOTYPE; + } + + return false; + } +}