本文整理汇总了PHP中eZ\Publish\API\Repository\Repository类的典型用法代码示例。如果您正苦于以下问题:PHP Repository类的具体用法?PHP Repository怎么用?PHP Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Repository类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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
示例9: buildSPILocationCreateStruct
/**
* Creates an array of SPI location create structs from given array of API location create structs
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*
* @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct
* @param \eZ\Publish\API\Repository\Values\Content\Location $parentLocation
* @param mixed $mainLocation
* @param mixed $contentId
* @param mixed $contentVersionNo
*
* @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct
*/
public function buildSPILocationCreateStruct($locationCreateStruct, APILocation $parentLocation, $mainLocation, $contentId, $contentVersionNo)
{
if ($locationCreateStruct->priority !== null && !is_int($locationCreateStruct->priority)) {
throw new InvalidArgumentValue("priority", $locationCreateStruct->priority, "LocationCreateStruct");
}
if (!is_bool($locationCreateStruct->hidden)) {
throw new InvalidArgumentValue("hidden", $locationCreateStruct->hidden, "LocationCreateStruct");
}
if ($locationCreateStruct->remoteId !== null && (!is_string($locationCreateStruct->remoteId) || empty($locationCreateStruct->remoteId))) {
throw new InvalidArgumentValue("remoteId", $locationCreateStruct->remoteId, "LocationCreateStruct");
}
if ($locationCreateStruct->sortField !== null && !$this->isValidLocationSortField($locationCreateStruct->sortField)) {
throw new InvalidArgumentValue("sortField", $locationCreateStruct->sortField, "LocationCreateStruct");
}
if ($locationCreateStruct->sortOrder !== null && !$this->isValidLocationSortOrder($locationCreateStruct->sortOrder)) {
throw new InvalidArgumentValue("sortOrder", $locationCreateStruct->sortOrder, "LocationCreateStruct");
}
$remoteId = $locationCreateStruct->remoteId;
if (null === $remoteId) {
$remoteId = $this->getUniqueHash($locationCreateStruct);
} else {
try {
$this->repository->getLocationService()->loadLocationByRemoteId($remoteId);
throw new InvalidArgumentException("\$locationCreateStructs", "Another Location with remoteId '{$remoteId}' exists");
} catch (NotFoundException $e) {
// Do nothing
}
}
return new SPILocationCreateStruct(array("priority" => $locationCreateStruct->priority, "hidden" => $locationCreateStruct->hidden, "invisible" => $locationCreateStruct->hidden === true || $parentLocation->invisible, "remoteId" => $remoteId, "contentId" => $contentId, "contentVersion" => $contentVersionNo, "pathIdentificationString" => null, "mainLocationId" => $mainLocation, "sortField" => $locationCreateStruct->sortField !== null ? $locationCreateStruct->sortField : Location::SORT_FIELD_NAME, "sortOrder" => $locationCreateStruct->sortOrder !== null ? $locationCreateStruct->sortOrder : Location::SORT_ORDER_ASC, "parentId" => $locationCreateStruct->parentLocationId));
}
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:43,代码来源:DomainMapper.php
示例10: buildDomainUserObject
/**
* Builds the domain user object from provided persistence user object
*
* @param \eZ\Publish\SPI\Persistence\User $spiUser
* @param \eZ\Publish\API\Repository\Values\Content\Content|null $content
*
* @return \eZ\Publish\API\Repository\Values\User\User
*/
protected function buildDomainUserObject(SPIUser $spiUser, APIContent $content = null)
{
if ($content === null) {
$content = $this->repository->getContentService()->internalLoadContent($spiUser->id);
}
return new User(array('content' => $content, 'login' => $spiUser->login, 'email' => $spiUser->email, 'passwordHash' => $spiUser->passwordHash, 'hashAlgorithm' => (int) $spiUser->hashAlgorithm, 'enabled' => $spiUser->isEnabled, 'maxLogin' => (int) $spiUser->maxLogin));
}
开发者ID:masev,项目名称:ezpublish-kernel,代码行数:15,代码来源:UserService.php
示例11: publishContentTypeDraft
/**
* Publish the content type and update content objects.
*
* This method updates content objects, depending on the changed field definitions.
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If the content type has no draft
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the content type has no field definitions
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish a content type
*
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft $contentTypeDraft
*/
public function publishContentTypeDraft(APIContentTypeDraft $contentTypeDraft)
{
if ($this->repository->hasAccess('class', 'update') !== true) {
throw new UnauthorizedException('ContentType', 'update');
}
try {
$loadedContentTypeDraft = $this->loadContentTypeDraft($contentTypeDraft->id);
} catch (APINotFoundException $e) {
throw new BadStateException("\$contentTypeDraft", "The content type does not have a draft.", $e);
}
if (count($loadedContentTypeDraft->getFieldDefinitions()) === 0) {
throw new InvalidArgumentException("\$contentTypeDraft", "The content type draft should have at least one field definition.");
}
$this->repository->beginTransaction();
try {
if (empty($loadedContentTypeDraft->nameSchema)) {
$fieldDefinitions = $loadedContentTypeDraft->getFieldDefinitions();
$this->contentTypeHandler->update($contentTypeDraft->id, $contentTypeDraft->status, $this->buildSPIContentTypeUpdateStruct($loadedContentTypeDraft, new ContentTypeUpdateStruct(array("nameSchema" => "<" . $fieldDefinitions[0]->identifier . ">"))));
}
$this->contentTypeHandler->publish($loadedContentTypeDraft->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
开发者ID:dfritschy,项目名称:ezpublish-kernel,代码行数:37,代码来源:ContentTypeService.php
示例12: getContentType
/**
* Get ContentType by Content/ContentInfo.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content|\eZ\Publish\API\Repository\Values\Content\ContentInfo $content
*
* @return \eZ\Publish\API\Repository\Values\ContentType\ContentType|null
*/
private function getContentType(ValueObject $content)
{
if ($content instanceof Content) {
return $this->repository->getContentTypeService()->loadContentType($content->getVersionInfo()->getContentInfo()->contentTypeId);
} elseif ($content instanceof ContentInfo) {
return $this->repository->getContentTypeService()->loadContentType($content->contentTypeId);
}
}
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:15,代码来源:ContentExtension.php
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: 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
示例19: 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
示例20: 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;未经允许,请勿转载。 |
请发表评论