1<?php 2 3namespace Doctrine\Common\Collections\Expr; 4 5use RuntimeException; 6 7/** 8 * Expression of Expressions combined by AND or OR operation. 9 */ 10class CompositeExpression implements Expression 11{ 12 public const TYPE_AND = 'AND'; 13 public const TYPE_OR = 'OR'; 14 15 /** @var string */ 16 private $type; 17 18 /** @var Expression[] */ 19 private $expressions = []; 20 21 /** 22 * @param string $type 23 * @param array $expressions 24 * 25 * @throws RuntimeException 26 */ 27 public function __construct($type, array $expressions) 28 { 29 $this->type = $type; 30 31 foreach ($expressions as $expr) { 32 if ($expr instanceof Value) { 33 throw new RuntimeException('Values are not supported expressions as children of and/or expressions.'); 34 } 35 if (! ($expr instanceof Expression)) { 36 throw new RuntimeException('No expression given to CompositeExpression.'); 37 } 38 39 $this->expressions[] = $expr; 40 } 41 } 42 43 /** 44 * Returns the list of expressions nested in this composite. 45 * 46 * @return Expression[] 47 */ 48 public function getExpressionList() 49 { 50 return $this->expressions; 51 } 52 53 /** 54 * @return string 55 */ 56 public function getType() 57 { 58 return $this->type; 59 } 60 61 /** 62 * {@inheritDoc} 63 */ 64 public function visit(ExpressionVisitor $visitor) 65 { 66 return $visitor->walkCompositeExpression($this); 67 } 68} 69