forked from zend-patterns/ZRay-Extension-Magento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzray.php
65 lines (54 loc) · 2.16 KB
/
zray.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class Magento {
public function mageRunExit($context, &$storage){
$storage['observers'] = array();
$this->storeObservers($storage['observers']);
$storage['info'] = array('store' => Mage::app()->getStore(), 'website' => Mage::app()->getWebsite(), 'frontcontroller' => Mage::app()->getFrontController(), 'request' => Mage::app()->getRequest());
$storage['handles'] = Mage::app()->getLayout()->getUpdate()->getHandles();
}
public function appCallObserverMethod($context, & $storage){
$method = $context['functionArgs'][1];
$observerData = $context['functionArgs'][2]->getData();
$event = $observerData['event']->getName();
$object = get_class($context['functionArgs'][0]);
$storage['events'] = array('event' => $event, 'class' => $object, 'method' => $method);
}
/**
* @param array $storage
*/
private function storeObservers(& $storage) {
foreach (array('global', 'adminhtml', 'frontend') as $eventArea) {
$eventConfig = $this->getEventAreaEventConfigs($eventArea);
if (! ($eventConfig instanceof Mage_Core_Model_Config_Element)) {
continue;
}
$events = $eventConfig->children();
$this->processEventObservers($events, $eventArea, $storage);
}
}
/**
* @param string $eventArea
* @return Mage_Core_Model_Config_Element|null
*/
private function getEventAreaEventConfigs($eventArea) {
return Mage::app()->getConfig()->getNode(sprintf('%s/events', $eventArea));
}
private function processEventObservers($areaEvents, $eventArea, & $storage) {
foreach ($areaEvents as $eventName => $event) {
foreach ($event->observers->children() as $observerName => $observer) {
$observerData = array(
'area' => $eventArea,
'event' => $eventName,
'name' => $observerName,
'class' => Mage::app()->getConfig()->getModelClassName($observer->class),
'method' => (string)$observer->method
);
$storage[] = $observerData;
}
}
}
}
$zrayMagento = new Magento();
$zre = new ZRayExtension('magento');
$zre->traceFunction('Mage::run', function(){}, array($zrayMagento, 'mageRunExit'));
$zre->traceFunction('Mage_Core_Model_App::_callObserverMethod', function(){}, array($zrayMagento, 'appCallObserverMethod'));