[TASK] Prepare AbstractRepository of FAL for FLOW sync
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / AbstractRepository.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Abstract repository implementing the basic repository methods
31 *
32 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
33 * @author Ingmar Schlecht <ingmar@typo3.org>
34 */
35 abstract class AbstractRepository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface, \TYPO3\CMS\Core\SingletonInterface {
36
37 /**
38 * @var string
39 */
40 protected $table = '';
41
42 /**
43 * @var \TYPO3\CMS\Core\Resource\ResourceFactory
44 */
45 protected $factory;
46
47 /**
48 * @var string
49 */
50 protected $typeField = '';
51
52 /**
53 * @var string
54 */
55 protected $type = '';
56
57 /**
58 * Creates this object.
59 */
60 public function __construct() {
61 $this->factory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
62 }
63
64 /**
65 * Adds an object to this repository.
66 *
67 * @param object $object The object to add
68 * @return void
69 * @api
70 */
71 public function add($object) {
72
73 }
74
75 /**
76 * Removes an object from this repository.
77 *
78 * @param object $object The object to remove
79 * @return void
80 * @api
81 */
82 public function remove($object) {
83
84 }
85
86 /**
87 * Replaces an object by another.
88 *
89 * @param object $existingObject The existing object
90 * @param object $newObject The new object
91 * @return void
92 * @api
93 */
94 public function replace($existingObject, $newObject) {
95
96 }
97
98 /**
99 * Replaces an existing object with the same identifier by the given object
100 *
101 * @param object $modifiedObject The modified object
102 * @api
103 */
104 public function update($modifiedObject) {
105
106 }
107
108 /**
109 * Returns all objects of this repository add()ed but not yet persisted to
110 * the storage layer.
111 *
112 * @return array An array of objects
113 */
114 public function getAddedObjects() {
115
116 }
117
118 /**
119 * Returns an array with objects remove()d from the repository that
120 * had been persisted to the storage layer before.
121 *
122 * @return array
123 */
124 public function getRemovedObjects() {
125
126 }
127
128 /**
129 * Returns all objects of this repository.
130 *
131 * @return array An array of objects, empty if no objects found
132 * @api
133 */
134 public function findAll() {
135 $itemList = array();
136 $whereClause = 'deleted = 0';
137 if ($this->type != '') {
138 $whereClause .= ' AND ' . $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->type, $this->table);
139 }
140 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->table, $whereClause);
141 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
142 $itemList[] = $this->createDomainObject($row);
143 }
144 $GLOBALS['TYPO3_DB']->sql_free_result($res);
145 return $itemList;
146 }
147
148 /**
149 * Creates an object managed by this repository.
150 *
151 * @abstract
152 * @param array $databaseRow
153 * @return object
154 */
155 abstract protected function createDomainObject(array $databaseRow);
156
157 /**
158 * Returns the total number objects of this repository.
159 *
160 * @return integer The object count
161 * @api
162 */
163 public function countAll() {
164
165 }
166
167 /**
168 * Removes all objects of this repository as if remove() was called for
169 * all of them.
170 *
171 * @return void
172 * @api
173 */
174 public function removeAll() {
175
176 }
177
178 /**
179 * Finds an object matching the given identifier.
180 *
181 * @param int $uid The identifier of the object to find
182 * @return object The matching object
183 * @api
184 */
185 public function findByUid($uid) {
186 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
187 throw new \InvalidArgumentException('uid has to be integer.', 1316779798);
188 }
189 $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $this->table, 'uid=' . intval($uid) . ' AND deleted=0');
190 if (empty($row) || !is_array($row)) {
191 throw new \RuntimeException('Could not find row with uid "' . $uid . '" in table $this->table.', 1314354065);
192 }
193 return $this->createDomainObject($row);
194 }
195
196 /**
197 * Sets the property names to order the result by per default.
198 * Expected like this:
199 * array(
200 * 'foo' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING,
201 * 'bar' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING
202 * )
203 *
204 * @param array $defaultOrderings The property names to order by
205 * @return void
206 * @api
207 */
208 public function setDefaultOrderings(array $defaultOrderings) {
209 throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1313185906);
210 }
211
212 /**
213 * Sets the default query settings to be used in this repository
214 *
215 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings The query settings to be used by default
216 * @return void
217 * @api
218 */
219 public function setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings) {
220 throw new \BadMethodCallException('Repository does not support the setDefaultQuerySettings() method.', 1313185907);
221 }
222
223 /**
224 * Returns a query for objects of this repository
225 *
226 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
227 * @api
228 */
229 public function createQuery() {
230 throw new \BadMethodCallException('Repository does not support the createQuery() method.', 1313185908);
231 }
232
233 /**
234 * Finds an object matching the given identifier.
235 *
236 * @param mixed $identifier The identifier of the object to find
237 * @return object The matching object if found, otherwise NULL
238 * @api
239 */
240 public function findByIdentifier($identifier) {
241 return $this->findByUid($identifier);
242 }
243
244 /**
245 * Magic call method for repository methods.
246 *
247 * @param string $method Name of the method
248 * @param array $arguments The arguments
249 * @return void
250 */
251 public function __call($method, $arguments) {
252 // deliberately empty
253 }
254
255 /**
256 * Returns the object type this repository is managing.
257 *
258 * @return string
259 * @api
260 */
261 public function getEntityClassName() {
262 return $this->objectType;
263 }
264
265 }
266
267
268 ?>