[TASK] Make current persistence replaceable
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / PersistenceManagerInterface.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * This class is a backport of the corresponding class of TYPO3 Flow.
8 * All credits go to the TYPO3 Flow team.
9 * All rights reserved.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * The Extbase Persistence Manager interface
32 */
33 interface PersistenceManagerInterface {
34
35 /**
36 * Injects the Extbase settings, called by Extbase.
37 *
38 * @param array $settings
39 * @return void
40 * @api
41 */
42 public function injectSettings(array $settings);
43
44 /**
45 * Initializes the persistence manager, called by Extbase.
46 *
47 * @return void
48 * @api
49 */
50 public function initialize();
51
52 /**
53 * Commits new objects and changes to objects in the current persistence
54 * session into the backend
55 *
56 * @return void
57 * @api
58 */
59 public function persistAll();
60
61 /**
62 * Clears the in-memory state of the persistence.
63 *
64 * Managed instances become detached, any fetches will
65 * return data directly from the persistence "backend".
66 *
67 * @return void
68 */
69 public function clearState();
70
71 /**
72 * Checks if the given object has ever been persisted.
73 *
74 * @param object $object The object to check
75 * @return boolean TRUE if the object is new, FALSE if the object exists in the repository
76 * @api
77 */
78 public function isNewObject($object);
79
80 /**
81 * Returns the (internal) identifier for the object, if it is known to the
82 * backend. Otherwise NULL is returned.
83 *
84 * Note: this returns an identifier even if the object has not been
85 * persisted in case of AOP-managed entities. Use isNewObject() if you need
86 * to distinguish those cases.
87 *
88 * @param object $object
89 * @return mixed The identifier for the object if it is known, or NULL
90 * @api
91 */
92 public function getIdentifierByObject($object);
93
94 /**
95 * Returns the object with the (internal) identifier, if it is known to the
96 * backend. Otherwise NULL is returned.
97 *
98 * @param mixed $identifier
99 * @param string $objectType
100 * @param boolean $useLazyLoading Set to TRUE if you want to use lazy loading for this object
101 * @return object The object for the identifier if it is known, or NULL
102 * @api
103 */
104 public function getObjectByIdentifier($identifier, $objectType = NULL, $useLazyLoading = FALSE);
105
106 /**
107 * Converts the given object into an array containing the identity of the domain object.
108 *
109 * @param object $object The object to be converted
110 * @return array The identity array in the format array('__identity' => '...')
111 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if the given object is not known to the Persistence Manager
112 * @api
113 */
114 public function convertObjectToIdentityArray($object);
115
116 /**
117 * Recursively iterates through the given array and turns objects
118 * into arrays containing the identity of the domain object.
119 *
120 * @param array $array The array to be iterated over
121 * @return array The modified array without objects
122 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if array contains objects that are not known to the Persistence Manager
123 * @api
124 * @see convertObjectToIdentityArray()
125 */
126 public function convertObjectsToIdentityArrays(array $array);
127
128 /**
129 * Return a query object for the given type.
130 *
131 * @param string $type
132 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
133 * @api
134 */
135 public function createQueryForType($type);
136
137 /**
138 * Adds an object to the persistence.
139 *
140 * @param object $object The object to add
141 * @return void
142 * @api
143 */
144 public function add($object);
145
146 /**
147 * Removes an object to the persistence.
148 *
149 * @param object $object The object to remove
150 * @return void
151 * @api
152 */
153 public function remove($object);
154
155 /**
156 * Update an object in the persistence.
157 *
158 * @param object $object The modified object
159 * @return void
160 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
161 * @api
162 */
163 public function update($object);
164 }
165
166 ?>