|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Onoi\EventDispatcher; |
|
4
|
|
|
|
|
5
|
|
|
use Onoi\EventDispatcher\Dispatcher\GenericEventDispatcher; |
|
6
|
|
|
use Onoi\EventDispatcher\Listener\NullEventListener; |
|
7
|
|
|
use Onoi\EventDispatcher\Listener\GenericCallbackEventListener; |
|
8
|
|
|
use Onoi\EventDispatcher\Listener\GenericEventListenerCollection; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @license GNU GPL v2+ |
|
12
|
|
|
* @since 1.0 |
|
13
|
|
|
* |
|
14
|
|
|
* @author mwjames |
|
15
|
|
|
*/ |
|
16
|
|
|
class EventDispatcherFactory { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var EventDispatcherFactory |
|
20
|
|
|
*/ |
|
21
|
|
|
private static $instance = null; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @since 1.0 |
|
25
|
|
|
* |
|
26
|
|
|
* @return EventDispatcherFactory |
|
27
|
|
|
*/ |
|
28
|
1 |
|
public static function getInstance() { |
|
29
|
|
|
|
|
30
|
1 |
|
if ( self::$instance === null ) { |
|
31
|
1 |
|
self::$instance = new self(); |
|
32
|
1 |
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
return self::$instance; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @since 1.0 |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public static function clear() { |
|
41
|
1 |
|
self::$instance = null; |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @since 1.0 |
|
46
|
|
|
* |
|
47
|
|
|
* @return GenericEventDispatcher |
|
48
|
|
|
*/ |
|
49
|
4 |
|
public function newGenericEventDispatcher() { |
|
50
|
4 |
|
return new GenericEventDispatcher(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @since 1.0 |
|
55
|
|
|
* |
|
56
|
|
|
* @return DispatchContext |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function newDispatchContext() { |
|
59
|
1 |
|
return new DispatchContext(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @since 1.0 |
|
64
|
|
|
* |
|
65
|
|
|
* @return NullEventListener |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function newNullEventListener() { |
|
68
|
1 |
|
return new NullEventListener(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @since 1.0 |
|
73
|
|
|
* |
|
74
|
|
|
* @return GenericCallbackEventListener |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function newGenericCallbackEventListener() { |
|
77
|
1 |
|
return new GenericCallbackEventListener(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @since 1.0 |
|
82
|
|
|
* |
|
83
|
|
|
* @return GenericEventListenerCollection |
|
84
|
|
|
*/ |
|
85
|
3 |
|
public function newGenericEventListenerCollection() { |
|
86
|
3 |
|
return new GenericEventListenerCollection(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|