ParserResult.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\ORM\Query;
  20. use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
  21. /**
  22. * Encapsulates the resulting components from a DQL query parsing process that
  23. * can be serialized.
  24. *
  25. * @link http://www.doctrine-project.org
  26. */
  27. class ParserResult
  28. {
  29. /**
  30. * The SQL executor used for executing the SQL.
  31. *
  32. * @var AbstractSqlExecutor
  33. */
  34. private $_sqlExecutor;
  35. /**
  36. * The ResultSetMapping that describes how to map the SQL result set.
  37. *
  38. * @var ResultSetMapping
  39. */
  40. private $_resultSetMapping;
  41. /**
  42. * The mappings of DQL parameter names/positions to SQL parameter positions.
  43. *
  44. * @psalm-var array<string|int, list<int>>
  45. */
  46. private $_parameterMappings = [];
  47. /**
  48. * Initializes a new instance of the <tt>ParserResult</tt> class.
  49. * The new instance is initialized with an empty <tt>ResultSetMapping</tt>.
  50. */
  51. public function __construct()
  52. {
  53. $this->_resultSetMapping = new ResultSetMapping();
  54. }
  55. /**
  56. * Gets the ResultSetMapping for the parsed query.
  57. *
  58. * @return ResultSetMapping The result set mapping of the parsed query
  59. */
  60. public function getResultSetMapping()
  61. {
  62. return $this->_resultSetMapping;
  63. }
  64. /**
  65. * Sets the ResultSetMapping of the parsed query.
  66. *
  67. * @return void
  68. */
  69. public function setResultSetMapping(ResultSetMapping $rsm)
  70. {
  71. $this->_resultSetMapping = $rsm;
  72. }
  73. /**
  74. * Sets the SQL executor that should be used for this ParserResult.
  75. *
  76. * @param AbstractSqlExecutor $executor
  77. *
  78. * @return void
  79. */
  80. public function setSqlExecutor($executor)
  81. {
  82. $this->_sqlExecutor = $executor;
  83. }
  84. /**
  85. * Gets the SQL executor used by this ParserResult.
  86. *
  87. * @return AbstractSqlExecutor
  88. */
  89. public function getSqlExecutor()
  90. {
  91. return $this->_sqlExecutor;
  92. }
  93. /**
  94. * Adds a DQL to SQL parameter mapping. One DQL parameter name/position can map to
  95. * several SQL parameter positions.
  96. *
  97. * @param string|int $dqlPosition
  98. * @param int $sqlPosition
  99. *
  100. * @return void
  101. */
  102. public function addParameterMapping($dqlPosition, $sqlPosition)
  103. {
  104. $this->_parameterMappings[$dqlPosition][] = $sqlPosition;
  105. }
  106. /**
  107. * Gets all DQL to SQL parameter mappings.
  108. *
  109. * @psalm-return array<int|string, list<int>> The parameter mappings.
  110. */
  111. public function getParameterMappings()
  112. {
  113. return $this->_parameterMappings;
  114. }
  115. /**
  116. * Gets the SQL parameter positions for a DQL parameter name/position.
  117. *
  118. * @param string|int $dqlPosition The name or position of the DQL parameter.
  119. *
  120. * @psalm-return list<int> The positions of the corresponding SQL parameters.
  121. */
  122. public function getSqlParameterPositions($dqlPosition)
  123. {
  124. return $this->_parameterMappings[$dqlPosition];
  125. }
  126. }