forked from fengruzhuo/debug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
executable file
·107 lines (95 loc) · 3.49 KB
/
Module.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace YcheukfDebug;
use YcheukfDebug\Model\Debug;
use Zend\Mvc\MvcEvent;
use Zend\ModuleManager\ModuleManagerInterface;
class Module
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function setAttach($sm, $em){
$em->attach(
array('YcheukfDebugSetProfiler'),
function($e) use($sm) {
$oDbAdapter = $sm->get('ycheukf_debug_db_adapter');
//add profiler to adapter
$oProfiler = new \YcheukfDebug\Model\Profiler;
$oProfiler->setConnectionParameters($oDbAdapter->getDriver()->getConnection()->getConnectionParameters());
$oDbAdapter->setProfiler($oProfiler);
if(get_class($oDbAdapter) == 'BjyProfiler\Db\Adapter\ProfilingAdapter')//Compatible with BjyProfiler\Db\Adapter\ProfilingAdapter
$oDbAdapter->injectProfilingStatementPrototype();
//add profiler to slaver adapter if exist
if(method_exists($oDbAdapter, 'getSlaveAdapter')){
$oProfiler = new \YcheukfDebug\Model\Profiler;
$oProfiler->setConnectionParameters($oDbAdapter->getSlaveAdapter()->getDriver()->getConnection()->getConnectionParameters());
$oDbAdapter->getSlaveAdapter()->setProfiler($oProfiler);
if(get_class($oDbAdapter->getSlaveAdapter()) == 'BjyProfiler\Db\Adapter\ProfilingAdapter')//Compatible with BjyProfiler\Db\Adapter\ProfilingAdapter
$oDbAdapter->getSlaveAdapter()->injectProfilingStatementPrototype();
}
},
-100
);
/**
* use the below code to add profiler when using master-slaver adatper
$em->clearListeners('YcheukfDebugSetProfiler');
$em->attach(
array('YcheukfDebugSetProfiler'),
function($e) {
//set profiler code
},
100
);
*/
}
public function onBootstrap(MvcEvent $event){
if (PHP_SAPI === 'cli') return;
$app = $event->getApplication();
$em = $app->getEventManager();
$sm = $app->getServiceManager();
\YcheukfDebug\Model\Debug::setEventManager($em);
\YcheukfDebug\Model\Debug::setServiceManager($sm);
if (PHP_SAPI === 'cli'){
\YcheukfDebug\Model\Debug::dump($sm->get('console'), '[inline]---[request]---console start', array('datatag'=>'xmp'), 'w');
return;
}
// $aConfig = $this->getConfig();
$aConfig = $sm->get('config');
if(isset($aConfig['debugconfig']['ignore_request'])){
foreach($aConfig['debugconfig']['ignore_request'] as $sRule){
if(is_string($_SERVER['REQUEST_URI']) &&
preg_match("/.*".str_replace("/", "\/", $sRule).".*/i", $_SERVER['REQUEST_URI'])
){
return ;
}
}
}
if(is_string($_SERVER['REQUEST_URI']) && (//ignore some request
preg_match("/.*".str_replace("/", "\/", $aConfig['router']['routes']['debug']['options']['route']).".*/i", $_SERVER['REQUEST_URI'])
)
){
return true;
}
$this->setAttach($sm, $em);
$em->trigger('YcheukfDebugSetProfiler', $this);
if($sm->get('request')->isXmlHttpRequest() == false){
\YcheukfDebug\Model\Debug::dump($_SERVER, '[inline]---[request http]---'.$sm->get('request')->getRequestUri(), array('datatag'=>'xmp'), 'w');
}else
\YcheukfDebug\Model\Debug::dump($_REQUEST, '[inline]---[request ajax]---'.$sm->get('request')->getRequestUri());
}
public function init(ModuleManagerInterface $manager)
{
if (PHP_SAPI === 'cli') return;
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/Debug',
),
),
);
}
}