当前位置: 首页>>代码示例>>PHP>>正文


PHP Repository::sudo方法代码示例

本文整理汇总了PHP中eZ\Publish\API\Repository\Repository::sudo方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::sudo方法的具体用法?PHP Repository::sudo怎么用?PHP Repository::sudo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZ\Publish\API\Repository\Repository的用法示例。


在下文中一共展示了Repository::sudo方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getController

 /**
  * Detects if there is a custom controller to use to render a Location/Content.
  *
  * @param FilterControllerEvent $event
  *
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  */
 public function getController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     // Only taking content related controller (i.e. ez_content:viewLocation or ez_content:viewContent)
     if (strpos($request->attributes->get('_controller'), 'ez_content:') === false) {
         return;
     }
     try {
         if ($request->attributes->has('locationId')) {
             $valueObject = $this->repository->getLocationService()->loadLocation($request->attributes->get('locationId'));
         } elseif ($request->attributes->get('location') instanceof Location) {
             $valueObject = $request->attributes->get('location');
             $request->attributes->set('locationId', $valueObject->id);
         } elseif ($request->attributes->has('contentId')) {
             $valueObject = $this->repository->sudo(function (Repository $repository) use($request) {
                 return $repository->getContentService()->loadContentInfo($request->attributes->get('contentId'));
             });
         } elseif ($request->attributes->get('contentInfo') instanceof ContentInfo) {
             $valueObject = $request->attributes->get('contentInfo');
             $request->attributes->set('contentId', $valueObject->id);
         }
     } catch (UnauthorizedException $e) {
         throw new AccessDeniedException();
     }
     if (!isset($valueObject)) {
         $this->logger->error('Could not resolver a view controller, invalid value object to match.');
         return;
     }
     $controllerReference = $this->controllerManager->getControllerReference($valueObject, $request->attributes->get('viewType'));
     if (!$controllerReference instanceof ControllerReference) {
         return;
     }
     $request->attributes->set('_controller', $controllerReference->controller);
     $event->setController($this->controllerResolver->getController($request));
 }
开发者ID:xcorp1986,项目名称:ezpublish-kernel,代码行数:42,代码来源:ViewControllerListener.php

示例2: sudo

 protected function sudo(Closure $callback)
 {
     $resolver = new OptionsResolver();
     $this->configureOptions($resolver);
     $this->params = $resolver->resolve($this->params);
     return $this->repository->sudo($callback);
 }
开发者ID:ezsystems,项目名称:repository-forms,代码行数:7,代码来源:ConfigurableSudoRepositoryLoader.php

示例3: load

 /**
  * @inheritdoc
  */
 public function load($data)
 {
     $this->doProgress('Creating database schema...');
     $this->databaseSchemaCreator->createSchema();
     $this->doProgress('Loading fixtures...');
     // Always use repositoty sudo to get access for content creation
     $this->repository->sudo(function () use($data) {
         $this->loader->load($data);
     });
 }
开发者ID:silversolutions,项目名称:content-loader-bundle,代码行数:13,代码来源:FixtureLoader.php

示例4: saveDraft

 /**
  * Saves content draft corresponding to $data.
  * Depending on the nature of $data (create or update data), the draft will either be created or simply updated.
  *
  * @param ContentStruct|\EzSystems\RepositoryForms\Data\User\UserCreateData $data
  * @param $languageCode
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 private function saveDraft(UserCreateData $data, $languageCode)
 {
     foreach ($data->fieldsData as $fieldDefIdentifier => $fieldData) {
         if ($fieldData->getFieldTypeIdentifier() !== 'ezuser') {
             $data->setField($fieldDefIdentifier, $fieldData->value, $languageCode);
         }
     }
     return $this->repository->sudo(function () use($data) {
         return $this->userService->createUser($data, $data->getParentGroups());
     });
 }
开发者ID:ezsystems,项目名称:repository-forms,代码行数:20,代码来源:UserRegisterFormProcessor.php

示例5: createNewUser

 /**
  * @param $login
  * @param $email
  * @param $firstName
  * @param $lastName
  * @return User
  */
 public function createNewUser($login, $email, $firstName, $lastName)
 {
     $userService = $this->repository->getUserService();
     $userCreateStruct = $userService->newUserCreateStruct($login, $email, md5($email . $login . time() . rand(1, 10000)), 'eng-GB', $this->repository->getContentTypeService()->loadContentTypeByIdentifier('user'));
     $userCreateStruct->setField('first_name', $firstName);
     $userCreateStruct->setField('last_name', $lastName);
     $user = $this->repository->sudo(function () use($userService, $userCreateStruct) {
         $userGroup = $userService->loadUserGroup('11');
         // guest accounts
         return $userService->createUser($userCreateStruct, array($userGroup));
     });
     return $user;
 }
