示例#1
0
 /**
  * Create a query tree containing this filter
  *
  * Query parts that couldn't be parsed can be retrieved with Filter::getIgnoredQueryParts
  *
  * @param  String $query    The query string to parse into a query tree
  * @return Tree             The resulting query tree (empty for invalid queries)
  */
 public function createQueryTreeForFilter($query)
 {
     $this->ignoredQueryParts = array();
     $right = $query;
     $domain = null;
     $tree = new Tree();
     do {
         list($left, $conjunction, $right) = $this->splitQueryAtNextConjunction($right);
         $domain = $this->getFirstDomainForQuery($left);
         if ($domain === null) {
             $this->ignoredQueryParts[] = $left;
             continue;
         }
         $node = $domain->convertToTreeNode($left);
         if (!$node) {
             $this->ignoredQueryParts[] = $left;
             continue;
         }
         $tree->insert($node);
         if ($conjunction === 'AND') {
             $tree->insert(Node::createAndNode());
         } elseif ($conjunction === 'OR') {
             $tree->insert(Node::createOrNode());
         }
     } while ($right !== null);
     return $tree;
 }
示例#2
0
 /**
  * Add an lower priority filter expression to be applied on this query
  *
  * The syntax of the expression and valid parameters are to be defined by the concrete
  * backend-specific query implementation.
  *
  * @param string $expression    Implementation specific search expression
  * @param mixed $parameters    Implementation specific search value to use for query placeholders
  * @return self                 Fluent interface
  */
 public function orWhere($expression, $parameters = null)
 {
     $node = $this->parseFilterExpression($expression, $parameters);
     if ($node === null) {
         Logger::debug('Ignoring invalid filter expression: %s (params: %s)', $expression, $parameters);
         return $this;
     }
     $this->filter->insert(Node::createOrNode());
     $this->filter->insert($node);
     return $this;
 }
示例#3
0
 /**
  * Copy the given node or branch into the given tree
  *
  * @param Node $node        The node to copy
  * @param Tree $tree        The tree to insert the copied node and it's subnodes to
  */
 private function copyBranch(Node $node, Tree &$tree)
 {
     if ($node->type === Node::TYPE_OPERATOR) {
         $copy = Node::createOperatorNode($node->operator, $node->left, $node->right);
         $copy->context = $node->context;
         $tree->insert($copy);
     } else {
         if ($node->left) {
             $this->copyBranch($node->left, $tree);
         }
         $tree->insert($node->type === Node::TYPE_OR ? Node::createOrNode() : Node::createAndNode());
         if ($node->right) {
             $this->copyBranch($node->right, $tree);
         }
     }
 }