-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdebugpdoparser.class.php
More file actions
89 lines (71 loc) · 2.51 KB
/
debugpdoparser.class.php
File metadata and controls
89 lines (71 loc) · 2.51 KB
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
<?php
class debugPdoParser extends pdoParser {
public $tags = array();
public $from_cache = false;
/** @var debugParser $parser */
protected $parser = null;
function __construct(xPDO &$modx) {
parent::__construct($modx);
if (!class_exists('debugParser')) {
require dirname(__FILE__) . '/debugparser.class.php';
}
$this->parser = new debugParser($modx);
}
/** {inheritDoc} */
public function processElementTags($parentTag, & $content, $processUncacheable = false, $removeUnprocessed = false, $prefix = "[[", $suffix = "]]", $tokens = array(), $depth = 0) {
$work = is_string($content) && empty($parentTag) && $processUncacheable && preg_match('#\{(\$|\/|\w+\s)#', $content)
&& !empty($this->pdoTools->config['useFenomParser']) && !empty($this->pdoTools->config['useFenom']);
$tag = htmlentities(trim($content), ENT_QUOTES, 'UTF-8');
$hash = sha1($tag);
$parse_time_start = microtime(true);
$query_time_start = $this->modx->queryTime;
$queries_start = $this->modx->executedQueries;
$result = parent::processElementTags($parentTag, $content, $processUncacheable, $removeUnprocessed, $prefix, $suffix, $tokens, $depth);
if ($work) {
$parse_time = number_format(round(microtime(true) - $parse_time_start, 7), 7);
$query_time = number_format(round($this->modx->queryTime - $query_time_start, 7), 7);
$queries = $this->modx->executedQueries - $queries_start;
if (isset($this->tags[$hash])) {
$this->tags[$hash]['attempts']++;
$this->tags[$hash]['queries'] += $queries;
$this->tags[$hash]['queries_time'] += $query_time;
$this->tags[$hash]['parse_time'] += $parse_time;
}
else {
$this->tags[$hash] = array(
'tag' => $tag,
'attempts' => 1,
'queries' => $queries,
'queries_time' => $query_time,
'parse_time' => $parse_time,
);
}
}
return $result;
}
/** {inheritDoc} */
public function processTag($tag, $processUncacheable = true) {
return $this->parser->processTag($tag, $processUncacheable);
}
/**
* Generates table with report
*/
public function generateReport() {
$this->parser->tags = array_merge($this->parser->tags, $this->tags);
$this->parser->from_cache = $this->from_cache;
return $this->parser->generateReport();
}
/**
* Clearing cache of the resource
*
* @param string $context Key of context for clearing
*
* @return void
*/
public function clearCache($context = null) {
$this->parser->clearCache($context);
}
public function addNFElement($class, $name) {
$this->parser->addNFElement($class, $name);
}
}