‪TYPO3CMS  ‪main
DatabaseRecord.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 
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 
29 {
30  protected string ‪$table;
31  protected int ‪$uid;
32  protected ?array ‪$row;
33 
40  public static function ‪create(string ‪$table, int ‪$uid): ‪DatabaseRecord
41  {
42  return GeneralUtility::makeInstance(DatabaseRecord::class, ‪$table, ‪$uid);
43  }
44 
51  public static function ‪createFromArray(string ‪$table, array ‪$row): ‪DatabaseRecord
52  {
53  return GeneralUtility::makeInstance(DatabaseRecord::class, ‪$table, ‪$row['uid'], ‪$row);
54  }
55 
56  public function ‪__construct(string ‪$table, int ‪$uid, array ‪$row = null)
57  {
58  $this->‪setTable($table);
59  $this->‪setUid($uid);
60  if (‪$row !== null) {
61  $this->‪setRow($row);
62  }
63  }
64 
68  public function ‪getTable(): string
69  {
70  return ‪$this->table;
71  }
72 
76  public function ‪setTable(string ‪$table): void
77  {
78  $this->table = ‪$table;
79  }
80 
84  public function ‪getUid(): int
85  {
86  return ‪$this->uid;
87  }
88 
92  public function ‪setUid(int ‪$uid): void
93  {
94  $this->uid = ‪$uid;
95  }
96 
100  public function ‪getRow(): array
101  {
102  $this->‪loadRow();
103  return ‪$this->row;
104  }
105 
109  public function ‪setRow(array ‪$row): void
110  {
111  $this->row = ‪$row;
112  }
113 
117  public function ‪getIdentifier(): string
118  {
119  return implode(':', [$this->‪getTable(), $this->‪getUid()]);
120  }
121 
125  protected function ‪loadRow(): void
126  {
127  $this->row ??= BackendUtility::getRecord($this->‪getTable(), $this->‪getUid()) ?? [];
128  }
129 }
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\getTable
‪getTable()
Definition: DatabaseRecord.php:68
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\$table
‪string $table
Definition: DatabaseRecord.php:30
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\__construct
‪__construct(string $table, int $uid, array $row=null)
Definition: DatabaseRecord.php:56
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\getRow
‪getRow()
Definition: DatabaseRecord.php:100
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\$row
‪array $row
Definition: DatabaseRecord.php:32
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord
Definition: DatabaseRecord.php:29
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\loadRow
‪loadRow()
Definition: DatabaseRecord.php:125
‪TYPO3\CMS\Workspaces\Domain\Model
Definition: CombinedRecord.php:18
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\createFromArray
‪static createFromArray(string $table, array $row)
Definition: DatabaseRecord.php:51
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\getIdentifier
‪getIdentifier()
Definition: DatabaseRecord.php:117
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\getUid
‪getUid()
Definition: DatabaseRecord.php:84
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\create
‪static create(string $table, int $uid)
Definition: DatabaseRecord.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\setTable
‪setTable(string $table)
Definition: DatabaseRecord.php:76
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\setUid
‪setUid(int $uid)
Definition: DatabaseRecord.php:92
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\$uid
‪int $uid
Definition: DatabaseRecord.php:31
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\setRow
‪setRow(array $row)
Definition: DatabaseRecord.php:109