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\Definition;
13 use Behat\Behat\Definition\Exception\RedundantStepException;
14 use Behat\Testwork\Environment\Environment;
15 use Behat\Testwork\Environment\EnvironmentManager;
18 * Provides step definitions using environment manager.
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
22 final class DefinitionRepository
25 * @var EnvironmentManager
27 private $environmentManager;
30 * Initializes repository.
32 * @param EnvironmentManager $environmentManager
34 public function __construct(EnvironmentManager $environmentManager)
36 $this->environmentManager = $environmentManager;
40 * Returns all available definitions for a specific environment.
42 * @param Environment $environment
44 * @return Definition[]
46 * @throws RedundantStepException
48 public function getEnvironmentDefinitions(Environment $environment)
51 $definitions = array();
53 foreach ($this->environmentManager->readEnvironmentCallees($environment) as $callee) {
54 if (!$callee instanceof Definition) {
58 $pattern = $callee->getPattern();
59 if (isset($patterns[$pattern])) {
60 throw new RedundantStepException($callee, $patterns[$pattern]);
63 $patterns[$pattern] = $callee;
65 $definitions[] = $callee;