TYPO3 CMS  TYPO3_8-7
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 
69  public function add($object)
70  {
71  }
72 
79  public function remove($object)
80  {
81  }
82 
90  public function replace($existingObject, $newObject)
91  {
92  }
93 
100  public function update($modifiedObject)
101  {
102  }
103 
110  public function getAddedObjects()
111  {
112  }
113 
120  public function getRemovedObjects()
121  {
122  }
123 
130  public function findAll()
131  {
132  $items = [];
133  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
134  if ($this->getEnvironmentMode() === 'FE') {
135  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
136  }
137  $queryBuilder
138  ->select('*')
139  ->from($this->table);
140 
141  if (!empty($this->type)) {
142  $queryBuilder->where(
143  $queryBuilder->expr()->eq(
144  $this->typeField,
145  $queryBuilder->createNamedParameter($this->type, \PDO::PARAM_STR)
146  )
147  );
148  }
149  $result = $queryBuilder->execute();
150 
151  // fetch all records and create objects out of them
152  while ($row = $result->fetch()) {
153  $items[] = $this->createDomainObject($row);
154  }
155  return $items;
156  }
157 
165  abstract protected function createDomainObject(array $databaseRow);
166 
173  public function countAll()
174  {
175  }
176 
183  public function removeAll()
184  {
185  }
186 
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' && !empty($GLOBALS['TSFE']->sys_page)) {
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 
233  public function setDefaultOrderings(array $defaultOrderings)
234  {
235  throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1313185906);
236  }
237 
246  public function setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings)
247  {
248  throw new \BadMethodCallException('Repository does not support the setDefaultQuerySettings() method.', 1313185907);
249  }
250 
258  public function createQuery()
259  {
260  throw new \BadMethodCallException('Repository does not support the createQuery() method.', 1313185908);
261  }
262 
270  public function findByIdentifier($identifier)
271  {
272  return $this->findByUid($identifier);
273  }
274 
283  public function __call($method, $arguments)
284  {
285  throw new \BadMethodCallException('Repository method "' . $method . '" is not implemented.', 1378918410);
286  }
287 
294  public function getEntityClassName()
295  {
296  return $this->objectType;
297  }
298 
305  protected function getEnvironmentMode()
306  {
307  return TYPO3_MODE;
308  }
309 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings)