Last active
November 18, 2017 17:14
-
-
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.
This file contains hidden or 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
<?php | |
/** | |
* @file | |
* gvdump.php | |
* | |
* @author: Frédéric G. MARAND <[email protected]> | |
* | |
* @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(); |
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
run via:
Thanks! Awesome script!