219751f336d7765f5707bdb095f82a938bb40b16
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / PersistenceManagerInterface.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence;
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 * The Extbase Persistence Manager interface
18 */
19 interface PersistenceManagerInterface {
20
21 /**
22 * Commits new objects and changes to objects in the current persistence
23 * session into the backend
24 *
25 * @return void
26 * @api
27 */
28 public function persistAll();
29
30 /**
31 * Clears the in-memory state of the persistence.
32 *
33 * Managed instances become detached, any fetches will
34 * return data directly from the persistence "backend".
35 *
36 * @return void
37 */
38 public function clearState();
39
40 /**
41 * Checks if the given object has ever been persisted.
42 *
43 * @param object $object The object to check
44 * @return bool TRUE if the object is new, FALSE if the object exists in the repository
45 * @api
46 */
47 public function isNewObject($object);
48
49 // TODO realign with Flow PersistenceManager again
50
51 /**
52 * Returns the (internal) identifier for the object, if it is known to the
53 * backend. Otherwise NULL is returned.
54 *
55 * Note: this returns an identifier even if the object has not been
56 * persisted in case of AOP-managed entities. Use isNewObject() if you need
57 * to distinguish those cases.
58 *
59 * @param object $object
60 * @return mixed The identifier for the object if it is known, or NULL
61 * @api
62 */
63 public function getIdentifierByObject($object);
64
65 /**
66 * Returns the object with the (internal) identifier, if it is known to the
67 * backend. Otherwise NULL is returned.
68 *
69 * @param mixed $identifier
70 * @param string $objectType
71 * @param bool $useLazyLoading Set to TRUE if you want to use lazy loading for this object
72 * @return object The object for the identifier if it is known, or NULL
73 * @api
74 */
75 public function getObjectByIdentifier($identifier, $objectType = NULL, $useLazyLoading = FALSE);
76
77 /**
78 * Returns the number of records matching the query.
79 *
80 * @param QueryInterface $query
81 * @return int
82 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0. It is deprecated only in the interface to be more
83 * in sync with Flow in future and will stay in Generic Persistence.
84 * @api
85 */
86 public function getObjectCountByQuery(QueryInterface $query);
87
88 /**
89 * Returns the object data matching the $query.
90 *
91 * @param QueryInterface $query
92 * @return array
93 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0. It is deprecated only in the interface to be more
94 * in sync with Flow in future and will stay in Generic Persistence.
95 * @api
96 */
97 public function getObjectDataByQuery(QueryInterface $query);
98
99 /**
100 * Registers a repository
101 *
102 * @param string $className The class name of the repository to be registered
103 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0. It is deprecated only in the interface to be more
104 * in sync with Flow in future and will stay in Generic Persistence.
105 * @return void
106 */
107 public function registerRepositoryClassName($className);
108
109 /**
110 * Adds an object to the persistence.
111 *
112 * @param object $object The object to add
113 * @return void
114 * @api
115 */
116 public function add($object);
117
118 /**
119 * Removes an object to the persistence.
120 *
121 * @param object $object The object to remove
122 * @return void
123 * @api
124 */
125 public function remove($object);
126
127 /**
128 * Update an object in the persistence.
129 *
130 * @param object $object The modified object
131 * @return void
132 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
133 * @api
134 */
135 public function update($object);
136
137 /**
138 * Injects the Extbase settings, called by Extbase.
139 *
140 * @param array $settings
141 * @return void
142 * @api
143 */
144 public function injectSettings(array $settings);
145
146 /**
147 * Converts the given object into an array containing the identity of the domain object.
148 *
149 * @param object $object The object to be converted
150 * @return array The identity array in the format array('__identity' => '...')
151 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if the given object is not known to the Persistence Manager
152 * @api
153 */
154 public function convertObjectToIdentityArray($object);
155
156 /**
157 * Recursively iterates through the given array and turns objects
158 * into arrays containing the identity of the domain object.
159 *
160 * @param array $array The array to be iterated over
161 * @return array The modified array without objects
162 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if array contains objects that are not known to the Persistence Manager
163 * @api
164 * @see convertObjectToIdentityArray()
165 */
166 public function convertObjectsToIdentityArrays(array $array);
167
168 /**
169 * Return a query object for the given type.
170 *
171 * @param string $type
172 * @return QueryInterface
173 * @api
174 */
175 public function createQueryForType($type);
176 }