Skip to content

Instantly share code, notes, and snippets.

@sagikazarmark
Last active August 1, 2020 06:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagikazarmark/4b52811c96e0fe6225022e038c7ccb9a to your computer and use it in GitHub Desktop.
Save sagikazarmark/4b52811c96e0fe6225022e038c7ccb9a to your computer and use it in GitHub Desktop.
Symfony container graph
#!/usr/bin/env php
<?php
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
set_time_limit(0);
/**
* @var Composer\Autoload\ClassLoader $loader
*/
$loader = require __DIR__.'/../app/autoload.php';
final class HacKernel extends AppKernel
{
/**
* Recompiles the container without warming up the whole cache.
*
* Can be called upon docker container start to inject custom parameters.
*/
public function exposeContainer()
{
// Load class cache
if ($this->loadClassCache) {
$this->doLoadClassCache($this->loadClassCache[0], $this->loadClassCache[1]);
}
// Initialize bundles to be able to parse configurations
$this->initializeBundles();
return $this->buildContainer();
}
}
$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new HacKernel($env, $debug);
$container = $kernel->exposeContainer();
$container->compile();
$graphDumper = new \Symfony\Component\DependencyInjection\Dumper\GraphvizDumper($container);
echo $graphDumper->dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment