Parcourir la source

[Profiler] Profilers now return a status which is used for visual feedback

Victor Berchet il y a 14 ans
Parent
commit
f752dd34a0

+ 7 - 0
src/Symfony/Bundle/DoctrineBundle/DataCollector/DoctrineDataCollector.php

@@ -67,4 +67,11 @@ class DoctrineDataCollector extends DataCollector
     {
         return 'db';
     }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getStatus() {
+        return $this->getQueryCount() < 10 ? self::INFO : self::WARNING;
+    }
 }

Fichier diff supprimé car celui-ci est trop grand
+ 2 - 2
src/Symfony/Bundle/DoctrineBundle/Resources/views/Collector/db.html.twig


+ 7 - 0
src/Symfony/Bundle/DoctrineMongoDBBundle/DataCollector/DoctrineMongoDBDataCollector.php

@@ -56,4 +56,11 @@ class DoctrineMongoDBDataCollector extends DataCollector
     {
         return 'mongodb';
     }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getStatus() {
+        return $this->getQueryCount() < 10 ? self::INFO : self::WARNING;
+    }
 }

Fichier diff supprimé car celui-ci est trop grand
+ 2 - 2
src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig


+ 1 - 1
src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig

@@ -15,7 +15,7 @@
             {% endif %}
         </span>
     {% endset %}
-    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text } only %}
+    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text, 'status' : collector.status } only %}
 {% endblock %}
 
 {% block menu %}

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig

@@ -7,7 +7,7 @@
     {% set text %}
         <span>{{ collector.counterrors }}</span>
     {% endset %}
-    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text } only %}
+    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text, 'status' : collector.status } only %}
 {% endblock %}
 
 {% block menu %}

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/memory.html.twig

@@ -7,5 +7,5 @@
     {% set text %}
         {{ '%.0f'|format(collector.memory / 1024) }} KB
     {% endset %}
-    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text } only %}
+    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text, 'status' : collector.status } only %}
 {% endblock %}

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig

@@ -13,7 +13,7 @@
         <span style="margin: 0; padding: 0; color: #979696;">|</span>
         {{ collector.contenttype }}
     {% endset %}
-    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text } only %}
+    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text, 'status' : collector.status } only %}
 {% endblock %}
 
 {% block menu %}

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/timer.html.twig

@@ -7,5 +7,5 @@
     {% set text %}
         {{ '%.0f'|format(collector.time * 1000) }} ms
     {% endset %}
-    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text } only %}
+    {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with {'icon' : icon, 'text' : text, 'status' : collector.status } only %}
 {% endblock %}

+ 10 - 3
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_item.html.twig

@@ -1,5 +1,12 @@
-<span style="white-space:nowrap; color:#2f2f2f; display:inline-block; min-height:24px; border-right:1px solid #cdcdcd; padding:5px 10px 5px 6px; ">
+{% set style = '' %}
+{% if status is defined %}
+    {% if 'error' == status %}
+        {% set style = 'background-color: #f66;' %}
+    {% elseif 'warning' == status %}
+        {% set style = 'background-color: #fa2;' %}
+    {% endif %}
+{% endif %}
+<span style="{{ style }}white-space:nowrap; color:#2f2f2f; display:inline-block; min-height:24px; border-right:1px solid #cdcdcd; padding:5px 10px 5px 6px; ">
      {% if icon is defined %}{{ icon }}{% endif %}
      {% if text is defined %}{{ text }}{% endif %}
-</span>
-
+</span>

+ 10 - 0
src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php

@@ -24,6 +24,16 @@ abstract class DataCollector implements DataCollectorInterface, \Serializable
 {
     protected $data;
 
+    /**
+     * Returns the status of the collector.
+     *
+     * @return integer The status of the collector
+     */
+    public function getStatus()
+    {
+        return self::INFO;
+    }
+
     public function serialize()
     {
         return serialize($this->data);

+ 11 - 0
src/Symfony/Component/HttpKernel/DataCollector/DataCollectorInterface.php

@@ -22,6 +22,10 @@ use Symfony\Component\HttpFoundation\Response;
  */
 interface DataCollectorInterface
 {
+    const INFO = 'info';
+    const WARNING = 'warning';
+    const ERROR = 'error';
+    
     /**
      * Collects data for the given Request and Response.
      *
@@ -37,4 +41,11 @@ interface DataCollectorInterface
      * @return string The collector name
      */
     function getName();
+
+    /**
+     * Returns the status of the collector.
+     *
+     * @return string The status of the collector
+     */
+    function getStatus();
 }

+ 8 - 0
src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

@@ -72,4 +72,12 @@ class LoggerDataCollector extends DataCollector
     {
         return 'logger';
     }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getStatus()
+    {
+        return 0 === $this->countErrors() ? self::INFO : self::ERROR;
+    }
 }