eZ\Publish\Core\REST\Common\Output\Visitor::setHeader PHP Method

setHeader() public method

Does not allow overwriting of response headers. The first definition of a header will be used.
public setHeader ( string $name, string $value )
$name string
$value string
    public function setHeader($name, $value)
    {
        if (!$this->response->headers->has($name)) {
            $this->response->headers->set($name, $value);
        }
    }

Usage Example

 /**
  * 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\ContentTypeGroup $data
  */
 public function visit(Visitor $visitor, Generator $generator, $data)
 {
     $generator->startObjectElement('ContentTypeGroup');
     $visitor->setHeader('Content-Type', $generator->getMediaType('ContentTypeGroup'));
     $visitor->setHeader('Accept-Patch', $generator->getMediaType('ContentTypeGroupInput'));
     $generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadContentTypeGroup', array('contentTypeGroupId' => $data->id)));
     $generator->endAttribute('href');
     $generator->startValueElement('id', $data->id);
     $generator->endValueElement('id');
     $generator->startValueElement('identifier', $data->identifier);
     $generator->endValueElement('identifier');
     $generator->startValueElement('created', $data->creationDate->format('c'));
     $generator->endValueElement('created');
     $generator->startValueElement('modified', $data->modificationDate->format('c'));
     $generator->endValueElement('modified');
     $generator->startObjectElement('Creator', 'User');
     $generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadUser', array('userId' => $data->creatorId)));
     $generator->endAttribute('href');
     $generator->endObjectElement('Creator');
     $generator->startObjectElement('Modifier', 'User');
     $generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadUser', array('userId' => $data->modifierId)));
     $generator->endAttribute('href');
     $generator->endObjectElement('Modifier');
     $generator->startObjectElement('ContentTypes', 'ContentTypeInfoList');
     $generator->startAttribute('href', $this->router->generate('ezpublish_rest_listContentTypesForGroup', array('contentTypeGroupId' => $data->id)));
     $generator->endAttribute('href');
     $generator->endObjectElement('ContentTypes');
     $generator->endObjectElement('ContentTypeGroup');
 }
All Usage Examples Of eZ\Publish\Core\REST\Common\Output\Visitor::setHeader