Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Event | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toParams | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Event; |
| 16 | |
| 17 | /** |
| 18 | * Generic event class - used by trigger() for any ad-hoc, non-typed event name |
| 19 | * |
| 20 | * @category Pop |
| 21 | * @package Pop\Event |
| 22 | * @author Nick Sagona, III <nick@popphp.org> |
| 23 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 24 | * @license https://www.popphp.org/license New BSD License |
| 25 | * @version 5.0.0 |
| 26 | */ |
| 27 | class Event extends AbstractEvent |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * Event name |
| 32 | * @var string |
| 33 | */ |
| 34 | protected string $name; |
| 35 | |
| 36 | /** |
| 37 | * Event params |
| 38 | * @var array |
| 39 | */ |
| 40 | protected array $params; |
| 41 | |
| 42 | /** |
| 43 | * Constructor |
| 44 | * |
| 45 | * Instantiate the generic event object. |
| 46 | * |
| 47 | * @param string $name |
| 48 | * @param array $params |
| 49 | */ |
| 50 | public function __construct(string $name, array $params = []) |
| 51 | { |
| 52 | $this->name = $name; |
| 53 | $this->params = $params; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get the event name |
| 58 | * |
| 59 | * @return string |
| 60 | */ |
| 61 | public function getName(): string |
| 62 | { |
| 63 | return $this->name; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get the params array |
| 68 | * |
| 69 | * @return array |
| 70 | */ |
| 71 | public function toParams(): array |
| 72 | { |
| 73 | return $this->params; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get a single param by key |
| 78 | * |
| 79 | * @param string $key |
| 80 | * @return mixed |
| 81 | */ |
| 82 | public function get(string $key): mixed |
| 83 | { |
| 84 | return $this->params[$key] ?? null; |
| 85 | } |
| 86 | |
| 87 | } |