vendor/jackalope/jackalope/src/Jackalope/Query/QOM/QueryObjectModelFactory.php line 66

Open in your IDE?
  1. <?php
  2. namespace Jackalope\Query\QOM;
  3. use InvalidArgumentException;
  4. use Jackalope\ObjectManager;
  5. use Jackalope\FactoryInterface;
  6. use PHPCR\Query\QOM\QueryObjectModelConstantsInterface;
  7. use PHPCR\Query\QOM\QueryObjectModelFactoryInterface;
  8. use PHPCR\Query\QOM\SourceInterface;
  9. use PHPCR\Query\QOM\ConstraintInterface;
  10. use PHPCR\Query\QOM\JoinConditionInterface;
  11. use PHPCR\Query\QOM\DynamicOperandInterface;
  12. use PHPCR\Query\QOM\StaticOperandInterface;
  13. use PHPCR\Query\QOM\PropertyValueInterface;
  14. /**
  15. * {@inheritDoc}
  16. *
  17. * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
  18. * @license http://opensource.org/licenses/MIT MIT License
  19. *
  20. * @api
  21. */
  22. class QueryObjectModelFactory implements QueryObjectModelFactoryInterface
  23. {
  24. /**
  25. * The factory to instantiate objects
  26. *
  27. * @var FactoryInterface
  28. */
  29. protected $factory;
  30. /**
  31. * @var ObjectManager
  32. */
  33. protected $objectManager;
  34. /**
  35. * Create the query object model factory - get this from the QueryManager
  36. *
  37. * @param FactoryInterface $factory the object factory
  38. * @param ObjectManager $objectManager only used to create the query (can
  39. * be omitted if you do not want to execute the query but just use it
  40. * with a parser)
  41. */
  42. public function __construct(FactoryInterface $factory, ObjectManager $objectManager = null)
  43. {
  44. $this->factory = $factory;
  45. $this->objectManager = $objectManager;
  46. }
  47. /**
  48. * {@inheritDoc}
  49. *
  50. * @return \PHPCR\Query\QOM\QueryObjectModelInterface the query
  51. *
  52. * @api
  53. */
  54. public function createQuery(
  55. SourceInterface $source,
  56. ConstraintInterface $constraint = null,
  57. array $orderings = [],
  58. array $columns = []
  59. ) {
  60. return $this->factory->get(
  61. QueryObjectModel::class,
  62. [$this->objectManager, $source, $constraint, $orderings, $columns]
  63. );
  64. }
  65. // TODO: should we use the factory ->get here? but this would mean all of them need to expect the factory as first parameter
  66. // or refactor the factory to make the first param optional.
  67. /**
  68. * {@inheritDoc}
  69. *
  70. * @return \PHPCR\Query\QOM\SelectorInterface the selector
  71. *
  72. * @api
  73. */
  74. public function selector($selectorName, $nodeTypeName)
  75. {
  76. return new Selector($selectorName, $nodeTypeName);
  77. }
  78. /**
  79. * {@inheritDoc}
  80. *
  81. * @return \PHPCR\Query\QOM\JoinInterface the join
  82. *
  83. * @api
  84. */
  85. public function join(SourceInterface $left, SourceInterface $right, $joinType, JoinConditionInterface $joinCondition)
  86. {
  87. return new Join($left, $right, $joinType, $joinCondition);
  88. }
  89. /**
  90. * {@inheritDoc}
  91. *
  92. * @return \PHPCR\Query\QOM\EquiJoinConditionInterface the constraint
  93. *
  94. * @api
  95. */
  96. public function equiJoinCondition($selector1Name, $property1Name, $selector2Name, $property2Name)
  97. {
  98. return new EquiJoinCondition($selector1Name, $property1Name, $selector2Name, $property2Name);
  99. }
  100. /**
  101. * {@inheritDoc}
  102. *
  103. * @return \PHPCR\Query\QOM\SameNodeJoinConditionInterface the constraint
  104. *
  105. * @api
  106. */
  107. public function sameNodeJoinCondition($selector1Name, $selector2Name, $selector2Path = null)
  108. {
  109. return new SameNodeJoinCondition($selector1Name, $selector2Name, $selector2Path);
  110. }
  111. /**
  112. * {@inheritDoc}
  113. *
  114. * @return \PHPCR\Query\QOM\ChildNodeJoinConditionInterface the constraint
  115. *
  116. * @api
  117. */
  118. public function childNodeJoinCondition($childSelectorName, $parentSelectorName)
  119. {
  120. return new ChildNodeJoinCondition($childSelectorName, $parentSelectorName);
  121. }
  122. /**
  123. * {@inheritDoc}
  124. *
  125. * @return \PHPCR\Query\QOM\DescendantNodeJoinConditionInterface the constraint
  126. *
  127. * @api
  128. */
  129. public function descendantNodeJoinCondition($descendantSelectorName, $ancestorSelectorName)
  130. {
  131. return new DescendantNodeJoinCondition($descendantSelectorName, $ancestorSelectorName);
  132. }
  133. /**
  134. * {@inheritDoc}
  135. *
  136. * @return \PHPCR\Query\QOM\AndInterface the And constraint
  137. *
  138. * @api
  139. */
  140. public function andConstraint(ConstraintInterface $constraint1, ConstraintInterface $constraint2)
  141. {
  142. return new AndConstraint($constraint1, $constraint2);
  143. }
  144. /**
  145. * {@inheritDoc}
  146. *
  147. * @return \PHPCR\Query\QOM\OrInterface the Or constraint
  148. *
  149. * @api
  150. */
  151. public function orConstraint(ConstraintInterface $constraint1, ConstraintInterface $constraint2)
  152. {
  153. return new OrConstraint($constraint1, $constraint2);
  154. }
  155. /**
  156. * {@inheritDoc}
  157. *
  158. * @return \PHPCR\Query\QOM\NotInterface the Not constraint
  159. *
  160. * @api
  161. */
  162. public function notConstraint(ConstraintInterface $constraint)
  163. {
  164. return new NotConstraint($constraint);
  165. }
  166. /**
  167. * {@inheritDoc}
  168. *
  169. * @return \PHPCR\Query\QOM\ComparisonInterface the constraint
  170. *
  171. * @api
  172. */
  173. public function comparison(DynamicOperandInterface $operand1, $operator, StaticOperandInterface $operand2)
  174. {
  175. return new ComparisonConstraint($operand1, $operator, $operand2);
  176. }
  177. /**
  178. * {@inheritDoc}
  179. *
  180. * @return \PHPCR\Query\QOM\PropertyExistenceInterface the constraint
  181. *
  182. * @api
  183. */
  184. public function propertyExistence($selectorName, $propertyName)
  185. {
  186. return new PropertyExistence($selectorName, $propertyName);
  187. }
  188. /**
  189. * {@inheritDoc}
  190. *
  191. * @return \PHPCR\Query\QOM\FullTextSearchInterface the constraint
  192. *
  193. * @throws InvalidArgumentException
  194. *
  195. * @api
  196. */
  197. public function fullTextSearch($selectorName, $propertyName, $fullTextSearchExpression)
  198. {
  199. return new FullTextSearchConstraint($selectorName, $propertyName, $fullTextSearchExpression);
  200. }
  201. /**
  202. * {@inheritDoc}
  203. *
  204. * @return \PHPCR\Query\QOM\SameNodeInterface the constraint
  205. *
  206. * @api
  207. */
  208. public function sameNode($selectorName, $path)
  209. {
  210. return new SameNode($selectorName, $path);
  211. }
  212. /**
  213. * {@inheritDoc}
  214. *
  215. * @return \PHPCR\Query\QOM\ChildNodeInterface the constraint
  216. *
  217. * @api
  218. */
  219. public function childNode($selectorName, $path)
  220. {
  221. return new ChildNodeConstraint($selectorName, $path);
  222. }
  223. /**
  224. * {@inheritDoc}
  225. *
  226. * @return \PHPCR\Query\QOM\DescendantNodeInterface the constraint
  227. *
  228. * @api
  229. */
  230. public function descendantNode($selectorName, $path)
  231. {
  232. return new DescendantNodeConstraint($selectorName, $path);
  233. }
  234. /**
  235. * {@inheritDoc}
  236. *
  237. * @return \PHPCR\Query\QOM\PropertyValueInterface the operand
  238. *
  239. * @throws InvalidArgumentException
  240. *
  241. * @api
  242. */
  243. public function propertyValue($selectorName, $propertyName)
  244. {
  245. return new PropertyValue($selectorName, $propertyName);
  246. }
  247. /**
  248. * {@inheritDoc}
  249. *
  250. * @return \PHPCR\Query\QOM\LengthInterface the operand
  251. *
  252. * @api
  253. */
  254. public function length(PropertyValueInterface $propertyValue)
  255. {
  256. return new Length($propertyValue);
  257. }
  258. /**
  259. * {@inheritDoc}
  260. *
  261. * @return \PHPCR\Query\QOM\NodeNameInterface the operand
  262. *
  263. * @throws InvalidArgumentException
  264. *
  265. * @api
  266. */
  267. public function nodeName($selectorName)
  268. {
  269. return new NodeName($selectorName);
  270. }
  271. /**
  272. * {@inheritDoc}
  273. *
  274. * @return \PHPCR\Query\QOM\NodeLocalNameInterface the operand
  275. *
  276. * @api
  277. */
  278. public function nodeLocalName($selectorName)
  279. {
  280. return new NodeLocalName($selectorName);
  281. }
  282. /**
  283. * {@inheritDoc}
  284. *
  285. * @return \PHPCR\Query\QOM\FullTextSearchScoreInterface the operand
  286. *
  287. * @throws InvalidArgumentException
  288. *
  289. * @api
  290. */
  291. public function fullTextSearchScore($selectorName)
  292. {
  293. return new FullTextSearchScore($selectorName);
  294. }
  295. /**
  296. * {@inheritDoc}
  297. *
  298. * @return \PHPCR\Query\QOM\LowerCaseInterface the operand
  299. *
  300. * @api
  301. */
  302. public function lowerCase(DynamicOperandInterface $operand)
  303. {
  304. return new LowerCase($operand);
  305. }
  306. /**
  307. * {@inheritDoc}
  308. *
  309. * @return \PHPCR\Query\QOM\UpperCaseInterface the operand
  310. *
  311. * @api
  312. */
  313. public function upperCase(DynamicOperandInterface $operand)
  314. {
  315. return new UpperCase($operand);
  316. }
  317. /**
  318. * {@inheritDoc}
  319. *
  320. * @return \PHPCR\Query\QOM\BindVariableValueInterface the operand
  321. *
  322. * @api
  323. */
  324. public function bindVariable($bindVariableName)
  325. {
  326. return new BindVariableValue($bindVariableName);
  327. }
  328. /**
  329. * {@inheritDoc}
  330. *
  331. * @return mixed the operand
  332. *
  333. * @api
  334. */
  335. public function literal($literalValue)
  336. {
  337. return new Literal($literalValue);
  338. }
  339. /**
  340. * {@inheritDoc}
  341. *
  342. * @return \PHPCR\Query\QOM\OrderingInterface the ordering
  343. *
  344. * @api
  345. */
  346. public function ascending(DynamicOperandInterface $operand)
  347. {
  348. return new Ordering($operand, QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING);
  349. }
  350. /**
  351. * {@inheritDoc}
  352. *
  353. * @return \PHPCR\Query\QOM\OrderingInterface the ordering
  354. *
  355. * @api
  356. */
  357. public function descending(DynamicOperandInterface $operand)
  358. {
  359. return new Ordering($operand, QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING);
  360. }
  361. /**
  362. * {@inheritDoc}
  363. *
  364. * @return \PHPCR\Query\QOM\ColumnInterface the column
  365. *
  366. * @throws \InvalidArgumentException
  367. *
  368. * @api
  369. */
  370. public function column($selectorName, $propertyName = null, $columnName = null)
  371. {
  372. return new Column($selectorName, $propertyName, $columnName);
  373. }
  374. }