vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Repository/Repository.php line 438

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