Completed
Push — ezp_30827 ( c6ab75...809fcf )
by
unknown
14:52
created

Repository   F

Complexity

Total Complexity 71

Size/Duplication

Total Lines 973
Duplicated Lines 3.6 %

Coupling/Cohesion

Components 1
Dependencies 34

Importance

Changes 0
Metric Value
dl 35
loc 973
rs 2.347
c 0
b 0
f 0
wmc 71
lcom 1
cbo 34

How to fix   Duplicated Code    Complexity   

Duplicated Code

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 Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

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
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Repository;
8
9
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
10
use eZ\Publish\Core\FieldType\FieldTypeRegistry;
11
use eZ\Publish\Core\Repository\User\PasswordHashGeneratorInterface;
12
use eZ\Publish\Core\Repository\Helper\RelationProcessor;
13
use eZ\Publish\Core\Repository\Permission\CachedPermissionService;
14
use eZ\Publish\Core\Repository\Permission\PermissionCriterionResolver;
15
use eZ\Publish\Core\Repository\Values\User\UserReference;
16
use eZ\Publish\Core\Search\Common\BackgroundIndexer;
17
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler;
18
use eZ\Publish\SPI\Search\Handler as SearchHandler;
19
use Exception;
20
use Psr\Log\LoggerInterface;
21
use Psr\Log\NullLogger;
22
use RuntimeException;
23
use eZ\Publish\API\Repository\NotificationService as NotificationServiceInterface;
24
25
/**
26
 * Repository class.
27
 */
