Completed
Push — readme ( 4da83f...7adc69 )
by
unknown
28:00 queued 04:49
created

Repository::getURLAliasService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
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\API\Repository\Values\ValueObject;
11
use eZ\Publish\API\Repository\Values\User\User;
12
use eZ\Publish\API\Repository\Values\User\UserReference as APIUserReference;
13
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue;
14
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;
15
use eZ\Publish\Core\Repository\Helper\RelationProcessor;
16
use eZ\Publish\Core\Repository\Permission\CachedPermissionService;
17
use eZ\Publish\Core\Repository\Permission\PermissionCriterionResolver;
18
use eZ\Publish\Core\Repository\Values\User\UserReference;
19
use eZ\Publish\Core\Search\Common\BackgroundIndexer;
20
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler;
21
use eZ\Publish\SPI\Search\Handler as SearchHandler;
22
use Exception;
23
use Psr\Log\LoggerInterface;
24
use Psr\Log\NullLogger;
25
use RuntimeException;
26
use eZ\Publish\API\Repository\NotificationService as NotificationServiceInterface;
27
28
/**
29
 * Repository class.
30
 */
31
class Repository implements RepositoryInterface
32
{
33
    /**
34
     * Repository Handler object.
35
     *
36
     * @var \eZ\Publish\SPI\Persistence\Handler
37
     */
38
    protected $persistenceHandler;
39
40
    /**
41
     * Instance of main Search Handler.
42
     *
43
     * @var \eZ\Publish\SPI\Search\Handler
44
     */
45
    protected $searchHandler;
46
47
    /**
48
     * @deprecated since 6.6, to be removed. Current user handling is moved to PermissionResolver.
49
     *
50
     * Currently logged in user object if already loaded.
51
     *
52
     * @var \eZ\Publish\API\Repository\Values\User\User|null
53
     */
54
    protected $currentUser;
55
56
    /**
57
     * @deprecated since 6.6, to be removed. Current user handling is moved to PermissionResolver.
58
     *
59
     * Currently logged in user reference for permission purposes.
60
     *
61
     * @var \eZ\Publish\API\Repository\Values\User\UserReference
62
     */
63
    protected $currentUserRef;
64
65
    /**
66
     * Instance of content service.
67
     *
68
     * @var \eZ\Publish\API\Repository\ContentService
69
     */
70
    protected $contentService;
71
72
    /**
73
     * Instance of section service.
74
     *
75
     * @var \eZ\Publish\API\Repository\SectionService
76
     */
77
    protected $sectionService;
78
79
    /**
80
     * Instance of role service.
81
     *
82
     * @var \eZ\Publish\API\Repository\RoleService
83
     */
84
    protected $roleService;
85
86
    /**
87
     * Instance of search service.
88
     *
89
     * @var \eZ\Publish\API\Repository\SearchService
90
     */
91
    protected $searchService;
92
93
    /**
94
     * Instance of user service.
95
     *
96
     * @var \eZ\Publish\API\Repository\UserService
97
     */
98
    protected $userService;
99
100
    /**
101
     * Instance of language service.
102
     *
103
     * @var \eZ\Publish\API\Repository\LanguageService
104
     */
105
    protected $languageService;
106
107
    /**
108
     * Instance of location service.
109
     *
110
     * @var \eZ\Publish\API\Repository\LocationService
111
     */
112
    protected $locationService;
113
114
    /**
115
     * Instance of Trash service.
116
     *
117
     * @var \eZ\Publish\API\Repository\TrashService
118
     */
119
    protected $trashService;
120
121
    /**
122
     * Instance of content type service.
123
     *
124
     * @var \eZ\Publish\API\Repository\ContentTypeService
125
     */
126
    protected $contentTypeService;
127
128
    /**
129
     * Instance of object state service.
130
     *
131
     * @var \eZ\Publish\API\Repository\ObjectStateService
132
     */
133
    protected $objectStateService;
134
135
    /**
136
     * Instance of field type service.
137
     *
138
     * @var \eZ\Publish\API\Repository\FieldTypeService
139
     */
140
    protected $fieldTypeService;
141
142
    /**
143
     * Instance of FieldTypeRegistry.
144
     *
145
     * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry
146
     */
147
    private $fieldTypeRegistry;
148
149
    /**
150
     * Instance of NameableFieldTypeRegistry.
151
     *
152
     * @var \eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry
153
     */
154
    private $nameableFieldTypeRegistry;
155
156
    /**
157
     * Instance of name schema resolver service.
158
     *
159
     * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService
160
     */
161
    protected $nameSchemaService;
162
163
    /**
164
     * Instance of relation processor service.
165
     *
166
     * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor
167
     */
168
    protected $relationProcessor;
169
170
    /**
171
     * Instance of URL alias service.
172
     *
173
     * @var \eZ\Publish\Core\Repository\URLAliasService
174
     */
175
    protected $urlAliasService;
176
177
    /**
178
     * Instance of URL wildcard service.
179
     *
180
     * @var \eZ\Publish\Core\Repository\URLWildcardService
181
     */
182
    protected $urlWildcardService;
183
184
    /**
185
     * Instance of URL service.
186
     *
187
     * @var \eZ\Publish\Core\Repository\URLService
188
     */
189
    protected $urlService;
190
191
    /**
192
     * Instance of Bookmark service.
193
     *
194
     * @var \eZ\Publish\API\Repository\BookmarkService
195
     */
196
    protected $bookmarkService;
197
198
    /**
199
     * Instance of Notification service.
200
     *
201
     * @var \eZ\Publish\API\Repository\NotificationService
202
     */
203
    protected $notificationService;
204
205
    /**
206
     * Instance of User Preference service.
207
     *
208
     * @var \eZ\Publish\API\Repository\UserPreferenceService
209
     */
210
    protected $userPreferenceService;
211
212
    /**
213
     * Service settings, first level key is service name.
214
     *
215
     * @var array
216
     */
217
    protected $serviceSettings;
218
219
    /**
220
     * Instance of role service.
221
     *
222
     * @var \eZ\Publish\Core\Repository\Helper\LimitationService
223
     */
224
    protected $limitationService;
225
226
    /** @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper */
227
    protected $roleDomainMapper;
228
229
    /**
230
     * Instance of domain mapper.
231
     *
232
     * @var \eZ\Publish\Core\Repository\Helper\DomainMapper
233
     */
234
    protected $domainMapper;
235
236
    /**
237
     * Instance of content type domain mapper.
238
     *
239
     * @var \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
240
     */
241
    protected $contentTypeDomainMapper;
242
243
    /**
244
     * Instance of permissions-resolver and -criterion resolver.
245
     *
246
     * @var \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver
247
     */
248
    protected $permissionsHandler;
249
250
    /** @var \eZ\Publish\Core\Search\Common\BackgroundIndexer|null */
251
    protected $backgroundIndexer;
252
253
    /** @var \Psr\Log\LoggerInterface */
254
    private $logger;
255
256
    /**
257
     * Constructor.
258
     *
259
     * Construct repository object with provided storage engine
260
     *
261
     * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler
262
     * @param \eZ\Publish\SPI\Search\Handler $searchHandler
263
     * @param \eZ\Publish\Core\Search\Common\BackgroundIndexer $backgroundIndexer
264
     * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor
265
     * @param array $serviceSettings
266
     * @param \eZ\Publish\API\Repository\Values\User\UserReference|null $user
267
     * @param \Psr\Log\LoggerInterface|null $logger
268
     */
269
    public function __construct(
270
        PersistenceHandler $persistenceHandler,
271
        SearchHandler $searchHandler,
272
        BackgroundIndexer $backgroundIndexer,
273
        RelationProcessor $relationProcessor,
274
        array $serviceSettings = [],
275
        APIUserReference $user = null,
276
        LoggerInterface $logger = null
277
    ) {
278
        $this->persistenceHandler = $persistenceHandler;
279
        $this->searchHandler = $searchHandler;
280
        $this->backgroundIndexer = $backgroundIndexer;
281
        $this->relationProcessor = $relationProcessor;
282
        $this->serviceSettings = $serviceSettings + [
283
            'content' => [],
284
            'contentType' => [],
285
            'location' => [],
286
            'section' => [],
287
            'role' => [],
288
            'user' => [
289
                'anonymousUserID' => 10,
290
            ],
291
            'language' => [],
292
            'trash' => [],
293
            'io' => [],
294
            'objectState' => [],
295
            'search' => [],
296
            'fieldType' => [],
297
            'nameableFieldTypes' => [],
298
            'urlAlias' => [],
299
            'urlWildcard' => [],
300
            'nameSchema' => [],
301
            'languages' => [],
302
        ];
303
304
        if (!empty($this->serviceSettings['languages'])) {
305
            $this->serviceSettings['language']['languages'] = $this->serviceSettings['languages'];
306
        }
307
308
        if ($user instanceof User) {
309
            $this->currentUser = $user;
310
            $this->currentUserRef = new UserReference($user->getUserId());
311
        } elseif ($user instanceof APIUserReference) {
312
            $this->currentUserRef = $user;
313
        } else {
314
            $this->currentUserRef = new UserReference($this->serviceSettings['user']['anonymousUserID']);
315
        }
316
317
        $this->logger = null !== $logger ? $logger : new NullLogger();
318
    }
319
320
    /**
321
     * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
322
     *
323
     * Get current user.
324
     *
325
     * Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}
326
     *
327
     * @return \eZ\Publish\API\Repository\Values\User\User
328
     */
329
    public function getCurrentUser()
330
    {
331
        if ($this->currentUser === null) {
332
            $this->currentUser = $this->getUserService()->loadUser(
333
                $this->getPermissionResolver()->getCurrentUserReference()->getUserId()
334
            );
335
        }
336
337
        return $this->currentUser;
338
    }
339
340
    /**
341
     * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
342
     *
343
     * Get current user reference.
344
     *
345
     * @since 5.4.5
346
     * @return \eZ\Publish\API\Repository\Values\User\UserReference
347
     */
348
    public function getCurrentUserReference()
349
    {
350
        return $this->getPermissionResolver()->getCurrentUserReference();
351
    }
352
353
    /**
354
     * @deprecated since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead.
355
     *
356
     * Sets the current user to the given $user.
357
     *
358
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
359
     *
360
     * @throws InvalidArgumentValue If UserReference does not contain a id
361
     */
362
    public function setCurrentUser(APIUserReference $user)
363
    {
364
        $id = $user->getUserId();
365
        if (!$id) {
366
            throw new InvalidArgumentValue('$user->getUserId()', $id);
367
        }
368
369
        if ($user instanceof User) {
370
            $this->currentUser = $user;
371
            $this->currentUserRef = new UserReference($id);
372
        } else {
373
            $this->currentUser = null;
374
            $this->currentUserRef = $user;
375
        }
376
377
        return $this->getPermissionResolver()->setCurrentUserReference($this->currentUserRef);
378
    }
379
380
    /**
381
     * {@inheritdoc}
382
     */
383
    public function sudo(callable $callback, RepositoryInterface $outerRepository = null)
384
    {
385
        return $this->getPermissionResolver()->sudo($callback, $outerRepository ?? $this);
386
    }
387
388
    /**
389
     * @deprecated since 6.6, to be removed. Use PermissionResolver::hasAccess() instead.
390
     *
391
     * Check if user has access to a given module / function.
392
     *
393
     * Low level function, use canUser instead if you have objects to check against.
394
     *
395
     * @param string $module
396
     * @param string $function
397
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
398
     *
399
     * @return bool|array Bool if user has full or no access, array if limitations if not
400
     */
401
    public function hasAccess($module, $function, APIUserReference $user = null)
402
    {
403
        return $this->getPermissionResolver()->hasAccess($module, $function, $user);
404
    }
405
406
    /**
407
     * @deprecated since 6.6, to be removed. Use PermissionResolver::canUser() instead.
408
     *
409
     * Check if user has access to a given action on a given value object.
410
     *
411
     * Indicates if the current user is allowed to perform an action given by the function on the given
412
     * objects.
413
     *
414
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If any of the arguments are invalid
415
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If value of the LimitationValue is unsupported
416
     *
417
     * @param string $module The module, aka controller identifier to check permissions on
418
     * @param string $function The function, aka the controller action to check permissions on
419
     * @param \eZ\Publish\API\Repository\Values\ValueObject $object The object to check if the user has access to
420
     * @param mixed $targets The location, parent or "assignment" value object, or an array of the same
421
     *
422
     * @return bool
423
     */
424
    public function canUser($module, $function, ValueObject $object, $targets = null)
425
    {
426
        if ($targets instanceof ValueObject) {
427
            $targets = [$targets];
428
        } elseif ($targets === null) {
429
            $targets = [];
430
        } elseif (!is_array($targets)) {
431
            throw new InvalidArgumentType(
432
                '$targets',
433
                'null|\\eZ\\Publish\\API\\Repository\\Values\\ValueObject|\\eZ\\Publish\\API\\Repository\\Values\\ValueObject[]',
434
                $targets
435
            );
436
        }
437
438
        return $this->getPermissionResolver()->canUser($module, $function, $object, $targets);
439
    }
440
441
    /**
442
     * Get Content Service.
443
     *
444
     * Get service object to perform operations on Content objects and it's aggregate members.
445
     *
446
     * @return \eZ\Publish\API\Repository\ContentService
447
     */
448
    public function getContentService()
449
    {
450
        if ($this->contentService !== null) {
451
            return $this->contentService;
452
        }
453
454
        $this->contentService = new ContentService(
455
            $this,
456
            $this->persistenceHandler,
457
            $this->getDomainMapper(),
458
            $this->getRelationProcessor(),
459
            $this->getNameSchemaService(),
460
            $this->getFieldTypeRegistry(),
461
            $this->serviceSettings['content']
462
        );
463
464
        return $this->contentService;
465
    }
466
467
    /**
468
     * Get Content Language Service.
469
     *
470
     * Get service object to perform operations on Content language objects
471
     *
472
     * @return \eZ\Publish\API\Repository\LanguageService
473
     */
474
    public function getContentLanguageService()
475
    {
476
        if ($this->languageService !== null) {
477
            return $this->languageService;
478
        }
479
480
        $this->languageService = new LanguageService(
481
            $this,
482
            $this->persistenceHandler->contentLanguageHandler(),
483
            $this->serviceSettings['language']
484
        );
485
486
        return $this->languageService;
487
    }
488
489
    /**
490
     * Get Content Type Service.
491
     *
492
     * Get service object to perform operations on Content Type objects and it's aggregate members.
493
     * ( Group, Field & FieldCategory )
494
     *
495
     * @return \eZ\Publish\API\Repository\ContentTypeService
496
     */
497 View Code Duplication
    public function getContentTypeService()
498
    {
499
        if ($this->contentTypeService !== null) {
500
            return $this->contentTypeService;
501
        }
502
503
        $this->contentTypeService = new ContentTypeService(
504
            $this,
505
            $this->persistenceHandler->contentTypeHandler(),
506
            $this->persistenceHandler->userHandler(),
507
            $this->getDomainMapper(),
508
            $this->getContentTypeDomainMapper(),
509
            $this->getFieldTypeRegistry(),
510
            $this->serviceSettings['contentType']
511
        );
512
513
        return $this->contentTypeService;
514
    }
515
516
    /**
517
     * Get Content Location Service.
518
     *
519
     * Get service object to perform operations on Location objects and subtrees
520
     *
521
     * @return \eZ\Publish\API\Repository\LocationService
522
     */
523
    public function getLocationService()
524
    {
525
        if ($this->locationService !== null) {
526
            return $this->locationService;
527
        }
528
529
        $this->locationService = new LocationService(
530
            $this,
531
            $this->persistenceHandler,
532
            $this->getDomainMapper(),
533
            $this->getNameSchemaService(),
534
            $this->getPermissionCriterionResolver(),
535
            $this->serviceSettings['location'],
536
            $this->logger
537
        );
538
539
        return $this->locationService;
540
    }
541
542
    /**
543
     * Get Content Trash service.
544
     *
545
     * Trash service allows to perform operations related to location trash
546
     * (trash/untrash, load/list from trash...)
547
     *
548
     * @return \eZ\Publish\API\Repository\TrashService
549
     */
550
    public function getTrashService()
551
    {
552
        if ($this->trashService !== null) {
553
            return $this->trashService;
554
        }
555
556
        $this->trashService = new TrashService(
557
            $this,
558
            $this->persistenceHandler,
559
            $this->getNameSchemaService(),
560
            $this->getPermissionCriterionResolver(),
561
            $this->serviceSettings['trash']
562
        );
563
564
        return $this->trashService;
565
    }
566
567
    /**
568
     * Get Content Section Service.
569
     *
570
     * Get Section service that lets you manipulate section objects
571
     *
572
     * @return \eZ\Publish\API\Repository\SectionService
573
     */
574
    public function getSectionService()
575
    {
576
        if ($this->sectionService !== null) {
577
            return $this->sectionService;
578
        }
579
580
        $this->sectionService = new SectionService(
581
            $this,
582
            $this->persistenceHandler->sectionHandler(),
583
            $this->persistenceHandler->locationHandler(),
584
            $this->getPermissionCriterionResolver(),
585
            $this->serviceSettings['section']
586
        );
587
588
        return $this->sectionService;
589
    }
590
591
    /**
592
     * Get User Service.
593
     *
594
     * Get service object to perform operations on Users and UserGroup
595
     *
596
     * @return \eZ\Publish\API\Repository\UserService
597
     */
598
    public function getUserService()
599
    {
600
        if ($this->userService !== null) {
601
            return $this->userService;
602
        }
603
604
        $this->userService = new UserService(
605
            $this,
606
            $this->persistenceHandler->userHandler(),
607
            $this->persistenceHandler->locationHandler(),
608
            $this->serviceSettings['user']
609
        );
610
611
        return $this->userService;
612
    }
613
614
    /**
615
     * Get URLAliasService.
616
     *
617
     * @return \eZ\Publish\API\Repository\URLAliasService
618
     */
619
    public function getURLAliasService()
620
    {
621
        if ($this->urlAliasService !== null) {
622
            return $this->urlAliasService;
623
        }
624
625
        $this->urlAliasService = new URLAliasService(
626
            $this,
627
            $this->persistenceHandler->urlAliasHandler(),
628
            $this->getNameSchemaService(),
629
            $this->getPermissionResolver(),
630
            $this->serviceSettings['urlAlias']
631
        );
632
633
        return $this->urlAliasService;
634
    }
635
636
    /**
637
     * Get URLWildcardService.
638
     *
639
     * @return \eZ\Publish\API\Repository\URLWildcardService
640
     */
641
    public function getURLWildcardService()
642
    {
643
        if ($this->urlWildcardService !== null) {
644
            return $this->urlWildcardService;
645
        }
646
647
        $this->urlWildcardService = new URLWildcardService(
648
            $this,
649
            $this->persistenceHandler->urlWildcardHandler(),
650
            $this->getPermissionResolver(),
651
            $this->serviceSettings['urlWildcard']
652
        );
653
654
        return $this->urlWildcardService;
655
    }
656
657
    /**
658
     * Get URLService.
659
     *
660
     * @return \eZ\Publish\API\Repository\URLService
661
     */
662
    public function getURLService()
663
    {
664
        if ($this->urlService !== null) {
665
            return $this->urlService;
666
        }
667
668
        $this->urlService = new URLService(
669
            $this,
670
            $this->persistenceHandler->urlHandler(),
671
            $this->getPermissionResolver()
672
        );
673
674
        return $this->urlService;
675
    }
676
677
    /**
678
     * Get BookmarkService.
679
     *
680
     * @return \eZ\Publish\API\Repository\BookmarkService
681
     */
682
    public function getBookmarkService()
683
    {
684
        if ($this->bookmarkService === null) {
685
            $this->bookmarkService = new BookmarkService(
686
                $this,
687
                $this->persistenceHandler->bookmarkHandler()
688
            );
689
        }
690
691
        return $this->bookmarkService;
692
    }
693
694
    /**
695
     * Get UserPreferenceService.
696
     *
697
     * @return \eZ\Publish\API\Repository\UserPreferenceService
698
     */
699
    public function getUserPreferenceService()
700
    {
701
        if ($this->userPreferenceService === null) {
702
            $this->userPreferenceService = new UserPreferenceService(
703
                $this,
704
                $this->persistenceHandler->userPreferenceHandler()
705
            );
706
        }
707
708
        return $this->userPreferenceService;
709
    }
710
711
    /**
712
     * Get ObjectStateService.
713
     *
714
     * @return \eZ\Publish\API\Repository\ObjectStateService
715
     */
716
    public function getObjectStateService()
717
    {
718
        if ($this->objectStateService !== null) {
719
            return $this->objectStateService;
720
        }
721
722
        $this->objectStateService = new ObjectStateService(
723
            $this,
724
            $this->persistenceHandler->objectStateHandler(),
725
            $this->serviceSettings['objectState']
726
        );
727
728
        return $this->objectStateService;
729
    }
730
731
    /**
732
     * Get RoleService.
733
     *
734
     * @return \eZ\Publish\API\Repository\RoleService
735
     */
736
    public function getRoleService()
737
    {
738
        if ($this->roleService !== null) {
739
            return $this->roleService;
740
        }
741
742
        $this->roleService = new RoleService(
743
            $this,
744
            $this->persistenceHandler->userHandler(),
745
            $this->getLimitationService(),
746
            $this->getRoleDomainMapper(),
747
            $this->serviceSettings['role']
748
        );
749
750
        return $this->roleService;
751
    }
752
753
    /**
754
     * Get LimitationService.
755
     *
756
     * @return \eZ\Publish\Core\Repository\Helper\LimitationService
757
     */
758
    protected function getLimitationService()
759
    {
760
        if ($this->limitationService !== null) {
761
            return $this->limitationService;
762
        }
763
764
        $this->limitationService = new Helper\LimitationService($this->serviceSettings['role']);
765
766
        return $this->limitationService;
767
    }
768
769
    /**
770
     * Get RoleDomainMapper.
771
     *
772
     * @return \eZ\Publish\Core\Repository\Helper\RoleDomainMapper
773
     */
774
    protected function getRoleDomainMapper()
775
    {
776
        if ($this->roleDomainMapper !== null) {
777
            return $this->roleDomainMapper;
778
        }
779
780
        $this->roleDomainMapper = new Helper\RoleDomainMapper($this->getLimitationService());
781
782
        return $this->roleDomainMapper;
783
    }
784
785
    /**
786
     * Get SearchService.
787
     *
788
     * @return \eZ\Publish\API\Repository\SearchService
789
     */
790
    public function getSearchService()
791
    {
792
        if ($this->searchService !== null) {
793
            return $this->searchService;
794
        }
795
796
        $this->searchService = new SearchService(
797
            $this,
798
            $this->searchHandler,
799
            $this->getDomainMapper(),
800
            $this->getPermissionCriterionResolver(),
801
            $this->backgroundIndexer,
0 ignored issues
show
Bug introduced by
It seems like $this->backgroundIndexer can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
802
            $this->serviceSettings['search']
803
        );
804
805
        return $this->searchService;
806
    }
807
808
    /**
809
     * Get FieldTypeService.
810
     *
811
     * @return \eZ\Publish\API\Repository\FieldTypeService
812
     */
813
    public function getFieldTypeService()
814
    {
815
        if ($this->fieldTypeService !== null) {
816
            return $this->fieldTypeService;
817
        }
818
819
        $this->fieldTypeService = new FieldTypeService($this->getFieldTypeRegistry());
820
821
        return $this->fieldTypeService;
822
    }
823
824
    /**
825
     * Get PermissionResolver.
826
     *
827
     * @return \eZ\Publish\API\Repository\PermissionResolver
828
     */
829
    public function getPermissionResolver()
830
    {
831
        return $this->getCachedPermissionsResolver();
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getCachedPermissionsResolver(); of type eZ\Publish\API\Repositor...tory\PermissionResolver adds the type eZ\Publish\API\Repositor...issionCriterionResolver to the return on line 831 which is incompatible with the return type declared by the interface eZ\Publish\API\Repositor...::getPermissionResolver of type eZ\Publish\API\Repository\PermissionResolver.
Loading history...
832
    }
833
834
    /**
835
     * @return Helper\FieldTypeRegistry
836
     */
837
    protected function getFieldTypeRegistry()
838
    {
839
        if ($this->fieldTypeRegistry !== null) {
840
            return $this->fieldTypeRegistry;
841
        }
842
843
        $this->fieldTypeRegistry = new Helper\FieldTypeRegistry($this->serviceSettings['fieldType']);
844
845
        return $this->fieldTypeRegistry;
846
    }
847
848
    /**
849
     * @return Helper\NameableFieldTypeRegistry
850
     */
851
    protected function getNameableFieldTypeRegistry()
852
    {
853
        if ($this->nameableFieldTypeRegistry !== null) {
854
            return $this->nameableFieldTypeRegistry;
855
        }
856
857
        $this->nameableFieldTypeRegistry = new Helper\NameableFieldTypeRegistry($this->serviceSettings['nameableFieldTypes']);
858
859
        return $this->nameableFieldTypeRegistry;
860
    }
861
862
    /**
863
     * Get NameSchemaResolverService.
864
     *
865
     *
866
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
867
     *
868
     * @internal
869
     * @private
870
     *
871
     * @return \eZ\Publish\Core\Repository\Helper\NameSchemaService
872
     */
873
    public function getNameSchemaService()
874
    {
875
        if ($this->nameSchemaService !== null) {
876
            return $this->nameSchemaService;
877
        }
878
879
        $this->nameSchemaService = new Helper\NameSchemaService(
880
            $this->persistenceHandler->contentTypeHandler(),
881
            $this->getContentTypeDomainMapper(),
882
            $this->getNameableFieldTypeRegistry(),
883
            $this->serviceSettings['nameSchema']
884
        );
885
886
        return $this->nameSchemaService;
887
    }
888
889
    /**
890
     * @return \eZ\Publish\API\Repository\NotificationService
891
     */
892
    public function getNotificationService(): NotificationServiceInterface
893
    {
894
        if (null !== $this->notificationService) {
895
            return $this->notificationService;
896
        }
897
898
        $this->notificationService = new NotificationService(
899
            $this->persistenceHandler->notificationHandler(),
900
            $this->getPermissionResolver()
901
        );
902
903
        return $this->notificationService;
904
    }
905
906
    /**
907
     * Get RelationProcessor.
908
     *
909
     *
910
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
911
     *
912
     * @return \eZ\Publish\Core\Repository\Helper\RelationProcessor
913
     */
914
    protected function getRelationProcessor()
915
    {
916
        return $this->relationProcessor;
917
    }
918
919
    /**
920
     * Get Content Domain Mapper.
921
     *
922
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
923
     *
924
     * @return \eZ\Publish\Core\Repository\Helper\DomainMapper
925
     */
926 View Code Duplication
    protected function getDomainMapper()
927
    {
928
        if ($this->domainMapper !== null) {
929
            return $this->domainMapper;
930
        }
931
932
        $this->domainMapper = new Helper\DomainMapper(
933
            $this->persistenceHandler->contentHandler(),
934
            $this->persistenceHandler->locationHandler(),
935
            $this->persistenceHandler->contentTypeHandler(),
936
            $this->getContentTypeDomainMapper(),
937
            $this->persistenceHandler->contentLanguageHandler(),
938
            $this->getFieldTypeRegistry()
939
        );
940
941
        return $this->domainMapper;
942
    }
943
944
    /**
945
     * Get ContentType Domain Mapper.
946
     *
947
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
948
     *
949
     * @return \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
950
     */
951
    protected function getContentTypeDomainMapper()
952
    {
953
        if ($this->contentTypeDomainMapper !== null) {
954
            return $this->contentTypeDomainMapper;
955
        }
956
957
        $this->contentTypeDomainMapper = new Helper\ContentTypeDomainMapper(
958
            $this->persistenceHandler->contentTypeHandler(),
959
            $this->persistenceHandler->contentLanguageHandler(),
960
            $this->getFieldTypeRegistry()
961
        );
962
963
        return $this->contentTypeDomainMapper;
964
    }
965
966
    /**
967
     * Get PermissionCriterionResolver.
968
     *
969
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
970
     *
971
     * @return \eZ\Publish\API\Repository\PermissionCriterionResolver
972
     */
973
    protected function getPermissionCriterionResolver()
974
    {
975
        return $this->getCachedPermissionsResolver();
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getCachedPermissionsResolver(); of type eZ\Publish\API\Repositor...tory\PermissionResolver adds the type eZ\Publish\API\Repository\PermissionResolver to the return on line 975 which is incompatible with the return type documented by eZ\Publish\Core\Reposito...issionCriterionResolver of type eZ\Publish\API\Repositor...issionCriterionResolver.
Loading history...
976
    }
977
978
    /**
979
     * @return \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver
980
     */
981
    protected function getCachedPermissionsResolver()
982
    {
983
        if ($this->permissionsHandler === null) {
984
            $this->permissionsHandler = new CachedPermissionService(
985
                $permissionResolver = new Permission\PermissionResolver(
986
                    $this->getRoleDomainMapper(),
987
                    $this->getLimitationService(),
988
                    $this->persistenceHandler->userHandler(),
989
                    $this->currentUserRef,
990
                    $this->serviceSettings['role']['policyMap']
991
                ),
992
                new PermissionCriterionResolver(
993
                    $permissionResolver,
994
                    $this->getLimitationService()
995
                )
996
            );
997
        }
998
999
        return $this->permissionsHandler;
1000
    }
1001
1002
    /**
1003
     * Begin transaction.
1004
     *
1005
     * Begins an transaction, make sure you'll call commit or rollback when done,
1006
     * otherwise work will be lost.
1007
     */
1008
    public function beginTransaction()
1009
    {
1010
        $this->persistenceHandler->beginTransaction();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\SPI\Persisten...ler::beginTransaction() has been deprecated with message: Since 5.3 {@use transactionHandler()->beginTransaction()}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1011
    }
1012
1013
    /**
1014
     * Commit transaction.
1015
     *
1016
     * Commit transaction, or throw exceptions if no transactions has been started.
1017
     *
1018
     * @throws RuntimeException If no transaction has been started
1019
     */
1020
    public function commit()
1021
    {
1022
        try {
1023
            $this->persistenceHandler->commit();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\SPI\Persistence\Handler::commit() has been deprecated with message: Since 5.3 {@use transactionHandler()->commit()}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1024
        } catch (Exception $e) {
1025
            throw new RuntimeException($e->getMessage(), 0, $e);
1026
        }
1027
    }
1028
1029
    /**
1030
     * Rollback transaction.
1031
     *
1032
     * Rollback transaction, or throw exceptions if no transactions has been started.
1033
     *
1034
     * @throws RuntimeException If no transaction has been started
1035
     */
1036
    public function rollback()
1037
    {
1038
        try {
1039
            $this->persistenceHandler->rollback();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\SPI\Persistence\Handler::rollback() has been deprecated with message: Since 5.3 {@use transactionHandler()->rollback()}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1040
        } catch (Exception $e) {
1041
            throw new RuntimeException($e->getMessage(), 0, $e);
1042
        }
1043
    }
1044
}
1045