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

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 $factoryObjectManager $objectManager)
  37.     {
  38.         $this->factory $factory;
  39.         $this->objectManager $objectManager;
  40.     }
  41.     /**
  42.      * {@inheritDoc}
  43.      *
  44.      * @api
  45.      */
  46.     public function createQuery($statement$language)
  47.     {
  48.         if (!in_array($language$this->getSupportedQueryLanguages())) {
  49.             throw new InvalidQueryException("Unsupported query language: $language");
  50.         }
  51.         switch ($language) {
  52.             case QueryInterface::JCR_SQL2:
  53.                 return $this->factory->get(SqlQuery::class, [$statement$this->objectManager]);
  54.             case QueryInterface::XPATH:
  55.                 return $this->factory->get(XpathQuery::class, [$statement$this->objectManager]);
  56.             case QueryInterface::SQL:
  57.                 return $this->factory->get(Sql1Query::class, [$statement$this->objectManager]);
  58.             case QueryInterface::JCR_JQOM:
  59.                 throw new InvalidQueryException('Please use getQOMFactory to get the query object model factory. You can not build a QOM query from a string.');
  60.             default:
  61.                 throw new InvalidQueryException("Transport supports this query language but jackalope not: $language");
  62.         }
  63.     }
  64.     /**
  65.      * {@inheritDoc}
  66.      *
  67.      * @api
  68.      */
  69.     public function getQOMFactory()
  70.     {
  71.         return $this->factory->get(QueryObjectModelFactory::class, [$this->objectManager]);
  72.     }
  73.     /**
  74.      * {@inheritDoc}
  75.      *
  76.      * @api
  77.      */
  78.     public function getQuery($node)
  79.     {
  80.         throw new NotImplementedException();
  81.     }
  82.     /**
  83.      * {@inheritDoc}
  84.      *
  85.      * @api
  86.      */
  87.     public function getSupportedQueryLanguages()
  88.     {
  89.         // Workspace checks if transport implements QueryInterface
  90.         return $this->objectManager->getTransport()->getSupportedQueryLanguages();
  91.     }
  92. }