1 | <?php |
||
50 | class Repository implements RepositoryInterface |
||
51 | { |
||
52 | // Name of the php class used to create entities. Subclasses have to set a value to this, to be able to create entities |
||
53 | protected $entityClass; |
||
54 | |||
55 | /** @var eZRepository $repository */ |
||
56 | protected $repository; |
||
57 | protected $entityManager; |
||
58 | /** @var string $contentTypeIdentifier */ |
||
59 | protected $contentTypeIdentifier; |
||
60 | /** @var array $settings */ |
||
61 | 10 | protected $settings; |
|
62 | /** @var LoggerInterface $logger */ |
||
63 | 10 | protected $logger; |
|
64 | 10 | ||
65 | 10 | public function __construct(eZRepository $repository, $entityManager, array $settings=array(), $contentTypeIdentifier='') |
|
72 | 10 | ||
73 | /** |
||
74 | * @param string $contentTypeIdentifier |
||
75 | * @return $this|RepositoryInterface |
||
76 | * @todo we could disallow setting a $contentTypeIdentifier when it was already set... |
||
77 | */ |
||
78 | public function setContentTypeIdentifier($contentTypeIdentifier) |
||
83 | 10 | ||
84 | 10 | public function getContentTypeIdentifier() |
|
88 | |||
89 | public function setSettings(array $settings) |
||
94 | |||
95 | 10 | public function setLogger(LoggerInterface $logger=null) |
|
100 | |||
101 | /** |
||
102 | * Called from the constructor, with the settings received from the caller. |
||
103 | * Subclasses can implement checking here, or merge the received settings with other data, using f.e. the Symfony |
||
104 | * OptionsResolver component (see http://symfony.com/doc/current/components/options_resolver.html). |
||
105 | * |
||
106 | * @param array $settings |
||
107 | * @return array |
||
108 | */ |
||
109 | protected function validateSettings(array $settings) |
||
113 | 10 | ||
114 | 10 | /** |
|
115 | 10 | * Nice syntactic sugar ( manually typehinted :-) ) |
|
116 | 10 | * Allow all logger methods and eZ repo methods to be called on this extended repo |
|
117 | 10 | * |
|
118 | 10 | * @param string $method |
|
119 | 10 | * @param array $args |
|
120 | 10 | * @return mixed |
|
121 | 10 | * |
|
122 | * @todo !important move this method to protected access? |
||
123 | */ |
||
124 | public function __call($method, $args) |
||
145 | 10 | ||
146 | 10 | /** |
|
147 | 10 | * To be overridden in subclasses, this method allows injecting extra services/settings in the entities created. |
|
148 | * This version 'knows' about EntityManagerAware and Logging entity traits. |
||
149 | * |
||
150 | * @param \Kaliop\eZObjectWrapperBundle\Core\EntityInterface $entity |
||
151 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
152 | */ |
||
153 | protected function enrichEntityAtLoad($entity) |
||
163 | |||
164 | /** |
||
165 | * @param Content $content |
||
166 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
167 | 4 | * |
|
168 | * @todo optionally (?) throw an error if bad content type is detected |
||
169 | 4 | */ |
|
170 | 4 | public function loadEntityFromContent(Content $content) |
|
176 | |||
177 | /** |
||
178 | 2 | * @param Location $location |
|
179 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
180 | 2 | */ |
|
181 | public function loadEntityFromLocation(Location $location) |
||
187 | |||
188 | /** |
||
189 | 10 | * This method is useful f.e. when you want to create an Entity that matches a given version and specific location. |
|
190 | * This happens notably when doing content previews, where eZ will inject into your controllers both of them. |
||
191 | 10 | * |
|
192 | * @param Content $content |
||
193 | * @param Location $location |
||
194 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
195 | */ |
||
196 | public function loadEntityFromContentAndLocation(Content $content, Location $location) |
||
202 | |||
203 | 10 | /** |
|
204 | * @param ContentInfo $contentInfo |
||
205 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
206 | */ |
||
207 | public function loadEntityFromContentInfo(ContentInfo $contentInfo) |
||
211 | |||
212 | 1 | /** |
|
213 | * @param int $id |
||
214 | 1 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
|
215 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content with the given id does not exist |
||
216 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
||
217 | */ |
||
218 | public function loadEntityFromContentId($id) |
||
222 | |||
223 | 1 | /** |
|
224 | * An alias for loadEntityFromContentId, to keep the API close to Doctrine |
||
225 | 1 | * @param int $id |
|
226 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
227 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content with the given id does not exist |
||
228 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
||
229 | */ |
||
230 | public function find($id) |
||
234 | 1 | ||
235 | /** |
||
236 | 1 | * @param int $id |
|
237 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
238 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location |
||
239 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found |
||
240 | */ |
||
241 | public function loadEntityFromLocationId($id) |
||
245 | |||
246 | /** |
||
247 | * @param string $remoteId |
||
248 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
249 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content with the given id does not exist |
||
250 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
||
251 | */ |
||
252 | public function loadEntityFromContentRemoteId($remoteId) |
||
256 | |||
257 | /** |
||
258 | * @param string $remoteId |
||
259 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
260 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location |
||
261 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found |
||
262 | */ |
||
263 | public function loadEntityFromLocationRemoteId($remoteId) |
||
267 | |||
268 | /** |
||
269 | * NB: assumes that all search results are homogeneous (same content type) |
||
270 | * @param SearchResult $searchResult |
||
271 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface[] |
||
272 | */ |
||
273 | protected function loadEntitiesFromSearchResults(SearchResult $searchResult) |
||
286 | } |
||
287 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.