‪TYPO3CMS  ‪main
AbstractRecord.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 
27 
33 abstract class ‪AbstractRecord
34 {
35  protected array ‪$record;
36 
37  protected static function ‪fetch(string $tableName, int ‪$uid): array
38  {
39  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
40  $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
41  ‪$record = $queryBuilder->select('*')
42  ->from($tableName)
43  ->where(
44  $queryBuilder->expr()->eq(
45  'uid',
46  $queryBuilder->createNamedParameter(‪$uid, ‪Connection::PARAM_INT)
47  )
48  )
49  ->executeQuery()
50  ->fetchAssociative();
51  if (empty(‪$record)) {
52  throw new \RuntimeException('Record "' . $tableName . ': ' . ‪$uid . '" not found', 1476122008);
53  }
54  return ‪$record;
55  }
56 
57  protected static function ‪getBackendUser(): ‪BackendUserAuthentication
58  {
59  return ‪$GLOBALS['BE_USER'];
60  }
61 
62  protected static function ‪getLanguageService(): ‪LanguageService
63  {
64  return ‪$GLOBALS['LANG'];
65  }
66 
67  public function ‪__construct(array ‪$record)
68  {
69  $this->record = ‪$record;
70  }
71 
72  public function ‪__toString(): string
73  {
74  return (string)$this->‪getUid();
75  }
76 
77  public function ‪getUid(): int
78  {
79  return (int)$this->record['uid'];
80  }
81 
82  public function ‪getTitle(): string
83  {
84  return (string)$this->record['title'];
85  }
86 
87  protected function ‪getStagesService(): ‪StagesService
88  {
89  return GeneralUtility::makeInstance(StagesService::class);
90  }
91 }
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\__toString
‪__toString()
Definition: AbstractRecord.php:72
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\__construct
‪__construct(array $record)
Definition: AbstractRecord.php:67
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getTitle
‪getTitle()
Definition: AbstractRecord.php:82
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getStagesService
‪getStagesService()
Definition: AbstractRecord.php:87
‪TYPO3\CMS\Workspaces\Domain\Record
Definition: AbstractRecord.php:18
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord
Definition: AbstractRecord.php:34
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getBackendUser
‪static getBackendUser()
Definition: AbstractRecord.php:57
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getLanguageService
‪static getLanguageService()
Definition: AbstractRecord.php:62
‪TYPO3\CMS\Workspaces\Service\StagesService
Definition: StagesService.php:33
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\fetch
‪static fetch(string $tableName, int $uid)
Definition: AbstractRecord.php:37
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getUid
‪getUid()
Definition: AbstractRecord.php:77
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\$record
‪array $record
Definition: AbstractRecord.php:35