コード例 #1
0
 /**
  * Parses a non-bracketed expression
  *
  * Returns a ClauseGroup for a multi-part expression, or returns a string for an
  * expression containing just one (<col> <test> <value>) part
  */
 private function parse($clause)
 {
     // If the input string is essentially empty then return null
     if (trim($clause) == '') {
         return null;
     }
     // Ensure that ANDs and ORs are not mixed
     $strAnd = ClauseGroup::BOOLEAN_AND;
     $strOr = ClauseGroup::BOOLEAN_OR;
     $boolAnd = strpos($clause, " {$strAnd} ") !== false;
     $boolOr = strpos($clause, " {$strOr} ") !== false;
     if ($boolAnd && $boolOr) {
         throw new SyntaxError("Need to bracket ANDs and ORs to indicate precedence in clause <{$clause}>");
     }
     if ($boolOr) {
         $split = $strOr;
     } elseif ($boolAnd) {
         $split = $strAnd;
     } else {
         $split = null;
     }
     // If applicable, split the clause into subclauses and decide the type
     if ($split) {
         $subClauses = explode(" {$split} ", $clause);
     } else {
         $subClauses = array($clause);
     }
     $group = new ClauseGroup();
     $group->setType($split);
     // Then add all the subclauses in
     foreach ($subClauses as $subClause) {
         if (trim($subClause) != '') {
             QuotedStringParser::insertStrings($subClause, $this->strings);
             $group->addSubclause($subClause);
         }
     }
     // If there is only one subclause, return a string rather than a ClauseGroup
     /*
     		$subClauseArray = $group->getSubclauses();
     		if (count($subClauseArray) == 1)
     		{
     			return $subClauseArray[0];
     		}
     		else
     		{
     			return $group;
     		}*/
     return $group;
 }