Completed
Push — master ( cf76cc...aeebc0 )
by Jared
01:28
created

EventManager::reset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Pulsar;
4
5
use Symfony\Component\EventDispatcher\EventDispatcher;
6
7
/**
8
 * Manages the event bus for model lifecycle events.
9
 */
10
class EventManager
11
{
12
    /**
13
     * @var array
14
     */
15
    private static $dispatchers = [];
16
17
    /**
18
     * Gets the event dispatcher.
19
     */
20
    public static function getDispatcher(string $class): EventDispatcher
21
    {
22
        if (!isset(self::$dispatchers[$class])) {
23
            self::$dispatchers[$class] = new EventDispatcher();
24
        }
25
26
        return self::$dispatchers[$class];
27
    }
28
29
    /**
30
     * Resets the event dispatcher for a given class.
31
     */
32
    public static function reset(string $class): void
33
    {
34
        if (isset(self::$dispatchers[$class])) {
35
            unset(self::$dispatchers[$class]);
36
        }
37
    }
38
}
39