4 * This file is part of the Behat Testwork.
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\Testwork\Hook;
13 use Behat\Testwork\Call\Callee;
14 use Behat\Testwork\Environment\Environment;
15 use Behat\Testwork\Environment\EnvironmentManager;
16 use Behat\Testwork\Hook\Scope\HookScope;
19 * Finds hooks using provided environments or scopes.
21 * @author Konstantin Kudryashov <ever.zet@gmail.com>
23 final class HookRepository
26 * @var EnvironmentManager
28 private $environmentManager;
31 * Initializes repository.
33 * @param EnvironmentManager $environmentManager
35 public function __construct(EnvironmentManager $environmentManager)
37 $this->environmentManager = $environmentManager;
41 * Returns all available hooks for a specific environment.
43 * @param Environment $environment
47 public function getEnvironmentHooks(Environment $environment)
50 $this->environmentManager->readEnvironmentCallees($environment),
51 function (Callee $callee) {
52 return $callee instanceof Hook;
58 * Returns hooks for a specific event.
60 * @param HookScope $scope
64 public function getScopeHooks(HookScope $scope)
67 $this->getEnvironmentHooks($scope->getEnvironment()),
68 function (Hook $hook) use ($scope) {
69 if ($scope->getName() !== $hook->getScopeName()) {
73 return !($hook instanceof FilterableHook && !$hook->filterMatches($scope));