merged branch symfony/deprecated (PR #6232)
This PR was squashed before being merged into the master branch (closes #6232).
Commits
-------
7428bf9
[WebProfilerBundle] Some eye candy for deprecated calls
Discussion
----------
[WebProfilerBundle] Some eye candy for deprecated calls
![Ohhh](https://lh4.googleusercontent.com/-T9DKsHWf4YU/UMIRqT0g_II/AAAAAAAAJ84/tRDRP8IMwRM/s840/stack.jpg).
@fabpot is [`|raw`](https://github.com/symfony/symfony/pull/new/deprecated#L0R117) a twig defect ?
---------------------------------------------------------------------------
by Baachi at 2012-12-08T09:12:12Z
Really nice 👍
---------------------------------------------------------------------------
by vicb at 2012-12-11T10:00:24Z
should be ready now
This commit is contained in:
commit
f25750e378
@ -1,16 +1,18 @@
|
|||||||
{% extends '@WebProfiler/Profiler/layout.html.twig' %}
|
{% extends '@WebProfiler/Profiler/layout.html.twig' %}
|
||||||
|
|
||||||
|
{% import _self as logger %}
|
||||||
|
|
||||||
{% block toolbar %}
|
{% block toolbar %}
|
||||||
{% if collector.counterrors or collector.countdeprecations %}
|
{% if collector.counterrors or collector.countdeprecations %}
|
||||||
{% set icon %}
|
{% set icon %}
|
||||||
<img width="15" height="28" alt="Logs" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAcCAYAAABoMT8aAAAA4klEQVQ4y2P4//8/AyWYYXgYwOPp6Xnc3t7+P7EYpB6k7+zZs2ADNEjRjIwDAgKWgAywIUfz8+fPVzg7O/8AGeCATQEQnAfi/SAah/wcV1dXvAYUgORANA75ehcXl+/4DHAABRIe+ZrhbgAhTHsDiEgHBA0glA6GfSDiw5mZma+A+sphBlhVVFQ88vHx+Xfu3Ll7QP5haOjjwtuAuGHv3r3NIMNABqh8+/atsaur666vr+9XUlwSHx//AGQANxCbAnEWyGQicRMQ9wBxIQM0qjiBWAFqkB00/glhayBWHwb1AgB38EJsUtxtWwAAAABJRU5ErkJggg=="/>
|
<img width="15" height="28" alt="Logs" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAcCAYAAABoMT8aAAAA4klEQVQ4y2P4//8/AyWYYXgYwOPp6Xnc3t7+P7EYpB6k7+zZs2ADNEjRjIwDAgKWgAywIUfz8+fPVzg7O/8AGeCATQEQnAfi/SAah/wcV1dXvAYUgORANA75ehcXl+/4DHAABRIe+ZrhbgAhTHsDiEgHBA0glA6GfSDiw5mZma+A+sphBlhVVFQ88vHx+Xfu3Ll7QP5haOjjwtuAuGHv3r3NIMNABqh8+/atsaur666vr+9XUlwSHx//AGQANxCbAnEWyGQicRMQ9wBxIQM0qjiBWAFqkB00/glhayBWHwb1AgB38EJsUtxtWwAAAABJRU5ErkJggg=="/>
|
||||||
{% if collector.counterrors %}
|
{% if collector.counterrors %}
|
||||||
{% set statusColor = "red" %}
|
{% set status_color = "red" %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set statusColor = "yellow" %}
|
{% set status_color = "yellow" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% set errorCount = collector.counterrors + collector.countdeprecations %}
|
{% set error_count = collector.counterrors + collector.countdeprecations %}
|
||||||
<span class="sf-toolbar-status sf-toolbar-status-{{ statusColor }}">{{ errorCount }}</span>
|
<span class="sf-toolbar-status sf-toolbar-status-{{ status_color }}">{{ error_count }}</span>
|
||||||
{% endset %}
|
{% endset %}
|
||||||
{% set text %}
|
{% set text %}
|
||||||
{% if collector.counterrors %}
|
{% if collector.counterrors %}
|
||||||
@ -35,9 +37,9 @@
|
|||||||
<span class="icon"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAgCAYAAAAMq2gFAAABjElEQVRIx2MIDw+vd3R0/GFvb/+fGtjFxeVJSUmJ1f///5nv37/PAMMMzs7OVLMEhoODgy/k5+cHJCYmagAtZAJbRG1L0DEwxCYALeOgiUXbt2+/X1NT8xTEdnd3/wi0SI4mFgHBDCBeCLXoF5BtwkCEpvNAvB8JnydCTwgQR0It+g1kWxNjUQEQOyDhAiL0gNUiWWRDjEUOyMkUZsCoRaMWjVpEvEVkFkGjFmEUqgc+fvx4hVYWIReqzi9evKileaoDslnu3LkTNLQtGk3edLPIycnpL9Bge5pb1NXVdQNosDmGRcAm7F+QgKur6783b95cBQoeRGv1kII3QPOdAoZF8+fPP4PUqnx55syZVKCEI1rLh1hsAbWEZ8aMGaUoFoFcMG3atKdIjfSPISEhawICAlaQgwMDA1f6+/sfB5rzE2Sej4/PD3C7DkjoAHHVoUOHLpSVlX3w8vL6Sa34Alr6Z8WKFaCoMARZxAHEoFZ/HBD3A/FyIF4BxMvIxCC964F4G6hZDMTxQCwJAGWE8pur5kFDAAAAAElFTkSuQmCC" alt="Logger" /></span>
|
<span class="icon"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAgCAYAAAAMq2gFAAABjElEQVRIx2MIDw+vd3R0/GFvb/+fGtjFxeVJSUmJ1f///5nv37/PAMMMzs7OVLMEhoODgy/k5+cHJCYmagAtZAJbRG1L0DEwxCYALeOgiUXbt2+/X1NT8xTEdnd3/wi0SI4mFgHBDCBeCLXoF5BtwkCEpvNAvB8JnydCTwgQR0It+g1kWxNjUQEQOyDhAiL0gNUiWWRDjEUOyMkUZsCoRaMWjVpEvEVkFkGjFmEUqgc+fvx4hVYWIReqzi9evKileaoDslnu3LkTNLQtGk3edLPIycnpL9Bge5pb1NXVdQNosDmGRcAm7F+QgKur6783b95cBQoeRGv1kII3QPOdAoZF8+fPP4PUqnx55syZVKCEI1rLh1hsAbWEZ8aMGaUoFoFcMG3atKdIjfSPISEhawICAlaQgwMDA1f6+/sfB5rzE2Sej4/PD3C7DkjoAHHVoUOHLpSVlX3w8vL6Sa34Alr6Z8WKFaCoMARZxAHEoFZ/HBD3A/FyIF4BxMvIxCC964F4G6hZDMTxQCwJAGWE8pur5kFDAAAAAElFTkSuQmCC" alt="Logger" /></span>
|
||||||
<strong>Logs</strong>
|
<strong>Logs</strong>
|
||||||
{% if collector.counterrors or collector.countdeprecations %}
|
{% if collector.counterrors or collector.countdeprecations %}
|
||||||
{% set errorCount = collector.counterrors + collector.countdeprecations %}
|
{% set error_count = collector.counterrors + collector.countdeprecations %}
|
||||||
<span class="count">
|
<span class="count">
|
||||||
<span>{{ errorCount }}</span>
|
<span>{{ error_count }}</span>
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
@ -56,7 +58,19 @@
|
|||||||
<input type="hidden" name="panel" value="logger" />
|
<input type="hidden" name="panel" value="logger" />
|
||||||
<label for="priority">Priority</label>
|
<label for="priority">Priority</label>
|
||||||
<select id="priority" name="priority" onchange="document.getElementById('priority-form').submit(); ">
|
<select id="priority" name="priority" onchange="document.getElementById('priority-form').submit(); ">
|
||||||
{% for value, text in { 100: 'DEBUG', 200: 'INFO', 250: 'NOTICE', 300: 'WARNING', 400: 'ERROR', 500: 'CRITICAL', 550: 'ALERT', 600: 'EMERGENCY' } %}
|
{# values < 0 are custom levels #}
|
||||||
|
{% for value, text in {
|
||||||
|
100: 'DEBUG',
|
||||||
|
200: 'INFO',
|
||||||
|
250: 'NOTICE',
|
||||||
|
300: 'WARNING',
|
||||||
|
400: 'ERROR',
|
||||||
|
500: 'CRITICAL',
|
||||||
|
550: 'ALERT',
|
||||||
|
600: 'EMERGENCY',
|
||||||
|
'-100': 'DEPRECATION only'
|
||||||
|
}
|
||||||
|
%}
|
||||||
<option value="{{ value }}"{{ value == priority ? ' selected' : '' }}>{{ text }}</option>
|
<option value="{{ value }}"{{ value == priority ? ' selected' : '' }}>{{ text }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
@ -70,15 +84,9 @@
|
|||||||
|
|
||||||
{% if collector.logs %}
|
{% if collector.logs %}
|
||||||
<ul class="alt">
|
<ul class="alt">
|
||||||
{% for log in collector.logs if log.priority >= priority %}
|
{% for log in collector.logs if priority >= 0 and log.priority >= priority or priority < 0 and log.context.type|default(0) == priority %}
|
||||||
<li class="{{ cycle(['odd', 'even'], loop.index) }}{% if log.priority >= 400 %} error{% elseif log.priority >= 300 %} warning{% endif %}">
|
<li class="{{ cycle(['odd', 'even'], loop.index) }}{% if log.priority >= 400 %} error{% elseif log.priority >= 300 %} warning{% endif %}">
|
||||||
{{ log.priorityName }} - {{ log.message }}
|
{{ logger.display_message(loop.index, log) }}
|
||||||
{% if log.context is defined and log.context is not empty %}
|
|
||||||
<br />
|
|
||||||
<small>
|
|
||||||
<strong>Context</strong>: {{ log.context|yaml_encode }}
|
|
||||||
</small>
|
|
||||||
{% endif %}
|
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><em>No logs available for this priority.</em></li>
|
<li><em>No logs available for this priority.</em></li>
|
||||||
@ -90,3 +98,39 @@
|
|||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% macro display_message(log_index, log) %}
|
||||||
|
{% if constant('Symfony\\Component\\HttpKernel\\Debug\\ErrorHandler::TYPE_DEPRECATION') == log.context.type|default(0) %}
|
||||||
|
DEPRECATION - Deprecated call in {{ log.context.file|format_file(log.context.line) }}.
|
||||||
|
{% set id = 'sf-call-stack-' ~ log_index %}
|
||||||
|
<a href="#" onclick="Sfjs.toggle('{{ id }}', document.getElementById('{{ id }}-on'), document.getElementById('{{ id }}-off')); return false;">
|
||||||
|
<img class="toggle" id="{{ id }}-off" alt="-" src="data:image/gif;base64,R0lGODlhEgASAMQSANft94TG57Hb8GS44ez1+mC24IvK6ePx+Wa44dXs92+942e54o3L6W2844/M6dnu+P/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABIALAAAAAASABIAQAVCoCQBTBOd6Kk4gJhGBCTPxysJb44K0qD/ER/wlxjmisZkMqBEBW5NHrMZmVKvv9hMVsO+hE0EoNAstEYGxG9heIhCADs=" style="display:none" />
|
||||||
|
<img class="toggle" id="{{ id }}-on" alt="+" src="data:image/gif;base64,R0lGODlhEgASAMQTANft99/v+Ga44bHb8ITG52S44dXs9+z1+uPx+YvK6WC24G+944/M6W28443L6dnu+Ge54v/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABMALAAAAAASABIAQAVS4DQBTiOd6LkwgJgeUSzHSDoNaZ4PU6FLgYBA5/vFID/DbylRGiNIZu74I0h1hNsVxbNuUV4d9SsZM2EzWe1qThVzwWFOAFCQFa1RQq6DJB4iIQA7" style="display:inline" />
|
||||||
|
</a>
|
||||||
|
{% for index, call in log.context.stack if index > 0 %}
|
||||||
|
{% if index == 1 %}
|
||||||
|
<ul class="sf-call-stack" id="{{ id }}" style="display: none">
|
||||||
|
{% endif %}
|
||||||
|
{% if call.class is defined %}
|
||||||
|
{% set from = call.class|abbr_class ~ '::' ~ call.function|abbr_method() %}
|
||||||
|
{% elseif call.function is defined %}
|
||||||
|
{% set from = call.function|abbr_method %}
|
||||||
|
{% elseif call.file is defined %}
|
||||||
|
{% set from = call.file %}
|
||||||
|
{% else %}
|
||||||
|
{% set from = '-' %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<li>Called from {{ call.file is defined and call.line is defined
|
||||||
|
? call.file|format_file(call.line, from)
|
||||||
|
: from|raw
|
||||||
|
}}
|
||||||
|
</li>
|
||||||
|
|
||||||
|
{{ index == log.context.stack|length - 1 ? '</ul>' : '' }}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
{{ log.priorityName }} - {{ log.message }}
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
|
@ -273,6 +273,10 @@ ul.alt li.warning {
|
|||||||
background-color: #ffcc00;
|
background-color: #ffcc00;
|
||||||
margin-bottom: 1px;
|
margin-bottom: 1px;
|
||||||
}
|
}
|
||||||
|
ul.sf-call-stack li {
|
||||||
|
text-size: small;
|
||||||
|
padding: 0 0 0 20px;
|
||||||
|
}
|
||||||
td.main, td.menu {
|
td.main, td.menu {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\HttpKernel\DataCollector;
|
namespace Symfony\Component\HttpKernel\DataCollector;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ class LoggerDataCollector extends DataCollector
|
|||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($this->logger->getLogs() as $log) {
|
foreach ($this->logger->getLogs() as $log) {
|
||||||
if (isset($log['context']['type']) && 'deprecation' === $log['context']['type']) {
|
if (isset($log['context']['type']) && ErrorHandler::TYPE_DEPRECATION === $log['context']['type']) {
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
|||||||
*/
|
*/
|
||||||
class ErrorHandler
|
class ErrorHandler
|
||||||
{
|
{
|
||||||
|
const TYPE_DEPRECATION = -100;
|
||||||
|
|
||||||
private $levels = array(
|
private $levels = array(
|
||||||
E_WARNING => 'Warning',
|
E_WARNING => 'Warning',
|
||||||
E_NOTICE => 'Notice',
|
E_NOTICE => 'Notice',
|
||||||
@ -82,9 +84,18 @@ class ErrorHandler
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($level & E_USER_DEPRECATED || $level & E_DEPRECATED) {
|
if ($level & (E_USER_DEPRECATED | E_DEPRECATED)) {
|
||||||
if (null !== self::$logger) {
|
if (null !== self::$logger) {
|
||||||
self::$logger->warn($message, array('type' => 'deprecation', 'file' => $file, 'line' => $line));
|
$deprecation = array(
|
||||||
|
'type' => self::TYPE_DEPRECATION,
|
||||||
|
'file' => $file,
|
||||||
|
'line' => $line,
|
||||||
|
'stack' => version_compare(PHP_VERSION, '5.4', '<')
|
||||||
|
? array_slice(debug_backtrace(false), 0, 10)
|
||||||
|
: debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10)
|
||||||
|
);
|
||||||
|
|
||||||
|
self::$logger->warn($message, $deprecation);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -91,7 +91,6 @@ class ExceptionHandler
|
|||||||
*/
|
*/
|
||||||
public function getContent(FlattenException $exception)
|
public function getContent(FlattenException $exception)
|
||||||
{
|
{
|
||||||
$title = '';
|
|
||||||
switch ($exception->getStatusCode()) {
|
switch ($exception->getStatusCode()) {
|
||||||
case 404:
|
case 404:
|
||||||
$title = 'Sorry, the page you are looking for could not be found.';
|
$title = 'Sorry, the page you are looking for could not be found.';
|
||||||
@ -103,13 +102,10 @@ class ExceptionHandler
|
|||||||
$content = '';
|
$content = '';
|
||||||
if ($this->debug) {
|
if ($this->debug) {
|
||||||
try {
|
try {
|
||||||
$message = nl2br($exception->getMessage());
|
|
||||||
$class = $this->abbrClass($exception->getClass());
|
|
||||||
$count = count($exception->getAllPrevious());
|
$count = count($exception->getAllPrevious());
|
||||||
$content = '';
|
$total = $count + 1;
|
||||||
foreach ($exception->toArray() as $position => $e) {
|
foreach ($exception->toArray() as $position => $e) {
|
||||||
$ind = $count - $position + 1;
|
$ind = $count - $position + 1;
|
||||||
$total = $count + 1;
|
|
||||||
$class = $this->abbrClass($e['class']);
|
$class = $this->abbrClass($e['class']);
|
||||||
$message = nl2br($e['message']);
|
$message = nl2br($e['message']);
|
||||||
$content .= sprintf(<<<EOF
|
$content .= sprintf(<<<EOF
|
||||||
@ -121,7 +117,7 @@ class ExceptionHandler
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
, $ind, $total, $class, $message);
|
, $ind, $total, $class, $message);
|
||||||
foreach ($e['trace'] as $i => $trace) {
|
foreach ($e['trace'] as $trace) {
|
||||||
$content .= ' <li>';
|
$content .= ' <li>';
|
||||||
if ($trace['function']) {
|
if ($trace['function']) {
|
||||||
$content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
|
$content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
|
use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
|
||||||
|
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
@ -66,8 +67,8 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
1,
|
1,
|
||||||
array(
|
array(
|
||||||
array('message' => 'foo', 'context' => array('type' => 'deprecation')),
|
array('message' => 'foo', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION)),
|
||||||
array('message' => 'foo2', 'context' => array('type' => 'deprecation'))
|
array('message' => 'foo2', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION))
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
2
|
2
|
||||||
|
@ -68,10 +68,25 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
|
|
||||||
$logger = $this->getMock('Symfony\Component\HttpKernel\Log\LoggerInterface');
|
$logger = $this->getMock('Symfony\Component\HttpKernel\Log\LoggerInterface');
|
||||||
$logger->expects($this->once())->method('warn')->with(
|
|
||||||
$this->equalTo('foo'),
|
$that = $this;
|
||||||
$this->equalTo(array('type' => 'deprecation', 'file' => 'foo.php', 'line' => '12'))
|
$warnArgCheck = function($message, $context) use ($that) {
|
||||||
);
|
$that->assertEquals('foo', $message);
|
||||||
|
$that->assertArrayHasKey('file', $context);
|
||||||
|
$that->assertEquals($context['file'], 'foo.php');
|
||||||
|
$that->assertArrayHasKey('line', $context);
|
||||||
|
$that->assertEquals($context['line'], 12);
|
||||||
|
$that->assertArrayHasKey('type', $context);
|
||||||
|
$that->assertEquals($context['type'], ErrorHandler::TYPE_DEPRECATION);
|
||||||
|
$that->assertArrayHasKey('stack', $context);
|
||||||
|
$that->assertInternalType('array', $context['stack']);
|
||||||
|
};
|
||||||
|
|
||||||
|
$logger
|
||||||
|
->expects($this->once())
|
||||||
|
->method('warn')
|
||||||
|
->will($this->returnCallback($warnArgCheck))
|
||||||
|
;
|
||||||
|
|
||||||
$handler = ErrorHandler::register(E_USER_DEPRECATED);
|
$handler = ErrorHandler::register(E_USER_DEPRECATED);
|
||||||
$handler->setLogger($logger);
|
$handler->setLogger($logger);
|
||||||
|
Reference in New Issue
Block a user