Completed
Push — 7.2 ( d2cec4...c31c28 )
by
unknown
19:06 queued 10s
created

Repository::getCurrentUserReference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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