1: <?php
2:
3: namespace Alchemy\core\query;
4:
5: 6: 7:
8: class Predicate extends Expression {
9:
10: 11: 12: 13: 14:
15: public function not() {
16: return new Predicate('not', array($this));
17: }
18:
19:
20: 21: 22: 23: 24: 25: 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: