‪TYPO3CMS  9.5
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 
60  {
61  $this->restrictions = ‪$this->enforcedRestrictions;
62  return $this;
63  }
64 
71  public function ‪removeByType(string $restrictionType): ‪QueryRestrictionContainerInterface
72  {
73  unset($this->restrictions[$restrictionType], $this->enforcedRestrictions[$restrictionType]);
74  return $this;
75  }
76 
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): ‪QueryRestrictionInterface
100  {
101  return GeneralUtility::makeInstance($restrictionClass);
102  }
103 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:33
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: AbstractRestrictionContainer.php:43
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\removeByType
‪QueryRestrictionContainerInterface removeByType(string $restrictionType)
Definition: AbstractRestrictionContainer.php:69
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\createRestriction
‪QueryRestrictionInterface createRestriction($restrictionClass)
Definition: AbstractRestrictionContainer.php:97
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface
Definition: QueryRestrictionContainerInterface.php:23
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\$enforcedRestrictions
‪QueryRestrictionInterface[] $enforcedRestrictions
Definition: AbstractRestrictionContainer.php:33
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\removeAll
‪QueryRestrictionContainerInterface removeAll()
Definition: AbstractRestrictionContainer.php:57
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\add
‪QueryRestrictionContainerInterface add(QueryRestrictionInterface $restriction)
Definition: AbstractRestrictionContainer.php:81
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\$restrictions
‪QueryRestrictionInterface[] $restrictions
Definition: AbstractRestrictionContainer.php:29
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:23
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\andX
‪CompositeExpression andX(... $expressions)
Definition: ExpressionBuilder.php:68
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:3
‪TYPO3\CMS\Core\Database\Query\Restriction\EnforceableQueryRestrictionInterface
Definition: EnforceableQueryRestrictionInterface.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer
Definition: AbstractRestrictionContainer.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45