diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index df8b0501a7..ef24fe8f69 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -143,6 +143,15 @@ class CodeHelper extends Helper public function fileExcerpt($file, $line) { if (is_readable($file)) { + if (extension_loaded('fileinfo')) { + $finfo = new \Finfo(); + + // Check if the file is an application/octet-stream (eg. Phar file) because hightlight_file cannot parse these files + if ('application/octet-stream' === $finfo->file($file, FILEINFO_MIME_TYPE)) { + return; + } + } + $code = highlight_file($file, true); // remove main code/span tags $code = preg_replace('#^\s*(.*)\s*#s', '\\1', $code);