Completed
Push — master ( 97e40f...89ec5c )
by André
40:26 queued 12:35
created

Repository::getURLWildcardService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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