TYPO3 CMS  TYPO3_8-7
AbstractRestrictionContainer.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
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 
35  protected $enforcedRestrictions = [];
36 
45  public function buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
46  {
47  $constraints = [];
48  foreach ($this->restrictions as $restriction) {
49  $constraints[] = $restriction->buildExpression($queriedTables, $expressionBuilder);
50  }
51  return $expressionBuilder->andX(...$constraints);
52  }
53 
59  public function removeAll()
60  {
61  $this->restrictions = $this->enforcedRestrictions;
62  return $this;
63  }
64 
71  public function removeByType(string $restrictionType)
72  {
73  unset($this->restrictions[$restrictionType], $this->enforcedRestrictions[$restrictionType]);
74  return $this;
75  }
76 
83  public function add(QueryRestrictionInterface $restriction)
84  {
85  $this->restrictions[get_class($restriction)] = $restriction;
86  if ($restriction instanceof EnforceableQueryRestrictionInterface && $restriction->isEnforced()) {
87  $this->enforcedRestrictions[get_class($restriction)] = $restriction;
88  }
89  return $this;
90  }
91 
99  protected function createRestriction($restrictionClass)
100  {
101  return GeneralUtility::makeInstance($restrictionClass);
102  }
103 }
static makeInstance($className,... $constructorArguments)
buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)