28
class Repository implements RepositoryInterface
29
{
30
    /**
31
     * Repository Handler object.
32
     *
33
     * @var \eZ\Publish\SPI\Persistence\Handler
34
     */
35
    protected $persistenceHandler;
36
37
    /**
38
     * Instance of main Search Handler.
39
     *
40
     * @var \eZ\Publish\SPI\Search\Handler
41
     */
42
    protected $searchHandler;
43
44
    /**
45
     * Instance of content service.
46
     *
47
     * @var \eZ\Publish\API\Repository\ContentService
48
     */
49
    protected $contentService;
50
51
    /**
52
     * Instance of section service.
53
     *
54
     * @var \eZ\Publish\API\Repository\SectionService
55
     */
56
    protected $sectionService;
57
58
    /**
59
     * Instance of role service.
60
     *
61
     * @var \eZ\Publish\API\Repository\RoleService
62
     */
63
    protected $roleService;
64
65
    /**
66
     * Instance of search service.
67
     *
68
     * @var \eZ\Publish\API\Repository\SearchService
69
     */
70
    protected $searchService;
71
72
    /**
73
     * Instance of user service.
74
     *
75
     * @var \eZ\Publish\API\Repository\UserService
76
     */
77
    protected $userService;
78
79
    /**
80
     * Instance of language service.
81
     *
82
     * @var \eZ\Publish\API\Repository\LanguageService
83
     */
84
    protected $languageService;
85
86
    /**
87
     * Instance of location service.
88
     *
89
     * @var \eZ\Publish\API\Repository\LocationService
90
     */
91
    protected $locationService;
92
93
    /**
94
     * Instance of Trash service.
95
     *
96
     * @var \eZ\Publish\API\Repository\TrashService
97
     */
98
    protected $trashService;
99
100
    /**
101
     * Instance of content type service.
102
     *
103
     * @var \eZ\Publish\API\Repository\ContentTypeService
104
     */
105
    protected $contentTypeService;
106
107
    /**
108
     * Instance of object state service.
109
     *
110
     * @var \eZ\Publish\API\Repository\ObjectStateService
111
     */
112
    protected $objectStateService;
113
114
    /**
115
     * Instance of field type service.
116
     *
117
     * @var \eZ\Publish\API\Repository\FieldTypeService
118
     */
119
    protected $fieldTypeService;
120
121
    /** @var \eZ\Publish\Core\FieldType\FieldTypeRegistry */
122
    private $fieldTypeRegistry;
123
124
    /**
125
     * Instance of name schema resolver service.
126
     *
127
     * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService
128
     */
129
    protected $nameSchemaService;
130
131
    /**
132
     * Instance of relation processor service.
133
     *
134
     * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor
135
     */
136
    protected $relationProcessor;
137
138
    /**
139
     * Instance of URL alias service.
140
     *
141
     * @var \eZ\Publish\Core\Repository\URLAliasService
142
     */
143
    protected $urlAliasService;
144
145
    /**
146
     * Instance of URL wildcard service.
147
     *
148
     * @var \eZ\Publish\Core\Repository\URLWildcardService
149
     */
150
    protected $urlWildcardService;
151
152
    /**
153
     * Instance of URL service.
154
     *
155
     * @var \eZ\Publish\Core\Repository\URLService
156
     */
157
    protected $urlService;
158
159
    /**
160
     * Instance of Bookmark service.
161
     *
162
     * @var \eZ\Publish\API\Repository\BookmarkService
163
     */
164
    protected $bookmarkService;
165
166
    /**
167
     * Instance of Notification service.
168
     *
169
     * @var \eZ\Publish\API\Repository\NotificationService
170
     */
171
    protected $notificationService;
172
173
    /**
174
     * Instance of User Preference service.
175
     *
176
     * @var \eZ\Publish\API\Repository\UserPreferenceService
177
     */
178
    protected $userPreferenceService;
179
180
    /**
181
     * Service settings, first level key is service name.
182
     *
183
     * @var array
184
     */
185
    protected $serviceSettings;
186
187
    /**
188
     * Instance of role service.
189
     *
190
     * @var \eZ\Publish\Core\Repository\Helper\LimitationService
191
     */
192
    protected $limitationService;
193
194
    /** @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper */
195
    protected $roleDomainMapper;
196
197
    /**
198
     * Instance of domain mapper.
199
     *
200
     * @var \eZ\Publish\Core\Repository\Helper\DomainMapper
201
     */
202
    protected $domainMapper;
203
204
    /**
205
     * Instance of content type domain mapper.
206
     *
207
     * @var \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
208
     */
209
    protected $contentTypeDomainMapper;
210
211
    /**
212
     * Instance of permissions-resolver and -criterion resolver.
213
     *
214
     * @var \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver
215
     */
216
    protected $permissionsHandler;
217
218
    /** @var \eZ\Publish\Core\Search\Common\BackgroundIndexer|null */
219
    protected $backgroundIndexer;
220
221
    /** @var \Psr\Log\LoggerInterface */
222
    private $logger;
223
224
    /** @var \eZ\Publish\Core\Repository\User\PasswordHashGeneratorInterface */
225
    private $passwordHashGenerator;
226
227
    /**
228
     * Construct repository object with provided storage engine.
229
     *
230
     * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler
231
     * @param \eZ\Publish\SPI\Search\Handler $searchHandler
232
     * @param \eZ\Publish\Core\Search\Common\BackgroundIndexer $backgroundIndexer
233
     * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor
234
     * @param \eZ\Publish\Core\FieldType\FieldTypeRegistry $fieldTypeRegistry
235
     * @param \eZ\Publish\Core\Repository\User\PasswordHashGeneratorInterface $passwordHashGenerator
236
     * @param array $serviceSettings
237
     * @param \Psr\Log\LoggerInterface|null $logger
238
     */
239
    public function __construct(
240
        PersistenceHandler $persistenceHandler,
241
        SearchHandler $searchHandler,
242
        BackgroundIndexer $backgroundIndexer,
243
        RelationProcessor $relationProcessor,
244
        FieldTypeRegistry $fieldTypeRegistry,
245
        PasswordHashGeneratorInterface $passwordHashGenerator,
246
        array $serviceSettings = [],
247
        LoggerInterface $logger = null
248
    ) {
249
        $this->persistenceHandler = $persistenceHandler;
250
        $this->searchHandler = $searchHandler;
251
        $this->backgroundIndexer = $backgroundIndexer;
252
        $this->relationProcessor = $relationProcessor;
253
        $this->fieldTypeRegistry = $fieldTypeRegistry;
254
        $this->passwordHashGenerator = $passwordHashGenerator;
255
256
        $this->serviceSettings = $serviceSettings + [
257
            'content' => [],
258
            'contentType' => [],
259
            'location' => [],
260
            'section' => [],
261
            'role' => [],
262
            'user' => [
263
                'anonymousUserID' => 10,
264
            ],
265
            'language' => [],
266
            'trash' => [],
267
            'io' => [],
268
            'objectState' => [],
269
            'search' => [],
270
            'urlAlias' => [],
271
            'urlWildcard' => [],
272
            'nameSchema' => [],
273
            'languages' => [],
274
        ];
275
276
        if (!empty($this->serviceSettings['languages'])) {
277
            $this->serviceSettings['language']['languages'] = $this->serviceSettings['languages'];
278
        }
279
280
        $this->logger = null !== $logger ? $logger : new NullLogger();
281
    }
282
283
    /**
284
     * {@inheritdoc}
285
     */
286
    public function sudo(callable $callback, RepositoryInterface $outerRepository = null)
287
    {
288
        return $this->getPermissionResolver()->sudo($callback, $outerRepository ?? $this);
289
    }
290
291
    /**
292
     * Get Content Service.
293
     *
294
     * Get service object to perform operations on Content objects and it's aggregate members.
295
     *
296
     * @return \eZ\Publish\API\Repository\ContentService
297
     */
298
    public function getContentService()
299
    {
300
        if ($this->contentService !== null) {
301
            return $this->contentService;
302
        }
303
304
        $this->contentService = new ContentService(
305
            $this,
306
            $this->persistenceHandler,
307
            $this->getDomainMapper(),
308
            $this->getRelationProcessor(),
309
            $this->getNameSchemaService(),
310
            $this->fieldTypeRegistry,
311
            $this->getPermissionResolver(),
312
            $this->serviceSettings['content'],
313
        );
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ')'
Loading history...
314
315
        return $this->contentService;
316
    }
317
318
    /**
319
     * Get Content Language Service.
320
     *
321
     * Get service object to perform operations on Content language objects
322
     *
323
     * @return \eZ\Publish\API\Repository\LanguageService
324
     */
325
    public function getContentLanguageService()
326
    {
327
        if ($this->languageService !== null) {
328
            return $this->languageService;
329
        }
330
331
        $this->languageService = new LanguageService(
332
            $this,
333
            $this->persistenceHandler->contentLanguageHandler(),
334
            $this->getPermissionResolver(),
335
            $this->serviceSettings['language']
336
        );
337
338
        return $this->languageService;
339
    }
340
341
    /**
342
     * Get Content Type Service.
343
     *
344
     * Get service object to perform operations on Content Type objects and it's aggregate members.
345
     * ( Group, Field & FieldCategory )
346
     *
347
     * @return \eZ\Publish\API\Repository\ContentTypeService
348
     */
349
    public function getContentTypeService()
350
    {
351
        if ($this->contentTypeService !== null) {
352
            return $this->contentTypeService;
353
        }
354
355
        $this->contentTypeService = new ContentTypeService(
356
            $this,
357
            $this->persistenceHandler->contentTypeHandler(),
358
            $this->persistenceHandler->userHandler(),
359
            $this->getDomainMapper(),
360
            $this->getContentTypeDomainMapper(),
361
            $this->fieldTypeRegistry,
362
            $this->getPermissionResolver(),
363
            $this->serviceSettings['contentType']
364
        );
365
366
        return $this->contentTypeService;
367
    }
368
369
    /**
370
     * Get Content Location Service.
371
     *
372
     * Get service object to perform operations on Location objects and subtrees
373
     *
374
     * @return \eZ\Publish\API\Repository\LocationService
375
     */
376
    public function getLocationService()
377
    {
378
        if ($this->locationService !== null) {
379
            return $this->locationService;
380
        }
381
382
        $this->locationService = new LocationService(
383
            $this,
384
            $this->persistenceHandler,
385
            $this->getDomainMapper(),
386
            $this->getNameSchemaService(),
387
            $this->getPermissionCriterionResolver(),
388
            $this->getPermissionResolver(),
389
            $this->serviceSettings['location'],
390
            $this->logger
391
        );
392
393
        return $this->locationService;
394
    }
395
396
    /**
397
     * Get Content Trash service.
398
     *
399
     * Trash service allows to perform operations related to location trash
400
     * (trash/untrash, load/list from trash...)
401
     *
402
     * @return \eZ\Publish\API\Repository\TrashService
403
     */
404
    public function getTrashService()
405
    {
406
        if ($this->trashService !== null) {
407
            return $this->trashService;
408
        }
409
410
        $this->trashService = new TrashService(
411
            $this,
412
            $this->persistenceHandler,
413
            $this->getNameSchemaService(),
414
            $this->getPermissionCriterionResolver(),
415
            $this->getPermissionResolver(),
416
            $this->serviceSettings['trash']
417
        );
418
419
        return $this->trashService;
420
    }
421
422
    /**
423
     * Get Content Section Service.
424
     *
425
     * Get Section service that lets you manipulate section objects
426
     *
427
     * @return \eZ\Publish\API\Repository\SectionService
428
     */
429
    public function getSectionService()
430
    {
431
        if ($this->sectionService !== null) {
432
            return $this->sectionService;
433
        }
434
435
        $this->sectionService = new SectionService(
436
            $this,
437
            $this->persistenceHandler->sectionHandler(),
438
            $this->persistenceHandler->locationHandler(),
439
            $this->getPermissionCriterionResolver(),
440
            $this->serviceSettings['section']
441
        );
442
443
        return $this->sectionService;
444
    }
445
446
    /**
447
     * Get User Service.
448
     *
449
     * Get service object to perform operations on Users and UserGroup
450
     *
451
     * @return \eZ\Publish\API\Repository\UserService
452
     */
453
    public function getUserService()
454
    {
455
        if ($this->userService !== null) {
456
            return $this->userService;
457
        }
458
459
        $this->userService = new UserService(
460
            $this,
461
            $this->getPermissionResolver(),
462
            $this->persistenceHandler->userHandler(),
463
            $this->persistenceHandler->locationHandler(),
464
            $this->passwordHashGenerator,
465
            $this->serviceSettings['user']
466
        );
467
468
        return $this->userService;
469
    }
470
471
    /**
472
     * Get URLAliasService.
473
     *
474
     * @return \eZ\Publish\API\Repository\URLAliasService
475
     */
476
    public function getURLAliasService()
477
    {
478
        if ($this->urlAliasService !== null) {
479
            return $this->urlAliasService;
480
        }
481
482
        $this->urlAliasService = new URLAliasService(
483
            $this,
484
            $this->persistenceHandler->urlAliasHandler(),
485
            $this->getNameSchemaService(),
486
            $this->getPermissionResolver(),
487
            $this->serviceSettings['urlAlias']
488
        );
489
490
        return $this->urlAliasService;
491
    }
492
493
    /**
494
     * Get URLWildcardService.
495
     *
496
     * @return \eZ\Publish\API\Repository\URLWildcardService
497
     */
498
    public function getURLWildcardService()
499
    {
500
        if ($this->urlWildcardService !== null) {
501
            return $this->urlWildcardService;
502
        }
503
504
        $this->urlWildcardService = new URLWildcardService(
505
            $this,
506
            $this->persistenceHandler->urlWildcardHandler(),
507
            $this->getPermissionResolver(),
508
            $this->serviceSettings['urlWildcard']
509
        );
510
511
        return $this->urlWildcardService;
512
    }
513
514
    /**
515
     * Get URLService.
516
     *
517
     * @return \eZ\Publish\API\Repository\URLService
518
     */
519
    public function getURLService()
520
    {
521
        if ($this->urlService !== null) {
522
            return $this->urlService;
523
        }
524
525
        $this->urlService = new URLService(
526
            $this,
527
            $this->persistenceHandler->urlHandler(),
528
            $this->getPermissionResolver()
529
        );
530
531
        return $this->urlService;
532
    }
533
534
    /**
535
     * Get BookmarkService.
536
     *
537
     * @return \eZ\Publish\API\Repository\BookmarkService
538
     */
539
    public function getBookmarkService()
540
    {
541
        if ($this->bookmarkService === null) {
542
            $this->bookmarkService = new BookmarkService(
543
                $this,
544
                $this->persistenceHandler->bookmarkHandler()
545
            );
546
        }
547
548
        return $this->bookmarkService;
549
    }
550
551
    /**
552
     * Get UserPreferenceService.
553
     *
554
     * @return \eZ\Publish\API\Repository\UserPreferenceService
555
     */
556
    public function getUserPreferenceService()
557
    {
558
        if ($this->userPreferenceService === null) {
559
            $this->userPreferenceService = new UserPreferenceService(
560
                $this,
561
                $this->persistenceHandler->userPreferenceHandler()
562
            );
563
        }
564
565
        return $this->userPreferenceService;
566
    }
567
568
    /**
569
     * Get ObjectStateService.
570
     *
571
     * @return \eZ\Publish\API\Repository\ObjectStateService
572
     */
573
    public function getObjectStateService()
574
    {
575
        if ($this->objectStateService !== null) {
576
            return $this->objectStateService;
577
        }
578
579
        $this->objectStateService = new ObjectStateService(
580
            $this,
581
            $this->persistenceHandler->objectStateHandler(),
582
            $this->getPermissionResolver(),
583
            $this->serviceSettings['objectState']
584
        );
585
586
        return $this->objectStateService;
587
    }
588
589
    /**
590
     * Get RoleService.
591
     *
592
     * @return \eZ\Publish\API\Repository\RoleService
593
     */
594
    public function getRoleService()
595
    {
596
        if ($this->roleService !== null) {
597
            return $this->roleService;
598
        }
599
600
        $this->roleService = new RoleService(
601
            $this,
602
            $this->persistenceHandler->userHandler(),
603
            $this->getLimitationService(),
604
            $this->getRoleDomainMapper(),
605
            $this->serviceSettings['role']
606
        );
607
608
        return $this->roleService;
609
    }
610
611
    /**
612
     * Get LimitationService.
613
     *
614
     * @return \eZ\Publish\Core\Repository\Helper\LimitationService
615
     */
616
    protected function getLimitationService()
617
    {
618
        if ($this->limitationService !== null) {
619
            return $this->limitationService;
620
        }
621
622
        $this->limitationService = new Helper\LimitationService($this->serviceSettings['role']);
623
624
        return $this->limitationService;
625
    }
626
627
    /**
628
     * Get RoleDomainMapper.
629
     *
630
     * @return \eZ\Publish\Core\Repository\Helper\RoleDomainMapper
631
     */
632
    protected function getRoleDomainMapper()
633
    {
634
        if ($this->roleDomainMapper !== null) {
635
            return $this->roleDomainMapper;
636
        }
637
638
        $this->roleDomainMapper = new Helper\RoleDomainMapper($this->getLimitationService());
639
640
        return $this->roleDomainMapper;
641
    }
642
643
    /**
644
     * Get SearchService.
645
     *
646
     * @return \eZ\Publish\API\Repository\SearchService
647
     */
648
    public function getSearchService()
649
    {
650
        if ($this->searchService !== null) {
651
            return $this->searchService;
652
        }
653
654
        $this->searchService = new SearchService(
655
            $this,
656
            $this->searchHandler,
657
            $this->getDomainMapper(),
658
            $this->getPermissionCriterionResolver(),
659
            $this->backgroundIndexer,
660
            $this->serviceSettings['search']
661
        );
662
663
        return $this->searchService;
664
    }
665
666
    /**
667
     * Get FieldTypeService.
668
     *
669
     * @return \eZ\Publish\API\Repository\FieldTypeService
670
     */
671
    public function getFieldTypeService()
672
    {
673
        if ($this->fieldTypeService !== null) {
674
            return $this->fieldTypeService;
675
        }
676
677
        $this->fieldTypeService = new FieldTypeService($this->fieldTypeRegistry);
678
679
        return $this->fieldTypeService;
680
    }
681
682
    /**
683
     * Get PermissionResolver.
684
     *
685
     * @return \eZ\Publish\API\Repository\PermissionResolver
686
     */
687
    public function getPermissionResolver()
688
    {
689
        return $this->getCachedPermissionsResolver();
690
    }
691
692
    /**
693
     * Get NameSchemaResolverService.
694
     *
695
     *
696
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
697
     *
698
     * @internal
699
     * @private
700
     *
701
     * @return \eZ\Publish\Core\Repository\Helper\NameSchemaService
702
     */
703
    public function getNameSchemaService()
704
    {
705
        if ($this->nameSchemaService !== null) {
706
            return $this->nameSchemaService;
707
        }
708
709
        $this->nameSchemaService = new Helper\NameSchemaService(
710
            $this->persistenceHandler->contentTypeHandler(),
711
            $this->getContentTypeDomainMapper(),
712
            $this->fieldTypeRegistry,
713
            $this->serviceSettings['nameSchema']
714
        );
715
716
        return $this->nameSchemaService;
717
    }
718
719
    /**
720
     * @return \eZ\Publish\API\Repository\NotificationService
721
     */
722
    public function getNotificationService(): NotificationServiceInterface
723
    {
724
        if (null !== $this->notificationService) {
725
            return $this->notificationService;
726
        }
727
728
        $this->notificationService = new NotificationService(
729
            $this->persistenceHandler->notificationHandler(),
730
            $this->getPermissionResolver()
731
        );
732
733
        return $this->notificationService;
734
    }
735
736
    /**
737
     * Get RelationProcessor.
738
     *
739
     *
740
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
741
     *
742
     * @return \eZ\Publish\Core\Repository\Helper\RelationProcessor
743
     */
744
    protected function getRelationProcessor()
745
    {
746
        return $this->relationProcessor;
747
    }
748
749
    /**
750
     * Get Content Domain Mapper.
751
     *
752
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
753
     *
754
     * @return \eZ\Publish\Core\Repository\Helper\DomainMapper
755
     */
756
    protected function getDomainMapper()
757
    {
758
        if ($this->domainMapper !== null) {
759
            return $this->domainMapper;
760
        }
761
762
        $this->domainMapper = new Helper\DomainMapper(
763
            $this->persistenceHandler->contentHandler(),
764
            $this->persistenceHandler->locationHandler(),
765
            $this->persistenceHandler->contentTypeHandler(),
766
            $this->getContentTypeDomainMapper(),
767
            $this->persistenceHandler->contentLanguageHandler(),
768
            $this->fieldTypeRegistry
769
        );
770
771
        return $this->domainMapper;
772
    }
773
774
    /**
775
     * Get ContentType Domain Mapper.
776
     *
777
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
778
     *
779
     * @return \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
780
     */
781
    protected function getContentTypeDomainMapper()
782
    {
783
        if ($this->contentTypeDomainMapper !== null) {
784
            return $this->contentTypeDomainMapper;
785
        }
786
787
        $this->contentTypeDomainMapper = new Helper\ContentTypeDomainMapper(
788
            $this->persistenceHandler->contentTypeHandler(),
789
            $this->persistenceHandler->contentLanguageHandler(),
790
            $this->fieldTypeRegistry
791
        );
792
793
        return $this->contentTypeDomainMapper;
794
    }
795
796
    /**
797
     * Get PermissionCriterionResolver.
798
     *
799
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
800
     *
801
     * @return \eZ\Publish\API\Repository\PermissionCriterionResolver
802
     */
803
    protected function getPermissionCriterionResolver()
804
    {
805
        return $this->getCachedPermissionsResolver();
806
    }
807
808
    /**
809
     * @return \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver
810
     */
811
    protected function getCachedPermissionsResolver()
812
    {
813
        if ($this->permissionsHandler === null) {
814
            $this->permissionsHandler = new CachedPermissionService(
815
                $permissionResolver = new Permission\PermissionResolver(
816
                    $this->getRoleDomainMapper(),
817
                    $this->getLimitationService(),
818
                    $this->persistenceHandler->userHandler(),
819
                    new UserReference($this->serviceSettings['user']['anonymousUserID']),
820
                    $this->serviceSettings['role']['policyMap']
821
                ),
822
                new PermissionCriterionResolver(
823
                    $permissionResolver,
824
                    $this->getLimitationService()
825
                )
826
            );
827
        }
828
829
        return $this->permissionsHandler;
830
    }
831
832
    /**
833
     * Begin transaction.
834
     *
835
     * Begins an transaction, make sure you'll call commit or rollback when done,
836
     * otherwise work will be lost.
837
     */
838
    public function beginTransaction()
839
    {
840
        $this->persistenceHandler->beginTransaction();
841
    }
842
843
    /**
844
     * Commit transaction.
845
     *
846
     * Commit transaction, or throw exceptions if no transactions has been started.
847
     *
848
     * @throws RuntimeException If no transaction has been started
849
     */
850
    public function commit()
851
    {
852
        try {
853
            $this->persistenceHandler->commit();
854
        } catch (Exception $e) {
855
            throw new RuntimeException($e->getMessage(), 0, $e);
856
        }
857
    }
858
859
    /**
860
     * Rollback transaction.
861
     *
862
     * Rollback transaction, or throw exceptions if no transactions has been started.
863
     *
864
     * @throws RuntimeException If no transaction has been started
865
     */
866
    public function rollback()
867
    {
868
        try {
869
            $this->persistenceHandler->rollback();
870
        } catch (Exception $e) {
871
            throw new RuntimeException($e->getMessage(), 0, $e);
872
        }
873
    }
874
}
875