Chris@0: . Chris@0: */ Chris@0: Chris@0: namespace Doctrine\Common\Collections\Expr; Chris@0: Chris@0: /** Chris@0: * Expression of Expressions combined by AND or OR operation. Chris@0: * Chris@0: * @author Benjamin Eberlei Chris@0: * @since 2.3 Chris@0: */ Chris@0: class CompositeExpression implements Expression Chris@0: { Chris@0: const TYPE_AND = 'AND'; Chris@0: const TYPE_OR = 'OR'; Chris@0: Chris@0: /** Chris@0: * @var string Chris@0: */ Chris@0: private $type; Chris@0: Chris@0: /** Chris@0: * @var Expression[] Chris@0: */ Chris@0: private $expressions = array(); Chris@0: Chris@0: /** Chris@0: * @param string $type Chris@0: * @param array $expressions Chris@0: * Chris@0: * @throws \RuntimeException Chris@0: */ Chris@0: public function __construct($type, array $expressions) Chris@0: { Chris@0: $this->type = $type; Chris@0: Chris@0: foreach ($expressions as $expr) { Chris@0: if ($expr instanceof Value) { Chris@0: throw new \RuntimeException("Values are not supported expressions as children of and/or expressions."); Chris@0: } Chris@0: if ( ! ($expr instanceof Expression)) { Chris@0: throw new \RuntimeException("No expression given to CompositeExpression."); Chris@0: } Chris@0: Chris@0: $this->expressions[] = $expr; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the list of expressions nested in this composite. Chris@0: * Chris@0: * @return Expression[] Chris@0: */ Chris@0: public function getExpressionList() Chris@0: { Chris@0: return $this->expressions; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function getType() Chris@0: { Chris@0: return $this->type; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritDoc} Chris@0: */ Chris@0: public function visit(ExpressionVisitor $visitor) Chris@0: { Chris@0: return $visitor->walkCompositeExpression($this); Chris@0: } Chris@0: }