‪TYPO3CMS  9.5
PersistedAliasMapperLegacyTrait.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(...$this->persistenceFieldNames)->‪where(
34  ...$this->createFieldConstraints($queryBuilder, $values)
35  );
36  };
37  $generateModifier = function (‪QueryBuilder $queryBuilder, array $values) {
38  return $queryBuilder->‪select(...$this->persistenceFieldNames)->‪where(
39  ...$this->createFieldConstraints($queryBuilder, $values)
40  );
41  };
42 
43  return $this->persistenceDelegate = new ‪PersistenceDelegate(
44  $queryBuilder,
45  $resolveModifier,
46  $generateModifier
47  );
48  }
49 
56  protected function createFieldConstraints(‪QueryBuilder $queryBuilder, array $values): array
57  {
58  $constraints = [];
59  foreach ($values as $fieldName => $fieldValue) {
60  $constraints[] = $queryBuilder->‪expr()->‪eq(
61  $fieldName,
62  $queryBuilder->‪createNamedParameter(
63  $fieldValue,
64  \PDO::PARAM_STR
65  )
66  );
67  }
68  return $constraints;
69  }
70 }
‪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\Legacy\PersistedAliasMapperLegacyTrait
Definition: PersistedAliasMapperLegacyTrait.php:12
‪TYPO3\CMS\Core\Routing\Aspect\PersistenceDelegate
Definition: PersistenceDelegate.php:28
‪TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\$persistenceDelegate
‪PersistenceDelegate $persistenceDelegate
Definition: PersistedAliasMapperLegacyTrait.php:15
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:47
‪TYPO3\CMS\Core\Routing\Legacy
Definition: PersistedAliasMapperLegacyTrait.php:4
‪TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\getPersistenceDelegate
‪PersistenceDelegate getPersistenceDelegate()
Definition: PersistedAliasMapperLegacyTrait.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\PersistedAliasMapperLegacyTrait\createFieldConstraints
‪array createFieldConstraints(QueryBuilder $queryBuilder, array $values)
Definition: PersistedAliasMapperLegacyTrait.php:55