PHP code example of serginhold / phalcon-profiler

1. Go to this page and download the library: Download serginhold/phalcon-profiler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

serginhold / phalcon-profiler example snippets


use Phalcon\Di\DiInterface;
use Phalcon\Mvc\Application;
use SerginhoLD\Phalcon\WebProfiler\WebProfiler;

/** @var DiInterface $di */
if ('dev' === $env) {
    $di->register(new WebProfiler());
}

/** @var Application $application */
$application->setEventsManager($di->getShared('eventsManager'));

// ./config/config.php

return [
    'profiler' => [
        'viewsCachePath' => '/var/www/var/cache/volt/',
        'tagsDir' => '/var/www/var/profiler',
        'routePrefix' => '/_profiler',
        'collectors' => [
            /** @see \SerginhoLD\Phalcon\WebProfiler\Collector\CollectorInterface */
            CustomCollector::class,
        ],
    ],
];

$container->setShared('devLoggerAdapter', function () use ($container) {
    return $container->has('profilerLoggerAdapter')
        ? $container->getShared('profilerLoggerAdapter')
        : new \Phalcon\Logger\Adapter\Noop();
});

use Phalcon\Di\DiInterface;
use Phalcon\Di\ServiceProviderInterface;

class StopwatchProvider implements ServiceProviderInterface
{
    public function register(DiInterface $di): void
    {
        $di->setShared('stopwatch', function () use ($di) {
            return $di->has('profilerStopwatch') ? $di->getShared('profilerStopwatch') : null;
        });
    }
}

$di->get('stopwatch')?->start('test');
// ...
$di->get('stopwatch')?->stop('test');

use SerginhoLD\Phalcon\WebProfiler\Collector\CollectorInterface;

class CustomCollector implements CollectorInterface
{
    public function templatePath(): string
    {
        return '/var/www/templates/custom'; // .volt
    }

    public function name(): string
    {
        return 'Custom';
    }

    public function icon(): string
    {
        return '';
    }

    public function collect(): array
    {
        return [
            'message' => 'hello',
        ];
    }
}