silexphp / Silex-WebProfiler

MIT License
210 stars 61 forks source link

Fixed dump profiling #121

Closed qkdreyer closed 6 years ago

qkdreyer commented 7 years ago

Configuring the DumpListener before subscribing to its events, allowing it to correctly capture dump function calls in the WebProfilerToolbar

fabpot commented 7 years ago

/cc @nicolas-grekas Can you validate this one please?

shamotj commented 7 years ago

I confirm this resolves my issue with debug tag in toolbar, and also it resolves #95

nicolas-grekas commented 7 years ago

But please check that this patch doesn't have any unwanted side effect on CLI apps.

macintoshplus commented 7 years ago

This PR fix the issue for me.

In console mode I use \Knp\Provider\ConsoleServiceProvider() and the \Silex\Provider\WebProfilerServiceProvider() is not loaded. In fact, the dump() function work fine.

You need other test for merge ?

alehaa commented 7 years ago

I can confirm this patch fixes the issue for plain Silex web applications.

alehaa commented 7 years ago

@nicolas-grekas I think I know what you've meant ... After applying the patch, there's a tiny bug (maybe you can fix it @qkdreyer? ;) ): dump() outputs the HTML twice outside of the application, e.g. placing a dump($app); after $app->run(); will print the application's data twice. Without this patch there won't be any output et all.

mrak1990 commented 6 years ago

@fabpot @nicolas-grekas Any news on this issue? This fix works for me. Call of Symfony\Component\Debug\Debug::enable(); hide the Debug panel in profiler. Minimal working examle (index.php in the root of fabpot/silex-skeleton):

<?php

use Silex\Application;
use Silex\Provider;
use Silex\Provider\WebProfilerServiceProvider;
use Symfony\Component\VarDumper\VarDumper;

require_once __DIR__.'/vendor/autoload.php';

//Symfony\Component\Debug\Debug::enable();

$app = new Application();
$app['debug'] = true;

$app->register(new Provider\HttpFragmentServiceProvider());
$app->register(new Provider\ServiceControllerServiceProvider());
$app->register(new Provider\AssetServiceProvider());
$app->register(new Provider\TwigServiceProvider());
$app->register(new Silex\Provider\VarDumperServiceProvider());
$app->register(new WebProfilerServiceProvider(), array(
    'profiler.cache_dir' => __DIR__.'/../var/cache/profiler',
));
$app['twig.path'] = array(__DIR__.'/templates');

$app->get('/', function () use ($app) {
    VarDumper::dump([1, 2, 3]);
    dump([1, '2', 'three']);

    return $app['twig']->render('index.html.twig', []);
});

$app->run();

Composer.json from fabpot/silex-skeleton with two new packages: symfony/var-dumper and symfony/debug-bundle

{
    "name": "fabpot/silex-skeleton",
    "description": "A pre-configured skeleton for the Silex microframework",
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "silex/silex": "~2.0",
        "silex/web-profiler": "^2.0",
        "symfony/asset": "~2.8|^3.0",
        "symfony/browser-kit": "~2.8|^3.0",
        "symfony/class-loader": "~2.8|^3.0",
        "symfony/config": "~2.8|^3.0",
        "symfony/console": "~2.8|^3.0",
        "symfony/css-selector": "~2.8|^3.0",
        "symfony/debug": "~2.8|^3.0",
        "symfony/finder": "~2.8|^3.0",
        "symfony/form": "~2.8|^3.0",
        "symfony/monolog-bridge": "~2.8|^3.0",
        "symfony/process": "~2.8|^3.0",
        "symfony/security": "~2.8|^3.0",
        "symfony/translation": "~2.8|^3.0",
        "symfony/twig-bridge": "~2.8|^3.0",
        "symfony/validator": "~2.8|^3.0",
        "symfony/var-dumper": "^3.4",
        "symfony/debug-bundle": "^3.4"
    },
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "extra": {
        "branch-alias": {
            "dev-master": "2.0.x-dev"
        }
    },
    "scripts": {
        "run": [
            "echo 'Started web server on http://localhost:8888'",
            "php -S localhost:8888 -t web"
        ]
    }
}
fabpot commented 6 years ago

Thank you @qkdreyer.