TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AbstractRestrictionContainer.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\Database\Query\Restriction;
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 
21 
26 {
30  protected $restrictions = [];
31 
40  public function buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
41  {
42  $constraints = [];
43  foreach ($this->restrictions as $restriction) {
44  $constraints[] = $restriction->buildExpression($queriedTables, $expressionBuilder);
45  }
46  return $expressionBuilder->andX(...$constraints);
47  }
48 
54  public function removeAll()
55  {
56  $this->restrictions = [];
57  return $this;
58  }
59 
66  public function removeByType(string $restrictionType)
67  {
68  unset($this->restrictions[$restrictionType]);
69  return $this;
70  }
71 
78  public function add(QueryRestrictionInterface $restriction)
79  {
80  $this->restrictions[get_class($restriction)] = $restriction;
81  return $this;
82  }
83 
91  protected function createRestriction($restrictionClass)
92  {
93  return GeneralUtility::makeInstance($restrictionClass);
94  }
95 }
buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
static makeInstance($className,...$constructorArguments)