Skip to content

Instantly share code, notes, and snippets.

@hissy

hissy/app.php

Last active Sep 28, 2020
Embed
What would you like to do?
#concrete5 Visualize rendering time of each blocks with DebugBar
<?php
/**
* First, install the debug bar package. @link: https://github.com/concrete5cojp/concrete5_debugbar
* Then, add these code in your application/bootstrap/app.php
*/
if ($app->isInstalled()) {
$director = $app->make(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class);
$debugBar = $app->make(\Concrete\Core\Package\PackageService::class)->getByHandle('concrete5_debugbar');
if (is_object($debugBar) && $debugBar->isPackageInstalled()) {
$director->addListener('on_block_load', static function ($event) use ($app) {
$bID = $event->getArgument('bID');
$btHandle = $event->getArgument('btHandle');
$app->make('debugbar/time')->startMeasure(sprintf('block_%d', $bID), sprintf('Rendering %s block (bID: %d)', $btHandle, $bID));
});
$director->addListener('on_block_output', static function ($event) use ($app) {
/** @var \Concrete\Core\Block\Block $b */
$b = $event->getBlock();
$bID = $b->getBlockID();
$app->make('debugbar/time')->stopMeasure(sprintf('block_%d', $bID), [
'arHandle' => $b->getAreaHandle(),
'cacheBlockOutput' => $b->cacheBlockOutput(),
]);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment