TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
CompositeExpression.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\Database\Query\Expression;
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
22 class CompositeExpression extends \Doctrine\DBAL\Query\Expression\CompositeExpression
23 {
31  public function __toString()
32  {
33  if ($this->count() === 0) {
34  return '';
35  }
36  return parent::__toString();
37  }
38 
46  public function add($part)
47  {
48  // Due to a bug in Doctrine DBAL, we must add our own check here,
49  // which we luckily can, as we use a subclass anyway.
50  // @see https://github.com/doctrine/dbal/issues/2388
51  $isEmpty = $part instanceof self ? $part->count() === 0 : empty($part);
52  if (!$isEmpty) {
53  parent::add($part);
54  }
55 
56  return $this;
57  }
58 }