9
9
namespace Magento \Framework \Event \Invoker ;
10
10
11
11
use Magento \Framework \Event \Observer ;
12
+ use Psr \Log \LoggerInterface ;
13
+ use Magento \Framework \App \State ;
12
14
15
+ /**
16
+ * Default Invoker.
17
+ */
13
18
class InvokerDefault implements \Magento \Framework \Event \InvokerInterface
14
19
{
15
20
/**
@@ -22,20 +27,29 @@ class InvokerDefault implements \Magento\Framework\Event\InvokerInterface
22
27
/**
23
28
* Application state
24
29
*
25
- * @var \Magento\Framework\App\ State
30
+ * @var State
26
31
*/
27
32
protected $ _appState ;
28
33
34
+ /**
35
+ * @var LoggerInterface
36
+ */
37
+ private $ logger ;
38
+
29
39
/**
30
40
* @param \Magento\Framework\Event\ObserverFactory $observerFactory
31
- * @param \Magento\Framework\App\State $appState
41
+ * @param State $appState
42
+ * @param LoggerInterface $logger
32
43
*/
33
44
public function __construct (
34
45
\Magento \Framework \Event \ObserverFactory $ observerFactory ,
35
- \Magento \Framework \App \State $ appState
46
+ State $ appState ,
47
+ LoggerInterface $ logger = null
36
48
) {
37
49
$ this ->_observerFactory = $ observerFactory ;
38
50
$ this ->_appState = $ appState ;
51
+ $ this ->logger = $ logger ?: \Magento \Framework \App \ObjectManager::getInstance ()
52
+ ->get (LoggerInterface::class);
39
53
}
40
54
41
55
/**
@@ -61,6 +75,8 @@ public function dispatch(array $configuration, Observer $observer)
61
75
}
62
76
63
77
/**
78
+ * Execute Observer.
79
+ *
64
80
* @param \Magento\Framework\Event\ObserverInterface $object
65
81
* @param Observer $observer
66
82
* @return $this
@@ -70,14 +86,20 @@ protected function _callObserverMethod($object, $observer)
70
86
{
71
87
if ($ object instanceof \Magento \Framework \Event \ObserverInterface) {
72
88
$ object ->execute ($ observer );
73
- } elseif ($ this ->_appState ->getMode () == \ Magento \ Framework \ App \ State::MODE_DEVELOPER ) {
89
+ } elseif ($ this ->_appState ->getMode () == State::MODE_DEVELOPER ) {
74
90
throw new \LogicException (
75
91
sprintf (
76
92
'Observer "%s" must implement interface "%s" ' ,
77
93
get_class ($ object ),
78
94
\Magento \Framework \Event \ObserverInterface::class
79
95
)
80
96
);
97
+ } else {
98
+ $ this ->logger ->warning (sprintf (
99
+ 'Observer "%s" must implement interface "%s" ' ,
100
+ get_class ($ object ),
101
+ \Magento \Framework \Event \ObserverInterface::class
102
+ ));
81
103
}
82
104
return $ this ;
83
105
}
0 commit comments