Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Repository often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Repository, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | * @var \eZ\Publish\SPI\Persistence\Handler |
||
33 | */ |
||
34 | protected $persistenceHandler; |
||
35 | |||
36 | /** |
||
37 | * Instance of main Search Handler. |
||
38 | * |
||
39 | * @var \eZ\Publish\SPI\Search\Handler |
||
40 | */ |
||
41 | protected $searchHandler; |
||
42 | |||
43 | /** |
||
44 | * Instance of content service. |
||
45 | * |
||
46 | * @var \eZ\Publish\API\Repository\ContentService |
||
47 | */ |
||
48 | protected $contentService; |
||
49 | |||
50 | /** |
||
51 | * Instance of section service. |
||
52 | * |
||
53 | * @var \eZ\Publish\API\Repository\SectionService |
||
54 | */ |
||
55 | protected $sectionService; |
||
56 | |||
57 | /** |
||
58 | * Instance of role service. |
||
59 | * |
||
60 | * @var \eZ\Publish\API\Repository\RoleService |
||
61 | */ |
||
62 | protected $roleService; |
||
63 | |||
64 | /** |
||
65 | * Instance of search service. |
||
66 | * |
||
67 | * @var \eZ\Publish\API\Repository\SearchService |
||
68 | */ |
||
69 | protected $searchService; |
||
70 | |||
71 | /** |
||
72 | * Instance of user service. |
||
73 | * |
||
74 | * @var \eZ\Publish\API\Repository\UserService |
||
75 | */ |
||
76 | protected $userService; |
||
77 | |||
78 | /** |
||
79 | * Instance of language service. |
||
80 | * |
||
81 | * @var \eZ\Publish\API\Repository\LanguageService |
||
82 | */ |
||
83 | protected $languageService; |
||
84 | |||
85 | /** |
||
86 | * Instance of location service. |
||
87 | * |
||
88 | * @var \eZ\Publish\API\Repository\LocationService |
||
89 | */ |
||
90 | protected $locationService; |
||
91 | |||
92 | /** |
||
93 | * Instance of Trash service. |
||
94 | * |
||
95 | * @var \eZ\Publish\API\Repository\TrashService |
||
96 | */ |
||
97 | protected $trashService; |
||
98 | |||
99 | /** |
||
100 | * Instance of content type service. |
||
101 | * |
||
102 | * @var \eZ\Publish\API\Repository\ContentTypeService |
||
103 | */ |
||
104 | protected $contentTypeService; |
||
105 | |||
106 | /** |
||
107 | * Instance of object state service. |
||
108 | * |
||
109 | * @var \eZ\Publish\API\Repository\ObjectStateService |
||
110 | */ |
||
111 | protected $objectStateService; |
||
112 | |||
113 | /** |
||
114 | * Instance of field type service. |
||
115 | * |
||
116 | * @var \eZ\Publish\API\Repository\FieldTypeService |
||
117 | */ |
||
118 | protected $fieldTypeService; |
||
119 | |||
120 | /** @var \eZ\Publish\Core\FieldType\FieldTypeRegistry */ |
||
121 | private $fieldTypeRegistry; |
||
122 | |||
123 | /** |
||
124 | * Instance of name schema resolver service. |
||
125 | * |
||
126 | * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
127 | */ |
||
128 | protected $nameSchemaService; |
||
129 | |||
130 | /** |
||
131 | * Instance of relation processor service. |
||
132 | * |
||
133 | * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
134 | */ |
||
135 | protected $relationProcessor; |
||
136 | |||
137 | /** |
||
138 | * Instance of URL alias service. |
||
139 | * |
||
140 | * @var \eZ\Publish\Core\Repository\URLAliasService |
||
141 | */ |
||
142 | protected $urlAliasService; |
||
143 | |||
144 | /** |
||
145 | * Instance of URL wildcard service. |
||
146 | * |
||
147 | * @var \eZ\Publish\Core\Repository\URLWildcardService |
||
148 | */ |
||
149 | protected $urlWildcardService; |
||
150 | |||
151 | /** |
||
152 | * Instance of URL service. |
||
153 | * |
||
154 | * @var \eZ\Publish\Core\Repository\URLService |
||
155 | */ |
||
156 | protected $urlService; |
||
157 | |||
158 | /** |
||
159 | * Instance of Bookmark service. |
||
160 | * |
||
161 | * @var \eZ\Publish\API\Repository\BookmarkService |
||
162 | */ |
||
163 | protected $bookmarkService; |
||
164 | |||
165 | /** |
||
166 | * Instance of Notification service. |
||
167 | * |
||
168 | * @var \eZ\Publish\API\Repository\NotificationService |
||
169 | */ |
||
170 | protected $notificationService; |
||
171 | |||
172 | /** |
||
173 | * Instance of User Preference service. |
||
174 | * |
||
175 | * @var \eZ\Publish\API\Repository\UserPreferenceService |
||
176 | */ |
||
177 | protected $userPreferenceService; |
||
178 | |||
179 | /** |
||
180 | * Service settings, first level key is service name. |
||
181 | * |
||
182 | * @var array |
||
183 | */ |
||
184 | protected $serviceSettings; |
||
185 | |||
186 | /** |
||
187 | * Instance of role service. |
||
188 | * |
||
189 | * @var \eZ\Publish\Core\Repository\Helper\LimitationService |
||
190 | */ |
||
191 | protected $limitationService; |
||
192 | |||
193 | /** @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper */ |
||
194 | protected $roleDomainMapper; |
||
195 | |||
196 | /** |
||
197 | * Instance of domain mapper. |
||
198 | * |
||
199 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
200 | */ |
||
201 | protected $domainMapper; |
||
202 | |||
203 | /** |
||
204 | * Instance of content type domain mapper. |
||
205 | * |
||
206 | * @var \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper |
||
207 | */ |
||
208 | protected $contentTypeDomainMapper; |
||
209 | |||
210 | /** |
||
211 | * Instance of permissions-resolver and -criterion resolver. |
||
212 | * |
||
213 | * @var \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver |
||
214 | */ |
||
215 | protected $permissionsHandler; |
||
216 | |||
217 | /** @var \eZ\Publish\Core\Search\Common\BackgroundIndexer|null */ |
||
218 | protected $backgroundIndexer; |
||
219 | |||
220 | /** @var \Psr\Log\LoggerInterface */ |
||
221 | private $logger; |
||
222 | |||
223 | /** |
||
224 | * Construct repository object with provided storage engine. |
||
225 | * |
||
226 | * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler |
||
227 | * @param \eZ\Publish\SPI\Search\Handler $searchHandler |
||
228 | * @param \eZ\Publish\Core\Search\Common\BackgroundIndexer $backgroundIndexer |
||
229 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
230 | * @param \eZ\Publish\Core\FieldType\FieldTypeRegistry $fieldTypeRegistry |
||
231 | * @param array $serviceSettings |
||
232 | * @param \Psr\Log\LoggerInterface|null $logger |
||
233 | */ |
||
234 | public function __construct( |
||
235 | PersistenceHandler $persistenceHandler, |
||
236 | SearchHandler $searchHandler, |
||
237 | BackgroundIndexer $backgroundIndexer, |
||
238 | RelationProcessor $relationProcessor, |
||
239 | FieldTypeRegistry $fieldTypeRegistry, |
||
240 | array $serviceSettings = [], |
||
241 | LoggerInterface $logger = null |
||
242 | ) { |
||
243 | $this->persistenceHandler = $persistenceHandler; |
||
244 | $this->searchHandler = $searchHandler; |
||
245 | $this->backgroundIndexer = $backgroundIndexer; |
||
246 | $this->relationProcessor = $relationProcessor; |
||
247 | $this->fieldTypeRegistry = $fieldTypeRegistry; |
||
248 | $this->serviceSettings = $serviceSettings + [ |
||
249 | 'content' => [], |
||
250 | 'contentType' => [], |
||
251 | 'location' => [], |
||
252 | 'section' => [], |
||
253 | 'role' => [], |
||
254 | 'user' => [ |
||
255 | 'anonymousUserID' => 10, |
||
256 | ], |
||
257 | 'language' => [], |
||
258 | 'trash' => [], |
||
259 | 'io' => [], |
||
260 | 'objectState' => [], |
||
261 | 'search' => [], |
||
262 | 'urlAlias' => [], |
||
263 | 'urlWildcard' => [], |
||
264 | 'nameSchema' => [], |
||
265 | 'languages' => [], |
||
266 | ]; |
||
267 | |||
268 | if (!empty($this->serviceSettings['languages'])) { |
||
269 | $this->serviceSettings['language']['languages'] = $this->serviceSettings['languages']; |
||
270 | } |
||
271 | |||
272 | $this->logger = null !== $logger ? $logger : new NullLogger(); |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * {@inheritdoc} |
||
277 | */ |
||
278 | public function sudo(callable $callback, RepositoryInterface $outerRepository = null) |
||
279 | { |
||
280 | return $this->getPermissionResolver()->sudo($callback, $outerRepository ?? $this); |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * Get Content Service. |
||
285 | * |
||
286 | * Get service object to perform operations on Content objects and it's aggregate members. |
||
287 | * |
||
288 | * @return \eZ\Publish\API\Repository\ContentService |
||
289 | */ |
||
290 | public function getContentService() |
||
291 | { |
||
292 | if ($this->contentService !== null) { |
||
293 | return $this->contentService; |
||
294 | } |
||
295 | |||
296 | $this->contentService = new ContentService( |
||
297 | $this, |
||
298 | $this->persistenceHandler, |
||
299 | $this->getDomainMapper(), |
||
300 | $this->getRelationProcessor(), |
||
301 | $this->getNameSchemaService(), |
||
302 | $this->fieldTypeRegistry, |
||
303 | $this->getPermissionResolver(), |
||
304 | $this->serviceSettings['content'], |
||
305 | ); |
||
|
|||
306 | |||
307 | return $this->contentService; |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * Get Content Language Service. |
||
312 | * |
||
313 | * Get service object to perform operations on Content language objects |
||
314 | * |
||
315 | * @return \eZ\Publish\API\Repository\LanguageService |
||
316 | */ |
||
317 | public function getContentLanguageService() |
||
318 | { |
||
319 | if ($this->languageService !== null) { |
||
320 | return $this->languageService; |
||
321 | } |
||
322 | |||
323 | $this->languageService = new LanguageService( |
||
324 | $this, |
||
325 | $this->persistenceHandler->contentLanguageHandler(), |
||
326 | $this->getPermissionResolver(), |
||
327 | $this->serviceSettings['language'] |
||
328 | ); |
||
329 | |||
330 | return $this->languageService; |
||
331 | } |
||
332 | |||
333 | /** |
||
334 | * Get Content Type Service. |
||
335 | * |
||
336 | * Get service object to perform operations on Content Type objects and it's aggregate members. |
||
337 | * ( Group, Field & FieldCategory ) |
||
338 | * |
||
339 | * @return \eZ\Publish\API\Repository\ContentTypeService |
||
340 | */ |
||
341 | public function getContentTypeService() |
||
342 | { |
||
343 | if ($this->contentTypeService !== null) { |
||
344 | return $this->contentTypeService; |
||
345 | } |
||
346 | |||
347 | $this->contentTypeService = new ContentTypeService( |
||
348 | $this, |
||
349 | $this->persistenceHandler->contentTypeHandler(), |
||
350 | $this->persistenceHandler->userHandler(), |
||
351 | $this->getDomainMapper(), |
||
352 | $this->getContentTypeDomainMapper(), |
||
353 | $this->fieldTypeRegistry, |
||
354 | $this->getPermissionResolver(), |
||
355 | $this->serviceSettings['contentType'] |
||
356 | ); |
||
357 | |||
358 | return $this->contentTypeService; |
||
359 | } |
||
360 | |||
361 | /** |
||
362 | * Get Content Location Service. |
||
363 | * |
||
364 | * Get service object to perform operations on Location objects and subtrees |
||
365 | * |
||
366 | * @return \eZ\Publish\API\Repository\LocationService |
||
367 | */ |
||
368 | public function getLocationService() |
||
369 | { |
||
370 | if ($this->locationService !== null) { |
||
371 | return $this->locationService; |
||
372 | } |
||
373 | |||
374 | $this->locationService = new LocationService( |
||
375 | $this, |
||
376 | $this->persistenceHandler, |
||
377 | $this->getDomainMapper(), |
||
378 | $this->getNameSchemaService(), |
||
379 | $this->getPermissionCriterionResolver(), |
||
380 | $this->getPermissionResolver(), |
||
381 | $this->serviceSettings['location'], |
||
382 | $this->logger |
||
383 | ); |
||
384 | |||
385 | return $this->locationService; |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * Get Content Trash service. |
||
390 | * |
||
391 | * Trash service allows to perform operations related to location trash |
||
392 | * (trash/untrash, load/list from trash...) |
||
393 | * |
||
394 | * @return \eZ\Publish\API\Repository\TrashService |
||
395 | */ |
||
396 | public function getTrashService() |
||
397 | { |
||
398 | if ($this->trashService !== null) { |
||
399 | return $this->trashService; |
||
400 | } |
||
401 | |||
402 | $this->trashService = new TrashService( |
||
403 | $this, |
||
404 | $this->persistenceHandler, |
||
405 | $this->getNameSchemaService(), |
||
406 | $this->getPermissionCriterionResolver(), |
||
407 | $this->getPermissionResolver(), |
||
408 | $this->serviceSettings['trash'] |
||
409 | ); |
||
410 | |||
411 | return $this->trashService; |
||
412 | } |
||
413 | |||
414 | /** |
||
415 | * Get Content Section Service. |
||
416 | * |
||
417 | * Get Section service that lets you manipulate section objects |
||
418 | * |
||
419 | * @return \eZ\Publish\API\Repository\SectionService |
||
420 | */ |
||
421 | public function getSectionService() |
||
422 | { |
||
423 | if ($this->sectionService !== null) { |
||
424 | return $this->sectionService; |
||
425 | } |
||
426 | |||
427 | $this->sectionService = new SectionService( |
||
428 | $this, |
||
429 | $this->persistenceHandler->sectionHandler(), |
||
430 | $this->persistenceHandler->locationHandler(), |
||
431 | $this->getPermissionCriterionResolver(), |
||
432 | $this->serviceSettings['section'] |
||
433 | ); |
||
434 | |||
435 | return $this->sectionService; |
||
436 | } |
||
437 | |||
438 | /** |
||
439 | * Get User Service. |
||
440 | * |
||
441 | * Get service object to perform operations on Users and UserGroup |
||
442 | * |
||
443 | * @return \eZ\Publish\API\Repository\UserService |
||
444 | */ |
||
445 | public function getUserService() |
||
446 | { |
||
447 | if ($this->userService !== null) { |
||
448 | return $this->userService; |
||
449 | } |
||
450 | |||
451 | $this->userService = new UserService( |
||
452 | $this, |
||
453 | $this->getPermissionResolver(), |
||
454 | $this->persistenceHandler->userHandler(), |
||
455 | $this->persistenceHandler->locationHandler(), |
||
456 | $this->serviceSettings['user'] |
||
457 | ); |
||
458 | |||
459 | return $this->userService; |
||
460 | } |
||
461 | |||
462 | /** |
||
463 | * Get URLAliasService. |
||
464 | * |
||
465 | * @return \eZ\Publish\API\Repository\URLAliasService |
||
466 | */ |
||
467 | public function getURLAliasService() |
||
468 | { |
||
469 | if ($this->urlAliasService !== null) { |
||
470 | return $this->urlAliasService; |
||
471 | } |
||
472 | |||
473 | $this->urlAliasService = new URLAliasService( |
||
474 | $this, |
||
475 | $this->persistenceHandler->urlAliasHandler(), |
||
476 | $this->getNameSchemaService(), |
||
477 | $this->getPermissionResolver(), |
||
478 | $this->serviceSettings['urlAlias'] |
||
479 | ); |
||
480 | |||
481 | return $this->urlAliasService; |
||
482 | } |
||
483 | |||
484 | /** |
||
485 | * Get URLWildcardService. |
||
486 | * |
||
487 | * @return \eZ\Publish\API\Repository\URLWildcardService |
||
488 | */ |
||
489 | public function getURLWildcardService() |
||
490 | { |
||
491 | if ($this->urlWildcardService !== null) { |
||
492 | return $this->urlWildcardService; |
||
493 | } |
||
494 | |||
495 | $this->urlWildcardService = new URLWildcardService( |
||
496 | $this, |
||
497 | $this->persistenceHandler->urlWildcardHandler(), |
||
498 | $this->getPermissionResolver(), |
||
499 | $this->serviceSettings['urlWildcard'] |
||
500 | ); |
||
501 | |||
502 | return $this->urlWildcardService; |
||
503 | } |
||
504 | |||
505 | /** |
||
506 | * Get URLService. |
||
507 | * |
||
508 | * @return \eZ\Publish\API\Repository\URLService |
||
509 | */ |
||
510 | public function getURLService() |
||
511 | { |
||
512 | if ($this->urlService !== null) { |
||
513 | return $this->urlService; |
||
514 | } |
||
515 | |||
516 | $this->urlService = new URLService( |
||
517 | $this, |
||
518 | $this->persistenceHandler->urlHandler(), |
||
519 | $this->getPermissionResolver() |
||
520 | ); |
||
521 | |||
522 | return $this->urlService; |
||
523 | } |
||
524 | |||
525 | /** |
||
526 | * Get BookmarkService. |
||
527 | * |
||
528 | * @return \eZ\Publish\API\Repository\BookmarkService |
||
529 | */ |
||
530 | public function getBookmarkService() |
||
531 | { |
||
532 | if ($this->bookmarkService === null) { |
||
533 | $this->bookmarkService = new BookmarkService( |
||
534 | $this, |
||
535 | $this->persistenceHandler->bookmarkHandler() |
||
536 | ); |
||
537 | } |
||
538 | |||
539 | return $this->bookmarkService; |
||
540 | } |
||
541 | |||
542 | /** |
||
543 | * Get UserPreferenceService. |
||
544 | * |
||
545 | * @return \eZ\Publish\API\Repository\UserPreferenceService |
||
546 | */ |
||
547 | public function getUserPreferenceService() |
||
548 | { |
||
549 | if ($this->userPreferenceService === null) { |
||
550 | $this->userPreferenceService = new UserPreferenceService( |
||
551 | $this, |
||
552 | $this->persistenceHandler->userPreferenceHandler() |
||
553 | ); |
||
554 | } |
||
555 | |||
556 | return $this->userPreferenceService; |
||
557 | } |
||
558 | |||
559 | /** |
||
560 | * Get ObjectStateService. |
||
561 | * |
||
562 | * @return \eZ\Publish\API\Repository\ObjectStateService |
||
563 | */ |
||
564 | public function getObjectStateService() |
||
565 | { |
||
566 | if ($this->objectStateService !== null) { |
||
567 | return $this->objectStateService; |
||
568 | } |
||
569 | |||
570 | $this->objectStateService = new ObjectStateService( |
||
571 | $this, |
||
572 | $this->persistenceHandler->objectStateHandler(), |
||
573 | $this->getPermissionResolver(), |
||
574 | $this->serviceSettings['objectState'] |
||
575 | ); |
||
576 | |||
577 | return $this->objectStateService; |
||
578 | } |
||
579 | |||
580 | /** |
||
581 | * Get RoleService. |
||
582 | * |
||
583 | * @return \eZ\Publish\API\Repository\RoleService |
||
584 | */ |
||
585 | public function getRoleService() |
||
586 | { |
||
587 | if ($this->roleService !== null) { |
||
588 | return $this->roleService; |
||
589 | } |
||
590 | |||
591 | $this->roleService = new RoleService( |
||
592 | $this, |
||
593 | $this->persistenceHandler->userHandler(), |
||
594 | $this->getLimitationService(), |
||
595 | $this->getRoleDomainMapper(), |
||
596 | $this->serviceSettings['role'] |
||
597 | ); |
||
598 | |||
599 | return $this->roleService; |
||
600 | } |
||
601 | |||
602 | /** |
||
603 | * Get LimitationService. |
||
604 | * |
||
605 | * @return \eZ\Publish\Core\Repository\Helper\LimitationService |
||
606 | */ |
||
607 | protected function getLimitationService() |
||
608 | { |
||
609 | if ($this->limitationService !== null) { |
||
610 | return $this->limitationService; |
||
611 | } |
||
612 | |||
613 | $this->limitationService = new Helper\LimitationService($this->serviceSettings['role']); |
||
614 | |||
615 | return $this->limitationService; |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * Get RoleDomainMapper. |
||
620 | * |
||
621 | * @return \eZ\Publish\Core\Repository\Helper\RoleDomainMapper |
||
622 | */ |
||
623 | protected function getRoleDomainMapper() |
||
624 | { |
||
625 | if ($this->roleDomainMapper !== null) { |
||
626 | return $this->roleDomainMapper; |
||
627 | } |
||
628 | |||
629 | $this->roleDomainMapper = new Helper\RoleDomainMapper($this->getLimitationService()); |
||
630 | |||
631 | return $this->roleDomainMapper; |
||
632 | } |
||
633 | |||
634 | /** |
||
635 | * Get SearchService. |
||
636 | * |
||
637 | * @return \eZ\Publish\API\Repository\SearchService |
||
638 | */ |
||
639 | public function getSearchService() |
||
640 | { |
||
641 | if ($this->searchService !== null) { |
||
642 | return $this->searchService; |
||
643 | } |
||
644 | |||
645 | $this->searchService = new SearchService( |
||
646 | $this, |
||
647 | $this->searchHandler, |
||
648 | $this->getDomainMapper(), |
||
649 | $this->getPermissionCriterionResolver(), |
||
650 | $this->backgroundIndexer, |
||
651 | $this->serviceSettings['search'] |
||
652 | ); |
||
653 | |||
654 | return $this->searchService; |
||
655 | } |
||
656 | |||
657 | /** |
||
658 | * Get FieldTypeService. |
||
659 | * |
||
660 | * @return \eZ\Publish\API\Repository\FieldTypeService |
||
661 | */ |
||
662 | public function getFieldTypeService() |
||
663 | { |
||
664 | if ($this->fieldTypeService !== null) { |
||
665 | return $this->fieldTypeService; |
||
666 | } |
||
667 | |||
668 | $this->fieldTypeService = new FieldTypeService($this->fieldTypeRegistry); |
||
669 | |||
670 | return $this->fieldTypeService; |
||
671 | } |
||
672 | |||
673 | /** |
||
674 | * Get PermissionResolver. |
||
675 | * |
||
676 | * @return \eZ\Publish\API\Repository\PermissionResolver |
||
677 | */ |
||
678 | public function getPermissionResolver() |
||
679 | { |
||
680 | return $this->getCachedPermissionsResolver(); |
||
681 | } |
||
682 | |||
683 | /** |
||
684 | * Get NameSchemaResolverService. |
||
685 | * |
||
686 | * |
||
687 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
688 | * |
||
689 | * @internal |
||
690 | * @private |
||
691 | * |
||
692 | * @return \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
693 | */ |
||
694 | public function getNameSchemaService() |
||
695 | { |
||
696 | if ($this->nameSchemaService !== null) { |
||
697 | return $this->nameSchemaService; |
||
698 | } |
||
699 | |||
700 | $this->nameSchemaService = new Helper\NameSchemaService( |
||
701 | $this->persistenceHandler->contentTypeHandler(), |
||
702 | $this->getContentTypeDomainMapper(), |
||
703 | $this->fieldTypeRegistry, |
||
704 | $this->serviceSettings['nameSchema'] |
||
705 | ); |
||
706 | |||
707 | return $this->nameSchemaService; |
||
708 | } |
||
709 | |||
710 | /** |
||
711 | * @return \eZ\Publish\API\Repository\NotificationService |
||
712 | */ |
||
713 | public function getNotificationService(): NotificationServiceInterface |
||
714 | { |
||
715 | if (null !== $this->notificationService) { |
||
716 | return $this->notificationService; |
||
717 | } |
||
718 | |||
719 | $this->notificationService = new NotificationService( |
||
720 | $this->persistenceHandler->notificationHandler(), |
||
721 | $this->getPermissionResolver() |
||
722 | ); |
||
723 | |||
724 | return $this->notificationService; |
||
725 | } |
||
726 | |||
727 | /** |
||
728 | * Get RelationProcessor. |
||
729 | * |
||
730 | * |
||
731 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
732 | * |
||
733 | * @return \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
734 | */ |
||
735 | protected function getRelationProcessor() |
||
736 | { |
||
737 | return $this->relationProcessor; |
||
738 | } |
||
739 | |||
740 | /** |
||
741 | * Get Content Domain Mapper. |
||
742 | * |
||
743 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
744 | * |
||
745 | * @return \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
746 | */ |
||
747 | protected function getDomainMapper() |
||
748 | { |
||
749 | if ($this->domainMapper !== null) { |
||
750 | return $this->domainMapper; |
||
751 | } |
||
752 | |||
753 | $this->domainMapper = new Helper\DomainMapper( |
||
754 | $this->persistenceHandler->contentHandler(), |
||
755 | $this->persistenceHandler->locationHandler(), |
||
756 | $this->persistenceHandler->contentTypeHandler(), |
||
757 | $this->getContentTypeDomainMapper(), |
||
758 | $this->persistenceHandler->contentLanguageHandler(), |
||
759 | $this->fieldTypeRegistry |
||
760 | ); |
||
761 | |||
762 | return $this->domainMapper; |
||
763 | } |
||
764 | |||
765 | /** |
||
766 | * Get ContentType Domain Mapper. |
||
767 | * |
||
768 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
769 | * |
||
770 | * @return \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper |
||
771 | */ |
||
772 | protected function getContentTypeDomainMapper() |
||
773 | { |
||
774 | if ($this->contentTypeDomainMapper !== null) { |
||
775 | return $this->contentTypeDomainMapper; |
||
776 | } |
||
777 | |||
778 | $this->contentTypeDomainMapper = new Helper\ContentTypeDomainMapper( |
||
779 | $this->persistenceHandler->contentTypeHandler(), |
||
780 | $this->persistenceHandler->contentLanguageHandler(), |
||
781 | $this->fieldTypeRegistry |
||
782 | ); |
||
783 | |||
784 | return $this->contentTypeDomainMapper; |
||
785 | } |
||
786 | |||
787 | /** |
||
788 | * Get PermissionCriterionResolver. |
||
789 | * |
||
790 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
791 | * |
||
792 | * @return \eZ\Publish\API\Repository\PermissionCriterionResolver |
||
793 | */ |
||
794 | protected function getPermissionCriterionResolver() |
||
795 | { |
||
796 | return $this->getCachedPermissionsResolver(); |
||
797 | } |
||
798 | |||
799 | /** |
||
800 | * @return \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver |
||
801 | */ |
||
802 | protected function getCachedPermissionsResolver() |
||
803 | { |
||
804 | if ($this->permissionsHandler === null) { |
||
805 | $this->permissionsHandler = new CachedPermissionService( |
||
806 | $permissionResolver = new Permission\PermissionResolver( |
||
807 | $this->getRoleDomainMapper(), |
||
808 | $this->getLimitationService(), |
||
809 | $this->persistenceHandler->userHandler(), |
||
810 | new UserReference($this->serviceSettings['user']['anonymousUserID']), |
||
811 | $this->serviceSettings['role']['policyMap'] |
||
812 | ), |
||
813 | new PermissionCriterionResolver( |
||
814 | $permissionResolver, |
||
815 | $this->getLimitationService() |
||
816 | ) |
||
817 | ); |
||
818 | } |
||
819 | |||
820 | return $this->permissionsHandler; |
||
821 | } |
||
822 | |||
823 | /** |
||
824 | * Begin transaction. |
||
825 | * |
||
826 | * Begins an transaction, make sure you'll call commit or rollback when done, |
||
827 | * otherwise work will be lost. |
||
828 | */ |
||
829 | public function beginTransaction() |
||
830 | { |
||
831 | $this->persistenceHandler->beginTransaction(); |
||
832 | } |
||
833 | |||
834 | /** |
||
835 | * Commit transaction. |
||
836 | * |
||
837 | * Commit transaction, or throw exceptions if no transactions has been started. |
||
838 | * |
||
839 | * @throws RuntimeException If no transaction has been started |
||
840 | */ |
||
841 | public function commit() |
||
842 | { |
||
843 | try { |
||
844 | $this->persistenceHandler->commit(); |
||
845 | } catch (Exception $e) { |
||
846 | throw new RuntimeException($e->getMessage(), 0, $e); |
||
847 | } |
||
848 | } |
||
849 | |||
850 | /** |
||
851 | * Rollback transaction. |
||
852 | * |
||
853 | * Rollback transaction, or throw exceptions if no transactions has been started. |
||
854 | * |
||
855 | * @throws RuntimeException If no transaction has been started |
||
856 | */ |
||
857 | public function rollback() |
||
858 | { |
||
859 | try { |
||
860 | $this->persistenceHandler->rollback(); |
||
861 | } catch (Exception $e) { |
||
862 | throw new RuntimeException($e->getMessage(), 0, $e); |
||
863 | } |
||
864 | } |
||
865 | } |
||
866 |