本文整理汇总了PHP中eZ\Publish\Core\REST\Common\Output\Visitor::setStatus方法的典型用法代码示例。如果您正苦于以下问题:PHP Visitor::setStatus方法的具体用法?PHP Visitor::setStatus怎么用?PHP Visitor::setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\Core\REST\Common\Output\Visitor
的用法示例。
在下文中一共展示了Visitor::setStatus方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 \Exception $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');
if ($data instanceof Translatable && $this->translator) {
/** @Ignore */
$errorDescription = $this->translator->trans($data->getMessageTemplate(), $data->getParameters(), 'repository_exceptions');
} else {
$errorDescription = $data->getMessage();
}
$generator->startValueElement('errorDescription', $errorDescription);
$generator->endValueElement('errorDescription');
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');
}
if ($previous = $data->getPrevious()) {
$generator->startObjectElement('Previous', 'ErrorMessage');
$visitor->visitValueObject($previous);
$generator->endObjectElement('Previous');
}
$generator->endObjectElement('ErrorMessage');
}
示例2: visit
/**
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
* @param mixed $data
* @return mixed
* @throws \EzSystems\RecommendationBundle\Rest\Exception\ResponseClassNotImplementedException
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$visitor->setHeader('Content-Type', $generator->getMediaType('ContentList'));
if (empty($data->contents)) {
$visitor->setStatus(204);
return;
}
if (!isset($this->responseRenderers[$data->options['responseType']])) {
throw new ResponseClassNotImplementedException(sprintf('Renderer for %s response not implemented.', $data->options['responseType']));
}
return $this->responseRenderers[$data->options['responseType']]->render($generator, $data);
}
示例3: 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');
}
示例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\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');
}
示例5: 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 \Exception $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');
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');
}
示例6: 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\UserSession $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$status = $data->created ? 201 : 200;
$visitor->setStatus($status);
$visitor->setHeader('Content-Type', $generator->getMediaType('Session'));
$sessionHref = $this->router->generate('ezpublish_rest_deleteSession', array('sessionId' => $data->sessionId));
//@todo Needs refactoring, disabling certain headers should not be done this way
$visitor->setHeader('Accept-Patch', false);
$generator->startObjectElement('Session');
$generator->startAttribute('href', $sessionHref);
$generator->endAttribute('href');
$generator->startValueElement('name', $data->sessionName);
$generator->endValueElement('name');
$generator->startValueElement('identifier', $data->sessionId);
$generator->endValueElement('identifier');
$generator->startValueElement('csrfToken', $data->csrfToken);
$generator->endValueElement('csrfToken');
$generator->startObjectElement('User', 'User');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadUser', array('userId' => $data->user->id)));
$generator->endAttribute('href');
$generator->endObjectElement('User');
$generator->endObjectElement('Session');
}
示例7: visit
public function visit(Visitor $visitor, Generator $generator, $data)
{
$visitor->setStatus(303);
$visitor->setHeader('Location', $data->redirectUri);
}
示例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\NoContent $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$visitor->setStatus(204);
}
示例9: visit
public function visit(Visitor $visitor, Generator $generator, $data)
{
$visitor->setHeader('Allow', implode(',', $data->allowedMethods));
$visitor->setHeader('Content-Length', 0);
$visitor->setStatus(200);
}