‪TYPO3CMS  9.5
PersistedPatternMapperLegacyTrait.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
10 
12 {
16  protected $persistenceDelegate;
17 
22  protected function getPersistenceDelegate(): ‪PersistenceDelegate
23  {
24  if ($this->persistenceDelegate !== null) {
25  return $this->persistenceDelegate;
26  }
27  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
28  ->getQueryBuilderForTable($this->tableName)
29  ->from($this->tableName);
30  // @todo Restrictions (Hidden? Workspace?)
31 
32  $resolveModifier = function (‪QueryBuilder $queryBuilder, array $values) {
33  return $queryBuilder->‪select('*')->‪where(
34  ...$this->createFieldConstraints($queryBuilder, $values, true)
35  );
36  };
37  $generateModifier = function (‪QueryBuilder $queryBuilder, array $values) {
38  return $queryBuilder->‪select('*')->‪where(
39  ...$this->createFieldConstraints($queryBuilder, $values)
40  );
41  };
42 
43  return $this->persistenceDelegate = new ‪PersistenceDelegate(
44  $queryBuilder,
45  $resolveModifier,
46  $generateModifier
47  );
48  }
49 
57  protected function createFieldConstraints(
58  ‪QueryBuilder $queryBuilder,
59  array $values,
60  bool $resolveExpansion = false
61  ): array {
62  $languageExpansion = $this->languageParentFieldName
63  && $resolveExpansion
64  && isset($values['uid']);
65 
66  $constraints = [];
67  foreach ($values as $fieldName => $fieldValue) {
68  if ($languageExpansion && $fieldName === 'uid') {
69  continue;
70  }
71  $constraints[] = $queryBuilder->‪expr()->‪eq(
72  $fieldName,
73  $queryBuilder->‪createNamedParameter(
74  $fieldValue,
75  \PDO::PARAM_STR
76  )
77  );
78  }
79  // If requested, either match uid or language parent field value
80  if ($languageExpansion) {
81  $idParameter = $queryBuilder->‪createNamedParameter(
82  $values['uid'],
83  \PDO::PARAM_INT
84  );
85  $constraints[] = $queryBuilder->‪expr()->‪orX(
86  $queryBuilder->‪expr()->‪eq('uid', $idParameter),
87  $queryBuilder->‪expr()->‪eq($this->languageParentFieldName, $idParameter)
88  );
89  }
90 
91  return $constraints;
92  }
93 }
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\select
‪QueryBuilder select(string ... $selects)
Definition: QueryBuilder.php:390
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\eq
‪string eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:107
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\createNamedParameter
‪string createNamedParameter($value, int $type=\PDO::PARAM_STR, string $placeHolder=null)
Definition: QueryBuilder.php:894
‪TYPO3\CMS\Core\Routing\Aspect\PersistenceDelegate
Definition: PersistenceDelegate.php:28
‪TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait
Definition: PersistedPatternMapperLegacyTrait.php:12
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:47
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:80
‪TYPO3\CMS\Core\Routing\Legacy
Definition: PersistedAliasMapperLegacyTrait.php:4
‪TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait\$persistenceDelegate
‪PersistenceDelegate $persistenceDelegate
Definition: PersistedPatternMapperLegacyTrait.php:15
‪TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait\getPersistenceDelegate
‪PersistenceDelegate getPersistenceDelegate()
Definition: PersistedPatternMapperLegacyTrait.php:21
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\where
‪QueryBuilder where(... $predicates)
Definition: QueryBuilder.php:630
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\expr
‪ExpressionBuilder expr()
Definition: QueryBuilder.php:125
‪TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait\createFieldConstraints
‪array createFieldConstraints(QueryBuilder $queryBuilder, array $values, bool $resolveExpansion=false)
Definition: PersistedPatternMapperLegacyTrait.php:56