‪TYPO3CMS  ‪main
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->‪and(...$constraints);
54  }
55 
60  {
61  $this->restrictions = ‪$this->enforcedRestrictions;
62  return $this;
63  }
64 
70  public function ‪removeByType(string $restrictionType): ‪QueryRestrictionContainerInterface
71  {
72  foreach ($this->restrictions as $type => $instance) {
73  if ($instance instanceof $restrictionType) {
74  unset($this->restrictions[$type]);
75  break;
76  }
77  }
78 
79  foreach ($this->enforcedRestrictions as $type => $instance) {
80  if ($instance instanceof $restrictionType) {
81  unset($this->enforcedRestrictions[$type]);
82  break;
83  }
84  }
85 
86  return $this;
87  }
88 
93  {
94  $this->restrictions[get_class($restriction)] = $restriction;
95  if ($restriction instanceof ‪EnforceableQueryRestrictionInterface && $restriction->isEnforced()) {
96  $this->enforcedRestrictions[get_class($restriction)] = $restriction;
97  }
98  return $this;
99  }
100 
107  protected function ‪createRestriction($restrictionClass): ‪QueryRestrictionInterface
108  {
109  return GeneralUtility::makeInstance($restrictionClass);
110  }
111 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:40
‪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\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\$restrictions
‪QueryRestrictionInterface[] $restrictions
Definition: AbstractRestrictionContainer.php:31
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\createRestriction
‪createRestriction($restrictionClass)
Definition: AbstractRestrictionContainer.php:105
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:27
‪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\Database\Query\Expression\ExpressionBuilder\and
‪and(CompositeExpression|\Doctrine\DBAL\Query\Expression\CompositeExpression|string|null ... $expressions,)
Definition: ExpressionBuilder.php:50
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\add
‪add(QueryRestrictionInterface $restriction)
Definition: AbstractRestrictionContainer.php:90
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\removeByType
‪removeByType(string $restrictionType)
Definition: AbstractRestrictionContainer.php:68
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\removeAll
‪removeAll()
Definition: AbstractRestrictionContainer.php:57