forked from ezsystems/ezpublish-kernel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ezsystems#1129 from ezsystems/fix_EZP-23864_fixLeg…
…acyDebugBundle Fix EZP-23864: Fix coupling with legacy in debug bundle
- Loading branch information
Showing
21 changed files
with
765 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# eZ data collectors | ||
|
||
Symfony profiler let any bundle register *data collectors* and displayed collected data in the web profiler toolbar | ||
and debug panel. eZ has its own data collector. | ||
|
||
## Extensibility | ||
As of v6.0, it is possible to display custom collected data under eZ toolbar / panel. | ||
The main data collector has been splitted into several dedicated ones and now only aggregates data collected by | ||
registered sub-collectors. | ||
|
||
## Native data collectors | ||
Following data collectors are part of `EzPublishDebugBundle`: | ||
|
||
* `PersistenceCacheCollector`: Collects information on persistence cache (aka SPI cache) efficiency (hits/miss). | ||
* `TemplatesDataCollector`: Collects information on loaded templates. | ||
|
||
## Custom data collector | ||
For data to appear under eZ toolbar / panel, it is only needed to write a service implementing | ||
`Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface`, or simply extending `Symfony\Component\HttpKernel\DataCollector\DataCollector`. | ||
|
||
This service, instead of being tagged as `data_collector`, needs to be tagged as `ezpublish_data_collector`. | ||
This service tag takes 2 additional arguments indicating which template(s) to use for displaying collected data in the | ||
toolbar and/or panel. Those templates will be *included* by the main eZ data collector, exposing your collector object, | ||
like for any regular data collector. | ||
|
||
### Example | ||
```yml | ||
parameters: | ||
ezpublish_debug.persistence_collector.class: eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector | ||
ezpublish_debug.templates_collector.class: eZ\Bundle\EzPublishDebugBundle\Collector\TemplatesDataCollector | ||
|
||
services: | ||
ezpublish_debug.persistence_collector: | ||
class: %ezpublish_debug.persistence_collector.class% | ||
arguments: [@ezpublish.spi.persistence.cache.persistenceLogger] | ||
tags: | ||
- | ||
name: ezpublish_data_collector | ||
id: "ezpublish.debug.persistence" | ||
panelTemplate: "EzPublishDebugBundle:Profiler/persistence:panel.html.twig" | ||
toolbarTemplate: "EzPublishDebugBundle:Profiler/persistence:toolbar.html.twig" | ||
|
||
ezpublish_debug.templates_collector: | ||
class: %ezpublish_debug.templates_collector.class% | ||
tags: | ||
- | ||
name: ezpublish_data_collector | ||
panelTemplate: "EzPublishDebugBundle:Profiler/templates:panel.html.twig" | ||
toolbarTemplate: "EzPublishDebugBundle:Profiler/templates:toolbar.html.twig" | ||
|
||
``` | ||
|
||
For further example, refer to [`PersistenceCacheCollector`](https://github.com/ezsystems/ezpublish-kernel/blob/master/eZ/Bundle/EzPublishDebugBundle/Collector/PersistenceCacheCollector.php) | ||
or [`TemplatesDataCollector`](https://github.com/ezsystems/ezpublish-kernel/blob/master/eZ/Bundle/EzPublishDebugBundle/Collector/TemplatesDataCollector.php) implementation. |
112 changes: 112 additions & 0 deletions
112
eZ/Bundle/EzPublishDebugBundle/Collector/EzPublishCoreCollector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/** | ||
* File containing the EzPublishDataCollector class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @version //autogentag// | ||
*/ | ||
|
||
namespace eZ\Bundle\EzPublishDebugBundle\Collector; | ||
|
||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use InvalidArgumentException; | ||
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; | ||
|
||
class EzPublishCoreCollector extends DataCollector | ||
{ | ||
public function __construct() | ||
{ | ||
$this->data = [ | ||
'collectors' => [], | ||
'panelTemplates' => [], | ||
'toolbarTemplates' => [] | ||
]; | ||
} | ||
|
||
public function collect( Request $request, Response $response, \Exception $exception = null ) | ||
{ | ||
/** @var DataCollectorInterface $innerCollector */ | ||
foreach ( $this->data['collectors'] as $innerCollector ) | ||
{ | ||
$innerCollector->collect( $request, $response, $exception ); | ||
} | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'ezpublish.debug.toolbar'; | ||
} | ||
|
||
/** | ||
* @param DataCollectorInterface $collector | ||
*/ | ||
public function addCollector( DataCollectorInterface $collector, $panelTemplate = null, $toolbarTemplate = null ) | ||
{ | ||
$name = $collector->getName(); | ||
$this->data['collectors'][$name] = $collector; | ||
$this->data['panelTemplates'][$name] = $panelTemplate; | ||
$this->data['toolbarTemplates'][$name] = $toolbarTemplate; | ||
} | ||
|
||
/** | ||
* @param string $name Name of the collector | ||
* | ||
* @return DataCollectorInterface | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function getCollector( $name ) | ||
{ | ||
if ( !isset( $this->data['collectors'][$name] ) ) | ||
{ | ||
throw new InvalidArgumentException( "Invalid debug collector '$name'" ); | ||
} | ||
|
||
return $this->data['collectors'][$name]; | ||
} | ||
|
||
/** | ||
* @return DataCollectorInterface[] | ||
*/ | ||
public function getAllCollectors() | ||
{ | ||
return $this->data['collectors']; | ||
} | ||
|
||
/** | ||
* Returns toolbar template for given collector name. | ||
* | ||
* @param string $collectorName Name of corresponding collector. | ||
* | ||
* @return string | ||
*/ | ||
public function getToolbarTemplate( $collectorName ) | ||
{ | ||
if ( !isset( $this->data['toolbarTemplates'][$collectorName] ) ) | ||
{ | ||
return null; | ||
} | ||
|
||
return $this->data['toolbarTemplates'][$collectorName]; | ||
} | ||
|
||
/** | ||
* Returns panel template to use for given collector name. | ||
* | ||
* @param string $collectorName Name of corresponding collector. | ||
* | ||
* @return string | ||
*/ | ||
public function getPanelTemplate( $collectorName ) | ||
{ | ||
if ( !isset( $this->data['panelTemplates'][$collectorName] ) ) | ||
{ | ||
return null; | ||
} | ||
|
||
return $this->data['panelTemplates'][$collectorName]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.