Completed
Push — master ( 2d5a91...5e6a60 )
by André
72:09 queued 53:20
created

Repository::getCachedPermissionsResolver()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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