‪TYPO3CMS  9.5
AbstractRepository.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
22 
27 {
31  protected ‪$table = '';
32 
36  protected ‪$factory;
37 
41  protected ‪$typeField = '';
42 
46  protected ‪$type = '';
47 
53  protected ‪$objectType;
54 
58  public function ‪__construct()
59  {
60  $this->factory = GeneralUtility::makeInstance(ResourceFactory::class);
61  }
62 
68  public function ‪add($object)
69  {
70  }
71 
77  public function remove($object)
78  {
79  }
80 
87  public function ‪replace($existingObject, $newObject)
88  {
89  }
90 
96  public function ‪update($modifiedObject)
97  {
98  }
99 
107  public function ‪getAddedObjects()
108  {
109  }
110 
118  public function ‪getRemovedObjects()
119  {
120  }
121 
127  public function ‪findAll()
128  {
129  $items = [];
130  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
131  if ($this->‪getEnvironmentMode() === 'FE') {
132  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
133  }
134  $queryBuilder
135  ->select('*')
136  ->from($this->table);
137 
138  if (!empty($this->type)) {
139  $queryBuilder->where(
140  $queryBuilder->expr()->eq(
141  $this->typeField,
142  $queryBuilder->createNamedParameter($this->type, \PDO::PARAM_STR)
143  )
144  );
145  }
146  $result = $queryBuilder->execute();
147 
148  // fetch all records and create objects out of them
149  while ($row = $result->fetch()) {
150  $items[] = $this->‪createDomainObject($row);
151  }
152  return $items;
153  }
154 
162  abstract protected function ‪createDomainObject(array $databaseRow);
163 
169  public function ‪countAll()
170  {
171  }
172 
177  public function ‪removeAll()
178  {
179  }
180 
190  public function ‪findByUid($uid)
191  {
193  throw new \InvalidArgumentException('The UID has to be an integer. UID given: "' . $uid . '"', 1316779798);
194  }
195  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
196  if ($this->‪getEnvironmentMode() === 'FE') {
197  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
198  }
199  $row = $queryBuilder
200  ->select('*')
201  ->from($this->table)
202  ->where(
203  $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
204  )
205  ->execute()
206  ->fetch();
207  if (!is_array($row)) {
208  throw new \RuntimeException('Could not find row with UID "' . $uid . '" in table "' . $this->table . '"', 1314354065);
209  }
210  return $this->‪createDomainObject($row);
211  }
212 
225  public function ‪setDefaultOrderings(array $defaultOrderings)
226  {
227  throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1313185906);
228  }
229 
237  public function ‪setDefaultQuerySettings(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings)
238  {
239  throw new \BadMethodCallException('Repository does not support the setDefaultQuerySettings() method.', 1313185907);
240  }
241 
248  public function ‪createQuery()
249  {
250  throw new \BadMethodCallException('Repository does not support the createQuery() method.', 1313185908);
251  }
252 
259  public function ‪findByIdentifier($identifier)
260  {
261  return $this->‪findByUid($identifier);
262  }
263 
273  public function ‪__call($method, $arguments)
274  {
275  throw new \BadMethodCallException('Repository method "' . $method . '" is not implemented.', 1378918410);
276  }
277 
283  public function ‪getEntityClassName()
284  {
285  return ‪$this->objectType;
286  }
287 
294  protected function ‪getEnvironmentMode()
295  {
296  return TYPO3_MODE;
297  }
298 }
‪TYPO3\CMS\Core\Resource\AbstractRepository\findByIdentifier
‪object null findByIdentifier($identifier)
Definition: AbstractRepository.php:254
‪TYPO3\CMS\Core\Resource\AbstractRepository\setDefaultOrderings
‪setDefaultOrderings(array $defaultOrderings)
Definition: AbstractRepository.php:220
‪TYPO3\CMS\Core\Resource\AbstractRepository\getAddedObjects
‪array getAddedObjects()
Definition: AbstractRepository.php:102
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:73
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Core\Resource\AbstractRepository\$objectType
‪string $objectType
Definition: AbstractRepository.php:48
‪TYPO3\CMS\Core\Resource\AbstractRepository\update
‪update($modifiedObject)
Definition: AbstractRepository.php:91
‪TYPO3\CMS\Core\Resource\AbstractRepository\setDefaultQuerySettings
‪setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings)
Definition: AbstractRepository.php:232
‪TYPO3\CMS\Core\Resource\AbstractRepository\countAll
‪int countAll()
Definition: AbstractRepository.php:164
‪TYPO3\CMS\Core\Resource\AbstractRepository
Definition: AbstractRepository.php:27
‪TYPO3
‪TYPO3\CMS\Core\Resource\AbstractRepository\$typeField
‪string $typeField
Definition: AbstractRepository.php:38
‪TYPO3\CMS\Core\Resource\AbstractRepository\createQuery
‪TYPO3 CMS Extbase Persistence QueryInterface createQuery()
Definition: AbstractRepository.php:243
‪TYPO3\CMS\Core\Resource\AbstractRepository\$factory
‪ResourceFactory $factory
Definition: AbstractRepository.php:34
‪TYPO3\CMS\Core\Resource\AbstractRepository\__call
‪__call($method, $arguments)
Definition: AbstractRepository.php:268
‪TYPO3\CMS\Core\Resource\AbstractRepository\add
‪add($object)
Definition: AbstractRepository.php:63
‪TYPO3\CMS\Core\Resource\AbstractRepository\getEntityClassName
‪string getEntityClassName()
Definition: AbstractRepository.php:278
‪TYPO3\CMS\Core\Resource\AbstractRepository\$table
‪string $table
Definition: AbstractRepository.php:30
‪TYPO3\CMS\Extbase\Persistence\RepositoryInterface
Definition: RepositoryInterface.php:21
‪TYPO3\CMS\Core\Resource\AbstractRepository\$type
‪string $type
Definition: AbstractRepository.php:42
‪TYPO3\CMS\Core\Resource\AbstractRepository\replace
‪replace($existingObject, $newObject)
Definition: AbstractRepository.php:82
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Resource\AbstractRepository\findByUid
‪object findByUid($uid)
Definition: AbstractRepository.php:185
‪TYPO3\CMS\Core\Resource
Definition: generateMimeTypes.php:37
‪TYPO3\CMS\Core\Resource\AbstractRepository\removeAll
‪removeAll()
Definition: AbstractRepository.php:172
‪TYPO3\CMS\Core\Resource\AbstractRepository\getRemovedObjects
‪array getRemovedObjects()
Definition: AbstractRepository.php:113
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Resource\AbstractRepository\findAll
‪array findAll()
Definition: AbstractRepository.php:122
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Resource\AbstractRepository\__construct
‪__construct()
Definition: AbstractRepository.php:53
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer
Definition: FrontendRestrictionContainer.php:29
‪TYPO3\CMS\Core\Resource\AbstractRepository\createDomainObject
‪object createDomainObject(array $databaseRow)
‪TYPO3\CMS\Core\Resource\AbstractRepository\getEnvironmentMode
‪string getEnvironmentMode()
Definition: AbstractRepository.php:289