Completed
Push — master ( 0b3034...a98e2b )
by
unknown
36:06 queued 14:31
created

Repository::getNameSchemaService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 15
rs 9.7666
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 Closure;
23
use Exception;
24
use Psr\Log\LoggerInterface;
25
use Psr\Log\NullLogger;
26
use RuntimeException;
27
use eZ\Publish\API\Repository\NotificationService as NotificationServiceInterface;
28
29
/**
30
 * Repository class.
31
 */
32
class Repository implements RepositoryInterface
33
{
34
    /**
35
     * Repository Handler object.
36
     *
37
     * @var \eZ\Publish\SPI\Persistence\Handler
38
     */
39
    protected $persistenceHandler;
40
41
    /**
42
     * Instance of main Search Handler.
43
     *
44
     * @var \eZ\Publish\SPI\Search\Handler
45
     */
46
    protected $searchHandler;
47
48
    /**
49
     * @deprecated since 6.6, to be removed. Current user handling is moved to PermissionResolver.
50
     *
51
     * Currently logged in user object if already loaded.
52
     *
53
     * @var \eZ\Publish\API\Repository\Values\User\User|null
54
     */
55
    protected $currentUser;
56
57
    /**
58
     * @deprecated since 6.6, to be removed. Current user handling is moved to PermissionResolver.
59
     *
60
     * Currently logged in user reference for permission purposes.
61
     *
62
     * @var \eZ\Publish\API\Repository\Values\User\UserReference
63
     */
64
    protected $currentUserRef;
65
66
    /**
67
     * Instance of content service.
68
     *
69
     * @var \eZ\Publish\API\Repository\ContentService
70
     */
71
    protected $contentService;
72
73
    /**
74
     * Instance of section service.
75
     *
76
     * @var \eZ\Publish\API\Repository\SectionService
77
     */
78
    protected $sectionService;
79
80
    /**
81
     * Instance of role service.
82
     *
83
     * @var \eZ\Publish\API\Repository\RoleService
84
     */
85
    protected $roleService;
86
87
    /**
88
     * Instance of search service.
89
     *
90
     * @var \eZ\Publish\API\Repository\SearchService
91
     */
92
    protected $searchService;
93
94
    /**
95
     * Instance of user service.
96
     *
97
     * @var \eZ\Publish\API\Repository\UserService
98
     */
99
    protected $userService;
100
101
    /**
102
     * Instance of language service.
103
     *
104
     * @var \eZ\Publish\API\Repository\LanguageService
105
     */
106
    protected $languageService;
107
108
    /**
109
     * Instance of location service.
110
     *
111
     * @var \eZ\Publish\API\Repository\LocationService
112
     */
113
    protected $locationService;
114
115
    /**
116
     * Instance of Trash service.
117
     *
118
     * @var \eZ\Publish\API\Repository\TrashService
119
     */
120
    protected $trashService;
121
122
    /**
123
     * Instance of content type service.
124
     *
125
     * @var \eZ\Publish\API\Repository\ContentTypeService
126
     */
127
    protected $contentTypeService;
128
129
    /**
130
     * Instance of object state service.
131
     *
132
     * @var \eZ\Publish\API\Repository\ObjectStateService
133
     */
134
    protected $objectStateService;
135
136
    /**
137
     * Instance of field type service.
138
     *
139
     * @var \eZ\Publish\API\Repository\FieldTypeService
140
     */
141
    protected $fieldTypeService;
142
143
    /**
144
     * Instance of FieldTypeRegistry.
145
     *
146
     * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry
147
     */
148
    private $fieldTypeRegistry;
149
150
    /**
151
     * Instance of NameableFieldTypeRegistry.
152
     *
153
     * @var \eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry
154
     */
155
    private $nameableFieldTypeRegistry;
156
157
    /**
158
     * Instance of name schema resolver service.
159
     *
160
     * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService
161
     */
162
    protected $nameSchemaService;
163
164
    /**
165
     * Instance of relation processor service.
166
     *
167
     * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor
168
     */
169
    protected $relationProcessor;
170
171
    /**
172
     * Instance of URL alias service.
173
     *
174
     * @var \eZ\Publish\Core\Repository\URLAliasService
175
     */
176
    protected $urlAliasService;
177
178
    /**
179
     * Instance of URL wildcard service.
180
     *
181
     * @var \eZ\Publish\Core\Repository\URLWildcardService
182
     */
183
    protected $urlWildcardService;
184
185
    /**
186
     * Instance of URL service.
187
     *
188
     * @var \eZ\Publish\Core\Repository\URLService
189
     */
190
    protected $urlService;
191
192
    /**
193
     * Instance of Bookmark service.
194
     *
195
     * @var \eZ\Publish\API\Repository\BookmarkService
196
     */
197
    protected $bookmarkService;
198
199
    /**
200
     * Instance of Notification service.
201
     *
202
     * @var \eZ\Publish\API\Repository\NotificationService
203
     */
204
    protected $notificationService;
205
206
    /**
207
     * Instance of User Preference service.
208
     *
209
     * @var \eZ\Publish\API\Repository\UserPreferenceService
210
     */
211
    protected $userPreferenceService;
212
213
    /**
214
     * Service settings, first level key is service name.
215
     *
216
     * @var array
217
     */
218
    protected $serviceSettings;
219
220
    /**
221
     * Instance of role service.
222
     *
223
     * @var \eZ\Publish\Core\Repository\Helper\LimitationService
224
     */
225
    protected $limitationService;
226
227
    /**
228
     * @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper
229
     */
230
    protected $roleDomainMapper;
231
232
    /**
233
     * Instance of domain mapper.
234
     *
235
     * @var \eZ\Publish\Core\Repository\Helper\DomainMapper
236
     */
237
    protected $domainMapper;
238
239
    /**
240
     * Instance of content type domain mapper.
241
     *
242
     * @var \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
243
     */
244
    protected $contentTypeDomainMapper;
245
246
    /**
247
     * Instance of permissions-resolver and -criterion resolver.
248
     *
249
     * @var \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver
250
     */
251
    protected $permissionsHandler;
252
253
    /**
254
     * @var \eZ\Publish\Core\Search\Common\BackgroundIndexer|null
255
     */
256
    protected $backgroundIndexer;
257
258
    /**
259
     * @var \Psr\Log\LoggerInterface
260
     */
261
    private $logger;
262
263
    /**
264
     * Constructor.
265
     *
266
     * Construct repository object with provided storage engine
267
     *
268
     * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler
269
     * @param \eZ\Publish\SPI\Search\Handler $searchHandler
270
     * @param \eZ\Publish\Core\Search\Common\BackgroundIndexer $backgroundIndexer
271
     * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor
272
     * @param array $serviceSettings
273
     * @param \eZ\Publish\API\Repository\Values\User\UserReference|null $user
274
     * @param \Psr\Log\LoggerInterface|null $logger
275
     */
276
    public function __construct(
277
        PersistenceHandler $persistenceHandler,
278
        SearchHandler $searchHandler,
279
        BackgroundIndexer $backgroundIndexer,
280
        RelationProcessor $relationProcessor,
281
        array $serviceSettings = array(),
282
        APIUserReference $user = null,
283
        LoggerInterface $logger = null
284
    ) {
285
        $this->persistenceHandler = $persistenceHandler;
286
        $this->searchHandler = $searchHandler;
287
        $this->backgroundIndexer = $backgroundIndexer;
288
        $this->relationProcessor = $relationProcessor;
289
        $this->serviceSettings = $serviceSettings + array(
290
            'content' => array(),
291
            'contentType' => array(),
292
            'location' => array(),
293
            'section' => array(),
294
            'role' => array(),
295
            'user' => array(
296
                'anonymousUserID' => 10,
297
            ),
298
            'language' => array(),
299
            'trash' => array(),
300
            'io' => array(),
301
            'objectState' => array(),
302
            'search' => array(),
303
            'fieldType' => array(),
304
            'nameableFieldTypes' => array(),
305
            'urlAlias' => array(),
306
            'urlWildcard' => array(),
307
            'nameSchema' => array(),
308
            'languages' => array(),
309
        );
310
311
        if (!empty($this->serviceSettings['languages'])) {
312
            $this->serviceSettings['language']['languages'] = $this->serviceSettings['languages'];
313
        }
314
315
        if ($user instanceof User) {
316
            $this->currentUser = $user;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
317
            $this->currentUserRef = new UserReference($user->getUserId());
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
318
        } elseif ($user instanceof APIUserReference) {
319
            $this->currentUserRef = $user;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
320
        } else {
321
            $this->currentUserRef = new UserReference($this->serviceSettings['user']['anonymousUserID']);
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
322
        }
323
324
        $this->logger = null !== $logger ? $logger : new NullLogger();
325
    }
326
327
    /**
328
     * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
329
     *
330
     * Get current user.
331
     *
332
     * Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}
333
     *
334
     * @return \eZ\Publish\API\Repository\Values\User\User
335
     */
336
    public function getCurrentUser()
337
    {
338
        if ($this->currentUser === null) {
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
339
            $this->currentUser = $this->getUserService()->loadUser(
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
340
                $this->getPermissionResolver()->getCurrentUserReference()->getUserId()
341
            );
342
        }
343
344
        return $this->currentUser;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
345
    }
346
347
    /**
348
     * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
349
     *
350
     * Get current user reference.
351
     *
352
     * @since 5.4.5
353
     * @return \eZ\Publish\API\Repository\Values\User\UserReference
354
     */
355
    public function getCurrentUserReference()
356
    {
357
        return $this->getPermissionResolver()->getCurrentUserReference();
358
    }
359
360
    /**
361
     * @deprecated since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead.
362
     *
363
     * Sets the current user to the given $user.
364
     *
365
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
366
     *
367
     * @throws InvalidArgumentValue If UserReference does not contain a id
368
     */
369
    public function setCurrentUser(APIUserReference $user)
370
    {
371
        $id = $user->getUserId();
372
        if (!$id) {
373
            throw new InvalidArgumentValue('$user->getUserId()', $id);
374
        }
375
376
        if ($user instanceof User) {
377
            $this->currentUser = $user;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
378
            $this->currentUserRef = new UserReference($id);
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
379
        } else {
380
            $this->currentUser = null;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...epository::$currentUser has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user object if already loaded.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
381
            $this->currentUserRef = $user;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
382
        }
383
384
        return $this->getPermissionResolver()->setCurrentUserReference($this->currentUserRef);
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
385
    }
386
387
    /**
388
     * Allows API execution to be performed with full access sand-boxed.
389
     *
390
     * The closure sandbox will do a catch all on exceptions and rethrow after
391
     * re-setting the sudo flag.
392
     *
393
     * Example use:
394
     *     $location = $repository->sudo(
395
     *         function ( Repository $repo ) use ( $locationId )
396
     *         {
397
     *             return $repo->getLocationService()->loadLocation( $locationId )
398
     *         }
399
     *     );
400
     *
401
     *
402
     * @param \Closure $callback
403
     * @param \eZ\Publish\API\Repository\Repository|null $outerRepository
404
     *
405
     * @throws \RuntimeException Thrown on recursive sudo() use.
406
     * @throws \Exception Re throws exceptions thrown inside $callback
407
     *
408
     * @return mixed
409
     */
410
    public function sudo(Closure $callback, RepositoryInterface $outerRepository = null)
411
    {
412
        return $this->getPermissionResolver()->sudo($callback, $outerRepository ?? $this);
413
    }
414
415
    /**
416
     * @deprecated since 6.6, to be removed. Use PermissionResolver::hasAccess() instead.
417
     *
418
     * Check if user has access to a given module / function.
419
     *
420
     * Low level function, use canUser instead if you have objects to check against.
421
     *
422
     * @param string $module
423
     * @param string $function
424
     * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
425
     *
426
     * @return bool|array Bool if user has full or no access, array if limitations if not
427
     */
428
    public function hasAccess($module, $function, APIUserReference $user = null)
429
    {
430
        return $this->getPermissionResolver()->hasAccess($module, $function, $user);
431
    }
432
433
    /**
434
     * @deprecated since 6.6, to be removed. Use PermissionResolver::canUser() instead.
435
     *
436
     * Check if user has access to a given action on a given value object.
437
     *
438
     * Indicates if the current user is allowed to perform an action given by the function on the given
439
     * objects.
440
     *
441
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If any of the arguments are invalid
442
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If value of the LimitationValue is unsupported
443
     *
444
     * @param string $module The module, aka controller identifier to check permissions on
445
     * @param string $function The function, aka the controller action to check permissions on
446
     * @param \eZ\Publish\API\Repository\Values\ValueObject $object The object to check if the user has access to
447
     * @param mixed $targets The location, parent or "assignment" value object, or an array of the same
448
     *
449
     * @return bool
450
     */
451
    public function canUser($module, $function, ValueObject $object, $targets = null)
452
    {
453
        if ($targets instanceof ValueObject) {
454
            $targets = array($targets);
455
        } elseif ($targets === null) {
456
            $targets = [];
457
        } elseif (!is_array($targets)) {
458
            throw new InvalidArgumentType(
459
                '$targets',
460
                'null|\\eZ\\Publish\\API\\Repository\\Values\\ValueObject|\\eZ\\Publish\\API\\Repository\\Values\\ValueObject[]',
461
                $targets
462
            );
463
        }
464
465
        return $this->getPermissionResolver()->canUser($module, $function, $object, $targets);
466
    }
467
468
    /**
469
     * Get Content Service.
470
     *
471
     * Get service object to perform operations on Content objects and it's aggregate members.
472
     *
473
     * @return \eZ\Publish\API\Repository\ContentService
474
     */
475 View Code Duplication
    public function getContentService()
476
    {
477
        if ($this->contentService !== null) {
478
            return $this->contentService;
479
        }
480
481
        $this->contentService = new ContentService(
482
            $this,
483
            $this->persistenceHandler,
484
            $this->getDomainMapper(),
485
            $this->getRelationProcessor(),
486
            $this->getNameSchemaService(),
487
            $this->getFieldTypeRegistry(),
488
            $this->serviceSettings['content']
489
        );
490
491
        return $this->contentService;
492
    }
493
494
    /**
495
     * Get Content Language Service.
496
     *
497
     * Get service object to perform operations on Content language objects
498
     *
499
     * @return \eZ\Publish\API\Repository\LanguageService
500
     */
501
    public function getContentLanguageService()
502
    {
503
        if ($this->languageService !== null) {
504
            return $this->languageService;
505
        }
506
507
        $this->languageService = new LanguageService(
508
            $this,
509
            $this->persistenceHandler->contentLanguageHandler(),
510
            $this->serviceSettings['language']
511
        );
512
513
        return $this->languageService;
514
    }
515
516
    /**
517
     * Get Content Type Service.
518
     *
519
     * Get service object to perform operations on Content Type objects and it's aggregate members.
520
     * ( Group, Field & FieldCategory )
521
     *
522
     * @return \eZ\Publish\API\Repository\ContentTypeService
523
     */
524 View Code Duplication
    public function getContentTypeService()
525
    {
526
        if ($this->contentTypeService !== null) {
527
            return $this->contentTypeService;
528
        }
529
530
        $this->contentTypeService = new ContentTypeService(
531
            $this,
532
            $this->persistenceHandler->contentTypeHandler(),
533
            $this->getDomainMapper(),
534
            $this->getContentTypeDomainMapper(),
535
            $this->getFieldTypeRegistry(),
536
            $this->serviceSettings['contentType']
537
        );
538
539
        return $this->contentTypeService;
540
    }
541
542
    /**
543
     * Get Content Location Service.
544
     *
545
     * Get service object to perform operations on Location objects and subtrees
546
     *
547
     * @return \eZ\Publish\API\Repository\LocationService
548
     */
549
    public function getLocationService()
550
    {
551
        if ($this->locationService !== null) {
552
            return $this->locationService;
553
        }
554
555
        $this->locationService = new LocationService(
556
            $this,
557
            $this->persistenceHandler,
558
            $this->getDomainMapper(),
559
            $this->getNameSchemaService(),
560
            $this->getPermissionCriterionResolver(),
561
            $this->serviceSettings['location'],
562
            $this->logger
563
        );
564
565
        return $this->locationService;
566
    }
567
568
    /**
569
     * Get Content Trash service.
570
     *
571
     * Trash service allows to perform operations related to location trash
572
     * (trash/untrash, load/list from trash...)
573
     *
574
     * @return \eZ\Publish\API\Repository\TrashService
575
     */
576
    public function getTrashService()
577
    {
578
        if ($this->trashService !== null) {
579
            return $this->trashService;
580
        }
581
582
        $this->trashService = new TrashService(
583
            $this,
584
            $this->persistenceHandler,
585
            $this->getNameSchemaService(),
586
            $this->serviceSettings['trash']
587
        );
588
589
        return $this->trashService;
590
    }
591
592
    /**
593
     * Get Content Section Service.
594
     *
595
     * Get Section service that lets you manipulate section objects
596
     *
597
     * @return \eZ\Publish\API\Repository\SectionService
598
     */
599
    public function getSectionService()
600
    {
601
        if ($this->sectionService !== null) {
602
            return $this->sectionService;
603
        }
604
605
        $this->sectionService = new SectionService(
606
            $this,
607
            $this->persistenceHandler->sectionHandler(),
608
            $this->serviceSettings['section']
609
        );
610
611
        return $this->sectionService;
612
    }
613
614
    /**
615
     * Get User Service.
616
     *
617
     * Get service object to perform operations on Users and UserGroup
618
     *
619
     * @return \eZ\Publish\API\Repository\UserService
620
     */
621
    public function getUserService()
622
    {
623
        if ($this->userService !== null) {
624
            return $this->userService;
625
        }
626
627
        $this->userService = new UserService(
628
            $this,
629
            $this->persistenceHandler->userHandler(),
630
            $this->serviceSettings['user']
631
        );
632
633
        return $this->userService;
634
    }
635
636
    /**
637
     * Get URLAliasService.
638
     *
639
     * @return \eZ\Publish\API\Repository\URLAliasService
640
     */
641
    public function getURLAliasService()
642
    {
643
        if ($this->urlAliasService !== null) {
644
            return $this->urlAliasService;
645
        }
646
647
        $this->urlAliasService = new URLAliasService(
648
            $this,
649
            $this->persistenceHandler->urlAliasHandler(),
650
            $this->getNameSchemaService(),
651
            $this->serviceSettings['urlAlias']
652
        );
653
654
        return $this->urlAliasService;
655
    }
656
657
    /**
658
     * Get URLWildcardService.
659
     *
660
     * @return \eZ\Publish\API\Repository\URLWildcardService
661
     */
662
    public function getURLWildcardService()
663
    {
664
        if ($this->urlWildcardService !== null) {
665
            return $this->urlWildcardService;
666
        }
667
668
        $this->urlWildcardService = new URLWildcardService(
669
            $this,
670
            $this->persistenceHandler->urlWildcardHandler(),
671
            $this->serviceSettings['urlWildcard']
672
        );
673
674
        return $this->urlWildcardService;
675
    }
676
677
    /**
678
     * Get URLService.
679
     *
680
     * @return \eZ\Publish\API\Repository\URLService
681
     */
682
    public function getURLService()
683
    {
684
        if ($this->urlService !== null) {
685
            return $this->urlService;
686
        }
687
688
        $this->urlService = new URLService(
689
            $this,
690
            $this->persistenceHandler->urlHandler()
691
        );
692
693
        return $this->urlService;
694
    }
695
696
    /**
697
     * Get BookmarkService.
698
     *
699
     * @return \eZ\Publish\API\Repository\BookmarkService
700
     */
701
    public function getBookmarkService()
702
    {
703
        if ($this->bookmarkService === null) {
704
            $this->bookmarkService = new BookmarkService(
705
                $this,
706
                $this->persistenceHandler->bookmarkHandler()
707
            );
708
        }
709
710
        return $this->bookmarkService;
711
    }
712
713
    /**
714
     * Get UserPreferenceService.
715
     *
716
     * @return \eZ\Publish\API\Repository\UserPreferenceService
717
     */
718
    public function getUserPreferenceService()
719
    {
720
        if ($this->userPreferenceService === null) {
721
            $this->userPreferenceService = new UserPreferenceService(
722
                $this,
723
                $this->persistenceHandler->userPreferenceHandler()
724
            );
725
        }
726
727
        return $this->userPreferenceService;
728
    }
729
730
    /**
731
     * Get ObjectStateService.
732
     *
733
     * @return \eZ\Publish\API\Repository\ObjectStateService
734
     */
735
    public function getObjectStateService()
736
    {
737
        if ($this->objectStateService !== null) {
738
            return $this->objectStateService;
739
        }
740
741
        $this->objectStateService = new ObjectStateService(
742
            $this,
743
            $this->persistenceHandler->objectStateHandler(),
744
            $this->serviceSettings['objectState']
745
        );
746
747
        return $this->objectStateService;
748
    }
749
750
    /**
751
     * Get RoleService.
752
     *
753
     * @return \eZ\Publish\API\Repository\RoleService
754
     */
755
    public function getRoleService()
756
    {
757
        if ($this->roleService !== null) {
758
            return $this->roleService;
759
        }
760
761
        $this->roleService = new RoleService(
762
            $this,
763
            $this->persistenceHandler->userHandler(),
764
            $this->getLimitationService(),
765
            $this->getRoleDomainMapper(),
766
            $this->serviceSettings['role']
767
        );
768
769
        return $this->roleService;
770
    }
771
772
    /**
773
     * Get LimitationService.
774
     *
775
     * @return \eZ\Publish\Core\Repository\Helper\LimitationService
776
     */
777
    protected function getLimitationService()
778
    {
779
        if ($this->limitationService !== null) {
780
            return $this->limitationService;
781
        }
782
783
        $this->limitationService = new Helper\LimitationService($this->serviceSettings['role']);
784
785
        return $this->limitationService;
786
    }
787
788
    /**
789
     * Get RoleDomainMapper.
790
     *
791
     * @return \eZ\Publish\Core\Repository\Helper\RoleDomainMapper
792
     */
793
    protected function getRoleDomainMapper()
794
    {
795
        if ($this->roleDomainMapper !== null) {
796
            return $this->roleDomainMapper;
797
        }
798
799
        $this->roleDomainMapper = new Helper\RoleDomainMapper($this->getLimitationService());
800
801
        return $this->roleDomainMapper;
802
    }
803
804
    /**
805
     * Get SearchService.
806
     *
807
     * @return \eZ\Publish\API\Repository\SearchService
808
     */
809
    public function getSearchService()
810
    {
811
        if ($this->searchService !== null) {
812
            return $this->searchService;
813
        }
814
815
        $this->searchService = new SearchService(
816
            $this,
817
            $this->searchHandler,
818
            $this->getDomainMapper(),
819
            $this->getPermissionCriterionResolver(),
820
            $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...
821
            $this->serviceSettings['search']
822
        );
823
824
        return $this->searchService;
825
    }
826
827
    /**
828
     * Get FieldTypeService.
829
     *
830
     * @return \eZ\Publish\API\Repository\FieldTypeService
831
     */
832
    public function getFieldTypeService()
833
    {
834
        if ($this->fieldTypeService !== null) {
835
            return $this->fieldTypeService;
836
        }
837
838
        $this->fieldTypeService = new FieldTypeService($this->getFieldTypeRegistry());
839
840
        return $this->fieldTypeService;
841
    }
842
843
    /**
844
     * Get PermissionResolver.
845
     *
846
     * @return \eZ\Publish\API\Repository\PermissionResolver
847
     */
848
    public function getPermissionResolver()
849
    {
850
        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 850 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...
851
    }
852
853
    /**
854
     * @return Helper\FieldTypeRegistry
855
     */
856
    protected function getFieldTypeRegistry()
857
    {
858
        if ($this->fieldTypeRegistry !== null) {
859
            return $this->fieldTypeRegistry;
860
        }
861
862
        $this->fieldTypeRegistry = new Helper\FieldTypeRegistry($this->serviceSettings['fieldType']);
863
864
        return $this->fieldTypeRegistry;
865
    }
866
867
    /**
868
     * @return Helper\NameableFieldTypeRegistry
869
     */
870
    protected function getNameableFieldTypeRegistry()
871
    {
872
        if ($this->nameableFieldTypeRegistry !== null) {
873
            return $this->nameableFieldTypeRegistry;
874
        }
875
876
        $this->nameableFieldTypeRegistry = new Helper\NameableFieldTypeRegistry($this->serviceSettings['nameableFieldTypes']);
877
878
        return $this->nameableFieldTypeRegistry;
879
    }
880
881
    /**
882
     * Get NameSchemaResolverService.
883
     *
884
     *
885
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
886
     *
887
     * @internal
888
     * @private
889
     *
890
     * @return \eZ\Publish\Core\Repository\Helper\NameSchemaService
891
     */
892
    public function getNameSchemaService()
893
    {
894
        if ($this->nameSchemaService !== null) {
895
            return $this->nameSchemaService;
896
        }
897
898
        $this->nameSchemaService = new Helper\NameSchemaService(
899
            $this->persistenceHandler->contentTypeHandler(),
900
            $this->getContentTypeDomainMapper(),
901
            $this->getNameableFieldTypeRegistry(),
902
            $this->serviceSettings['nameSchema']
903
        );
904
905
        return $this->nameSchemaService;
906
    }
907
908
    /**
909
     * @return \eZ\Publish\API\Repository\NotificationService
910
     */
911
    public function getNotificationService(): NotificationServiceInterface
912
    {
913
        if (null !== $this->notificationService) {
914
            return $this->notificationService;
915
        }
916
917
        $this->notificationService = new NotificationService(
918
            $this->persistenceHandler->notificationHandler(),
919
            $this->getPermissionResolver()
920
        );
921
922
        return $this->notificationService;
923
    }
924
925
    /**
926
     * Get RelationProcessor.
927
     *
928
     *
929
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
930
     *
931
     * @return \eZ\Publish\Core\Repository\Helper\RelationProcessor
932
     */
933
    protected function getRelationProcessor()
934
    {
935
        return $this->relationProcessor;
936
    }
937
938
    /**
939
     * Get Content Domain Mapper.
940
     *
941
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
942
     *
943
     * @return \eZ\Publish\Core\Repository\Helper\DomainMapper
944
     */
945
    protected function getDomainMapper()
946
    {
947
        if ($this->domainMapper !== null) {
948
            return $this->domainMapper;
949
        }
950
951
        $this->domainMapper = new Helper\DomainMapper(
952
            $this->persistenceHandler->contentHandler(),
953
            $this->persistenceHandler->locationHandler(),
954
            $this->persistenceHandler->contentTypeHandler(),
955
            $this->persistenceHandler->contentLanguageHandler(),
956
            $this->getFieldTypeRegistry()
957
        );
958
959
        return $this->domainMapper;
960
    }
961
962
    /**
963
     * Get ContentType Domain Mapper.
964
     *
965
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
966
     *
967
     * @return \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper
968
     */
969
    protected function getContentTypeDomainMapper()
970
    {
971
        if ($this->contentTypeDomainMapper !== null) {
972
            return $this->contentTypeDomainMapper;
973
        }
974
975
        $this->contentTypeDomainMapper = new Helper\ContentTypeDomainMapper(
976
            $this->persistenceHandler->contentTypeHandler(),
977
            $this->persistenceHandler->contentLanguageHandler(),
978
            $this->getFieldTypeRegistry()
979
        );
980
981
        return $this->contentTypeDomainMapper;
982
    }
983
984
    /**
985
     * Get PermissionCriterionResolver.
986
     *
987
     * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory.
988
     *
989
     * @return \eZ\Publish\API\Repository\PermissionCriterionResolver
990
     */
991
    protected function getPermissionCriterionResolver()
992
    {
993
        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 993 which is incompatible with the return type documented by eZ\Publish\Core\Reposito...issionCriterionResolver of type eZ\Publish\API\Repositor...issionCriterionResolver.
Loading history...
994
    }
995
996
    /**
997
     * @return \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver
998
     */
999
    protected function getCachedPermissionsResolver()
1000
    {
1001
        if ($this->permissionsHandler === null) {
1002
            $this->permissionsHandler = new CachedPermissionService(
1003
                $permissionResolver = new Permission\PermissionResolver(
1004
                    $this->getRoleDomainMapper(),
1005
                    $this->getLimitationService(),
1006
                    $this->persistenceHandler->userHandler(),
1007
                    $this->currentUserRef,
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\Reposito...sitory::$currentUserRef has been deprecated with message: since 6.6, to be removed. Current user handling is moved to PermissionResolver. Currently logged in user reference for permission purposes.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
1008
                    $this->serviceSettings['role']['policyMap']
1009
                ),
1010
                new PermissionCriterionResolver(
1011
                    $permissionResolver,
1012
                    $this->getLimitationService()
1013
                )
1014
            );
1015
        }
1016
1017
        return $this->permissionsHandler;
1018
    }
1019
1020
    /**
1021
     * Begin transaction.
1022
     *
1023
     * Begins an transaction, make sure you'll call commit or rollback when done,
1024
     * otherwise work will be lost.
1025
     */
1026
    public function beginTransaction()
1027
    {
1028
        $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...
1029
    }
1030
1031
    /**
1032
     * Commit transaction.
1033
     *
1034
     * Commit transaction, or throw exceptions if no transactions has been started.
1035
     *
1036
     * @throws RuntimeException If no transaction has been started
1037
     */
1038
    public function commit()
1039
    {
1040
        try {
1041
            $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...
1042
        } catch (Exception $e) {
1043
            throw new RuntimeException($e->getMessage(), 0, $e);
1044
        }
1045
    }
1046
1047
    /**
1048
     * Rollback transaction.
1049
     *
1050
     * Rollback transaction, or throw exceptions if no transactions has been started.
1051
     *
1052
     * @throws RuntimeException If no transaction has been started
1053
     */
1054
    public function rollback()
1055
    {
1056
        try {
1057
            $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...
1058
        } catch (Exception $e) {
1059
            throw new RuntimeException($e->getMessage(), 0, $e);
1060
        }
1061
    }
1062
}
1063