4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\HelperContainer\Argument;
13 use Behat\Behat\Context\Argument\ArgumentResolver;
14 use Psr\Container\ContainerExceptionInterface;
15 use Psr\Container\ContainerInterface;
19 * Resolves arguments using provided service container.
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
25 final class ServicesResolver implements ArgumentResolver
28 * @var ContainerInterface
33 * Initialises resolver.
35 * @param ContainerInterface $container
37 public function __construct(ContainerInterface $container)
39 $this->container = $container;
45 * @throws ContainerExceptionInterface
47 public function resolveArguments(ReflectionClass $classReflection, array $arguments)
49 return array_map(array($this, 'resolveArgument'), $arguments);
53 * Attempts to resolve singular argument from container.
55 * Convention is strings starting with `@` are considered services and
56 * are expected to be present in the container.
62 * @throws ContainerExceptionInterface
64 private function resolveArgument($value)
66 if (0 === mb_strpos($value, '@')) {
67 return $this->container->get(mb_substr($value, 1));