‪TYPO3CMS  10.4
LimitToTablesRestrictionContainer.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 
22 
28 {
32  private ‪$restrictions = [];
33 
37  private ‪$restrictionContainer = [];
38 
43 
45  {
46  $this->applicableTableAliases = $this->restrictions = $this->restrictionContainer = [];
47  return $this;
48  }
49 
50  public function ‪removeByType(string $restrictionType): ‪QueryRestrictionContainerInterface
51  {
52  unset($this->applicableTableAliases[$restrictionType], $this->restrictions[$restrictionType]);
53  foreach ($this->restrictionContainer as ‪$restrictionContainer) {
54  ‪$restrictionContainer->‪removeByType($restrictionType);
55  }
56  return $this;
57  }
58 
60  {
61  $this->restrictions[get_class($restriction)] = $restriction;
62  if ($restriction instanceof ‪QueryRestrictionContainerInterface) {
63  $this->restrictionContainer[get_class($restriction)] = $restriction;
64  }
65  return $this;
66  }
67 
75  public function ‪addForTables(QueryRestrictionInterface $restriction, array $tableAliases): QueryRestrictionContainerInterface
76  {
77  $this->applicableTableAliases[get_class($restriction)] = $tableAliases;
78  return $this->‪add($restriction);
79  }
80 
88  public function ‪buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
89  {
90  $constraints = [];
91  foreach ($this->restrictions as $name => $restriction) {
92  $constraints[] = $restriction->buildExpression(
93  $this->‪filterApplicableTableAliases($queriedTables, $name),
94  $expressionBuilder
95  );
96  }
97  return $expressionBuilder->andX(...$constraints);
98  }
99 
100  private function ‪filterApplicableTableAliases(array $queriedTables, string $name): array
101  {
102  if (!isset($this->applicableTableAliases[$name])) {
103  return $queriedTables;
104  }
105 
106  $filteredTables = [];
107  foreach ($this->applicableTableAliases[$name] as $tableAlias) {
108  if (isset($queriedTables[$tableAlias])) {
109  $filteredTables[$tableAlias] = $queriedTables[$tableAlias];
110  }
111  }
112 
113  return $filteredTables;
114  }
115 }
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer
Definition: LimitToTablesRestrictionContainer.php:28
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\removeAll
‪removeAll()
Definition: LimitToTablesRestrictionContainer.php:41
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:35
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: LimitToTablesRestrictionContainer.php:85
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:27
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\removeByType
‪removeByType(string $restrictionType)
Definition: LimitToTablesRestrictionContainer.php:47
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\add
‪add(QueryRestrictionInterface $restriction)
Definition: LimitToTablesRestrictionContainer.php:56
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface
Definition: QueryRestrictionContainerInterface.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface\removeByType
‪QueryRestrictionContainerInterface removeByType(string $restrictionType)
‪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\LimitToTablesRestrictionContainer\$restrictions
‪QueryRestrictionInterface[] $restrictions
Definition: LimitToTablesRestrictionContainer.php:31
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\filterApplicableTableAliases
‪filterApplicableTableAliases(array $queriedTables, string $name)
Definition: LimitToTablesRestrictionContainer.php:97
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\addForTables
‪QueryRestrictionContainerInterface addForTables(QueryRestrictionInterface $restriction, array $tableAliases)
Definition: LimitToTablesRestrictionContainer.php:72
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\$applicableTableAliases
‪array $applicableTableAliases
Definition: LimitToTablesRestrictionContainer.php:39
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\$restrictionContainer
‪QueryRestrictionContainerInterface[] $restrictionContainer
Definition: LimitToTablesRestrictionContainer.php:35