Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
NamedEvent
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEvent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isPropagationStopped
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5/**
6 * This file is part of php-fast-forward/event-dispatcher.
7 *
8 * This source file is subject to the license bundled
9 * with this source code in the file LICENSE.
10 *
11 * @copyright Copyright (c) 2025-2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/event-dispatcher
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\EventDispatcher\Event;
20
21use Psr\EventDispatcher\StoppableEventInterface;
22
23/**
24 * Wrap an event object with an explicit dispatch name.
25 *
26 * The name defaults to the wrapped event class when no explicit identifier is provided.
27 */
28  class NamedEvent implements StoppableEventInterface
29{
30    /**
31     * Dispatch name associated with the wrapped event.
32     */
33    private string $name;
34
35    /**
36     * Create a named wrapper for the provided event.
37     *
38     * @param object $event original event instance
39     * @param string|null $name Explicit dispatch name. Defaults to the wrapped event class name.
40     */
41    public function __construct(
42        private object $event,
43        ?string $name = null
44    ) {
45        $this->name = $name ?? $this->event::class;
46    }
47
48    /**
49     * Get the dispatch name for the wrapped event.
50     *
51     * @return string event name used for listener lookup
52     */
53    public function getName(): string
54    {
55        return $this->name;
56    }
57
58    /**
59     * Get the original event instance.
60     *
61     * @return object wrapped event instance
62     */
63    public function getEvent(): object
64    {
65        return $this->event;
66    }
67
68    /**
69     * Determine whether propagation has been stopped for the wrapped event.
70     *
71     * @return bool whether the wrapped event stops propagation
72     */
73    public function isPropagationStopped(): bool
74    {
75        return $this->event instanceof StoppableEventInterface
76            && $this->event->isPropagationStopped();
77    }
78}