vendor/jackalope/jackalope/src/Jackalope/Query/Query.php line 109

Open in your IDE?
  1. <?php
  2. namespace Jackalope\Query;
  3. use PHPCR\UnsupportedRepositoryOperationException;
  4. use PHPCR\RepositoryException;
  5. use PHPCR\ItemNotFoundException;
  6. use PHPCR\Query\QueryInterface;
  7. use Jackalope\ObjectManager;
  8. use Jackalope\FactoryInterface;
  9. /**
  10. * Abstract Query implementation for the different Query-languages
  11. *
  12. * This can never be legally created if the transport does not implement
  13. * QueryInterface.
  14. *
  15. * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
  16. * @license http://opensource.org/licenses/MIT MIT License
  17. *
  18. * @api
  19. */
  20. abstract class Query implements QueryInterface
  21. {
  22. /**
  23. * The factory to instantiate objects
  24. *
  25. * @var FactoryInterface
  26. */
  27. protected $factory;
  28. /**
  29. * The query statement
  30. *
  31. * @var string
  32. */
  33. protected $statement;
  34. /**
  35. * Limit for the query
  36. *
  37. * @var integer
  38. */
  39. protected $limit;
  40. /**
  41. * Offset to start results from
  42. *
  43. * @var integer
  44. */
  45. protected $offset;
  46. /**
  47. * The object manager to execute the query with.
  48. *
  49. * @var ObjectManager
  50. */
  51. protected $objectManager;
  52. /**
  53. * If this is a stored query, the path to the node that stores this query.
  54. *
  55. * @var string
  56. */
  57. protected $path;
  58. /**
  59. * Create a new query instance
  60. *
  61. * @param FactoryInterface $factory the object factory
  62. * @param string $statement The statement for this query
  63. * @param ObjectManager $objectManager (can be omitted if you do not want
  64. * to execute the query but just use it with a parser)
  65. * @param string $path If this query is loaded from workspace with
  66. * QueryManager::getQuery(), path has to be provided here
  67. */
  68. public function __construct(FactoryInterface $factory, $statement, ObjectManager $objectManager = null, $path = null)
  69. {
  70. $this->factory = $factory;
  71. $this->statement = $statement;
  72. $this->objectManager = $objectManager;
  73. $this->path = $path;
  74. }
  75. /**
  76. * {@inheritDoc}
  77. *
  78. * @api
  79. */
  80. public function bindValue($varName, $value)
  81. {
  82. throw new RepositoryException('Not Implemented...');
  83. }
  84. /**
  85. * {@inheritDoc}
  86. *
  87. * @return \PHPCR\Query\QueryResultInterface a QueryResult object
  88. *
  89. * @api
  90. */
  91. public function execute()
  92. {
  93. if (null === $this->objectManager) {
  94. // if the ObjectManager was not injected in the header. this is only supposed to happen in the DBAL client.
  95. throw new RepositoryException('Jackalope implementation error: This query was built for parsing only. (There is no ObjectManager to run the query against.)');
  96. }
  97. $transport = $this->objectManager->getTransport();
  98. $rawData = $transport->query($this);
  99. $queryResult = $this->factory->get(QueryResult::class, [$rawData, $this->objectManager]);
  100. return $queryResult;
  101. }
  102. /**
  103. * {@inheritDoc}
  104. *
  105. * @return bool true if the query was executing and will be cancelled,
  106. * or false if the query cannot not be cancelled because it has either
  107. * already finished executing, it has already been cancelled, or the
  108. * implementation does not support canceling queries
  109. *
  110. * @api
  111. */
  112. public function cancel()
  113. {
  114. return false;
  115. }
  116. /**
  117. * {@inheritDoc}
  118. *
  119. * @return string[]
  120. *
  121. * @api
  122. */
  123. public function getBindVariableNames()
  124. {
  125. throw new RepositoryException('Not Implemented...');
  126. }
  127. /**
  128. * {@inheritDoc}
  129. *
  130. * @api
  131. */
  132. public function setLimit($limit)
  133. {
  134. $this->limit = $limit;
  135. }
  136. /**
  137. * Access the limit from the transport layer
  138. *
  139. * @return int the limit set with setLimit
  140. */
  141. public function getLimit()
  142. {
  143. return $this->limit;
  144. }
  145. /**
  146. * {@inheritDoc}
  147. *
  148. * @api
  149. */
  150. public function setOffset($offset)
  151. {
  152. $this->offset = $offset;
  153. }
  154. /**
  155. * Access the offset from the transport layer
  156. *
  157. * @return int the offset set with setOffset
  158. */
  159. public function getOffset()
  160. {
  161. return $this->offset;
  162. }
  163. /**
  164. * {@inheritDoc}
  165. *
  166. * @return string the query statement
  167. *
  168. * @api
  169. */
  170. public function getStatement()
  171. {
  172. return $this->statement;
  173. }
  174. /**
  175. * {@inheritDoc}
  176. *
  177. * @return string path of the node representing this query
  178. *
  179. * @api
  180. */
  181. public function getStoredQueryPath()
  182. {
  183. if ($this->path === null) {
  184. throw new ItemNotFoundException('Not a stored query');
  185. }
  186. return $this->path;
  187. }
  188. /**
  189. * {@inheritDoc}
  190. *
  191. * @return \PHPCR\NodeInterface the newly created node
  192. *
  193. * @api
  194. */
  195. public function storeAsNode($absPath)
  196. {
  197. // when implementing this, use ->getStatement***() and not $this->statement
  198. // so this works for the extending QueryObjectModel as well
  199. throw new UnsupportedRepositoryOperationException('Not implemented: Write');
  200. }
  201. }