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

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\SignalSlot;
  7. use eZ\Publish\API\Repository\BookmarkService;
  8. use eZ\Publish\API\Repository\Repository as RepositoryInterface;
  9. use eZ\Publish\API\Repository\Values\ValueObject;
  10. use eZ\Publish\API\Repository\Values\User\UserReference;
  11. use eZ\Publish\SPI\Persistence\TransactionHandler;
  12. /**
  13.  * Repository class.
  14.  */
  15. class Repository implements RepositoryInterface
  16. {
  17.     /**
  18.      * Repository Handler object.
  19.      *
  20.      * @var \eZ\Publish\API\Repository\Repository
  21.      */
  22.     protected $repository;
  23.     /**
  24.      * SignalDispatcher.
  25.      *
  26.      * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher
  27.      */
  28.     protected $signalDispatcher;
  29.     /**
  30.      * Instance of content service.
  31.      *
  32.      * @var \eZ\Publish\API\Repository\ContentService
  33.      */
  34.     protected $contentService;
  35.     /**
  36.      * Instance of section service.
  37.      *
  38.      * @var \eZ\Publish\API\Repository\SectionService
  39.      */
  40.     protected $sectionService;
  41.     /**
  42.      * Instance of role service.
  43.      *
  44.      * @var \eZ\Publish\API\Repository\RoleService
  45.      */
  46.     protected $roleService;
  47.     /**
  48.      * Instance of search service.
  49.      *
  50.      * @var \eZ\Publish\API\Repository\SearchService
  51.      */
  52.     protected $searchService;
  53.     /**
  54.      * Instance of user service.
  55.      *
  56.      * @var \eZ\Publish\API\Repository\UserService
  57.      */
  58.     protected $userService;
  59.     /**
  60.      * Instance of language service.
  61.      *
  62.      * @var \eZ\Publish\API\Repository\LanguageService
  63.      */
  64.     protected $languageService;
  65.     /**
  66.      * Instance of location service.
  67.      *
  68.      * @var \eZ\Publish\API\Repository\LocationService
  69.      */
  70.     protected $locationService;
  71.     /**
  72.      * Instance of Trash service.
  73.      *
  74.      * @var \eZ\Publish\API\Repository\TrashService
  75.      */
  76.     protected $trashService;
  77.     /**
  78.      * Instance of content type service.
  79.      *
  80.      * @var \eZ\Publish\API\Repository\ContentTypeService
  81.      */
  82.     protected $contentTypeService;
  83.     /**
  84.      * Instance of object state service.
  85.      *
  86.      * @var \eZ\Publish\API\Repository\ObjectStateService
  87.      */
  88.     protected $objectStateService;
  89.     /**
  90.      * Instance of field type service.
  91.      *
  92.      * @var \eZ\Publish\API\Repository\FieldTypeService
  93.      */
  94.     protected $fieldTypeService;
  95.     /**
  96.      * Instance of URL alias service.
  97.      *
  98.      * @var \eZ\Publish\Core\Repository\URLAliasService
  99.      */
  100.     protected $urlAliasService;
  101.     /**
  102.      * Instance of URL wildcard service.
  103.      *
  104.      * @var \eZ\Publish\Core\Repository\URLWildcardService
  105.      */
  106.     protected $urlWildcardService;
  107.     /**
  108.      * Instance of URL service.
  109.      *
  110.      * @var \eZ\Publish\API\Repository\URLService
  111.      */
  112.     protected $urlService;
  113.     /**
  114.      * Instance of Bookmark service.
  115.      *
  116.      * @var \eZ\Publish\API\Repository\BookmarkService
  117.      */
  118.     protected $bookmarkService;
  119.     /**
  120.      * Instance of Notification service.
  121.      *
  122.      * @var \eZ\Publish\API\Repository\NotificationService
  123.      */
  124.     protected $notificationService;
  125.     /**
  126.      * Instance of UserPreference service.
  127.      *
  128.      * @var \eZ\Publish\API\Repository\UserPreferenceService
  129.      */
  130.     protected $userPreferenceService;
  131.     /**
  132.      * Construct repository object from aggregated repository and signal dispatcher.
  133.      *
  134.      * @param \eZ\Publish\API\Repository\Repository $repository
  135.      * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher
  136.      * @param \eZ\Publish\Core\SignalSlot\ContentService $contentService
  137.      * @param \eZ\Publish\Core\SignalSlot\ContentTypeService $contentTypeService
  138.      * @param \eZ\Publish\Core\SignalSlot\FieldTypeService $fieldTypeService
  139.      * @param \eZ\Publish\Core\SignalSlot\RoleService $roleService
  140.      * @param \eZ\Publish\Core\SignalSlot\ObjectStateService $objectStateService
  141.      * @param \eZ\Publish\Core\SignalSlot\URLWildcardService $urlWildcardService
  142.      * @param \eZ\Publish\Core\SignalSlot\URLAliasService $urlAliasService
  143.      * @param \eZ\Publish\Core\SignalSlot\UserService $userService
  144.      * @param \eZ\Publish\Core\SignalSlot\SearchService $searchService
  145.      * @param \eZ\Publish\Core\SignalSlot\SectionService $sectionService
  146.      * @param \eZ\Publish\Core\SignalSlot\TrashService $trashService
  147.      * @param \eZ\Publish\Core\SignalSlot\LocationService $locationService
  148.      * @param \eZ\Publish\Core\SignalSlot\LanguageService $languageService
  149.      * @param \eZ\Publish\Core\SignalSlot\URLService $urlService
  150.      * @param \eZ\Publish\Core\SignalSlot\BookmarkService $bookmarkService
  151.      * @param \eZ\Publish\API\Repository\NotificationService $notificationService
  152.      * @param \eZ\Publish\Core\SignalSlot\UserPreferenceService $userPreferenceService
  153.      */
  154.     public function __construct(
  155.         RepositoryInterface $repository,
  156.         SignalDispatcher $signalDispatcher,
  157.         ContentService $contentService,
  158.         ContentTypeService $contentTypeService,
  159.         FieldTypeService $fieldTypeService,
  160.         RoleService $roleService,
  161.         ObjectStateService $objectStateService,
  162.         URLWildcardService $urlWildcardService,
  163.         URLAliasService $urlAliasService,
  164.         UserService $userService,
  165.         SearchService $searchService,
  166.         SectionService $sectionService,
  167.         TrashService $trashService,
  168.         LocationService $locationService,
  169.         LanguageService $languageService,
  170.         URLService $urlService,
  171.         BookmarkService $bookmarkService,
  172.         NotificationService $notificationService,
  173.         UserPreferenceService $userPreferenceService
  174.     ) {
  175.         $this->signalDispatcher $signalDispatcher;
  176.         $this->repository $repository;
  177.         $this->contentService $contentService;
  178.         $this->contentTypeService $contentTypeService;
  179.         $this->fieldTypeService $fieldTypeService;
  180.         $this->roleService $roleService;
  181.         $this->objectStateService $objectStateService;
  182.         $this->urlWildcardService $urlWildcardService;
  183.         $this->urlAliasService $urlAliasService;
  184.         $this->userService $userService;
  185.         $this->searchService $searchService;
  186.         $this->sectionService $sectionService;
  187.         $this->trashService $trashService;
  188.         $this->locationService $locationService;
  189.         $this->languageService $languageService;
  190.         $this->urlService $urlService;
  191.         $this->bookmarkService $bookmarkService;
  192.         $this->notificationService $notificationService;
  193.         $this->userPreferenceService $userPreferenceService;
  194.     }
  195.     /**
  196.      * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
  197.      *
  198.      * Get current user.
  199.      *
  200.      * @return \eZ\Publish\API\Repository\Values\User\User
  201.      */
  202.     public function getCurrentUser()
  203.     {
  204.         return $this->repository->getCurrentUser();
  205.     }
  206.     /**
  207.      * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead.
  208.      *
  209.      * Get current user ref.
  210.      *
  211.      * @return \eZ\Publish\API\Repository\Values\User\UserReference
  212.      */
  213.     public function getCurrentUserReference()
  214.     {
  215.         return $this->repository->getCurrentUserReference();
  216.     }
  217.     /**
  218.      * @deprecated since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead.
  219.      *
  220.      * Sets the current user to the given $user.
  221.      *
  222.      * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
  223.      */
  224.     public function setCurrentUser(UserReference $user)
  225.     {
  226.         return $this->repository->setCurrentUser($user);
  227.     }
  228.     /**
  229.      * {@inheritdoc}
  230.      */
  231.     public function sudo(callable $callbackRepositoryInterface $outerRepository null)
  232.     {
  233.         return $this->repository->sudo($callback$outerRepository ?? $this);
  234.     }
  235.     /**
  236.      * @deprecated since 6.6, to be removed. Use PermissionResolver::hasAccess() instead.
  237.      *
  238.      * Check if user has access to a given module / function.
  239.      *
  240.      * Low level function, use canUser instead if you have objects to check against.
  241.      *
  242.      * @param string $module
  243.      * @param string $function
  244.      * @param \eZ\Publish\API\Repository\Values\User\UserReference $user
  245.      *
  246.      * @return bool|array Bool if user has full or no access, array if limitations if not
  247.      */
  248.     public function hasAccess($module$functionUserReference $user null)
  249.     {
  250.         return $this->repository->hasAccess($module$function$user);
  251.     }
  252.     /**
  253.      * @deprecated since 6.6, to be removed. Use PermissionResolver::canUser() instead.
  254.      *
  255.      * Check if user has access to a given action on a given value object.
  256.      *
  257.      * Indicates if the current user is allowed to perform an action given by the function on the given
  258.      * objects.
  259.      *
  260.      * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If any of the arguments are invalid
  261.      * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If value of the LimitationValue is unsupported
  262.      *
  263.      * @param string $module The module, aka controller identifier to check permissions on
  264.      * @param string $function The function, aka the controller action to check permissions on
  265.      * @param \eZ\Publish\API\Repository\Values\ValueObject $object The object to check if the user has access to
  266.      * @param mixed $targets The location, parent or "assignment" value object, or an array of the same
  267.      *
  268.      * @return bool
  269.      */
  270.     public function canUser($module$functionValueObject $object$targets null)
  271.     {
  272.         return $this->repository->canUser($module$function$object$targets);
  273.     }
  274.     /**
  275.      * Get Content Service.
  276.      *
  277.      * Get service object to perform operations on Content objects and it's aggregate members.
  278.      *
  279.      * @return \eZ\Publish\API\Repository\ContentService
  280.      */
  281.     public function getContentService()
  282.     {
  283.         return $this->contentService;
  284.     }
  285.     /**
  286.      * Get Content Language Service.
  287.      *
  288.      * Get service object to perform operations on Content language objects
  289.      *
  290.      * @return \eZ\Publish\API\Repository\LanguageService
  291.      */
  292.     public function getContentLanguageService()
  293.     {
  294.         return $this->languageService;
  295.     }
  296.     /**
  297.      * Get Content Type Service.
  298.      *
  299.      * Get service object to perform operations on Content Type objects and it's aggregate members.
  300.      * ( Group, Field & FieldCategory )
  301.      *
  302.      * @return \eZ\Publish\API\Repository\ContentTypeService
  303.      */
  304.     public function getContentTypeService()
  305.     {
  306.         return $this->contentTypeService;
  307.     }
  308.     /**
  309.      * Get Content Location Service.
  310.      *
  311.      * Get service object to perform operations on Location objects and subtrees
  312.      *
  313.      * @return \eZ\Publish\API\Repository\LocationService
  314.      */
  315.     public function getLocationService()
  316.     {
  317.         return $this->locationService;
  318.     }
  319.     /**
  320.      * Get Content Trash service.
  321.      *
  322.      * Trash service allows to perform operations related to location trash
  323.      * (trash/untrash, load/list from trash...)
  324.      *
  325.      * @return \eZ\Publish\API\Repository\TrashService
  326.      */
  327.     public function getTrashService()
  328.     {
  329.         return $this->trashService;
  330.     }
  331.     /**
  332.      * Get Content Section Service.
  333.      *
  334.      * Get Section service that lets you manipulate section objects
  335.      *
  336.      * @return \eZ\Publish\API\Repository\SectionService
  337.      */
  338.     public function getSectionService()
  339.     {
  340.         return $this->sectionService;
  341.     }
  342.     /**
  343.      * Get User Service.
  344.      *
  345.      * Get service object to perform operations on Users and UserGroup
  346.      *
  347.      * @return \eZ\Publish\API\Repository\UserService
  348.      */
  349.     public function getUserService()
  350.     {
  351.         return $this->userService;
  352.     }
  353.     /**
  354.      * Get URLAliasService.
  355.      *
  356.      * @return \eZ\Publish\API\Repository\URLAliasService
  357.      */
  358.     public function getURLAliasService()
  359.     {
  360.         return $this->urlAliasService;
  361.     }
  362.     /**
  363.      * Get URLWildcardService.
  364.      *
  365.      * @return \eZ\Publish\API\Repository\URLWildcardService
  366.      */
  367.     public function getURLWildcardService()
  368.     {
  369.         return $this->urlWildcardService;
  370.     }
  371.     /**
  372.      * Get URLService.
  373.      *
  374.      * @return \eZ\Publish\API\Repository\URLService
  375.      */
  376.     public function getURLService()
  377.     {
  378.         return $this->urlService;
  379.     }
  380.     /**
  381.      * Get BookmarkService.
  382.      *
  383.      * @return \eZ\Publish\API\Repository\BookmarkService
  384.      */
  385.     public function getBookmarkService()
  386.     {
  387.         return $this->bookmarkService;
  388.     }
  389.     /**
  390.      * Get NotificationService.
  391.      *
  392.      * @return \eZ\Publish\API\Repository\NotificationService
  393.      */
  394.     public function getNotificationService()
  395.     {
  396.         return $this->notificationService;
  397.     }
  398.     /**
  399.      * Get UserPreferenceService.
  400.      *
  401.      * @return \eZ\Publish\API\Repository\UserPreferenceService
  402.      */
  403.     public function getUserPreferenceService()
  404.     {
  405.         return $this->userPreferenceService;
  406.     }
  407.     /**
  408.      * Get ObjectStateService.
  409.      *
  410.      * @return \eZ\Publish\API\Repository\ObjectStateService
  411.      */
  412.     public function getObjectStateService()
  413.     {
  414.         return $this->objectStateService;
  415.     }
  416.     /**
  417.      * Get RoleService.
  418.      *
  419.      * @return \eZ\Publish\API\Repository\RoleService
  420.      */
  421.     public function getRoleService()
  422.     {
  423.         return $this->roleService;
  424.     }
  425.     /**
  426.      * Get SearchService.
  427.      *
  428.      * @return \eZ\Publish\API\Repository\SearchService
  429.      */
  430.     public function getSearchService()
  431.     {
  432.         return $this->searchService;
  433.     }
  434.     /**
  435.      * Get FieldTypeService.
  436.      *
  437.      * @return \eZ\Publish\API\Repository\FieldTypeService
  438.      */
  439.     public function getFieldTypeService()
  440.     {
  441.         return $this->fieldTypeService;
  442.     }
  443.     /**
  444.      * Get PermissionResolver.
  445.      *
  446.      * @return \eZ\Publish\API\Repository\PermissionResolver
  447.      */
  448.     public function getPermissionResolver()
  449.     {
  450.         return $this->repository->getPermissionResolver();
  451.     }
  452.     /**
  453.      * Begin transaction.
  454.      *
  455.      * Begins an transaction, make sure you'll call commit or rollback when done,
  456.      * otherwise work will be lost.
  457.      */
  458.     public function beginTransaction()
  459.     {
  460.         $return $this->repository->beginTransaction();
  461.         if ($this->signalDispatcher instanceof TransactionHandler) {
  462.             $this->signalDispatcher->beginTransaction();
  463.         }
  464.         return $return;
  465.     }
  466.     /**
  467.      * Commit transaction.
  468.      *
  469.      * Commit transaction, or throw exceptions if no transactions has been started.
  470.      *
  471.      * @throws \RuntimeException If no transaction has been started
  472.      */
  473.     public function commit()
  474.     {
  475.         $return $this->repository->commit();
  476.         if ($this->signalDispatcher instanceof TransactionHandler) {
  477.             $this->signalDispatcher->commit();
  478.         }
  479.         return $return;
  480.     }
  481.     /**
  482.      * Rollback transaction.
  483.      *
  484.      * Rollback transaction, or throw exceptions if no transactions has been started.
  485.      *
  486.      * @throws \RuntimeException If no transaction has been started
  487.      */
  488.     public function rollback()
  489.     {
  490.         if ($this->signalDispatcher instanceof TransactionHandler) {
  491.             $this->signalDispatcher->rollback();
  492.         }
  493.         return $this->repository->rollback();
  494.     }
  495. }