Profiler.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Magento profiler for requests to database
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\DB;
  9. class Profiler extends \Zend_Db_Profiler
  10. {
  11. /**
  12. * Host IP whereto a request is sent
  13. *
  14. * @var string
  15. */
  16. protected $_host = '';
  17. /**
  18. * Database connection type
  19. *
  20. * @var string
  21. */
  22. protected $_type = '';
  23. /**
  24. * Last query Id
  25. *
  26. * @var string|null
  27. */
  28. private $_lastQueryId = null;
  29. /**
  30. * Setter for host IP
  31. *
  32. * @param string $host
  33. * @return \Magento\Framework\DB\Profiler
  34. */
  35. public function setHost($host)
  36. {
  37. $this->_host = $host;
  38. return $this;
  39. }
  40. /**
  41. * Setter for database connection type
  42. *
  43. * @param string $type
  44. * @return \Magento\Framework\DB\Profiler
  45. */
  46. public function setType($type)
  47. {
  48. $this->_type = $type;
  49. return $this;
  50. }
  51. /**
  52. * Starts a query. Creates a new query profile object (\Zend_Db_Profiler_Query)
  53. *
  54. * @param string $queryText SQL statement
  55. * @param integer|null $queryType OPTIONAL Type of query, one of the \Zend_Db_Profiler::* constants
  56. * @return integer|null
  57. */
  58. public function queryStart($queryText, $queryType = null)
  59. {
  60. $this->_lastQueryId = parent::queryStart($queryText, $queryType);
  61. return $this->_lastQueryId;
  62. }
  63. /**
  64. * Ends a query. Pass it the handle that was returned by queryStart().
  65. *
  66. * @param int $queryId
  67. * @return string|void
  68. */
  69. public function queryEnd($queryId)
  70. {
  71. $this->_lastQueryId = null;
  72. return parent::queryEnd($queryId);
  73. }
  74. /**
  75. * Ends the last query if exists. Used for finalize broken queries.
  76. *
  77. * @return string|void
  78. */
  79. public function queryEndLast()
  80. {
  81. if ($this->_lastQueryId !== null) {
  82. return $this->queryEnd($this->_lastQueryId);
  83. }
  84. return self::IGNORED;
  85. }
  86. }