Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Hook / HookDispatcher.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
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\Testwork\Hook;
12
13 use Behat\Testwork\Call\CallCenter;
14 use Behat\Testwork\Call\CallResult;
15 use Behat\Testwork\Call\CallResults;
16 use Behat\Testwork\Hook\Call\HookCall;
17 use Behat\Testwork\Hook\Scope\HookScope;
18
19 /**
20  * Dispatches registered hooks for provided events.
21  *
22  * @author Konstantin Kudryashov <ever.zet@gmail.com>
23  */
24 final class HookDispatcher
25 {
26     /**
27      * @var HookRepository
28      */
29     private $repository;
30     /**
31      * @var CallCenter
32      */
33     private $callCenter;
34
35     /**
36      * Initializes hook dispatcher.
37      *
38      * @param HookRepository $repository
39      * @param CallCenter     $callCenter
40      */
41     public function __construct(HookRepository $repository, CallCenter $callCenter)
42     {
43         $this->repository = $repository;
44         $this->callCenter = $callCenter;
45     }
46
47     /**
48      * Dispatches hooks for a specified event.
49      *
50      * @param HookScope $scope
51      *
52      * @return CallResults
53      */
54     public function dispatchScopeHooks(HookScope $scope)
55     {
56         $results = array();
57         foreach ($this->repository->getScopeHooks($scope) as $hook) {
58             $results[] = $this->dispatchHook($scope, $hook);
59         }
60
61         return new CallResults($results);
62     }
63
64     /**
65      * Dispatches single event hook.
66      *
67      * @param HookScope $scope
68      * @param Hook      $hook
69      *
70      * @return CallResult
71      */
72     private function dispatchHook(HookScope $scope, Hook $hook)
73     {
74         return $this->callCenter->makeCall(new HookCall($scope, $hook));
75     }
76 }