[CLEANUP] The correct case must be used for standard PHP types in phpdoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Domain / Model / DatabaseRecord.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Domain\Model;
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 */
16
17 /**
18 * Database record class
19 */
20 class DatabaseRecord
21 {
22 /**
23 * @var string
24 */
25 protected $table;
26
27 /**
28 * @var int
29 */
30 protected $uid;
31
32 /**
33 * @var array
34 */
35 protected $row;
36
37 /**
38 * Creates database record object just by id of database record.
39 *
40 * @param string $table Name of the database table
41 * @param int $uid Id of the datbase record row
42 * @return \TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord
43 */
44 public static function create($table, $uid)
45 {
46 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord::class, $table, $uid);
47 }
48
49 /**
50 * Creates datbase record object by relevant database record row.
51 *
52 * @param string $table Name of the database table
53 * @param array $row The relevant database record row
54 * @return \TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord
55 */
56 public static function createFromArray($table, array $row)
57 {
58 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord::class, $table, $row['uid'], $row);
59 }
60
61 /**
62 * @param string $table Name of the database table
63 * @param int $uid Id of the datbase record row
64 * @param array|null $row The relevant database record row
65 */
66 public function __construct($table, $uid, array $row = null)
67 {
68 $this->setTable($table);
69 $this->setUid($uid);
70 if ($row !== null) {
71 $this->setRow($row);
72 }
73 }
74
75 /**
76 * Gets the name of the database table.
77 *
78 * @return string
79 */
80 public function getTable()
81 {
82 return $this->table;
83 }
84
85 /**
86 * Sets the name of the database table.
87 *
88 * @param string $table
89 */
90 public function setTable($table)
91 {
92 $this->table = $table;
93 }
94
95 /**
96 * Gets the id of the database record row.
97 *
98 * @return int
99 */
100 public function getUid()
101 {
102 return $this->uid;
103 }
104
105 /**
106 * Sets the id of the database record row.
107 *
108 * @param int $uid
109 */
110 public function setUid($uid)
111 {
112 $this->uid = (int)$uid;
113 }
114
115 /**
116 * Gets the database record row.
117 *
118 * @return array
119 */
120 public function getRow()
121 {
122 $this->loadRow();
123 return $this->row;
124 }
125
126 /**
127 * Sets the database record row.
128 *
129 * @param array $row
130 */
131 public function setRow(array $row)
132 {
133 $this->row = $row;
134 }
135
136 /**
137 * Gets the record identifier (table:id).
138 *
139 * @return string
140 */
141 public function getIdentifier()
142 {
143 return implode(':', [$this->getTable(), $this->getUid()]);
144 }
145
146 /**
147 * Loads the database record row (if not available yet).
148 */
149 protected function loadRow()
150 {
151 if ($this->row === null) {
152 $this->row = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($this->getTable(), $this->getUid());
153 }
154 }
155 }