‪TYPO3CMS  10.4
AbstractRestrictionContainer.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
23 
28 {
32  protected ‪$restrictions = [];
33 
37  protected ‪$enforcedRestrictions = [];
38 
47  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
48  {
49  $constraints = [];
50  foreach ($this->restrictions as $restriction) {
51  $constraints[] = $restriction->buildExpression($queriedTables, $expressionBuilder);
52  }
53  return $expressionBuilder->‪andX(...$constraints);
54  }
55 
62  {
63  $this->restrictions = ‪$this->enforcedRestrictions;
64  return $this;
65  }
66 
73  public function ‪removeByType(string $restrictionType): ‪QueryRestrictionContainerInterface
74  {
75  unset($this->restrictions[$restrictionType], $this->enforcedRestrictions[$restrictionType]);
76  return $this;
77  }
78 
86  {
87  $this->restrictions[get_class($restriction)] = $restriction;
88  if ($restriction instanceof ‪EnforceableQueryRestrictionInterface && $restriction->isEnforced()) {
89  $this->enforcedRestrictions[get_class($restriction)] = $restriction;
90  }
91  return $this;
92  }
93 
101  protected function ‪createRestriction($restrictionClass): ‪QueryRestrictionInterface
102  {
103  return GeneralUtility::makeInstance($restrictionClass);
104  }
105 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:35
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: AbstractRestrictionContainer.php:45
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:27
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\removeByType
‪QueryRestrictionContainerInterface removeByType(string $restrictionType)
Definition: AbstractRestrictionContainer.php:71
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\createRestriction
‪QueryRestrictionInterface createRestriction($restrictionClass)
Definition: AbstractRestrictionContainer.php:99
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface
Definition: QueryRestrictionContainerInterface.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\$enforcedRestrictions
‪QueryRestrictionInterface[] $enforcedRestrictions
Definition: AbstractRestrictionContainer.php:35
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\removeAll
‪QueryRestrictionContainerInterface removeAll()
Definition: AbstractRestrictionContainer.php:59
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\add
‪QueryRestrictionContainerInterface add(QueryRestrictionInterface $restriction)
Definition: AbstractRestrictionContainer.php:83
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\$restrictions
‪QueryRestrictionInterface[] $restrictions
Definition: AbstractRestrictionContainer.php:31
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:25
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\andX
‪CompositeExpression andX(... $expressions)
Definition: ExpressionBuilder.php:70
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:18
‪TYPO3\CMS\Core\Database\Query\Restriction\EnforceableQueryRestrictionInterface
Definition: EnforceableQueryRestrictionInterface.php:27
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer
Definition: AbstractRestrictionContainer.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46