本文整理汇总了PHP中eZ\Publish\API\Repository\LocationService类的典型用法代码示例。如果您正苦于以下问题:PHP LocationService类的具体用法?PHP LocationService怎么用?PHP LocationService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LocationService类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var $repository \eZ\Publish\API\Repository\Repository */
$repository = $this->getContainer()->get('ezpublish.api.repository');
$this->contentService = $repository->getContentService();
$this->locationService = $repository->getLocationService();
// fetch the input argument
$locationId = $input->getArgument('locationId');
try {
// load the starting location and browse
$location = $this->locationService->loadLocation($locationId);
$this->browseLocation($location, $output);
} catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $e) {
$output->writeln("<error>No location found with id {$locationId}</error>");
} catch (\eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e) {
$output->writeln("<error>Anonymous users are not allowed to read location with id {$locationId}</error>");
}
}
开发者ID:haavardb,项目名称:CookbookBundle,代码行数:18,代码来源:BrowseLocationsCommand.php
示例2: onContentCacheClear
public function onContentCacheClear(ContentCacheClearEvent $event)
{
$contentInfo = $event->getContentInfo();
foreach ($this->locationService->loadLocations($contentInfo) as $location) {
$event->addLocationToClear($location);
}
}
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:7,代码来源:AssignedLocationsListener.php
示例3: parse
/**
* Parse input structure
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
if (!array_key_exists('ParentLocation', $data) || !is_array($data['ParentLocation'])) {
throw new Exceptions\Parser("Missing or invalid 'ParentLocation' element for LocationCreate.");
}
if (!array_key_exists('_href', $data['ParentLocation'])) {
throw new Exceptions\Parser("Missing '_href' attribute for ParentLocation element in LocationCreate.");
}
$locationHrefParts = explode('/', $this->requestParser->parseHref($data['ParentLocation']['_href'], 'locationPath'));
$locationCreateStruct = $this->locationService->newLocationCreateStruct(array_pop($locationHrefParts));
if (array_key_exists('priority', $data)) {
$locationCreateStruct->priority = (int) $data['priority'];
}
if (array_key_exists('hidden', $data)) {
$locationCreateStruct->hidden = $this->parserTools->parseBooleanValue($data['hidden']);
}
if (array_key_exists('remoteId', $data)) {
$locationCreateStruct->remoteId = $data['remoteId'];
}
if (!array_key_exists('sortField', $data)) {
throw new Exceptions\Parser("Missing 'sortField' element for LocationCreate.");
}
$locationCreateStruct->sortField = $this->parserTools->parseDefaultSortField($data['sortField']);
if (!array_key_exists('sortOrder', $data)) {
throw new Exceptions\Parser("Missing 'sortOrder' element for LocationCreate.");
}
$locationCreateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']);
return $locationCreateStruct;
}
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:37,代码来源:LocationCreate.php
示例4: convert
/**
* Converts internal links (ezcontent:// and ezlocation://) to URLs.
*
* @param \DOMDocument $document
*
* @return \DOMDocument
*/
public function convert(DOMDocument $document)
{
$document = clone $document;
$xpath = new DOMXPath($document);
$xpath->registerNamespace("docbook", "http://docbook.org/ns/docbook");
$linkAttributeExpression = "starts-with( @xlink:href, 'ezlocation://' ) or starts-with( @xlink:href, 'ezcontent://' )";
$xpathExpression = "//docbook:link[{$linkAttributeExpression}]|//docbook:ezlink";
/** @var \DOMElement $link */
foreach ($xpath->query($xpathExpression) as $link) {
// Set resolved href to number character as a default if it can't be resolved
$hrefResolved = "#";
$href = $link->getAttribute("xlink:href");
$location = null;
preg_match("~^(.+://)?([^#]*)?(#.*|\\s*)?\$~", $href, $matches);
list(, $scheme, $id, $fragment) = $matches;
if ($scheme === "ezcontent://") {
try {
$contentInfo = $this->contentService->loadContentInfo($id);
$location = $this->locationService->loadLocation($contentInfo->mainLocationId);
$hrefResolved = $this->urlAliasRouter->generate($location) . $fragment;
} catch (APINotFoundException $e) {
if ($this->logger) {
$this->logger->warning("While generating links for richtext, could not locate " . "Content object with ID " . $id);
}
} catch (APIUnauthorizedException $e) {
if ($this->logger) {
$this->logger->notice("While generating links for richtext, unauthorized to load " . "Content object with ID " . $id);
}
}
} else {
if ($scheme === "ezlocation://") {
try {
$location = $this->locationService->loadLocation($id);
$hrefResolved = $this->urlAliasRouter->generate($location) . $fragment;
} catch (APINotFoundException $e) {
if ($this->logger) {
$this->logger->warning("While generating links for richtext, could not locate " . "Location with ID " . $id);
}
} catch (APIUnauthorizedException $e) {
if ($this->logger) {
$this->logger->notice("While generating links for richtext, unauthorized to load " . "Location with ID " . $id);
}
}
} else {
$hrefResolved = $href;
}
}
$hrefAttributeName = "xlink:href";
// For embeds set the resolved href to the separate attribute
// Original href needs to be preserved in order to generate link parameters
// This will need to change with introduction of UrlService and removal of URL link
// resolving in external storage
if ($link->localName === "ezlink") {
$hrefAttributeName = "href_resolved";
}
$link->setAttribute($hrefAttributeName, $hrefResolved);
}
return $document;
}
开发者ID:nlescure,项目名称:ezpublish-kernel,代码行数:66,代码来源:Link.php
示例5: testGetPreviewLocationNoLocation
public function testGetPreviewLocationNoLocation()
{
$contentId = 123;
$contentInfo = $this->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo')->setConstructorArgs(array(array('id' => $contentId)))->getMockForAbstractClass();
$this->contentService->expects($this->once())->method('loadContentInfo')->with($contentId)->will($this->returnValue($contentInfo));
$this->locationHandler->expects($this->once())->method('loadParentLocationsForDraftContent')->with($contentId)->will($this->returnValue(array()));
$this->locationHandler->expects($this->never())->method('loadLocation');
$this->assertNull($this->provider->loadMainLocation($contentId));
}
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:9,代码来源:PreviewLocationProviderTest.php
示例6: setPostCategories
public function setPostCategories($postId, Request $request)
{
$this->login($request->request->get('username'), $request->request->get('password'));
// @todo Replace categories instead of adding
$contentInfo = $this->contentService->loadContentInfo($postId);
foreach ($request->request->get('categories') as $category) {
$this->locationService->createLocation($contentInfo, $this->locationService->newLocationCreateStruct($category['categoryId']));
}
return new Response(true);
}
开发者ID:bdunogier,项目名称:wordpressapibundle,代码行数:10,代码来源:DefaultController.php
示例7: filterLimitationValues
public function filterLimitationValues(Limitation $limitation)
{
if (!is_array($limitation->limitationValues)) {
return;
}
// UDW returns an array of location IDs. If we haven't used UDW, the value is as stored: an array of path strings.
foreach ($limitation->limitationValues as $key => $limitationValue) {
if (preg_match('/\\A\\d+\\z/', $limitationValue) === 1) {
$limitation->limitationValues[$key] = $this->locationService->loadLocation($limitationValue)->pathString;
}
}
}
开发者ID:ezsystems,项目名称:repository-forms,代码行数:12,代码来源:SubtreeLimitationMapper.php
示例8: parse
/**
* Parses input structure to a Criterion object.
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser
*
* @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ParentLocationId
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
if (!array_key_exists('ParentLocationRemoteIdCriterion', $data)) {
throw new Exceptions\Parser('Invalid <ParentLocationRemoteIdCriterion> format');
}
$contentIdArray = array();
foreach (explode(',', $data['ParentLocationRemoteIdCriterion']) as $parentRemoteId) {
$location = $this->locationService->loadLocationByRemoteId($parentRemoteId);
$contentIdArray[] = $location->id;
}
return new ParentLocationIdCriterion($contentIdArray);
}
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:22,代码来源:ParentLocationRemoteId.php
示例9: getPlaceListSorted
/**
* Returns all places contained in a place_list that are located between the range defined in
* the default configuration. A sort clause array can be provided in order to sort the results.
*
* @param int|string $locationId
* @param float $latitude
* @param float $longitude
* @param string|string[] $contentTypes to be retrieved
* @param int $maxDist Maximum distance for the search in km
* @param array $sortClauses
* @param string|string[] $languages to be retrieved
*
* @return \eZ\Publish\API\Repository\Values\Content\Content[]
*/
public function getPlaceListSorted($locationId, $latitude, $longitude, $contentTypes, $maxDist = null, $sortClauses = array(), $languages = array())
{
$location = $this->locationService->loadLocation($locationId);
if ($maxDist === null) {
$maxDist = $this->placeListMaxDist;
}
$query = new Query();
$query->filter = new Criterion\LogicalAnd(array(new Criterion\ContentTypeIdentifier($contentTypes), new Criterion\Subtree($location->pathString), new Criterion\LanguageCode($languages), new Criterion\MapLocationDistance("location", Criterion\Operator::BETWEEN, array($this->placeListMinDist, $maxDist), $latitude, $longitude)));
$query->sortClauses = $sortClauses;
$searchResults = $this->searchService->findContent($query);
return $this->searchHelper->buildListFromSearchResult($searchResults);
}
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:26,代码来源:PlaceHelper.php
示例10: visit
/**
* Visit struct returned by controllers.
*
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
* @param \eZ\Publish\API\Repository\Values\Content\Location $location
*/
public function visit(Visitor $visitor, Generator $generator, $location)
{
$generator->startObjectElement('Location');
$visitor->setHeader('Content-Type', $generator->getMediaType('Location'));
$visitor->setHeader('Accept-Patch', $generator->getMediaType('LocationUpdate'));
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => trim($location->pathString, '/'))));
$generator->endAttribute('href');
$generator->startValueElement('id', $location->id);
$generator->endValueElement('id');
$generator->startValueElement('priority', $location->priority);
$generator->endValueElement('priority');
$generator->startValueElement('hidden', $this->serializeBool($generator, $location->hidden));
$generator->endValueElement('hidden');
$generator->startValueElement('invisible', $this->serializeBool($generator, $location->invisible));
$generator->endValueElement('invisible');
$generator->startObjectElement('ParentLocation', 'Location');
if (trim($location->pathString, '/') !== '1') {
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => implode('/', array_slice($location->path, 0, count($location->path) - 1)))));
$generator->endAttribute('href');
}
$generator->endObjectElement('ParentLocation');
$generator->startValueElement('pathString', $location->pathString);
$generator->endValueElement('pathString');
$generator->startValueElement('depth', $location->depth);
$generator->endValueElement('depth');
$generator->startValueElement('childCount', $this->locationService->getLocationChildCount($location));
$generator->endValueElement('childCount');
$generator->startValueElement('remoteId', $location->remoteId);
$generator->endValueElement('remoteId');
$generator->startObjectElement('Children', 'LocationList');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadLocationChildren', array('locationPath' => trim($location->pathString, '/'))));
$generator->endAttribute('href');
$generator->endObjectElement('Children');
$generator->startObjectElement('Content');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $location->contentId)));
$generator->endAttribute('href');
$generator->endObjectElement('Content');
$generator->startValueElement('sortField', $this->serializeSortField($location->sortField));
$generator->endValueElement('sortField');
$generator->startValueElement('sortOrder', $this->serializeSortOrder($location->sortOrder));
$generator->endValueElement('sortOrder');
$generator->startObjectElement('UrlAliases', 'UrlAliasRefList');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_listLocationURLAliases', array('locationPath' => trim($location->pathString, '/'))));
$generator->endAttribute('href');
$generator->endObjectElement('UrlAliases');
$generator->startObjectElement('ContentInfo', 'ContentInfo');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $location->contentId)));
$generator->endAttribute('href');
$visitor->visitValueObject(new RestContentValue($location->contentInfo));
$generator->endObjectElement('ContentInfo');
$generator->endObjectElement('Location');
}
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:59,代码来源:Location.php
示例11: getChildNodesAction
/**
* Renders top menu with child items.
*
* @param string $template
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function getChildNodesAction($template)
{
$query = new LocationQuery();
$query->query = $this->menuCriteria->generateChildCriterion($this->locationService->loadLocation($this->topMenuLocationId), $this->configResolver->getParameter('languages'));
$query->sortClauses = [new SortClause\Location\Priority(LocationQuery::SORT_ASC)];
$query->performCount = false;
$content = $this->searchService->findLocations($query);
$menuItems = [];
foreach ($content->searchHits as $hit) {
$menuItems[] = $hit->valueObject;
}
return $this->templating->renderResponse($template, ['menuItems' => $menuItems], new Response());
}
开发者ID:damianz5,项目名称:ezplatform-demo,代码行数:20,代码来源:MenuController.php
示例12: createWithoutDraftAction
/**
* Displays and processes a content creation form. Showing the form does not create a draft in the repository.
*
* @param int $contentTypeIdentifier ContentType id to create
* @param string $language Language code to create the content in (eng-GB, ger-DE, ...))
* @param int $parentLocationId Location the content should be a child of
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function createWithoutDraftAction($contentTypeIdentifier, $language, $parentLocationId, Request $request)
{
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
$data = (new ContentCreateMapper())->mapToFormData($contentType, ['mainLanguageCode' => $language, 'parentLocation' => $this->locationService->newLocationCreateStruct($parentLocationId)]);
$form = $this->createForm(ContentEditType::class, $data, ['languageCode' => $language]);
$form->handleRequest($request);
if ($form->isValid()) {
$this->contentActionDispatcher->dispatchFormAction($form, $data, $form->getClickedButton()->getName());
if ($response = $this->contentActionDispatcher->getResponse()) {
return $response;
}
}
return $this->render('EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig', ['form' => $form->createView(), 'languageCode' => $language, 'pagelayout' => $this->pagelayout]);
}
开发者ID:ezsystems,项目名称:repository-forms,代码行数:24,代码来源:ContentEditController.php
示例13: getPreviewLocation
/**
* Returns a valid Location object for $contentId.
* Will either load mainLocationId (if available) or build a virtual Location object.
*
* @param mixed $contentId
*
* @return \eZ\Publish\API\Repository\Values\Content\Location|null Null when content does not have location
*/
public function getPreviewLocation($contentId)
{
// contentInfo must be reloaded as content is not published yet (e.g. no mainLocationId)
$contentInfo = $this->contentService->loadContentInfo($contentId);
// mainLocationId already exists, content has been published at least once.
if ($contentInfo->mainLocationId) {
$location = $this->locationService->loadLocation($contentInfo->mainLocationId);
} else {
// @todo In future releases this will be a full draft location when this feature
// is implemented. Or it might return null when content does not have location,
// but for now we can't detect that so we return a virtual draft location
$location = new Location(array('contentInfo' => $contentInfo, 'status' => Location::STATUS_DRAFT));
}
return $location;
}
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:23,代码来源:ContentPreviewHelper.php
示例14: restoreTrashItem
/**
* Restores a trashItem.
*
* @param $trashItemId
*
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
*
* @return \eZ\Publish\Core\REST\Server\Values\ResourceCreated
*/
public function restoreTrashItem($trashItemId, Request $request)
{
$requestDestination = null;
try {
$requestDestination = $request->headers->get('Destination');
} catch (InvalidArgumentException $e) {
// No Destination header
}
$parentLocation = null;
if ($request->headers->has('Destination')) {
$locationPathParts = explode('/', $this->requestParser->parseHref($request->headers->get('Destination'), 'locationPath'));
try {
$parentLocation = $this->locationService->loadLocation(array_pop($locationPathParts));
} catch (NotFoundException $e) {
throw new ForbiddenException($e->getMessage());
}
}
$trashItem = $this->trashService->loadTrashItem($trashItemId);
if ($requestDestination === null) {
// If we're recovering under the original location
// check if it exists, to return "403 Forbidden" in case it does not
try {
$this->locationService->loadLocation($trashItem->parentLocationId);
} catch (NotFoundException $e) {
throw new ForbiddenException($e->getMessage());
}
}
$location = $this->trashService->recover($trashItem, $parentLocation);
return new Values\ResourceCreated($this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => trim($location->pathString, '/'))));
}
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:39,代码来源:Trash.php
示例15: getLocationCreateStruct
/**
* Creates and prepares location create structure.
*
* @param array $data
* @param int $defaultLocationId
* @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
*/
private function getLocationCreateStruct($data, $defaultLocationId)
{
$parentLocationId = $this->getContentDataParentLocationId($data, $defaultLocationId);
$locationStruct = $this->locationService->newLocationCreateStruct($parentLocationId);
$locationStruct->priority = isset($data['priority']) ? $data['priority'] : 0;
return $locationStruct;
}
开发者ID:silversolutions,项目名称:content-loader-bundle,代码行数:14,代码来源:Content.php
示例16: assignUserToUserGroup
/**
* Assigns the user to a user group
*
* @param $userId
*
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
* @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList
*/
public function assignUserToUserGroup($userId)
{
$user = $this->userService->loadUser($userId);
try {
$userGroupLocation = $this->locationService->loadLocation($this->extractLocationIdFromPath($this->request->query->get('group')));
} catch (APINotFoundException $e) {
throw new Exceptions\ForbiddenException($e->getMessage());
}
try {
$userGroup = $this->userService->loadUserGroup($userGroupLocation->contentId);
} catch (APINotFoundException $e) {
throw new Exceptions\ForbiddenException($e->getMessage());
}
try {
$this->userService->assignUserToUserGroup($user, $userGroup);
} catch (InvalidArgumentException $e) {
throw new Exceptions\ForbiddenException($e->getMessage());
}
$userGroups = $this->userService->loadUserGroupsOfUser($user);
$restUserGroups = array();
foreach ($userGroups as $userGroup) {
$userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
$userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
$contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
$restUserGroups[] = new Values\RestUserGroup($userGroup, $contentType, $userGroupContentInfo, $userGroupLocation, $this->contentService->loadRelations($userGroup->getVersionInfo()));
}
return new Values\UserGroupRefList($restUserGroups, $this->router->generate('ezpublish_rest_loadUserGroupsOfUser', array('userId' => $userId)), $userId);
}
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:36,代码来源:User.php
示例17: getPreviewLocation
/**
* Returns a valid Location object for $contentId.
* Will either load mainLocationId (if available) or build a virtual Location object.
*
* @param mixed $contentId
*
* @return \eZ\Publish\API\Repository\Values\Content\Location|null Null when content does not have location
*/
public function getPreviewLocation( $contentId )
{
// contentInfo must be reloaded as content is not published yet (e.g. no mainLocationId)
$contentInfo = $this->contentService->loadContentInfo( $contentId );
// mainLocationId already exists, content has been published at least once.
if ( $contentInfo->mainLocationId )
{
$location = $this->locationService->loadLocation( $contentInfo->mainLocationId );
}
// New Content, never published, create a virtual location object.
else
{
// @todo In future releases this will be a full draft location when this feature
// is implemented. Or it might return null when content does not have location,
// but for now we can't detect that so we return a virtual draft location
$location = new Location(
array(
// Faking using root locationId
'id' => $this->configResolver->getParameter( 'content.tree_root.location_id' ),
'contentInfo' => $contentInfo,
'status' => Location::STATUS_DRAFT
)
);
}
return $location;
}
开发者ID:ataxel,项目名称:tp,代码行数:35,代码来源:ContentPreviewHelper.php
示例18: fetchItems
/**
* Returns array of child content objects from given $locationId.
*
* @param int $locationId
* @param int $limit
*
* @return array
*/
private function fetchItems($locationId, $limit)
{
$languages = $this->configResolver->getParameter('languages');
$query = new Query();
$location = $this->locationService->loadLocation($locationId);
$query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
$query->performCount = false;
$query->limit = $limit;
$query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)];
$results = $this->searchService->findContent($query);
$items = [];
foreach ($results->searchHits as $item) {
$items[] = $item->valueObject;
}
return $items;
}
开发者ID:clash82,项目名称:ezplatform-demo,代码行数:24,代码来源:HomeController.php
示例19: generate
/**
* Generates a URL for a location, from the given parameters.
*
* It is possible to directly pass a Location object as the route name, as the ChainRouter allows it through ChainedRouterInterface.
*
* If $name is a route name, the "location" key in $parameters must be set to a valid eZ\Publish\API\Repository\Values\Content\Location object.
* "locationId" can also be provided.
*
* If the generator is not able to generate the url, it must throw the RouteNotFoundException
* as documented below.
*
* @see UrlAliasRouter::supports()
*
* @param string|\eZ\Publish\API\Repository\Values\Content\Location $name The name of the route or a Location instance
* @param mixed $parameters An array of parameters
* @param int $referenceType The type of reference to be generated (one of the constants)
*
* @throws \LogicException
* @throws \Symfony\Component\Routing\Exception\RouteNotFoundException
* @throws \InvalidArgumentException
*
* @return string The generated URL
*
* @api
*/
public function generate($name, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
// Direct access to Location
if ($name instanceof Location) {
return $this->generator->generate($name, $parameters, $referenceType);
}
// Normal route name
if ($name === self::URL_ALIAS_ROUTE_NAME) {
if (isset($parameters['location']) || isset($parameters['locationId'])) {
// Check if location is a valid Location object
if (isset($parameters['location']) && !$parameters['location'] instanceof Location) {
throw new LogicException("When generating an UrlAlias route, 'location' parameter must be a valid eZ\\Publish\\API\\Repository\\Values\\Content\\Location.");
}
$location = isset($parameters['location']) ? $parameters['location'] : $this->locationService->loadLocation($parameters['locationId']);
unset($parameters['location'], $parameters['locationId'], $parameters['viewType'], $parameters['layout']);
return $this->generator->generate($location, $parameters, $referenceType);
}
if (isset($parameters['contentId'])) {
$contentInfo = $this->contentService->loadContentInfo($parameters['contentId']);
unset($parameters['contentId'], $parameters['viewType'], $parameters['layout']);
if (empty($contentInfo->mainLocationId)) {
throw new LogicException('Cannot generate an UrlAlias route for content without main location.');
}
return $this->generator->generate($this->locationService->loadLocation($contentInfo->mainLocationId), $parameters, $referenceType);
}
throw new InvalidArgumentException("When generating an UrlAlias route, either 'location', 'locationId' or 'contentId' must be provided.");
}
throw new RouteNotFoundException('Could not match route');
}
开发者ID:kuborgh,项目名称:ezpublish-kernel,代码行数:54,代码来源:UrlAliasRouter.php
示例20: visit
/**
* Visit struct returned by controllers.
*
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
* @param \eZ\Publish\Core\REST\Server\Values\RestExecutedView $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startObjectElement('View');
$visitor->setHeader('Content-Type', $generator->getMediaType('View'));
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_views_load', array('viewId' => $data->identifier)));
$generator->endAttribute('href');
$generator->startValueElement('identifier', $data->identifier);
$generator->endValueElement('identifier');
// BEGIN Query
$generator->startObjectElement('Query');
$generator->endObjectElement('Query');
// END Query
// BEGIN Result
$generator->startObjectElement('Result', 'ViewResult');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_views_load_results', array('viewId' => $data->identifier)));
$generator->endAttribute('href');
// BEGIN Result metadata
$generator->startValueElement('count', $data->searchResults->totalCount);
$generator->endValueElement('count');
$generator->startValueElement('time', $data->searchResults->time);
$generator->endValueElement('time');
$generator->startValueElement('timedOut', $generator->serializeBool($data->searchResults->timedOut));
$generator->endValueElement('timedOut');
$generator->startValueElement('maxScore', $data->searchResults->maxScore);
$generator->endValueElement('maxScore');
// END Result metadata
// BEGIN searchHits
$generator->startHashElement('searchHits');
$generator->startList('searchHit');
foreach ($data->searchResults->searchHits as $searchHit) {
$generator->startObjectElement('searchHit');
$generator->startAttribute('score', 0);
$generator->endAttribute('score');
$generator->startAttribute('index', 0);
$generator->endAttribute('index');
$generator->startObjectElement('value');
// @todo Refactor
if ($searchHit->valueObject instanceof ApiValues\Content) {
/** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */
$contentInfo = $searchHit->valueObject->contentInfo;
$valueObject = new RestContentValue($contentInfo, $this->locationService->loadLocation($contentInfo->mainLocationId), $searchHit->valueObject, $this->contentTypeService->loadContentType($contentInfo->contentTypeId), $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo()));
} elseif ($searchHit->valueObject instanceof ApiValues\Location) {
$valueObject = $searchHit->valueObject;
} elseif ($searchHit->valueObject instanceof ApiValues\ContentInfo) {
$valueObject = new RestContentValue($searchHit->valueObject);
} else {
throw new Exceptions\InvalidArgumentException('Unhandled object type');
}
$visitor->visitValueObject($valueObject);
$generator->endObjectElement('value');
$generator->endObjectElement('searchHit');
}
$generator->endList('searchHit');
$generator->endHashElement('searchHits');
// END searchHits
$generator->endObjectElement('Result');
// END Result
$generator->endObjectElement('View');
}
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:66,代码来源:RestExecutedView.php
注:本文中的eZ\Publish\API\Repository\LocationService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论