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


PHP Repository\Repository类代码示例

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


在下文中一共展示了Repository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getContent

 /**
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 public function getContent()
 {
     if ($this->content == null) {
         $this->content = $this->repository->getContentService()->loadContent($this->location->contentId);
     }
     return $this->content;
 }
开发者ID:truffo,项目名称:ez-content-decorator-bundle,代码行数:10,代码来源:ContentDecorator.php

示例3: 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

示例4: testAuthenticate

 public function testAuthenticate()
 {
     $anonymousUserId = 10;
     $this->configResolver->expects($this->once())->method('getParameter')->with('anonymous_user_id')->will($this->returnValue($anonymousUserId));
     $this->repository->expects($this->once())->method('setCurrentUser')->with(new UserReference($anonymousUserId));
     $key = 'some_key';
     $authProvider = new AnonymousAuthenticationProvider($key);
     $authProvider->setRepository($this->repository);
     $authProvider->setConfigResolver($this->configResolver);
     $anonymousToken = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\AnonymousToken')->setConstructorArgs(array($key, $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface')))->getMockForAbstractClass();
     $this->assertSame($anonymousToken, $authProvider->authenticate($anonymousToken));
 }
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:12,代码来源:AnonymousAuthenticationProviderTest.php

示例5: 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

示例6: vote

 /**
  * Returns the vote for the given parameters.
  * Checks if user has access to a given action on a given value object.
  *
  * $attributes->limitations is a hash that contains:
  *  - 'valueObject' - The ValueObject to check access on (eZ\Publish\API\Repository\Values\ValueObject). e.g. Location or Content.
  *  - 'targets' - The location, parent or "assignment" value object, or an array of the same.
  *
  * This method must return one of the following constants:
  * ACCESS_GRANTED, ACCESS_DENIED, or ACCESS_ABSTAIN.
  *
  * @see \eZ\Publish\API\Repository\Repository::canUser()
  *
  * @param TokenInterface $token      A TokenInterface instance
  * @param object         $object     The object to secure
  * @param array          $attributes An array of attributes associated with the method being invoked
  *
  * @return integer either ACCESS_GRANTED, ACCESS_ABSTAIN, or ACCESS_DENIED
  */
 public function vote(TokenInterface $token, $object, array $attributes)
 {
     foreach ($attributes as $attribute) {
         if ($this->supportsAttribute($attribute)) {
             $targets = isset($attribute->limitations['targets']) ? $attribute->limitations['targets'] : null;
             if ($this->repository->canUser($attribute->module, $attribute->function, $attribute->limitations['valueObject'], $targets) === false) {
                 return VoterInterface::ACCESS_DENIED;
             }
             return VoterInterface::ACCESS_GRANTED;
         }
     }
     return VoterInterface::ACCESS_ABSTAIN;
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:32,代码来源:ValueObjectVoter.php

示例7: getLatestContent

 /**
  * Returns latest published content that is located under $pathString and matching $contentTypeIdentifier.
  * The whole subtree will be passed through to find content.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $rootLocation Root location we want to start content search from.
  * @param string[] $includeContentTypeIdentifiers Array of ContentType identifiers we want content to match.
  * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion Additional criterion for filtering.
  * @param int|null $limit Max number of items to retrieve. If not provided, default limit will be used.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content[]
  */
 public function getLatestContent(Location $rootLocation, array $includeContentTypeIdentifiers = array(), Criterion $criterion = null, $limit = null)
 {
     $criteria = array(new Criterion\Subtree($rootLocation->pathString), new Criterion\Visibility(Criterion\Visibility::VISIBLE));
     if ($includeContentTypeIdentifiers) {
         $criteria[] = new Criterion\ContentTypeIdentifier($includeContentTypeIdentifiers);
     }
     if (!empty($criterion)) {
         $criteria[] = $criterion;
     }
     $query = new Query(array('criterion' => new Criterion\LogicalAnd($criteria), 'sortClauses' => array(new SortClause\DatePublished(Query::SORT_DESC))));
     $query->limit = $limit ?: $this->defaultMenuLimit;
     return $this->searchHelper->buildListFromSearchResult($this->repository->getSearchService()->findContent($query));
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:24,代码来源:MenuHelper.php

示例8: testVote

 /**
  * @dataProvider voteProvider
  */
 public function testVote(Attribute $attribute, $repositoryCanUser, $expectedResult)
 {
     $voter = new ValueObjectVoter($this->repository);
     $targets = isset($attribute->limitations['targets']) ? $attribute->limitations['targets'] : null;
     $this->repository->expects($this->once())->method('canUser')->with($attribute->module, $attribute->function, $attribute->limitations['valueObject'], $targets)->will($this->returnValue($repositoryCanUser));
     $this->assertSame($expectedResult, $voter->vote($this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'), new \stdClass(), array($attribute)));
 }
开发者ID:dfritschy,项目名称:ezpublish-kernel,代码行数:10,代码来源:ValueObjectVoterTest.php

示例9: 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

示例10: onKernelRequest

 /**
  * If user is logged-in in legacy_mode (e.g. legacy admin interface),
  * will inject currently logged-in user in the repository.
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver */
     $request = $event->getRequest();
     $session = $request->getSession();
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST || !$this->configResolver->getParameter('legacy_mode') || !($session->isStarted() && $session->has('eZUserLoggedInID'))) {
         return;
     }
     try {
         $apiUser = $this->repository->getUserService()->loadUser($session->get('eZUserLoggedInID'));
         $this->repository->setCurrentUser($apiUser);
         $token = $this->tokenStorage->getToken();
         if ($token instanceof TokenInterface) {
             $token->setUser(new User($apiUser));
             // Don't embed if we already have a LegacyToken, to avoid nested session storage.
             if (!$token instanceof LegacyToken) {
                 $this->tokenStorage->setToken(new LegacyToken($token));
             }
         }
     } catch (NotFoundException $e) {
         // Invalid user ID, the user may have been removed => invalidate the token and the session.
         $this->tokenStorage->setToken(null);
         $session->invalidate();
     }
 }
开发者ID:emodric,项目名称:LegacyBridge,代码行数:31,代码来源:RequestListener.php

示例11: refreshUser

 /**
  * Refreshes the user for the account interface.
  *
  * It is up to the implementation to decide if the user data should be
  * totally reloaded (e.g. from the database), or if the UserInterface
  * object can just be merged into some internal array of users / identity
  * map.
  *
  * @param \Symfony\Component\Security\Core\User\UserInterface $user
  *
  * @throws \Symfony\Component\Security\Core\Exception\UnsupportedUserException
  *
  * @return \Symfony\Component\Security\Core\User\UserInterface
  */
 public function refreshUser(CoreUserInterface $user)
 {
     if (!$user instanceof UserInterface) {
         throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
     }
     $this->repository->setCurrentUser($user->getAPIUser());
     return $user;
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:22,代码来源:Provider.php

示例12: handleAction

 public function handleAction(Request $request)
 {
     $user = $this->userService->loadUserByCredentials($request->username, $request->password);
     $this->repository->setCurrentUser($user);
     $contentCreateStruct = $this->contentProvider->newContentCreateStructFromRequest($request);
     $locationCreateStruct = $this->contentProvider->newLocationCreateStructFromRequest($request);
     $content = $this->contentService->createContent($contentCreateStruct, array($locationCreateStruct));
     $this->contentService->publishVersion($content->versionInfo);
 }
开发者ID:bdunogier,项目名称:eziftttbundle,代码行数:9,代码来源:Handler.php

示例13: 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

示例14: getContentTypeIdentifier

 /**
  * Gets content type identifier of field corresponding with the given node
  *
  * @param TreeNodeInterface $node
  * @return string
  */
 public function getContentTypeIdentifier(TreeNodeInterface $node)
 {
     $parent = $node->getParent();
     $fieldName = $parent->getName();
     $grandPa = $parent->getParent()->getParent();
     $contentTypeNode = $grandPa->getChildByName('content_type');
     $contentType = $this->repository->getContentTypeService()->loadContentTypeByIdentifier($contentTypeNode->getValue());
     $fieldDefinition = $contentType->getFieldDefinition($fieldName);
     return $fieldDefinition->fieldTypeIdentifier;
 }
开发者ID:silversolutions,项目名称:content-loader-bundle,代码行数:16,代码来源:AbstractFieldLoader.php

示例15: testVote

 /**
  * @dataProvider voteProvider
  */
 public function testVote(Attribute $attribute, $repositoryCanUser, $expectedResult)
 {
     $voter = new CoreVoter($this->repository);
     if ($repositoryCanUser !== null) {
         $this->repository->expects($this->once())->method('hasAccess')->with($attribute->module, $attribute->function)->will($this->returnValue($repositoryCanUser));
     } else {
         $this->repository->expects($this->never())->method('hasAccess');
     }
     $this->assertSame($expectedResult, $voter->vote($this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'), new \stdClass(), array($attribute)));
 }
开发者ID:dfritschy,项目名称:ezpublish-kernel,代码行数:13,代码来源:CoreVoterTest.php


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