src/Behat/Symfony2Extension/Context/Argument/ServiceArgumentResolver.php
private function replaceParameters(ContainerInterface $container, $argument)
    {
        if (preg_match('/^(?<!%)%([^%]+)%(?!%)$/', $argument, $matches)) {
            $replaced = $matches[1];

            if ($container->hasParameter($replaced)) {
                return $container->getParameter($replaced);
            }

            return $replaced;
        }
        
        return preg_replace_callback(
            '/(?<!%)%([^%]+)%(?!%)/',
            function ($matches) use ($container) {
                $parameter = $container->getParameter($matches[1]);

                if (is_array($parameter)) {
                    throw new InvalidArgumentException(
                        'Cannot reference a collection-type parameter with string interpolation.'
                    );
                }

                return $parameter;
            },
            $argument
        );
    }
private function replaceParameters(ContainerInterface $container, $argument)
    {
        if (preg_match('/^(?<!%)%([^%]+)%(?!%)$/', $argument, $matches)) {
            $replaced = $matches[1];

            if ($container->hasParameter($replaced)) {
                return $container->getParameter($replaced);
            }

            return $replaced;
        }
        
        return preg_replace_callback(
            '/(?<!%)%([^%]+)%(?!%)/',
            function ($matches) use ($container) {
                $parameter = $container->getParameter($matches[1]);

                if (is_array($parameter)) {
                    throw new InvalidArgumentException(
                        'Cannot reference a collection-type parameter with string interpolation.'
                    );
                }

                return $parameter;
            },
            $argument
        );
    }
private function replaceParameters ( ContainerInterface $ container , $ argument ) { if ( preg_match ( '/^(?<!%)%([^%]+)%(?!%)$/' , $ argument , $ matches ) ) { $ replaced = $ matches [ 1 ] ; if ( $ container -> hasParameter ( $ replaced ) ) { return $ container -> getParameter ( $ replaced ) ; } return $ replaced ; } return preg_replace_callback ( '/(?<!%)%([^%]+)%(?!%)/' , function ( $ matches ) use ( $ container ) { $ parameter = $ container -> getParameter ( $ matches [ 1 ] ) ; if ( is_array ( $ parameter ) ) { throw new InvalidArgumentException ( 'Cannot reference a collection-type parameter with string interpolation.' ) ; } return $ parameter ; } , $ argument ) ; }
Sanitise the container key given by the Behat config file,
and retrieve the parameter from the Container.

First, check if the whole string is one substitution, if it is, then pull it from the container.

Secondly, iterate over all substitutions in the string. Exception is thrown if referencing a
collection-type parameter when the key is not an entire substitution.

This is to handle the case where we're given an argument which should return a
collection-type parameter from the container.

@param  ContainerInterface $container
@param  string $argument
@throws InvalidArgumentException
@return mixed
Sanitise the container key given by the Behat config file and retrieve the parameter from the Container .