[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/maximebf/debugbar/src/DebugBar/Bridge/ -> DoctrineCollector.php (source)

   1  <?php
   2  /*
   3   * This file is part of the DebugBar package.
   4   *
   5   * (c) 2013 Maxime Bouroumeau-Fuseau
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  namespace DebugBar\Bridge;
  12  
  13  use DebugBar\DataCollector\AssetProvider;
  14  use DebugBar\DataCollector\DataCollector;
  15  use DebugBar\DataCollector\Renderable;
  16  use DebugBar\DebugBarException;
  17  use Doctrine\DBAL\Logging\DebugStack;
  18  use Doctrine\ORM\EntityManager;
  19  
  20  /**
  21   * Collects Doctrine queries
  22   *
  23   * http://doctrine-project.org
  24   *
  25   * Uses the DebugStack logger to collects data about queries
  26   *
  27   * <code>
  28   * $debugStack = new Doctrine\DBAL\Logging\DebugStack();
  29   * $entityManager->getConnection()->getConfiguration()->setSQLLogger($debugStack);
  30   * $debugbar->addCollector(new DoctrineCollector($debugStack));
  31   * </code>
  32   */
  33  class DoctrineCollector extends DataCollector implements Renderable, AssetProvider
  34  {
  35      protected $debugStack;
  36  
  37      /**
  38       * DoctrineCollector constructor.
  39       * @param $debugStackOrEntityManager
  40       * @throws DebugBarException
  41       */
  42      public function __construct($debugStackOrEntityManager)
  43      {
  44          if ($debugStackOrEntityManager instanceof EntityManager) {
  45              $debugStackOrEntityManager = $debugStackOrEntityManager->getConnection()->getConfiguration()->getSQLLogger();
  46          }
  47          if (!($debugStackOrEntityManager instanceof DebugStack)) {
  48              throw new DebugBarException("'DoctrineCollector' requires an 'EntityManager' or 'DebugStack' object");
  49          }
  50          $this->debugStack = $debugStackOrEntityManager;
  51      }
  52  
  53      /**
  54       * @return array
  55       */
  56      public function collect()
  57      {
  58          $queries = array();
  59          $totalExecTime = 0;
  60          foreach ($this->debugStack->queries as $q) {
  61              $queries[] = array(
  62                  'sql' => $q['sql'],
  63                  'params' => (object) $q['params'],
  64                  'duration' => $q['executionMS'],
  65                  'duration_str' => $this->formatDuration($q['executionMS'])
  66              );
  67              $totalExecTime += $q['executionMS'];
  68          }
  69  
  70          return array(
  71              'nb_statements' => count($queries),
  72              'accumulated_duration' => $totalExecTime,
  73              'accumulated_duration_str' => $this->formatDuration($totalExecTime),
  74              'statements' => $queries
  75          );
  76      }
  77  
  78      /**
  79       * @return string
  80       */
  81      public function getName()
  82      {
  83          return 'doctrine';
  84      }
  85  
  86      /**
  87       * @return array
  88       */
  89      public function getWidgets()
  90      {
  91          return array(
  92              "database" => array(
  93                  "icon" => "arrow-right",
  94                  "widget" => "PhpDebugBar.Widgets.SQLQueriesWidget",
  95                  "map" => "doctrine",
  96                  "default" => "[]"
  97              ),
  98              "database:badge" => array(
  99                  "map" => "doctrine.nb_statements",
 100                  "default" => 0
 101              )
 102          );
 103      }
 104  
 105      /**
 106       * @return array
 107       */
 108      public function getAssets()
 109      {
 110          return array(
 111              'css' => 'widgets/sqlqueries/widget.css',
 112              'js' => 'widgets/sqlqueries/widget.js'
 113          );
 114      }
 115  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer