vendor/jackalope/jackalope/src/Jackalope/Query/QueryManager.php line 61

Open in your IDE?
  1. <?php
  2. namespace Jackalope\Query;
  3. use Jackalope\Query\QOM\QueryObjectModelFactory;
  4. use PHPCR\Query\QueryInterface;
  5. use PHPCR\Query\QueryManagerInterface;
  6. use PHPCR\Query\InvalidQueryException;
  7. use Jackalope\ObjectManager;
  8. use Jackalope\NotImplementedException;
  9. use Jackalope\FactoryInterface;
  10. /**
  11. * {@inheritDoc}
  12. *
  13. * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
  14. * @license http://opensource.org/licenses/MIT MIT License
  15. *
  16. * @api
  17. */
  18. class QueryManager implements QueryManagerInterface
  19. {
  20. /**
  21. * The factory to instantiate objects
  22. *
  23. * @var FactoryInterface
  24. */
  25. protected $factory;
  26. /**
  27. * @var ObjectManager
  28. */
  29. protected $objectManager;
  30. /**
  31. * Create the query manager - acquire through the session.
  32. *
  33. * @param FactoryInterface $factory the object factory
  34. * @param ObjectManager $objectManager
  35. */
  36. public function __construct(FactoryInterface $factory, ObjectManager $objectManager)
  37. {
  38. $this->factory = $factory;
  39. $this->objectManager = $objectManager;
  40. }
  41. /**
  42. * {@inheritDoc}
  43. *
  44. * @return QueryInterface a Query object
  45. *
  46. * @api
  47. */
  48. public function createQuery($statement, $language)
  49. {
  50. if (!in_array($language, $this->getSupportedQueryLanguages())) {
  51. throw new InvalidQueryException("Unsupported query language: $language");
  52. }
  53. switch ($language) {
  54. case QueryInterface::JCR_SQL2:
  55. return $this->factory->get(SqlQuery::class, [$statement, $this->objectManager]);
  56. case QueryInterface::XPATH:
  57. return $this->factory->get(XpathQuery::class, [$statement, $this->objectManager]);
  58. case QueryInterface::SQL:
  59. return $this->factory->get(Sql1Query::class, [$statement, $this->objectManager]);
  60. case QueryInterface::JCR_JQOM:
  61. throw new InvalidQueryException('Please use getQOMFactory to get the query object model factory. You can not build a QOM query from a string.');
  62. default:
  63. throw new InvalidQueryException("Transport supports this query language but jackalope not: $language");
  64. }
  65. }
  66. /**
  67. * {@inheritDoc}
  68. *
  69. * @return \PHPCR\Query\QOM\QueryObjectModelFactoryInterface a QueryObjectModelFactory object
  70. *
  71. * @api
  72. */
  73. public function getQOMFactory()
  74. {
  75. return $this->factory->get(QueryObjectModelFactory::class, [$this->objectManager]);
  76. }
  77. /**
  78. * {@inheritDoc}
  79. *
  80. * @return QueryInterface a Query object
  81. *
  82. * @api
  83. */
  84. public function getQuery($node)
  85. {
  86. throw new NotImplementedException();
  87. }
  88. /**
  89. * {@inheritDoc}
  90. *
  91. * @return string[]
  92. *
  93. * @api
  94. */
  95. public function getSupportedQueryLanguages()
  96. {
  97. // Workspace checks if transport implements QueryInterface
  98. return $this->objectManager->getTransport()->getSupportedQueryLanguages();
  99. }
  100. }