vendor/jackalope/jackalope/src/Jackalope/Query/QOM/QueryObjectModel.php line 29

Open in your IDE?
  1. <?php
  2. namespace Jackalope\Query\QOM;
  3. use InvalidArgumentException;
  4. use PHPCR\Query\QOM\QueryObjectModelInterface;
  5. use PHPCR\Query\QOM\SourceInterface;
  6. use PHPCR\Query\QOM\ConstraintInterface;
  7. use PHPCR\Query\QOM\OrderingInterface;
  8. use PHPCR\Query\QOM\ColumnInterface;
  9. use PHPCR\Util\QOM\Sql2Generator;
  10. use PHPCR\Util\QOM\QomToSql2QueryConverter;
  11. use Jackalope\ObjectManager;
  12. use Jackalope\Query\SqlQuery;
  13. use Jackalope\FactoryInterface;
  14. use Jackalope\NotImplementedException;
  15. use PHPCR\Util\ValueConverter;
  16. /**
  17.  * {@inheritDoc}
  18.  *
  19.  * We extend SqlQuery to have features like limit and offset.
  20.  *
  21.  * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
  22.  * @license http://opensource.org/licenses/MIT MIT License
  23.  *
  24.  * @api
  25.  */
  26. class QueryObjectModel extends SqlQuery implements QueryObjectModelInterface
  27. {
  28.     /**
  29.      * @var SourceInterface
  30.      */
  31.     protected $source;
  32.     /**
  33.      * @var ConstraintInterface
  34.      */
  35.     protected $constraint;
  36.     /**
  37.      * @var array
  38.      */
  39.     protected $orderings;
  40.     /**
  41.      * @var array
  42.      */
  43.     protected $columns;
  44.     /**
  45.      * Constructor
  46.      *
  47.      * @param FactoryInterface $factory the object factory
  48.      * @param ObjectManager $objectManager (can be omitted if you do not want
  49.      *      to execute the query but just use it with a parser)
  50.      * @param SourceInterface $source
  51.      * @param ConstraintInterface $constraint
  52.      * @param array $orderings
  53.      * @param array $columns
  54.      *
  55.      * @throws InvalidArgumentException
  56.      */
  57.     public function __construct(
  58.         FactoryInterface $factory,
  59.         ObjectManager $objectManager null,
  60.         SourceInterface $source,
  61.         ConstraintInterface $constraint null,
  62.         array $orderings,
  63.         array $columns
  64.     ) {
  65.         foreach ($orderings as $o) {
  66.             if (! $o instanceof OrderingInterface) {
  67.                 throw new InvalidArgumentException("Not a valid ordering: $o");
  68.             }
  69.         }
  70.         foreach ($columns as $c) {
  71.             if (! $c instanceof ColumnInterface) {
  72.                 throw new InvalidArgumentException("Not a valid column: $c");
  73.             }
  74.         }
  75.         parent::__construct($factory''$objectManager);
  76.         $this->source $source;
  77.         $this->constraint $constraint;
  78.         $this->orderings $orderings;
  79.         $this->columns $columns;
  80.     }
  81.     /**
  82.      * {@inheritDoc}
  83.      *
  84.      * @api
  85.      */
  86.     public function getSource()
  87.     {
  88.         return $this->source;
  89.     }
  90.     /**
  91.      * {@inheritDoc}
  92.      *
  93.      * @api
  94.      */
  95.     public function getConstraint()
  96.     {
  97.         return $this->constraint;
  98.     }
  99.     /**
  100.      * {@inheritDoc}
  101.      *
  102.      * @api
  103.      */
  104.     public function getOrderings()
  105.     {
  106.         return $this->orderings;
  107.     }
  108.     /**
  109.      * {@inheritDoc}
  110.      *
  111.      * @api
  112.      */
  113.     public function getColumns()
  114.     {
  115.         return $this->columns;
  116.     }
  117.     /**
  118.      * {@inheritDoc}
  119.      *
  120.      * @api
  121.      */
  122.     public function getBindVariableNames()
  123.     {
  124.         // TODO: can we inherit from SqlQuery?
  125.         throw new NotImplementedException();
  126.     }
  127.     /**
  128.      * {@inheritDoc}
  129.      *
  130.      * @api
  131.      */
  132.     public function getStatement()
  133.     {
  134.         $valueConverter $this->factory->get(ValueConverter::class);
  135.         $converter = new QomToSql2QueryConverter(new Sql2Generator($valueConverter));
  136.         return $converter->convert($this);
  137.     }
  138.     /**
  139.      * {@inheritDoc}
  140.      *
  141.      * @api
  142.      */
  143.     public function getLanguage()
  144.     {
  145.         return self::JCR_SQL2;
  146.     }
  147. }