Skip to content

Instantly share code, notes, and snippets.

@fgm
Last active November 18, 2017 17:14
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fgm/9326598 to your computer and use it in GitHub Desktop.
Save fgm/9326598 to your computer and use it in GitHub Desktop.
Demonstrate how to use the GraphViz Dumper in a Symfony 2.4 project.
<?php
/**
* @file
* gvdump.php
*
* @author: Frédéric G. MARAND <fgm@osinet.fr>
*
* @copyright (c) 2014 Ouest Systèmes Informatiques (OSInet).
*
* @license MIT
*/
$loader = require_once __DIR__ . '/bootstrap.php.cache';
require_once __DIR__ . '/AppKernel.php';
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\DependencyInjection\Dumper\GraphvizDumper;
class DumperKernel extends \AppKernel {
/**
* Initializes the service container.
*/
protected function initializeContainer() {
$container = $this->buildContainer();
$container->compile();
return $container;
}
public function dump() {
$this->initializeBundles();
$container = $this->initializeContainer();
$dumper = new GraphvizDumper($container);
$content = $dumper->dump(array(
'graph' => array(
'rankdir' => 'RL',
),
));
if (!$this->debug) {
$content = static::stripComments($content);
}
echo $content;
}
}
$kernel = new DumperKernel('dev', true);
$kernel->dump();
@lakhman
Copy link

lakhman commented Nov 24, 2015

run via:

php gvdump.php > graph.dot
dot -Tpng graph.dot > output.png

Thanks! Awesome script!

@gquemener
Copy link

Just passing by,

I've come up with a shorter version:

<?php
# ./bin/dump-container.php
use Symfony\Component\DependencyInjection\Dumper\GraphvizDumper;

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

$kernel = new AppKernel('dev', true);
$getContainer = function() {
    $this->initializeBundles();
    $container = $this->buildContainer();
    $container->compile();

    return $container;
};
$container = $getContainer->call($kernel);
$dumper = new GraphvizDumper($container);

echo $dumper->dump([
    'graph' => [
        'rankdir' => 'RL',
    ]
]);

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment