Query.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\ReportXml;
  7. use Magento\Framework\DB\Select;
  8. /**
  9. * Query object, contains SQL statement, information about connection, query arguments
  10. */
  11. class Query implements \JsonSerializable
  12. {
  13. /**
  14. * @var Select
  15. */
  16. private $select;
  17. /**
  18. * @var \Magento\Analytics\ReportXml\SelectHydrator
  19. */
  20. private $selectHydrator;
  21. /**
  22. * @var string
  23. */
  24. private $connectionName;
  25. /**
  26. * @var array
  27. */
  28. private $config;
  29. /**
  30. * Query constructor.
  31. *
  32. * @param Select $select
  33. * @param SelectHydrator $selectHydrator
  34. * @param string $connectionName
  35. * @param array $config
  36. */
  37. public function __construct(
  38. Select $select,
  39. SelectHydrator $selectHydrator,
  40. $connectionName,
  41. $config
  42. ) {
  43. $this->select = $select;
  44. $this->connectionName = $connectionName;
  45. $this->selectHydrator = $selectHydrator;
  46. $this->config = $config;
  47. }
  48. /**
  49. * @return Select
  50. */
  51. public function getSelect()
  52. {
  53. return $this->select;
  54. }
  55. /**
  56. * @return string
  57. */
  58. public function getConnectionName()
  59. {
  60. return $this->connectionName;
  61. }
  62. /**
  63. * @return array
  64. */
  65. public function getConfig()
  66. {
  67. return $this->config;
  68. }
  69. /**
  70. * Specify data which should be serialized to JSON
  71. * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  72. * @return mixed data which can be serialized by <b>json_encode</b>,
  73. * which is a value of any type other than a resource.
  74. */
  75. public function jsonSerialize()
  76. {
  77. return [
  78. 'connectionName' => $this->getConnectionName(),
  79. 'select_parts' => $this->selectHydrator->extract($this->getSelect()),
  80. 'config' => $this->getConfig()
  81. ];
  82. }
  83. }