MediaWiki 1.42.1
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
23 public function __construct( IExpression ...$children ) {
24 $this->children = $children;
25 }
26
27 final protected function add( IExpression $expression ) {
28 $this->children[] = $expression;
29 }
30
31 abstract protected function getType(): string;
32
38 final public function toSql( DbQuoter $dbQuoter ): string {
39 if ( !$this->children ) {
40 throw new InvalidArgumentException( "The array of values can't be empty." );
41 }
42 $sqls = array_map( static fn ( $value ) => $value->toSql( $dbQuoter ), $this->children );
43 return '(' . implode( ' ' . $this->getType() . ' ', $sqls ) . ')';
44 }
45
46 final public function toGeneralizedSql(): string {
47 if ( !$this->children ) {
48 throw new InvalidArgumentException( "The array of values can't be empty." );
49 }
50 $sqls = array_map( static fn ( $value ) => $value->toGeneralizedSql(), $this->children );
51 return '(' . implode( ' ' . $this->getType() . ' ', $sqls ) . ')';
52 }
53}
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.