Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / HelperContainer / Argument / ServicesResolver.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\HelperContainer\Argument;
12
13 use Behat\Behat\Context\Argument\ArgumentResolver;
14 use Psr\Container\ContainerExceptionInterface;
15 use Psr\Container\ContainerInterface;
16 use ReflectionClass;
17
18 /**
19  * Resolves arguments using provided service container.
20  *
21  * @see ContextFactory
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 final class ServicesResolver implements ArgumentResolver
26 {
27     /**
28      * @var ContainerInterface
29      */
30     private $container;
31
32     /**
33      * Initialises resolver.
34      *
35      * @param ContainerInterface $container
36      */
37     public function __construct(ContainerInterface $container)
38     {
39         $this->container = $container;
40     }
41
42     /**
43      * {@inheritdoc}
44      *
45      * @throws ContainerExceptionInterface
46      */
47     public function resolveArguments(ReflectionClass $classReflection, array $arguments)
48     {
49         return array_map(array($this, 'resolveArgument'), $arguments);
50     }
51
52     /**
53      * Attempts to resolve singular argument from container.
54      *
55      * Convention is strings starting with `@` are considered services and
56      * are expected to be present in the container.
57      *
58      * @param mixed $value
59      *
60      * @return mixed
61      *
62      * @throws ContainerExceptionInterface
63      */
64     private function resolveArgument($value)
65     {
66         if (0 === mb_strpos($value, '@')) {
67             return $this->container->get(mb_substr($value, 1));
68         }
69
70         return $value;
71     }
72 }