‪TYPO3CMS  10.4
PersistedAliasMapperLegacyTrait.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 
24 
26 {
30  protected $persistenceDelegate;
31 
36  protected function getPersistenceDelegate(): ‪PersistenceDelegate
37  {
38  if ($this->persistenceDelegate !== null) {
39  return $this->persistenceDelegate;
40  }
41  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
42  ->getQueryBuilderForTable($this->tableName)
43  ->from($this->tableName);
44  // @todo Restrictions (Hidden? Workspace?)
45 
46  $resolveModifier = function (‪QueryBuilder $queryBuilder, array $values) {
47  return $queryBuilder->‪select(...$this->persistenceFieldNames)->‪where(
48  ...$this->createFieldConstraints($queryBuilder, $values)
49  );
50  };
51  $generateModifier = function (‪QueryBuilder $queryBuilder, array $values) {
52  return $queryBuilder->‪select(...$this->persistenceFieldNames)->‪where(
53  ...$this->createFieldConstraints($queryBuilder, $values)
54  );
55  };
56 
57  return $this->persistenceDelegate = new ‪PersistenceDelegate(
58  $queryBuilder,
59  $resolveModifier,
60  $generateModifier
61  );
62  }
63 
70  protected function createFieldConstraints(‪QueryBuilder $queryBuilder, array $values): array
71  {
72  $constraints = [];
73  foreach ($values as $fieldName => $fieldValue) {
74  $constraints[] = $queryBuilder->‪expr()->‪eq(
75  $fieldName,
76  $queryBuilder->‪createNamedParameter(
77  $fieldValue,
78  \PDO::PARAM_STR
79  )
80  );
81  }
82  return $constraints;
83  }
84 }
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\select
‪QueryBuilder select(string ... $selects)
Definition: QueryBuilder.php:416
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\eq
‪string eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:109
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\createNamedParameter
‪string createNamedParameter($value, int $type=\PDO::PARAM_STR, string $placeHolder=null)
Definition: QueryBuilder.php:941
‪TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait
Definition: PersistedAliasMapperLegacyTrait.php:26
‪TYPO3\CMS\Core\Routing\Aspect\PersistenceDelegate
Definition: PersistenceDelegate.php:29
‪TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\$persistenceDelegate
‪PersistenceDelegate $persistenceDelegate
Definition: PersistedAliasMapperLegacyTrait.php:29
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:52
‪TYPO3\CMS\Core\Routing\Legacy
Definition: PersistedAliasMapperLegacyTrait.php:18
‪TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\getPersistenceDelegate
‪PersistenceDelegate getPersistenceDelegate()
Definition: PersistedAliasMapperLegacyTrait.php:35
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\where
‪QueryBuilder where(... $predicates)
Definition: QueryBuilder.php:677
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\expr
‪ExpressionBuilder expr()
Definition: QueryBuilder.php:151
‪TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\createFieldConstraints
‪array createFieldConstraints(QueryBuilder $queryBuilder, array $values)
Definition: PersistedAliasMapperLegacyTrait.php:69