‪TYPO3CMS  10.4
AbstractRepository.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
26 
31 {
35  protected ‪$table = '';
36 
40  protected ‪$factory;
41 
45  protected ‪$typeField = '';
46 
50  protected ‪$type = '';
51 
57  protected ‪$objectType;
58 
62  public function ‪__construct()
63  {
64  $this->factory = GeneralUtility::makeInstance(ResourceFactory::class);
65  }
66 
72  public function ‪add($object)
73  {
74  }
75 
81  public function remove($object)
82  {
83  }
84 
91  public function ‪replace($existingObject, $newObject)
92  {
93  }
94 
100  public function ‪update($modifiedObject)
101  {
102  }
103 
111  public function ‪getAddedObjects()
112  {
113  return [];
114  }
115 
123  public function ‪getRemovedObjects()
124  {
125  return [];
126  }
127 
133  public function ‪findAll()
134  {
135  $items = [];
136  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
137  if ($this->‪getEnvironmentMode() === 'FE') {
138  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
139  }
140  $queryBuilder
141  ->select('*')
142  ->from($this->table);
143 
144  if (!empty($this->type)) {
145  $queryBuilder->where(
146  $queryBuilder->expr()->eq(
147  $this->typeField,
148  $queryBuilder->createNamedParameter($this->type, \PDO::PARAM_STR)
149  )
150  );
151  }
152  $result = $queryBuilder->execute();
153 
154  // fetch all records and create objects out of them
155  while ($row = $result->fetch()) {
156  $items[] = $this->‪createDomainObject($row);
157  }
158  return $items;
159  }
160 
168  abstract protected function ‪createDomainObject(array $databaseRow);
169 
175  public function ‪countAll()
176  {
177  return 0;
178  }
179 
184  public function ‪removeAll()
185  {
186  }
187 
197  public function ‪findByUid($uid)
198  {
200  throw new \InvalidArgumentException('The UID has to be an integer. UID given: "' . $uid . '"', 1316779798);
201  }
202  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
203  if ($this->‪getEnvironmentMode() === 'FE') {
204  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
205  }
206  $row = $queryBuilder
207  ->select('*')
208  ->from($this->table)
209  ->where(
210  $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
211  )
212  ->execute()
213  ->fetch();
214  if (!is_array($row)) {
215  throw new \RuntimeException('Could not find row with UID "' . $uid . '" in table "' . $this->table . '"', 1314354065);
216  }
217  return $this->‪createDomainObject($row);
218  }
219 
232  public function ‪setDefaultOrderings(array $defaultOrderings)
233  {
234  throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1313185906);
235  }
236 
244  public function ‪setDefaultQuerySettings(QuerySettingsInterface $defaultQuerySettings)
245  {
246  throw new \BadMethodCallException('Repository does not support the setDefaultQuerySettings() method.', 1313185907);
247  }
248 
255  public function ‪createQuery()
256  {
257  throw new \BadMethodCallException('Repository does not support the createQuery() method.', 1313185908);
258  }
259 
266  public function ‪findByIdentifier($identifier)
267  {
268  return $this->‪findByUid($identifier);
269  }
270 
280  public function ‪__call($method, $arguments)
281  {
282  throw new \BadMethodCallException('Repository method "' . $method . '" is not implemented.', 1378918410);
283  }
284 
290  public function ‪getEntityClassName()
291  {
292  return ‪$this->objectType;
293  }
294 
301  protected function ‪getEnvironmentMode()
302  {
303  return (‪$GLOBALS['TSFE'] ?? null) instanceof TypoScriptFrontendController ? 'FE' : 'BE';
304  }
305 }
‪TYPO3\CMS\Core\Resource\AbstractRepository\findByIdentifier
‪object null findByIdentifier($identifier)
Definition: AbstractRepository.php:261
‪TYPO3\CMS\Core\Resource\AbstractRepository\setDefaultOrderings
‪setDefaultOrderings(array $defaultOrderings)
Definition: AbstractRepository.php:227
‪TYPO3\CMS\Core\Resource\AbstractRepository\getAddedObjects
‪array getAddedObjects()
Definition: AbstractRepository.php:106
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Core\Resource\AbstractRepository\$objectType
‪string $objectType
Definition: AbstractRepository.php:52
‪TYPO3\CMS\Core\Resource\AbstractRepository\update
‪update($modifiedObject)
Definition: AbstractRepository.php:95
‪TYPO3\CMS\Core\Resource\AbstractRepository\countAll
‪int countAll()
Definition: AbstractRepository.php:170
‪TYPO3\CMS\Core\Resource\AbstractRepository
Definition: AbstractRepository.php:31
‪TYPO3\CMS\Core\Resource\AbstractRepository\$typeField
‪string $typeField
Definition: AbstractRepository.php:42
‪TYPO3\CMS\Core\Resource\AbstractRepository\createQuery
‪TYPO3 CMS Extbase Persistence QueryInterface createQuery()
Definition: AbstractRepository.php:250
‪TYPO3\CMS\Core\Resource\AbstractRepository\$factory
‪ResourceFactory $factory
Definition: AbstractRepository.php:38
‪TYPO3\CMS\Core\Resource\AbstractRepository\__call
‪__call($method, $arguments)
Definition: AbstractRepository.php:275
‪TYPO3\CMS\Core\Resource\AbstractRepository\add
‪add($object)
Definition: AbstractRepository.php:67
‪TYPO3\CMS\Core\Resource\AbstractRepository\getEntityClassName
‪string getEntityClassName()
Definition: AbstractRepository.php:285
‪TYPO3\CMS\Core\Resource\AbstractRepository\$table
‪string $table
Definition: AbstractRepository.php:34
‪TYPO3\CMS\Extbase\Persistence\RepositoryInterface
Definition: RepositoryInterface.php:24
‪TYPO3\CMS\Core\Resource\AbstractRepository\$type
‪string $type
Definition: AbstractRepository.php:46
‪TYPO3\CMS\Core\Resource\AbstractRepository\replace
‪replace($existingObject, $newObject)
Definition: AbstractRepository.php:86
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\AbstractRepository\findByUid
‪object findByUid($uid)
Definition: AbstractRepository.php:192
‪TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
Definition: QuerySettingsInterface.php:22
‪TYPO3\CMS\Core\Resource\AbstractRepository\setDefaultQuerySettings
‪setDefaultQuerySettings(QuerySettingsInterface $defaultQuerySettings)
Definition: AbstractRepository.php:239
‪TYPO3\CMS\Core\Resource
Definition: generateMimeTypes.php:52
‪TYPO3\CMS\Core\Resource\AbstractRepository\removeAll
‪removeAll()
Definition: AbstractRepository.php:179
‪TYPO3\CMS\Core\Resource\AbstractRepository\getRemovedObjects
‪array getRemovedObjects()
Definition: AbstractRepository.php:118
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Resource\AbstractRepository\findAll
‪array findAll()
Definition: AbstractRepository.php:128
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Resource\AbstractRepository\__construct
‪__construct()
Definition: AbstractRepository.php:57
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer
Definition: FrontendRestrictionContainer.php:31
‪TYPO3\CMS\Core\Resource\AbstractRepository\createDomainObject
‪object createDomainObject(array $databaseRow)
‪TYPO3\CMS\Core\Resource\AbstractRepository\getEnvironmentMode
‪string getEnvironmentMode()
Definition: AbstractRepository.php:296