‪TYPO3CMS  ‪main
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 
73  public function ‪addForTables(QueryRestrictionInterface $restriction, array $tableAliases): QueryRestrictionContainerInterface
74  {
75  $this->applicableTableAliases[get_class($restriction)] = $tableAliases;
76  return $this->‪add($restriction);
77  }
78 
86  public function ‪buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
87  {
88  $constraints = [];
89  foreach ($this->restrictions as ‪$name => $restriction) {
90  $constraints[] = $restriction->buildExpression(
91  $this->‪filterApplicableTableAliases($queriedTables, ‪$name),
92  $expressionBuilder
93  );
94  }
95  return $expressionBuilder->and(...$constraints);
96  }
97 
98  private function ‪filterApplicableTableAliases(array $queriedTables, string ‪$name): array
99  {
100  if (!isset($this->applicableTableAliases[‪$name])) {
101  return $queriedTables;
102  }
103 
104  $filteredTables = [];
105  foreach ($this->applicableTableAliases[‪$name] as $tableAlias) {
106  if (isset($queriedTables[$tableAlias])) {
107  $filteredTables[$tableAlias] = $queriedTables[$tableAlias];
108  }
109  }
110 
111  return $filteredTables;
112  }
113 }
‪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:40
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: LimitToTablesRestrictionContainer.php:83
‪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\LimitToTablesRestrictionContainer\addForTables
‪addForTables(QueryRestrictionInterface $restriction, array $tableAliases)
Definition: LimitToTablesRestrictionContainer.php:70
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface\removeByType
‪QueryRestrictionContainerInterface removeByType(string $restrictionType)
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:27
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:18
‪$name
‪$name
Definition: phpIntegrityChecker.php:235
‪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:95
‪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\LimitToTablesRestrictionContainer\$applicableTableAliases
‪array $applicableTableAliases
Definition: LimitToTablesRestrictionContainer.php:39
‪TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\$restrictionContainer
‪QueryRestrictionContainerInterface[] $restrictionContainer
Definition: LimitToTablesRestrictionContainer.php:35