开发者ID:crevillo,项目名称:ezsocialloginbundle,代码行数:20,代码来源:EzSocialLoginUserManager.php

示例6: loadLocation

 public function loadLocation(ContentInfo $contentInfo)
 {
     if (is_null($contentInfo->mainLocationId)) {
         throw new NotFoundException('main location of content', $contentInfo->id);
     }
     try {
         return $this->repository->sudo(function (Repository $repository) use($contentInfo) {
             return $repository->getLocationService()->loadLocation($contentInfo->mainLocationId);
         });
     } catch (Exception $e) {
         throw new NotFoundException('main location of content', $contentInfo->id);
     }
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:13,代码来源:SudoMainLocationLoader.php

示例7: userIsSubscriber

 public function userIsSubscriber(User $user)
 {
     $roleService = $this->repository->getRoleService();
     return $this->repository->sudo(function (Repository $repository) use($user, $roleService) {
         foreach ($repository->getUserService()->loadUserGroupsOfUser($user) as $group) {
             foreach ($roleService->getRoleAssignmentsForUserGroup($group) as $role) {
                 if ($this->isSubscriberRole($role->role)) {
                     return true;
                 }
             }
         }
         return false;
     });
 }
开发者ID:ezsystems,项目名称:demobundle,代码行数:14,代码来源:PremiumSubscriptionChecker.php

示例8: processTag

 /**
  * Process embed tags for a single tag type (embed or embed-inline)
  * @param \DOMDocument $xmlDoc
  * @param $tagName string name of the tag to extract
  */
 protected function processTag(DOMDocument $xmlDoc, $tagName)
 {
     /** @var $embed \DOMElement */
     foreach ($xmlDoc->getElementsByTagName($tagName) as $embed) {
         if (!($view = $embed->getAttribute("view"))) {
             $view = $tagName;
         }
         $embedContent = null;
         $parameters = array("noLayout" => true, "objectParameters" => array());
         foreach ($embed->attributes as $attribute) {
             // We only consider tags in the custom namespace, and skip disallowed names
             if (!isset($this->excludedAttributes[$attribute->localName])) {
                 $parameters["objectParameters"][$attribute->localName] = $attribute->nodeValue;
             }
         }
         if ($contentId = $embed->getAttribute("object_id")) {
             /** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
             $content = $this->repository->sudo(function (Repository $repository) use($contentId) {
                 return $repository->getContentService()->loadContent($contentId);
             });
             if (!$this->repository->canUser('content', 'read', $content) && !$this->repository->canUser('content', 'view_embed', $content)) {
                 throw new UnauthorizedException('content', 'read');
             }
             // Check published status of the Content
             if ($content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED && !$this->repository->canUser('content', 'versionread', $content)) {
                 throw new UnauthorizedException('content', 'versionread');
             }
             $embedContent = $this->viewManager->renderContent($content, $view, $parameters);
         } else {
             if ($locationId = $embed->getAttribute("node_id")) {
                 /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
                 $location = $this->repository->sudo(function (Repository $repository) use($locationId) {
                     return $repository->getLocationService()->loadLocation($locationId);
                 });
                 if (!$this->repository->canUser('content', 'read', $location->getContentInfo(), $location) && !$this->repository->canUser('content', 'view_embed', $location->getContentInfo(), $location)) {
                     throw new UnauthorizedException('content', 'read');
                 }
                 $embedContent = $this->viewManager->renderLocation($location, $view, $parameters);
             }
         }
         if ($embedContent !== null) {
             $embed->appendChild($xmlDoc->createCDATASection($embedContent));
         }
     }
 }
开发者ID:masev,项目名称:ezpublish-kernel,代码行数:50,代码来源:EmbedToHtml5.php

示例9: loadLocation

 /**
  * Loads a visible Location.
  * @todo Do we need to handle permissions here ?
  *
  * @param $locationId
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location
  */
 private function loadLocation($locationId)
 {
     $location = $this->repository->sudo(function (Repository $repository) use($locationId) {
         return $repository->getLocationService()->loadLocation($locationId);
     });
     if ($location->invisible) {
         throw new NotFoundHttpException('Location cannot be displayed as it is flagged as invisible.');
     }
     return $location;
 }
开发者ID:emodric,项目名称:ezpublish-kernel,代码行数:18,代码来源:ContentViewBuilder.php

示例10: processTag

 /**
  * Process embed tags for a single tag type (embed or embed-inline)
  * @param \DOMDocument $xmlDoc
  * @param $tagName string name of the tag to extract
  */
 protected function processTag(DOMDocument $xmlDoc, $tagName)
 {
     /** @var $embed \DOMElement */
     foreach ($xmlDoc->getElementsByTagName($tagName) as $embed) {
         if (!($view = $embed->getAttribute("view"))) {
             $view = $tagName;
         }
         $embedContent = null;
         $parameters = $this->getParameters($embed);
         if ($contentId = $embed->getAttribute("object_id")) {
             try {
                 /** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
                 $content = $this->repository->sudo(function (Repository $repository) use($contentId) {
                     return $repository->getContentService()->loadContent($contentId);
                 });
                 if (!$this->repository->canUser('content', 'read', $content) && !$this->repository->canUser('content', 'view_embed', $content)) {
                     throw new UnauthorizedException('content', 'read', array('contentId' => $contentId));
                 }
                 // Check published status of the Content
                 if ($content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED && !$this->repository->canUser('content', 'versionread', $content)) {
                     throw new UnauthorizedException('content', 'versionread', array('contentId' => $contentId));
                 }
                 $embedContent = $this->fragmentHandler->render(new ControllerReference('ez_content:embedContent', array('contentId' => $contentId, 'viewType' => $view, 'layout' => false, 'params' => $parameters)));
             } catch (APINotFoundException $e) {
                 if ($this->logger) {
                     $this->logger->error("While generating embed for xmltext, could not locate " . "Content object with ID " . $contentId);
                 }
             }
         } else {
             if ($locationId = $embed->getAttribute("node_id")) {
                 try {
                     /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
                     $location = $this->repository->sudo(function (Repository $repository) use($locationId) {
                         return $repository->getLocationService()->loadLocation($locationId);
                     });
                     if (!$this->repository->canUser('content', 'read', $location->getContentInfo(), $location) && !$this->repository->canUser('content', 'view_embed', $location->getContentInfo(), $location)) {
                         throw new UnauthorizedException('content', 'read', array('locationId' => $location->id));
                     }
                     $embedContent = $this->fragmentHandler->render(new ControllerReference('ez_content:embedLocation', array('locationId' => $locationId, 'viewType' => $view, 'layout' => false, 'params' => $parameters)));
                 } catch (APINotFoundException $e) {
                     if ($this->logger) {
                         $this->logger->error("While generating embed for xmltext, could not locate " . "Location with ID " . $locationId);
                     }
                 }
             }
         }
         if ($embedContent === null) {
             // Remove empty embed
             $embed->parentNode->removeChild($embed);
         } else {
             $embed->appendChild($xmlDoc->createCDATASection($embedContent));
         }
     }
 }
开发者ID:nlescure,项目名称:ezpublish-kernel,代码行数:59,代码来源:EmbedToHtml5.php

示例11: createDraft

 /**
  * Uses a content type identifier + a hash of fields values
  * to create and publish a draft below the root location.
  *
  * @param string $contentTypeIdentifier
  * @param array $fields Hash of field def identifier => field value
  *
  * @return Content the created draft.
  */
 public function createDraft($contentTypeIdentifier, array $fields)
 {
     $contentService = $this->repository->getContentService();
     $createStruct = $contentService->newContentCreateStruct($this->repository->getContentTypeService()->loadContentTypeByIdentifier($contentTypeIdentifier), 'eng-GB');
     foreach ($fields as $fieldDefIdentifier => $fieldValue) {
         $createStruct->setField($fieldDefIdentifier, $fieldValue);
     }
     $locationCreateStruct = $this->repository->getLocationService()->newLocationCreateStruct(2);
     $this->currentDraft = $this->repository->sudo(function () use($createStruct, $locationCreateStruct) {
         return $this->repository->getContentService()->createContent($createStruct, [$locationCreateStruct]);
     });
     return $this->currentDraft;
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:22,代码来源:ContentContext.php

示例12: loadUser

 /**
  * Loads a user for the given ID.
  *
  * @param $userId
  *
  * @return \eZ\Publish\Core\REST\Server\Values\RestUser
  */
 public function loadUser($userId)
 {
     $user = $this->userService->loadUser($userId);
     $userContentInfo = $user->getVersionInfo()->getContentInfo();
     $contentType = $this->contentTypeService->loadContentType($userContentInfo->contentTypeId);
     try {
         $userMainLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId);
         $relations = $this->contentService->loadRelations($user->getVersionInfo());
     } catch (UnauthorizedException $e) {
         // TODO: Hack for special case to allow current logged in user to load him/here self (but not relations)
         if ($user->id == $this->repository->getCurrentUser()->id) {
             $userMainLocation = $this->repository->sudo(function () use($userContentInfo) {
                 return $this->locationService->loadLocation($userContentInfo->mainLocationId);
             });
             // user may not have permissions to read related content, for security reasons do not use sudo().
             $relations = array();
         } else {
             throw $e;
         }
     }
     return new Values\CachedValue(new Values\RestUser($user, $contentType, $userContentInfo, $userMainLocation, $relations), array('locationId' => $userContentInfo->mainLocationId));
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:29,代码来源:User.php

示例13: sudo

 /**
  * Allows API execution to be performed with full access sand-boxed
  *
  * The closure sandbox will do a catch all on exceptions and rethrow after
  * re-setting the sudo flag.
  *
  * Example use:
  *     $location = $repository->sudo(
  *         function ( $repo ) use ( $locationId )
  *         {
  *             return $repo->getLocationService()->loadLocation( $locationId )
  *         }
  *     );
  *
  * @access private This function is not official API atm, and can change anytime.
  *
  * @param \Closure $callback
  *
  * @throws \RuntimeException Thrown on recursive sudo() use.
  * @throws \Exception Re throws exceptions thrown inside $callback
  * @return mixed
  */
 public function sudo(\Closure $callback)
 {
     return $this->repository->sudo($callback);
 }
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:26,代码来源:Repository.php

示例14: processTag

 /**
  * Process embed tags for a single tag type (embed or embed-inline)
  * @param \DOMDocument $xmlDoc
  * @param $tagName string name of the tag to extract
  */
 protected function processTag(DOMDocument $xmlDoc, $tagName)
 {
     /** @var $embed \DOMElement */
     foreach ($xmlDoc->getElementsByTagName($tagName) as $embed) {
         if (!($view = $embed->getAttribute("view"))) {
             $view = $tagName;
         }
         $embedContent = null;
         $parameters = array("noLayout" => true, "objectParameters" => array());
         foreach ($embed->attributes as $attribute) {
             // We only consider tags in the custom namespace, and skip disallowed names
             if (!isset($this->excludedAttributes[$attribute->localName])) {
                 $parameters["objectParameters"][$attribute->localName] = $attribute->nodeValue;
             }
         }
         if ($contentId = $embed->getAttribute("object_id")) {
             try {
                 /** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
                 $content = $this->repository->sudo(function (Repository $repository) use($contentId) {
                     return $repository->getContentService()->loadContent($contentId);
                 });
                 if (!$this->repository->canUser('content', 'read', $content) && !$this->repository->canUser('content', 'view_embed', $content)) {
                     throw new UnauthorizedException('content', 'read', array('contentId' => $contentId));
                 }
                 // Check published status of the Content
                 if ($content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED && !$this->repository->canUser('content', 'versionread', $content)) {
                     throw new UnauthorizedException('content', 'versionread', array('contentId' => $contentId));
                 }
                 $embedContent = $this->fragmentHandler->render(new ControllerReference('ez_content:embedContent', array('contentId' => $contentId, 'viewType' => $view, 'layout' => false, 'params' => $parameters)));
             } catch (APINotFoundException $e) {
                 if ($this->logger) {
                     $this->logger->error("While generating embed for xmltext, could not locate " . "Content object with ID " . $contentId);
                 }
             }
         } else {
             if ($locationId = $embed->getAttribute("node_id")) {
                 try {
                     /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
                     $location = $this->repository->sudo(function (Repository $repository) use($locationId) {
                         return $repository->getLocationService()->loadLocation($locationId);
                     });
                     if (!$this->repository->canUser('content', 'read', $location->getContentInfo(), $location) && !$this->repository->canUser('content', 'view_embed', $location->getContentInfo(), $location)) {
                         throw new UnauthorizedException('content', 'read', array('locationId' => $location->id));
                     }
                     $embedContent = $this->fragmentHandler->render(new ControllerReference('ez_content:embedLocation', array('locationId' => $locationId, 'viewType' => $view, 'layout' => false, 'params' => $parameters)));
                 } catch (APINotFoundException $e) {
                     if ($this->logger) {
                         $this->logger->error("While generating embed for xmltext, could not locate " . "Location with ID " . $locationId);
                     }
                 }
             }
         }
         if ($embedContent === null) {
             // Remove tmp paragraph
             if ($embed->parentNode->lookupNamespaceUri('tmp') !== null) {
                 $embed->parentNode->parentNode->removeChild($embed->parentNode);
             } else {
                 if ($embed->parentNode->localName === "link" && $embed->parentNode->childNodes->length === 1) {
                     // Remove paragraph with empty link
                     if ($embed->parentNode->parentNode->localName === "paragraph" && $embed->parentNode->parentNode->childNodes->length === 1) {
                         $embed->parentNode->parentNode->parentNode->removeChild($embed->parentNode->parentNode);
                     } else {
                         $embed->parentNode->parentNode->removeChild($embed->parentNode);
                     }
                 } else {
                     $embed->parentNode->removeChild($embed);
                 }
             }
         } else {
             $embed->appendChild($xmlDoc->createCDATASection($embedContent));
         }
     }
 }
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:78,代码来源:EmbedToHtml5.php


注:本文中的eZ\Publish\API\Repository\Repository::sudo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。