‪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  unset($this->restrictions[$restrictionType], $this->enforcedRestrictions[$restrictionType]);
73  return $this;
74  }
75 
80  {
81  $this->restrictions[get_class($restriction)] = $restriction;
82  if ($restriction instanceof ‪EnforceableQueryRestrictionInterface && $restriction->isEnforced()) {
83  $this->enforcedRestrictions[get_class($restriction)] = $restriction;
84  }
85  return $this;
86  }
87 
94  protected function ‪createRestriction($restrictionClass): ‪QueryRestrictionInterface
95  {
96  return GeneralUtility::makeInstance($restrictionClass);
97  }
98 }
‪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\Expression\ExpressionBuilder\and
‪and(CompositeExpression|string|null ... $expressions)
Definition: ExpressionBuilder.php:69
‪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:92
‪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\Restriction\AbstractRestrictionContainer\add
‪add(QueryRestrictionInterface $restriction)
Definition: AbstractRestrictionContainer.php:77
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\removeByType
‪removeByType(string $restrictionType)
Definition: AbstractRestrictionContainer.php:68
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\removeAll
‪removeAll()
Definition: AbstractRestrictionContainer.php:57