本文整理汇总了PHP中eZ\Publish\Core\REST\Common\Output\Generator::endHashElement方法的典型用法代码示例。如果您正苦于以下问题:PHP Generator::endHashElement方法的具体用法?PHP Generator::endHashElement怎么用?PHP Generator::endHashElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\Core\REST\Common\Output\Generator
的用法示例。
在下文中一共展示了Generator::endHashElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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 mixed $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startObjectElement('ObjectStateCreate');
$visitor->setHeader('Content-Type', $generator->getMediaType('ObjectStateCreate'));
$generator->startValueElement('identifier', $data->identifier);
$generator->endValueElement('identifier');
$generator->startValueElement('priority', $data->priority);
$generator->endValueElement('priority');
$generator->startValueElement('defaultLanguageCode', $data->defaultLanguageCode);
$generator->endValueElement('defaultLanguageCode');
$generator->startHashElement('names');
$generator->startList('value');
foreach ($data->names as $languageCode => $name) {
$generator->startValueElement('value', $name, array('languageCode' => $languageCode));
$generator->endValueElement('value');
}
$generator->endList('value');
$generator->endHashElement('names');
$generator->startHashElement('descriptions');
foreach ($data->descriptions as $languageCode => $description) {
$generator->startValueElement('value', $description, array('languageCode' => $languageCode));
$generator->endValueElement('value');
}
$generator->endHashElement('descriptions');
$generator->endObjectElement('ObjectStateCreate');
}
示例2: 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\Exceptions\ContentFieldValidationException $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startObjectElement('ErrorMessage');
$statusCode = $this->getStatus();
$visitor->setStatus($statusCode);
$visitor->setHeader('Content-Type', $generator->getMediaType('ErrorMessage'));
$generator->startValueElement('errorCode', $statusCode);
$generator->endValueElement('errorCode');
$generator->startValueElement('errorMessage', $this->httpStatusCodes[$statusCode]);
$generator->endValueElement('errorMessage');
$generator->startValueElement('errorDescription', $data->getMessage());
$generator->endValueElement('errorDescription');
$generator->startHashElement('errorDetails');
$generator->startList('fields');
foreach ($data->getFieldErrors() as $fieldTypeId => $translations) {
foreach ($translations as $languageCode => $validationErrors) {
if (!is_array($validationErrors)) {
$validationErrors = [$validationErrors];
}
foreach ($validationErrors as $validationError) {
$generator->startHashElement('field');
$generator->startAttribute('fieldTypeId', $fieldTypeId);
$generator->endAttribute('fieldTypeId');
$generator->startList('errors');
$generator->startHashElement('error');
$generator->startValueElement('type', $validationError->getTarget());
$generator->endValueElement('type');
$translation = $validationError->getTranslatableMessage();
$generator->startValueElement('message', $this->translator->trans($this->translationToString($translation), $translation->values, 'repository_exceptions'));
$generator->endValueElement('message');
$generator->endHashElement('error');
$generator->endList('errors');
$generator->endHashElement('field');
}
}
}
$generator->endList('fields');
$generator->endHashElement('errorDetails');
if ($this->debug) {
$generator->startValueElement('trace', $data->getTraceAsString());
$generator->endValueElement('trace');
$generator->startValueElement('file', $data->getFile());
$generator->endValueElement('file');
$generator->startValueElement('line', $data->getLine());
$generator->endValueElement('line');
}
$generator->endObjectElement('ErrorMessage');
}
示例3: 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\UserGroupRefList $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startObjectElement('UserGroupRefList');
$visitor->setHeader('Content-Type', $generator->getMediaType('UserGroupRefList'));
//@todo Needs refactoring, disabling certain headers should not be done this way
$visitor->setHeader('Accept-Patch', false);
$generator->startAttribute('href', $data->path);
$generator->endAttribute('href');
$groupCount = count($data->userGroups);
$generator->startList('UserGroup');
foreach ($data->userGroups as $userGroup) {
$generator->startObjectElement('UserGroup');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadUserGroup', array('groupPath' => trim($userGroup->mainLocation->pathString, '/'))));
$generator->endAttribute('href');
if ($data->userId !== null && $groupCount > 1) {
$generator->startHashElement('unassign');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_unassignUserFromUserGroup', array('userId' => $data->userId, 'groupPath' => $userGroup->mainLocation->path[count($userGroup->mainLocation->path) - 1])));
$generator->endAttribute('href');
$generator->startAttribute('method', 'DELETE');
$generator->endAttribute('method');
$generator->endHashElement('unassign');
}
$generator->endObjectElement('UserGroup');
}
$generator->endList('UserGroup');
$generator->endObjectElement('UserGroupRefList');
}
示例4: 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\ContentTypeGroupRefList $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startObjectElement('ContentTypeGroupRefList');
$visitor->setHeader('Content-Type', $generator->getMediaType('ContentTypeGroupRefList'));
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_listContentTypesForGroup', array('contentTypeGroupId' => $data->contentType->id)));
$generator->endAttribute('href');
$groupCount = count($data->contentTypeGroups);
$generator->startList('ContentTypeGroupRef');
foreach ($data->contentTypeGroups as $contentTypeGroup) {
$generator->startObjectElement('ContentTypeGroupRef', 'ContentTypeGroup');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadContentTypeGroup', array('contentTypeGroupId' => $contentTypeGroup->id)));
$generator->endAttribute('href');
// Unlinking last group is not allowed
if ($groupCount > 1) {
$generator->startHashElement('unlink');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_unlinkContentTypeFromGroup', array('contentTypeId' => $data->contentType->id, 'contentTypeGroupId' => $contentTypeGroup->id)));
$generator->endAttribute('href');
$generator->startAttribute('method', 'DELETE');
$generator->endAttribute('method');
$generator->endHashElement('unlink');
}
$generator->endObjectElement('ContentTypeGroupRef');
}
$generator->endList('ContentTypeGroupRef');
$generator->endObjectElement('ContentTypeGroupRefList');
}
示例5: visit
public function visit(Visitor $visitor, Generator $generator, $data)
{
if ($data instanceof LocationQueryValue) {
$rootObjectElement = 'LocationQuery';
} else {
if ($data instanceof ContentQueryValue) {
$rootObjectElement = 'ContentQuery';
} else {
throw new Exceptions\InvalidArgumentException("ViewInput Query", "No content nor location query found in ViewInput");
}
}
$generator->startObjectElement($rootObjectElement, 'Query');
if (isset($data->filter)) {
$generator->startHashElement('Filter');
$visitor->visitValueObject($data->filter);
$generator->endHashElement('Filter');
}
if (isset($data->query)) {
$generator->startHashElement('Query');
$visitor->visitValueObject($data->query);
$generator->endhashElement('Query');
}
// $generator->startObjectElement('SortClauses');
// foreach ($data->sortClauses as $sortClause) {
// $visitor->visitValueObject($sortClause);
// }
// $generator->endObjectElement('SortClauses');
$generator->endObjectElement($rootObjectElement);
}
示例6: visit
/**
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
* @param mixed $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$visitor->setHeader('Content-Type', $generator->getMediaType('ContentList'));
if (empty($data->contents)) {
$visitor->setStatus(204);
return;
}
$generator->startObjectElement('contentList');
$generator->startList('content');
foreach ($data->contents as $content) {
$generator->startObjectElement('content');
$generator->startValueElement('contentId', $content['contentId']);
$generator->endValueElement('contentId');
$generator->startValueElement('contentTypeId', $content['contentTypeId']);
$generator->endValueElement('contentTypeId');
$generator->startValueElement('identifier', $content['identifier']);
$generator->endValueElement('identifier');
$generator->startValueElement('language', $content['language']);
$generator->endValueElement('language');
$generator->startValueElement('publishedDate', $content['publishedDate']);
$generator->endValueElement('publishedDate');
$generator->startValueElement('author', $content['author']);
$generator->endValueElement('author');
$generator->startValueElement('uri', $content['uri']);
$generator->endValueElement('uri');
$generator->startValueElement('categoryPath', $content['categoryPath']);
$generator->endValueElement('categoryPath');
$generator->startObjectElement('mainLocation');
$generator->startAttribute('href', $content['mainLocation']['href']);
$generator->endAttribute('href');
$generator->endObjectElement('mainLocation');
$generator->startObjectElement('locations');
$generator->startAttribute('href', $content['locations']['href']);
$generator->endAttribute('href');
$generator->endObjectElement('locations');
$generator->startList('fields');
foreach ($content['fields'] as $field) {
$generator->startHashElement('fields');
$generator->startValueElement('key', $field['key']);
$generator->endValueElement('key');
$generator->startValueElement('value', $field['value']);
$generator->endValueElement('value');
$generator->endHashElement('fields');
}
$generator->endList('fields');
$generator->endObjectElement('content');
}
$generator->endList('content');
$generator->endObjectElement('contentList');
}
示例7: generateElement
/**
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
* @param array $contentList
*
* @return Generator
*/
public function generateElement(Generator $generator, array $contentList = [])
{
$generator->startObjectElement('contentList');
$generator->startList('content');
foreach ($contentList as $content) {
$generator->startObjectElement('content');
$generator->startValueElement('contentId', $content['contentId']);
$generator->endValueElement('contentId');
$generator->startValueElement('contentTypeId', $content['contentTypeId']);
$generator->endValueElement('contentTypeId');
$generator->startValueElement('identifier', $content['identifier']);
$generator->endValueElement('identifier');
$generator->startValueElement('language', $content['language']);
$generator->endValueElement('language');
$generator->startValueElement('publishedDate', $content['publishedDate']);
$generator->endValueElement('publishedDate');
$generator->startValueElement('author', $content['author']);
$generator->endValueElement('author');
$generator->startValueElement('uri', $content['uri']);
$generator->endValueElement('uri');
$generator->startValueElement('categoryPath', $content['categoryPath']);
$generator->endValueElement('categoryPath');
$generator->startObjectElement('mainLocation');
$generator->startAttribute('href', $content['mainLocation']['href']);
$generator->endAttribute('href');
$generator->endObjectElement('mainLocation');
$generator->startObjectElement('locations');
$generator->startAttribute('href', $content['locations']['href']);
$generator->endAttribute('href');
$generator->endObjectElement('locations');
$generator->startList('fields');
foreach ($content['fields'] as $field) {
$generator->startHashElement('fields');
$generator->startValueElement('key', $field['key']);
$generator->endValueElement('key');
$generator->startValueElement('value', $field['value']);
$generator->endValueElement('value');
$generator->endHashElement('fields');
}
$generator->endList('fields');
$generator->endObjectElement('content');
}
$generator->endList('content');
$generator->endObjectElement('contentList');
return $generator;
}
示例8: 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\VersionList $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startObjectElement('VersionList');
$visitor->setHeader('Content-Type', $generator->getMediaType('VersionList'));
//@todo Needs refactoring, disabling certain headers should not be done this way
$visitor->setHeader('Accept-Patch', false);
$generator->startAttribute('href', $data->path);
$generator->endAttribute('href');
$generator->startList('VersionItem');
foreach ($data->versions as $version) {
$generator->startHashElement('VersionItem');
$generator->startObjectElement('Version');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadContentInVersion', array('contentId' => $version->getContentInfo()->id, 'versionNumber' => $version->versionNo)));
$generator->endAttribute('href');
$generator->endObjectElement('Version');
$visitor->visitValueObject($version);
$generator->endHashElement('VersionItem');
}
$generator->endList('VersionItem');
$generator->endObjectElement('VersionList');
}
示例9: 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\Common\Values\Root $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startObjectElement('Root');
$visitor->setHeader('Content-Type', $generator->getMediaType('Root'));
foreach ($data->getResources() as $resource) {
if ($resource->mediaType === '') {
$generator->startHashElement($resource->name);
$generator->startAttribute('media-type', $resource->mediaType);
$generator->endAttribute('media-type');
} else {
$generator->startObjectElement($resource->name, $resource->mediaType);
}
$generator->startAttribute('href', $resource->href);
$generator->endAttribute('href');
if ($resource->mediaType === '') {
$generator->endHashElement($resource->name);
} else {
$generator->endObjectElement($resource->name);
}
}
$generator->endObjectElement('Root');
}
示例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\ContentType\ContentTypeCreateStruct $contentTypeCreateStruct
*/
public function visit(Visitor $visitor, Generator $generator, $contentTypeCreateStruct)
{
$generator->startObjectElement("ContentTypeCreate");
$visitor->setHeader("Content-Type", $generator->getMediaType("ContentTypeCreate"));
$generator->startValueElement("identifier", $contentTypeCreateStruct->identifier);
$generator->endValueElement("identifier");
$generator->startValueElement("remoteId", $contentTypeCreateStruct->remoteId);
$generator->endValueElement("remoteId");
$generator->startValueElement("urlAliasSchema", $contentTypeCreateStruct->urlAliasSchema);
$generator->endValueElement("urlAliasSchema");
$generator->startValueElement("nameSchema", $contentTypeCreateStruct->nameSchema);
$generator->endValueElement("nameSchema");
$generator->startValueElement("isContainer", $contentTypeCreateStruct->isContainer ? "true" : "false");
$generator->endValueElement("isContainer");
$generator->startValueElement("mainLanguageCode", $contentTypeCreateStruct->mainLanguageCode);
$generator->endValueElement("mainLanguageCode");
$generator->startValueElement("defaultAlwaysAvailable", $contentTypeCreateStruct->defaultAlwaysAvailable ? "true" : "false");
$generator->endValueElement("defaultAlwaysAvailable");
$generator->startValueElement("defaultSortField", $this->serializeSortField($contentTypeCreateStruct->defaultSortField));
$generator->endValueElement("defaultSortField");
$generator->startValueElement("defaultSortOrder", $this->serializeSortOrder($contentTypeCreateStruct->defaultSortOrder));
$generator->endValueElement("defaultSortOrder");
if (!empty($contentTypeCreateStruct->names)) {
$generator->startHashElement("names");
$generator->startList('value');
foreach ($contentTypeCreateStruct->names as $languageCode => $name) {
$generator->startValueElement("value", $name, array("languageCode" => $languageCode));
$generator->endValueElement("value");
}
$generator->endList('value');
$generator->endHashElement("names");
}
if (!empty($contentTypeCreateStruct->descriptions)) {
$generator->startHashElement("descriptions");
$generator->startList('value');
foreach ($contentTypeCreateStruct->descriptions as $languageCode => $description) {
$generator->startValueElement("value", $description, array("languageCode" => $languageCode));
$generator->endValueElement("value");
}
$generator->endList('value');
$generator->endHashElement("descriptions");
}
if ($contentTypeCreateStruct->creationDate !== null) {
$generator->startValueElement("modificationDate", $contentTypeCreateStruct->creationDate->format("c"));
$generator->endValueElement("modificationDate");
}
if ($contentTypeCreateStruct->creatorId !== null) {
$generator->startObjectElement("User");
$generator->startAttribute("href", $contentTypeCreateStruct->creatorId);
$generator->endAttribute("href");
$generator->endObjectElement("User");
}
if (!empty($contentTypeCreateStruct->fieldDefinitions)) {
$generator->startHashElement("FieldDefinitions");
$generator->startList("FieldDefinition");
foreach ($contentTypeCreateStruct->fieldDefinitions as $fieldDefinitionCreateStruct) {
$visitor->visitValueObject($fieldDefinitionCreateStruct);
}
$generator->endList("FieldDefinition");
$generator->endHashElement("FieldDefinitions");
}
$generator->endObjectElement("ContentTypeCreate");
}
示例11: 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_getView', 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_loadViewResults', array('viewId' => $data->identifier)));
$generator->endAttribute('href');
// 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');
/** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */
$contentInfo = $searchHit->valueObject->contentInfo;
$restContent = new RestContentValue($contentInfo, $this->locationService->loadLocation($contentInfo->mainLocationId), $searchHit->valueObject, $this->contentTypeService->loadContentType($contentInfo->contentTypeId), $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo()));
$visitor->visitValueObject($restContent);
$generator->endObjectElement('value');
$generator->endObjectElement('searchHit');
}
$generator->endList('searchHit');
$generator->endHashElement('searchHits');
// END searchHits
$generator->endObjectElement('Result');
// END Result
$generator->endObjectElement('View');
}
示例12: visitLimitation
/**
* Visits a limitation
*
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
* @param \eZ\Publish\API\Repository\Values\User\Limitation $limitation
*/
protected function visitLimitation(Generator $generator, Limitation $limitation)
{
$generator->startHashElement('limitation');
$generator->startAttribute('identifier', $limitation->getIdentifier());
$generator->endAttribute('identifier');
$generator->startHashElement('values');
$generator->startList('ref');
foreach ($limitation->limitationValues as $limitationValue) {
$generator->startObjectElement('ref');
$generator->startAttribute('href', $limitationValue);
$generator->endAttribute('href');
$generator->endObjectElement('ref');
}
$generator->endList('ref');
$generator->endHashElement('values');
$generator->endHashElement('limitation');
}
示例13: 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\Common\Values\Root $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startObjectElement('Root');
$visitor->setHeader('Content-Type', $generator->getMediaType('Root'));
// Uses hashElement instead of objectElement as a workaround to be able to have
// an empty media-type, since there is no media type for list of content yet
$generator->startHashElement('content');
$generator->startAttribute('media-type', '');
$generator->endAttribute('media-type');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_createContent'));
$generator->endAttribute('href');
$generator->endHashElement('content');
// Uses hashElement instead of objectElement as a workaround to be able to have
// an empty media-type, since there is no media type for list of content yet
$generator->startHashElement('contentByRemoteId');
$generator->startAttribute('media-type', '');
$generator->endAttribute('media-type');
$generator->startAttribute('href', $this->templateRouter->generate('ezpublish_rest_redirectContent', array('remoteId' => '{remoteId}')));
$generator->endAttribute('href');
$generator->endHashElement('contentByRemoteId');
// Content types list
$generator->startObjectElement('contentTypes', 'ContentTypeInfoList');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_listContentTypes'));
$generator->endAttribute('href');
$generator->endObjectElement('contentTypes');
// Content type by identifier
// See comment above regarding usage of hash element
$generator->startHashElement('contentTypeByIdentifier');
$generator->startAttribute('media-type', '');
$generator->endAttribute('media-type');
$generator->startAttribute('href', $this->templateRouter->generate('ezpublish_rest_listContentTypes', array('identifier' => '{identifier}')));
$generator->endAttribute('href');
$generator->endHashElement('contentTypeByIdentifier');
// Creating a ContentTypeGroup
$generator->startObjectElement('contentTypeGroups', 'ContentTypeGroupList');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_createContentTypeGroup'));
$generator->endAttribute('href');
$generator->endObjectElement('contentTypeGroups');
// Content type group by identifier
// See comment above regarding usage of hash element
$generator->startHashElement('contentTypeGroupByIdentifier');
$generator->startAttribute('media-type', '');
$generator->endAttribute('media-type');
$generator->startAttribute('href', $this->templateRouter->generate('ezpublish_rest_loadContentTypeGroupList', array('identifier' => '{identifier}')));
$generator->endAttribute('href');
$generator->endHashElement('contentTypeGroupByIdentifier');
// Users
$generator->startObjectElement('users', 'UserRefList');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadUsers'));
$generator->endAttribute('href');
$generator->endObjectElement('users');
// Users by role id
$generator->startObjectElement('usersByRoleId', 'UserRefList');
$generator->startAttribute('href', $this->templateRouter->generate('ezpublish_rest_loadUsers', ['roleId' => '{roleId}']));
$generator->endAttribute('href');
$generator->endObjectElement('usersByRoleId');
// Users by remote id
$generator->startObjectElement('usersByRemoteId', 'UserRefList');
$generator->startAttribute('href', $this->templateRouter->generate('ezpublish_rest_loadUsers', ['remoteId' => '{remoteId}']));
$generator->endAttribute('href');
$generator->endObjectElement('usersByRemoteId');
// Users by email
$generator->startObjectElement('usersByEmail', 'UserRefList');
$generator->startAttribute('href', $this->templateRouter->generate('ezpublish_rest_loadUsers', ['email' => '{email}']));
$generator->endAttribute('href');
$generator->endObjectElement('usersByEmail');
// Users by login
$generator->startObjectElement('usersByLogin', 'UserRefList');
$generator->startAttribute('href', $this->templateRouter->generate('ezpublish_rest_loadUsers', ['login' => '{login}']));
$generator->endAttribute('href');
$generator->endObjectElement('usersByLogin');
// Roles
$generator->startObjectElement('roles', 'RoleList');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_listRoles'));
$generator->endAttribute('href');
$generator->endObjectElement('roles');
// Content root location
$generator->startObjectElement('rootLocation', 'Location');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => '1/2')));
$generator->endAttribute('href');
$generator->endObjectElement('rootLocation');
// Users root location
$generator->startObjectElement('rootUserGroup', 'UserGroup');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadUserGroup', array('groupPath' => '1/5')));
$generator->endAttribute('href');
$generator->endObjectElement('rootUserGroup');
// Media root location
$generator->startObjectElement('rootMediaFolder', 'Location');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => '1/43')));
$generator->endAttribute('href');
$generator->endObjectElement('rootMediaFolder');
// Location by remote ID
// See comment above regarding usage of hash element
//.........这里部分代码省略.........
示例14: 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\ContentType\ContentTypeCreateStruct $contentTypeCreateStruct
*/
public function visit(Visitor $visitor, Generator $generator, $contentTypeCreateStruct)
{
$generator->startObjectElement('ContentTypeCreate');
$visitor->setHeader('Content-Type', $generator->getMediaType('ContentTypeCreate'));
$generator->startValueElement('identifier', $contentTypeCreateStruct->identifier);
$generator->endValueElement('identifier');
$generator->startValueElement('remoteId', $contentTypeCreateStruct->remoteId);
$generator->endValueElement('remoteId');
$generator->startValueElement('urlAliasSchema', $contentTypeCreateStruct->urlAliasSchema);
$generator->endValueElement('urlAliasSchema');
$generator->startValueElement('nameSchema', $contentTypeCreateStruct->nameSchema);
$generator->endValueElement('nameSchema');
$generator->startValueElement('isContainer', $contentTypeCreateStruct->isContainer ? 'true' : 'false');
$generator->endValueElement('isContainer');
$generator->startValueElement('mainLanguageCode', $contentTypeCreateStruct->mainLanguageCode);
$generator->endValueElement('mainLanguageCode');
$generator->startValueElement('defaultAlwaysAvailable', $contentTypeCreateStruct->defaultAlwaysAvailable ? 'true' : 'false');
$generator->endValueElement('defaultAlwaysAvailable');
$generator->startValueElement('defaultSortField', $this->serializeSortField($contentTypeCreateStruct->defaultSortField));
$generator->endValueElement('defaultSortField');
$generator->startValueElement('defaultSortOrder', $this->serializeSortOrder($contentTypeCreateStruct->defaultSortOrder));
$generator->endValueElement('defaultSortOrder');
if (!empty($contentTypeCreateStruct->names)) {
$generator->startHashElement('names');
$generator->startList('value');
foreach ($contentTypeCreateStruct->names as $languageCode => $name) {
$generator->startValueElement('value', $name, array('languageCode' => $languageCode));
$generator->endValueElement('value');
}
$generator->endList('value');
$generator->endHashElement('names');
}
if (!empty($contentTypeCreateStruct->descriptions)) {
$generator->startHashElement('descriptions');
$generator->startList('value');
foreach ($contentTypeCreateStruct->descriptions as $languageCode => $description) {
$generator->startValueElement('value', $description, array('languageCode' => $languageCode));
$generator->endValueElement('value');
}
$generator->endList('value');
$generator->endHashElement('descriptions');
}
if ($contentTypeCreateStruct->creationDate !== null) {
$generator->startValueElement('modificationDate', $contentTypeCreateStruct->creationDate->format('c'));
$generator->endValueElement('modificationDate');
}
if ($contentTypeCreateStruct->creatorId !== null) {
$generator->startObjectElement('User');
$generator->startAttribute('href', $contentTypeCreateStruct->creatorId);
$generator->endAttribute('href');
$generator->endObjectElement('User');
}
if (!empty($contentTypeCreateStruct->fieldDefinitions)) {
$generator->startHashElement('FieldDefinitions');
$generator->startList('FieldDefinition');
foreach ($contentTypeCreateStruct->fieldDefinitions as $fieldDefinitionCreateStruct) {
$visitor->visitValueObject($fieldDefinitionCreateStruct);
}
$generator->endList('FieldDefinition');
$generator->endHashElement('FieldDefinitions');
}
$generator->endObjectElement('ContentTypeCreate');
}
示例15: 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');
}