Skip to content

Commit e3b993e

Browse files
committed
Merge pull request #18 from sandrokeil/develop
added events panel and improved query parameter detection
2 parents 046bfd3 + 58fee84 commit e3b993e

File tree

13 files changed

+332
-69
lines changed

13 files changed

+332
-69
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Z-Ray-Doctrine2 CHANGELOG
22

3-
## 1.2.0 TBA
3+
## 1.2.0 (2015-08-17)
4+
* [3](https://github.com/sandrokeil/Z-Ray-Doctrine2/issues/3): Added events panel with Doctrine 2 and Symfony Doctrine 2 Bridge events
5+
* Improved query parameter detection
46
* fixed wrong cache detection
57

68
## 1.1.0 (2015-07-27)
79

8-
* All entity mappings now displayed
10+
* [1](https://github.com/sandrokeil/Z-Ray-Doctrine2/issues/1): All entity mappings now displayed
911
* Added count of executed queries with cache info
1012
* Added parameters to queries
1113
* Added SQL transaction tracking
1214
* Added query syntax highlighting and expand text support (show more / show less)
1315
* Added query number
14-
* Added cache tab
16+
* [4](https://github.com/sandrokeil/Z-Ray-Doctrine2/issues/4): Added cache tab
1517

16-
## Version 1.0.0 (2015-05-07)
18+
## 1.0.0 (2015-05-07)
1719

1820
* Added entities tab
1921
* Added queries tab

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
> Displays information about your Doctrine 2 queries
66
7+
> Displays information about your Doctrine 2 events
8+
79
> Displays information about your Doctrine 2 caches
810
911
This is a plugin to add functionality to the Zend Server Z-Ray. It will result in additional tab(s) to be presented in the browser.
@@ -33,18 +35,34 @@ There are the following columns:
3335
### Tab Queries
3436
![Tab Doctrine 2 Queries](docs/img/tab_queries.png)
3537

36-
The `Queries` tab displays information about executed queries. There are the following columns:
38+
The `Queries` tab displays information about executed queries.
39+
There are the following columns:
3740

41+
* **#**: Query number
3842
* **Query**: The executed query with parameter
3943
* **Number**: The number of executions
4044
* **Cached**: The number of cached queries
4145

4246
Note: real queries are calculated as `Number - Cached`.
4347

48+
### Tab Events
49+
![Tab Doctrine 2 Queries](docs/img/tab_events.png)
50+
51+
The `Events` tab displays information about Doctrine 2 events with `Symfony\Bridge\Doctrine` support.
52+
There are the following columns:
53+
54+
* **Event**: The event name
55+
* **Number**: The Number of occurrences
56+
* **Listeners**: Listener classes
57+
4458
### Tab Cache
4559
![Tab Doctrine 2 Queries](docs/img/tab_cache.png)
4660

47-
The `Cache` tab displays information about Doctrine 2 caches.
61+
The `Cache` tab displays information about Doctrine 2 caches and which cache driver is used.
62+
There are the following columns:
63+
64+
* **Type**: The cache type
65+
* **Status**: Which cache driver is used
4866

4967
## More Info
5068
Want to extend the Doctrine 2 Z-Ray extension? Looking for more information on Z-Ray? Try these links:

README.txt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
The Doctrine 2 plugin for Zend Server Z-Ray provides various information about the usage of Doctrine 2 in your application. Get a deeper look how entities and entity mappings, queries with parameter and caches are used.
2-
1+
The Doctrine 2 plugin for Zend Server Z-Ray provides various information about the usage of Doctrine 2 in your
2+
application. Get a deeper look how entities and entity mappings, queries with parameter, events and caches are used.
33

44
## Tab Entities
5-
The `Entities` tab displays information about used entities of the current page and entity mappings. There are the following columns:
5+
The `Entities` tab displays information about used entities of the current page and entity mappings.
6+
There are the following columns:
67

78
* **Entity**: FCQN of the entity class
89
* **Number Of Unique Entities**: How many unique objects of this entity exist
910
* **Number Of Referenced Entities**: How many references exist for this entity
1011

1112

1213
## Tab Queries
13-
The `Queries` tab displays information about executed queries. There are the following columns:
14+
The `Queries` tab displays information about executed queries.
15+
There are the following columns:
1416

17+
* **#**: Query number
1518
* **Query**: The executed query with parameter
1619
* **Number**: The number of executions
1720
* **Cached**: The number of cached queries
1821

1922
Note: real queries are calculated as `Number - Cached`.
2023

24+
### Tab Events
25+
The `Events` tab displays information about Doctrine 2 events with `Symfony\Bridge\Doctrine` support.
26+
There are the following columns:
27+
28+
* **Event**: The event name
29+
* **Number**: The Number of occurrences
30+
* **Listeners**: Listener classes
31+
32+
### Tab Cache
33+
The `Cache` tab displays information about Doctrine 2 caches and which cache driver is used.
34+
There are the following columns:
2135

22-
## Tab Cache
23-
The `Cache` tab displays information about Doctrine 2 caches.
36+
* **Type**: The cache type
37+
* **Status**: Which cache driver is used

deployment.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name" : "doctrine2",
44
"display_name" : "Doctrine 2",
5-
"version" : "1.1.0",
5+
"version" : "1.2.0",
66
"type": ["zray"],
77
"logo": "docs/img/doctrine.png",
88
"eula": "LICENSE.txt",

docs/img/plugin_gallery.png

131 KB
Loading

docs/img/tab_cache.png

-1.91 KB
Loading

docs/img/tab_events.png

93.1 KB
Loading

zray/DoctrineOrm.php

Lines changed: 143 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
*/
2323
class DoctrineOrm
2424
{
25-
const INDEX_ENTITIES_UNIQUE = 'unique_entities';
26-
const INDEX_ENTITIES_REFERENCE = 'referenced_entities';
27-
2825
/**
2926
* Entities
3027
*
@@ -46,13 +43,6 @@ class DoctrineOrm
4643
*/
4744
protected $queryNumber = 0;
4845

49-
/**
50-
* Last query to set parameters from persister
51-
*
52-
* @var string
53-
*/
54-
protected $lastQuery = '';
55-
5646
/**
5747
* Cache settings
5848
*/
@@ -79,6 +69,11 @@ class DoctrineOrm
7969
],
8070
];
8171

72+
/**
73+
* Events
74+
*/
75+
protected $events = [];
76+
8277
/**
8378
* Collects queries from \Doctrine\ORM\Persisters\Entity\BasicEntityPersister
8479
*
@@ -172,36 +167,6 @@ public function cache($context, &$storage)
172167
}
173168
}
174169

175-
/**
176-
* Collects queries from \Doctrine\ORM\Persisters\Entity\BasicEntityPersister
177-
*
178-
* @param array $context
179-
* @param array $storage
180-
*/
181-
public function persister($context, &$storage)
182-
{
183-
// dont break z-ray
184-
if (empty($context['functionArgs'][0])
185-
|| !$this->lastQuery
186-
|| empty($context['returnValue'])
187-
) {
188-
$this->lastQuery = '';
189-
return;
190-
}
191-
192-
$params = [];
193-
194-
foreach ($context['returnValue'] as &$values) {
195-
$params += $values;
196-
}
197-
198-
$this->queries[$this->lastQuery]['query'] = $this->formatQuery(
199-
$this->queries[$this->lastQuery]['query'],
200-
$params
201-
);
202-
$this->lastQuery = '';
203-
}
204-
205170
/**
206171
* Collects all queries from Doctrine\DBAL\Connection
207172
*
@@ -264,6 +229,9 @@ public function statement($context, &$storage)
264229
return;
265230
}
266231

232+
$query = '';
233+
$queryId = '';
234+
267235
switch ($context['functionName']) {
268236
case 'Doctrine\DBAL\Connection::beginTransaction':
269237
$query = 'Begin Transaction';
@@ -280,15 +248,45 @@ public function statement($context, &$storage)
280248
$this->queryNumber++;
281249
$queryId = $query . $this->queryNumber;
282250
break;
283-
case 'Doctrine\DBAL\Statement::__construct':
251+
case 'Doctrine\DBAL\Statement::execute':
252+
$reflection = new \ReflectionObject($context['this']);
253+
254+
if (!$reflection->hasProperty('params')
255+
|| !$reflection->hasProperty('types')
256+
|| !$reflection->hasProperty('sql')
257+
) {
258+
break;
259+
}
260+
261+
if (empty($context['functionArgs'][0])) {
262+
$params = $reflection->getProperty('params');
263+
$params->setAccessible(true);
264+
$params = $params->getValue($context['this']);
265+
} else {
266+
$params = $context['functionArgs'][0];
267+
}
268+
269+
$types = $reflection->getProperty('types');
270+
$types->setAccessible(true);
271+
$types = $types->getValue($context['this']);
272+
273+
$query = $reflection->getProperty('sql');
274+
$query->setAccessible(true);
275+
$query = $query->getValue($context['this']);
276+
277+
# doctrine does it right
278+
list($queryWithParams, $params, $types) = \Doctrine\DBAL\SQLParserUtils::expandListParameters(
279+
$query,
280+
$params,
281+
$types
282+
);
283+
284+
$query = $this->formatQuery($queryWithParams, $params);
284285
$this->queryNumber++;
285-
$query = isset($context['locals']['sql']) ? $context['locals']['sql'] : 'NO QUERY';
286286
$queryId = $query . $this->queryNumber;
287-
$this->lastQuery = $this->getQueryId($queryId);
288287
break;
289288
default:
290-
$query = '';
291-
$queryId = '';
289+
// nothing to do
292290
break;
293291
}
294292

@@ -365,6 +363,74 @@ public function entityMapping($context, &$storage)
365363
}
366364
}
367365

366+
/**
367+
* Collects events from Doctrine EventManager
368+
*
369+
* @param array $context
370+
* @param array $storage
371+
*/
372+
public function eventManagerDispatch($context, &$storage)
373+
{
374+
// dont break z-ray
375+
if (empty($context['functionArgs'][0])) {
376+
return;
377+
}
378+
379+
$eventName = $context['functionArgs'][0];
380+
381+
if (empty($this->events[$eventName])) {
382+
$this->events[$eventName] = [
383+
'name' => $eventName,
384+
'number' => 0,
385+
'listeners' => [],
386+
];
387+
}
388+
389+
$this->events[$eventName]['number']++;
390+
391+
if (empty($context['locals']['listener'])) {
392+
return;
393+
}
394+
$listener = get_class($context['locals']['listener']);
395+
$this->events[$eventName]['listeners'][$listener] = true;
396+
}
397+
398+
/**
399+
* Collects listener from Doctrine EventManager
400+
*
401+
* @param array $context
402+
* @param array $storage
403+
*/
404+
public function eventManagerAddListener($context, &$storage)
405+
{
406+
// dont break z-ray
407+
if (empty($context['functionArgs'][0])
408+
|| empty($context['functionArgs'][1])
409+
) {
410+
return;
411+
}
412+
413+
$events = (array) $context['functionArgs'][0];
414+
415+
$listener = $context['functionArgs'][1];
416+
417+
if (is_object($listener)) {
418+
$listener = get_class($listener);
419+
}
420+
421+
foreach ($events as $event) {
422+
if (empty($this->events[$event])) {
423+
$this->events[$event] = [
424+
'name' => $event,
425+
'number' => 0,
426+
'listeners' => [$listener => true],
427+
];
428+
} else {
429+
$this->events[$event]['listeners'][$listener] = true;
430+
}
431+
}
432+
}
433+
368434
/**
369435
* Collects all data from other functions to display information in Z-Ray
370436
*
@@ -398,6 +464,38 @@ public function collectAllData($context, &$storage)
398464

399465
// collect cache
400466
$storage['cache'] = $this->cache;
467+
468+
$events = [
469+
'onClear',
470+
'onFlush',
471+
'postFlush',
472+
'postLoad',
473+
'postPersist',
474+
'postRemove',
475+
'postUpdate',
476+
'preFlush',
477+
'prePersist',
478+
'preRemove',
479+
'preUpdate',
480+
'loadClassMetadata',
481+
'onClassMetadataNotFound',
482+
];
483+
484+
foreach ($events as $event) {
485+
$storage['events'][$event] = [
486+
'name' => $event,
487+
'number' => 0,
488+
'listeners' => '',
489+
];
490+
}
491+
492+
foreach ($this->events as $event => $data) {
493+
$storage['events'][$event] = [
494+
'name' => $data['name'],
495+
'number' => $data['number'],
496+
'listeners' => implode("\n", array_keys($data['listeners'])),
497+
];
498+
}
401499
}
402500

403501
/**

zray/Module.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function config()
2424
'defaultPanels' => array(
2525
'queries' => true,
2626
'entities' => true,
27+
'cache' => true,
28+
'events' => true,
2729
),
2830
'panels' => array(
2931
'cache' => array(
@@ -34,6 +36,14 @@ public function config()
3436
'searchId' => 'doctrine-cache-search',
3537
'pagerId' => 'doctrine-cache-pager',
3638
),
39+
'events' => array(
40+
'display' => true,
41+
'logo' => 'logo.png',
42+
'menuTitle' => 'Events',
43+
'panelTitle' => 'Doctrine 2 Events',
44+
'searchId' => 'doctrine-events-search',
45+
'pagerId' => 'doctrine-events-pager',
46+
),
3747
'entities' => array(
3848
'display' => true,
3949
'logo' => 'logo.png',

0 commit comments

Comments
 (0)