Overview

Namespaces

  • Alchemy
    • core
      • query
      • schema
    • dialect
    • engine
    • orm
    • tests
    • util
      • promise
  • PHP

Classes

  • ColumnRef
  • DDLQuery
  • Expression
  • Insert
  • Join
  • Predicate
  • Query
  • Scalar
  • TableRef

Interfaces

  • IQuery
  • IQueryFragment
  • IQueryValue
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace Alchemy\core\query;
 4: 
 5: /**
 6:  * Represents a true/false logical predicate
 7:  */
 8: class Predicate extends Expression {
 9: 
10:     /**
11:      * Return a negation of this Predicate like ->isNull()->not()
12:      *
13:      * @return Predicate::not
14:      */
15:     public function not() {
16:         return new Predicate('not', array($this));
17:     }
18: 
19: 
20:     /**
21:      * Return an AND-merge of all predicates given as arguments or arrays
22:      *
23:      * @param  Predicate $expr a Predicate or array of Predicates to include
24:      *                         ...
25:      * @return Predicate::AND
26:      */
27:     public static function all() {
28:         $elements = self::flatten(func_get_args());
29:         return count($elements) == 1 ? $elements[0] : new Predicate('and', $elements);
30:     }
31: 
32: 
33:     protected static function flatten(array $args) {
34:         $elements = array();
35: 
36:         foreach($args as $arg) {
37:             $new = array();
38: 
39:             if (is_array($arg)) {
40:                 $new = self::flatten($arg);
41:             } elseif ($arg instanceof Predicate) {
42:                 $new = ($arg->getType() == 'and') ? self::flatten($arg->elements()) : array($arg);
43:             }
44: 
45:             $elements = array_merge($elements, $new);
46:         }
47: 
48:         return $elements;
49:     }
50: }
51: 
API documentation generated by ApiGen 2.8.0