Procházet zdrojové kódy

[DoctrineBundle] added connections and entity managers in web profiler

Fabien Potencier před 14 roky
rodič
revize
74a243bdd6

+ 19 - 3
src/Symfony/Bundle/DoctrineBundle/DataCollector/DoctrineDataCollector.php

@@ -23,10 +23,14 @@ use Symfony\Bundle\DoctrineBundle\Logger\DbalLogger;
  */
 class DoctrineDataCollector extends DataCollector
 {
-    protected $logger;
+    private $connections;
+    private $managers;
+    private $logger;
 
-    public function __construct(DbalLogger $logger = null)
+    public function __construct($connections, $managers, DbalLogger $logger = null)
     {
+        $this->connections = $connections;
+        $this->managers = $managers;
         $this->logger = $logger;
     }
 
@@ -36,10 +40,22 @@ class DoctrineDataCollector extends DataCollector
     public function collect(Request $request, Response $response, \Exception $exception = null)
     {
         $this->data = array(
-            'queries' => null !== $this->logger ? $this->logger->queries : array(),
+            'queries'     => null !== $this->logger ? $this->logger->queries : array(),
+            'connections' => $this->connections,
+            'managers'    => $this->managers,
         );
     }
 
+    public function getManagers()
+    {
+        return $this->data['managers'];
+    }
+
+    public function getConnections()
+    {
+        return $this->data['connections'];
+    }
+
     public function getQueryCount()
     {
         return count($this->data['queries']);

+ 2 - 0
src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml

@@ -26,6 +26,8 @@
 
         <service id="data_collector.doctrine" class="%doctrine.data_collector.class%" public="false">
             <tag name="data_collector" template="DoctrineBundle:Collector:db" id="db" />
+            <argument>%doctrine.dbal.connections%</argument>
+            <argument>%doctrine.orm.entity_managers%</argument>
             <argument type="service" id="doctrine.dbal.logger" />
         </service>
 

+ 42 - 0
src/Symfony/Bundle/DoctrineBundle/Resources/views/Collector/db.html.twig

@@ -43,4 +43,46 @@
             {% endfor %}
         </ul>
     {% endif %}
+
+    <h2>Database Connections</h2>
+
+    {% if collector.connections %}
+        <table>
+            <tr>
+                <th>Name</th>
+                <th>Service</th>
+            </tr>
+            {% for name, service in collector.connections %}
+                <tr>
+                    <th>{{ name }}</th>
+                    <td>{{ service }}</td>
+                </tr>
+            {% endfor %}
+        </table>
+    {% else %}
+        <p>
+            <em>No entity managers.</em>
+        </p>
+    {% endif %}
+
+    <h2>Entity Managers</h2>
+
+    {% if collector.managers %}
+        <table>
+            <tr>
+                <th>Name</th>
+                <th>Service</th>
+            </tr>
+            {% for name, service in collector.managers %}
+                <tr>
+                    <th>{{ name }}</th>
+                    <td>{{ service }}</td>
+                </tr>
+            {% endfor %}
+        </table>
+    {% else %}
+        <p>
+            <em>No entity managers.</em>
+        </p>
+    {% endif %}
 {% endblock %}