Completed
Push — 7.0_deprecation_removal ( e8d685 )
by André
23:55
created

Repository::commit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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