Skip to content

Instantly share code, notes, and snippets.

@johnkary
Created January 4, 2015 21:51
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnkary/601b4071a4b923b22ac2 to your computer and use it in GitHub Desktop.
Save johnkary/601b4071a4b923b22ac2 to your computer and use it in GitHub Desktop.
Allow setting breakpoints in Symfony component code when step debugging with Xdebug. Disables cached/compiled files when step debugging. Thanks Joshua Thijssen <https://www.adayinthelifeof.nl/2014/12/31/debugging-symfony-components/> and Antonio J. García Lagar <http://aj.garcialagar.es/blog/debugging-symfony-with-xdebug-2/> for the inspiration.
<?php
use Symfony\Component\HttpFoundation\Request;
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);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
//header('HTTP/1.0 403 Forbidden');
//exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
// We don't want to use the cached/compiled framework files when step-debugging
// so we can set breakpoints in framework code
$enableCaching = !extension_loaded('xdebug') || (!isset($_REQUEST['XDEBUG_SESSION_START']) && !isset($_COOKIE['XDEBUG_SESSION']) && ini_get('xdebug.remote_autostart') == false);
if ($enableCaching) {
$loader = require_once __DIR__ . '/../app/bootstrap.php.cache';
} else {
require_once __DIR__ . '/../vendor/autoload.php';
}
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
if ($enableCaching) {
$kernel->loadClassCache();
}
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment