@@ -24,80 +24,80 @@ |
||
| 24 | 24 | |
| 25 | 25 | trait EmitterTrait { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var callable[][] $listeners |
|
| 29 | - */ |
|
| 30 | - protected $listeners = array(); |
|
| 27 | + /** |
|
| 28 | + * @var callable[][] $listeners |
|
| 29 | + */ |
|
| 30 | + protected $listeners = array(); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param string $scope |
|
| 34 | - * @param string $method |
|
| 35 | - * @param callable $callback |
|
| 36 | - */ |
|
| 37 | - public function listen($scope, $method, callable $callback) { |
|
| 38 | - $eventName = $scope . '::' . $method; |
|
| 39 | - if (!isset($this->listeners[$eventName])) { |
|
| 40 | - $this->listeners[$eventName] = array(); |
|
| 41 | - } |
|
| 42 | - if (array_search($callback, $this->listeners[$eventName], true) === false) { |
|
| 43 | - $this->listeners[$eventName][] = $callback; |
|
| 44 | - } |
|
| 45 | - } |
|
| 32 | + /** |
|
| 33 | + * @param string $scope |
|
| 34 | + * @param string $method |
|
| 35 | + * @param callable $callback |
|
| 36 | + */ |
|
| 37 | + public function listen($scope, $method, callable $callback) { |
|
| 38 | + $eventName = $scope . '::' . $method; |
|
| 39 | + if (!isset($this->listeners[$eventName])) { |
|
| 40 | + $this->listeners[$eventName] = array(); |
|
| 41 | + } |
|
| 42 | + if (array_search($callback, $this->listeners[$eventName], true) === false) { |
|
| 43 | + $this->listeners[$eventName][] = $callback; |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param string $scope optional |
|
| 49 | - * @param string $method optional |
|
| 50 | - * @param callable $callback optional |
|
| 51 | - */ |
|
| 52 | - public function removeListener($scope = null, $method = null, callable $callback = null) { |
|
| 53 | - $names = array(); |
|
| 54 | - $allNames = array_keys($this->listeners); |
|
| 55 | - if ($scope and $method) { |
|
| 56 | - $name = $scope . '::' . $method; |
|
| 57 | - if (isset($this->listeners[$name])) { |
|
| 58 | - $names[] = $name; |
|
| 59 | - } |
|
| 60 | - } elseif ($scope) { |
|
| 61 | - foreach ($allNames as $name) { |
|
| 62 | - $parts = explode('::', $name, 2); |
|
| 63 | - if ($parts[0] == $scope) { |
|
| 64 | - $names[] = $name; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - } elseif ($method) { |
|
| 68 | - foreach ($allNames as $name) { |
|
| 69 | - $parts = explode('::', $name, 2); |
|
| 70 | - if ($parts[1] == $method) { |
|
| 71 | - $names[] = $name; |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } else { |
|
| 75 | - $names = $allNames; |
|
| 76 | - } |
|
| 47 | + /** |
|
| 48 | + * @param string $scope optional |
|
| 49 | + * @param string $method optional |
|
| 50 | + * @param callable $callback optional |
|
| 51 | + */ |
|
| 52 | + public function removeListener($scope = null, $method = null, callable $callback = null) { |
|
| 53 | + $names = array(); |
|
| 54 | + $allNames = array_keys($this->listeners); |
|
| 55 | + if ($scope and $method) { |
|
| 56 | + $name = $scope . '::' . $method; |
|
| 57 | + if (isset($this->listeners[$name])) { |
|
| 58 | + $names[] = $name; |
|
| 59 | + } |
|
| 60 | + } elseif ($scope) { |
|
| 61 | + foreach ($allNames as $name) { |
|
| 62 | + $parts = explode('::', $name, 2); |
|
| 63 | + if ($parts[0] == $scope) { |
|
| 64 | + $names[] = $name; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + } elseif ($method) { |
|
| 68 | + foreach ($allNames as $name) { |
|
| 69 | + $parts = explode('::', $name, 2); |
|
| 70 | + if ($parts[1] == $method) { |
|
| 71 | + $names[] = $name; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } else { |
|
| 75 | + $names = $allNames; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - foreach ($names as $name) { |
|
| 79 | - if ($callback) { |
|
| 80 | - $index = array_search($callback, $this->listeners[$name], true); |
|
| 81 | - if ($index !== false) { |
|
| 82 | - unset($this->listeners[$name][$index]); |
|
| 83 | - } |
|
| 84 | - } else { |
|
| 85 | - $this->listeners[$name] = array(); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 78 | + foreach ($names as $name) { |
|
| 79 | + if ($callback) { |
|
| 80 | + $index = array_search($callback, $this->listeners[$name], true); |
|
| 81 | + if ($index !== false) { |
|
| 82 | + unset($this->listeners[$name][$index]); |
|
| 83 | + } |
|
| 84 | + } else { |
|
| 85 | + $this->listeners[$name] = array(); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * @param string $scope |
|
| 92 | - * @param string $method |
|
| 93 | - * @param array $arguments optional |
|
| 94 | - */ |
|
| 95 | - protected function emit($scope, $method, array $arguments = array()) { |
|
| 96 | - $eventName = $scope . '::' . $method; |
|
| 97 | - if (isset($this->listeners[$eventName])) { |
|
| 98 | - foreach ($this->listeners[$eventName] as $callback) { |
|
| 99 | - call_user_func_array($callback, $arguments); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 90 | + /** |
|
| 91 | + * @param string $scope |
|
| 92 | + * @param string $method |
|
| 93 | + * @param array $arguments optional |
|
| 94 | + */ |
|
| 95 | + protected function emit($scope, $method, array $arguments = array()) { |
|
| 96 | + $eventName = $scope . '::' . $method; |
|
| 97 | + if (isset($this->listeners[$eventName])) { |
|
| 98 | + foreach ($this->listeners[$eventName] as $callback) { |
|
| 99 | + call_user_func_array($callback, $arguments); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -29,29 +29,29 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Registry implements IRegistry { |
| 31 | 31 | |
| 32 | - /** @var IReporter[] */ |
|
| 33 | - private $reporters = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Register a reporter instance |
|
| 37 | - * |
|
| 38 | - * @param IReporter $reporter |
|
| 39 | - */ |
|
| 40 | - public function register(IReporter $reporter) { |
|
| 41 | - $this->reporters[] = $reporter; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Delegate crash reporting to all registered reporters |
|
| 46 | - * |
|
| 47 | - * @param Exception|Throwable $exception |
|
| 48 | - * @param array $context |
|
| 49 | - */ |
|
| 50 | - public function delegateReport($exception, array $context = []) { |
|
| 51 | - /** @var IReporter $reporter */ |
|
| 52 | - foreach ($this->reporters as $reporter) { |
|
| 53 | - $reporter->report($exception, $context); |
|
| 54 | - } |
|
| 55 | - } |
|
| 32 | + /** @var IReporter[] */ |
|
| 33 | + private $reporters = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Register a reporter instance |
|
| 37 | + * |
|
| 38 | + * @param IReporter $reporter |
|
| 39 | + */ |
|
| 40 | + public function register(IReporter $reporter) { |
|
| 41 | + $this->reporters[] = $reporter; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Delegate crash reporting to all registered reporters |
|
| 46 | + * |
|
| 47 | + * @param Exception|Throwable $exception |
|
| 48 | + * @param array $context |
|
| 49 | + */ |
|
| 50 | + public function delegateReport($exception, array $context = []) { |
|
| 51 | + /** @var IReporter $reporter */ |
|
| 52 | + foreach ($this->reporters as $reporter) { |
|
| 53 | + $reporter->report($exception, $context); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | } |