[WebProfiler] Detect empty file paths in file viewer
This commit is contained in:
parent
511b070ed6
commit
71aade3622
@ -134,7 +134,7 @@ class CodeExtension extends AbstractExtension
|
|||||||
*/
|
*/
|
||||||
public function fileExcerpt($file, $line, $srcContext = 3)
|
public function fileExcerpt($file, $line, $srcContext = 3)
|
||||||
{
|
{
|
||||||
if (is_readable($file)) {
|
if (is_file($file) && is_readable($file)) {
|
||||||
// highlight_file could throw warnings
|
// highlight_file could throw warnings
|
||||||
// see https://bugs.php.net/bug.php?id=25725
|
// see https://bugs.php.net/bug.php?id=25725
|
||||||
$code = @highlight_file($file, true);
|
$code = @highlight_file($file, true);
|
||||||
@ -157,6 +157,8 @@ class CodeExtension extends AbstractExtension
|
|||||||
|
|
||||||
return '<ol start="'.max($line - $srcContext, 1).'">'.implode("\n", $lines).'</ol>';
|
return '<ol start="'.max($line - $srcContext, 1).'">'.implode("\n", $lines).'</ol>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +54,11 @@ a.doc:hover {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.empty {
|
||||||
|
padding: 10px;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
.source {
|
.source {
|
||||||
margin-top: 41px;
|
margin-top: 41px;
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,16 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="header">
|
{% set source = filename|file_excerpt(line, -1) %}
|
||||||
|
<div class="header">
|
||||||
<h1>{{ file }}{% if 0 < line %} <small>line {{ line }}</small>{% endif %}</h1>
|
<h1>{{ file }}{% if 0 < line %} <small>line {{ line }}</small>{% endif %}</h1>
|
||||||
<a class="doc" href="https://symfony.com/doc/{{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}/reference/configuration/framework.html#ide" rel="help">Open in your IDE?</a>
|
<a class="doc" href="https://symfony.com/doc/{{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}/reference/configuration/framework.html#ide" rel="help">Open in your IDE?</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="source">
|
<div class="source">
|
||||||
{{ filename|file_excerpt(line, -1) }}
|
{% if source is null %}
|
||||||
</div>
|
<p class="empty">The file is not readable.</p>
|
||||||
|
{% else %}
|
||||||
|
{{ source|raw }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Reference in New Issue
Block a user