MediaWiki master
ExpressionGroup.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use InvalidArgumentException;
7
13abstract class ExpressionGroup implements IExpression {
17 protected array $children = [];
18
22 public function __construct( IExpression ...$children ) {
23 $this->children = $children;
24 }
25
26 final protected function add( IExpression $expression ) {
27 $this->children[] = $expression;
28 }
29
30 abstract protected function getType(): string;
31
37 final public function toSql( DbQuoter $dbQuoter ): string {
38 if ( !$this->children ) {
39 throw new InvalidArgumentException( "The array of values can't be empty." );
40 }
41 $sqls = array_map( static fn ( $value ) => $value->toSql( $dbQuoter ), $this->children );
42 return '(' . implode( ' ' . $this->getType() . ' ', $sqls ) . ')';
43 }
44
45 final public function toGeneralizedSql(): string {
46 if ( !$this->children ) {
47 throw new InvalidArgumentException( "The array of values can't be empty." );
48 }
49 $sqls = array_map( static fn ( $value ) => $value->toGeneralizedSql(), $this->children );
50 return '(' . implode( ' ' . $this->getType() . ' ', $sqls ) . ')';
51 }
52}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
A composite node representing a group of expressions.
add(IExpression $expression)
__construct(IExpression ... $children)
toGeneralizedSql()
Return SQL for aggregated logging.