ParserResult.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /**
  21. * Encapsulates the resulting components from a DQL query parsing process that
  22. * can be serialized.
  23. *
  24. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  25. * @author Janne Vanhala <jpvanhal@cc.hut.fi>
  26. * @author Roman Borschel <roman@code-factory.org>
  27. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  28. * @link http://www.doctrine-project.org
  29. * @since 2.0
  30. */
  31. class ParserResult
  32. {
  33. /**
  34. * The SQL executor used for executing the SQL.
  35. *
  36. * @var \Doctrine\ORM\Query\Exec\AbstractSqlExecutor
  37. */
  38. private $_sqlExecutor;
  39. /**
  40. * The ResultSetMapping that describes how to map the SQL result set.
  41. *
  42. * @var \Doctrine\ORM\Query\ResultSetMapping
  43. */
  44. private $_resultSetMapping;
  45. /**
  46. * The mappings of DQL parameter names/positions to SQL parameter positions.
  47. *
  48. * @var array
  49. */
  50. private $_parameterMappings = array();
  51. /**
  52. * Initializes a new instance of the <tt>ParserResult</tt> class.
  53. * The new instance is initialized with an empty <tt>ResultSetMapping</tt>.
  54. */
  55. public function __construct()
  56. {
  57. $this->_resultSetMapping = new ResultSetMapping;
  58. }
  59. /**
  60. * Gets the ResultSetMapping for the parsed query.
  61. *
  62. * @return ResultSetMapping|null The result set mapping of the parsed query or NULL
  63. * if the query is not a SELECT query.
  64. */
  65. public function getResultSetMapping()
  66. {
  67. return $this->_resultSetMapping;
  68. }
  69. /**
  70. * Sets the ResultSetMapping of the parsed query.
  71. *
  72. * @param ResultSetMapping $rsm
  73. *
  74. * @return void
  75. */
  76. public function setResultSetMapping(ResultSetMapping $rsm)
  77. {
  78. $this->_resultSetMapping = $rsm;
  79. }
  80. /**
  81. * Sets the SQL executor that should be used for this ParserResult.
  82. *
  83. * @param \Doctrine\ORM\Query\Exec\AbstractSqlExecutor $executor
  84. *
  85. * @return void
  86. */
  87. public function setSqlExecutor($executor)
  88. {
  89. $this->_sqlExecutor = $executor;
  90. }
  91. /**
  92. * Gets the SQL executor used by this ParserResult.
  93. *
  94. * @return \Doctrine\ORM\Query\Exec\AbstractSqlExecutor
  95. */
  96. public function getSqlExecutor()
  97. {
  98. return $this->_sqlExecutor;
  99. }
  100. /**
  101. * Adds a DQL to SQL parameter mapping. One DQL parameter name/position can map to
  102. * several SQL parameter positions.
  103. *
  104. * @param string|integer $dqlPosition
  105. * @param integer $sqlPosition
  106. *
  107. * @return void
  108. */
  109. public function addParameterMapping($dqlPosition, $sqlPosition)
  110. {
  111. $this->_parameterMappings[$dqlPosition][] = $sqlPosition;
  112. }
  113. /**
  114. * Gets all DQL to SQL parameter mappings.
  115. *
  116. * @return array The parameter mappings.
  117. */
  118. public function getParameterMappings()
  119. {
  120. return $this->_parameterMappings;
  121. }
  122. /**
  123. * Gets the SQL parameter positions for a DQL parameter name/position.
  124. *
  125. * @param string|integer $dqlPosition The name or position of the DQL parameter.
  126. *
  127. * @return array The positions of the corresponding SQL parameters.
  128. */
  129. public function getSqlParameterPositions($dqlPosition)
  130. {
  131. return $this->_parameterMappings[$dqlPosition];
  132. }
  133. }