|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Faulancer\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Faulancer\Service\Config; |
|
6
|
|
|
use Faulancer\ServiceLocator\ServiceLocator; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Observer |
|
10
|
|
|
* @package Faulancer\Event |
|
11
|
|
|
* @author Florian Knapp <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Observer |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** @var self */ |
|
17
|
|
|
protected static $instance; |
|
18
|
|
|
|
|
19
|
|
|
/** @var AbstractListener[] */ |
|
20
|
|
|
protected static $listener = []; |
|
21
|
|
|
|
|
22
|
|
|
/** @var bool */ |
|
23
|
|
|
protected static $missingConfig = false; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Observer constructor (private). |
|
27
|
|
|
*/ |
|
28
|
|
|
private function __construct() {} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Yeah... singleton... i know |
|
32
|
|
|
* |
|
33
|
|
|
* @return self |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function instance() |
|
36
|
|
|
{ |
|
37
|
|
|
if (!self::$instance) { |
|
38
|
|
|
|
|
39
|
|
|
/** @var Config $config */ |
|
40
|
|
|
$config = ServiceLocator::instance()->get(Config::class); |
|
41
|
|
|
self::$listener = $config->get('eventListener'); |
|
|
|
|
|
|
42
|
|
|
self::$instance = new self(); |
|
43
|
|
|
|
|
44
|
|
|
if (!self::$listener) { |
|
45
|
|
|
self::$missingConfig = true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return self::$instance; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Trigger listeners if registered for the type |
|
55
|
|
|
* |
|
56
|
|
|
* @param AbstractEvent $event |
|
57
|
|
|
* |
|
58
|
|
|
* @return bool |
|
59
|
|
|
*/ |
|
60
|
|
|
public function trigger(AbstractEvent $event) |
|
61
|
|
|
{ |
|
62
|
|
|
if (self::$missingConfig) { |
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
foreach (self::$listener as $typeName => $listenerList) { |
|
67
|
|
|
|
|
68
|
|
|
/** @var AbstractListener[] $listenerList */ |
|
69
|
|
|
foreach ($listenerList as $listener) { |
|
70
|
|
|
|
|
71
|
|
|
if ($typeName === $event::NAME) { |
|
72
|
|
|
|
|
73
|
|
|
if (!class_exists($listener)) { |
|
74
|
|
|
continue; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** @var AbstractListener $listener */ |
|
78
|
|
|
$listener = new $listener(); |
|
79
|
|
|
$listener->create(); |
|
80
|
|
|
$callback = $listener->getCallback(); |
|
81
|
|
|
$callback->execute($event); |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return true; |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..