Skip to content

Instantly share code, notes, and snippets.

@dmitrydyomin
Created December 12, 2018 14:11
Show Gist options
  • Save dmitrydyomin/46c41461cf627a3be4e35698e3f7b8c7 to your computer and use it in GitHub Desktop.
Save dmitrydyomin/46c41461cf627a3be4e35698e3f7b8c7 to your computer and use it in GitHub Desktop.
PHP Zend 1 click to open debug trace file in VS Code for unhandled errors
<?php
function dd()
{
echo('<pre>');
call_user_func_array('var_dump', func_get_args());
exit();
}
require_once '../vendor/autoload.php';
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Define path to ZFE directory
defined('ZFE_PATH')
|| define('ZFE_PATH', realpath(APPLICATION_PATH . '/../vendor/zfbase/zfe/library/ZFE'));
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
if (APPLICATION_ENV === 'development') {
$url = $_SERVER['REQUEST_URI'];
if (substr($_SERVER['REQUEST_URI'], 0, 16) === '/debug-open-file') {
$params = [];
parse_str(parse_url($url, PHP_URL_QUERY), $params);
if (isset($params['filename']) && isset($params['line'])) {
shell_exec("code -g '{$params['filename']}:{$params['line']}'");
}
exit();
}
try {
$application->bootstrap()->run();
} catch (Error $e) {
echo('<h3>' . $e->getMessage() . '</h3>' . "\n");
foreach ($e->getTrace() as $t) {
$url = '/debug-open-file?' . http_build_query([
'filename' => $t['file'],
'line' => $t['line'],
]);
$name = '.' . mb_substr($t['file'], mb_strlen(realpath(APPLICATION_PATH . '/..'))) . ':' . $t['line'];
echo('<a style="line-height: 1.5;" target="debug-open" href="' . $url . '">' . $name . '</a>' . '<br />' . "\n");
}
echo('<iframe name="debug-open" style="opacity: 0;"></iframe>');
}
} else {
$application->bootstrap()->run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment