Completed
Push — ezp-30882-thumbnail ( 274ed9...d4335b )
by
unknown
14:43
created

Repository::__construct()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 12
nop 9
dl 0
loc 52
rs 8.7361
c 0
b 0
f 0

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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