visit() public méthode

Visit struct returned by controllers.
public visit ( mixed $data ) : Response
$data mixed
Résultat Symfony\Component\HttpFoundation\Response
 /**
  * Display the controller result
  *
  * @param RMF\Request $request
  * @param mixed $result
  */
 public function display(RMF\Request $request, $result)
 {
     if ($result === null) {
         $message = new Common\Message(array('Status' => '200 No content'));
     } else {
         $message = $this->visitor->visit($result);
     }
     foreach ($message->headers as $name => $value) {
         if ($name === 'Status') {
             // Special handling for PHP running as an Apache module
             header($_SERVER['SERVER_PROTOCOL'] . ' ' . $value);
         }
         header("{$name}: {$value}");
     }
     echo $message->body;
 }
 /**
  * Assigns a role to the given user.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role
  * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid
  *
  * @todo add limitations
  *
  * @param \eZ\Publish\API\Repository\Values\User\Role $role
  * @param \eZ\Publish\API\Repository\Values\User\User $user
  * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation)
  */
 public function assignRoleToUser(APIRole $role, User $user, RoleLimitation $roleLimitation = null)
 {
     $roleAssignment = new RoleAssignment(array('role' => $role, 'limitation' => $roleLimitation));
     $inputMessage = $this->outputVisitor->visit($roleAssignment);
     $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('RoleAssignmentList');
     $result = $this->client->request('POST', $this->requestParser->generate('userRoleAssignments', array('user' => $user->id)), $inputMessage);
     $this->inputDispatcher->parse($result);
 }
 /**
  * Updates $location in the content repository
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
  */
 public function updateLocation(Location $location, LocationUpdateStruct $locationUpdateStruct)
 {
     $inputMessage = $this->outputVisitor->visit($locationUpdateStruct);
     $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Location');
     $inputMessage->headers['X-HTTP-Method-Override'] = 'PATCH';
     $result = $this->client->request('POST', $location->id, $inputMessage);
     return $this->inputDispatcher->parse($result);
 }
 public function testVisitValueObject()
 {
     $data = new stdClass();
     /** @var \PHPUnit_Framework_MockObject_MockObject|Common\Output\Generator $generatorMock */
     $generatorMock = $this->getMock('\\eZ\\Publish\\Core\\REST\\Common\\Output\\Generator');
     $valueObjectDispatcherMock = $this->getValueObjectDispatcherMock();
     $valueObjectDispatcherMock->expects($this->once())->method('visit')->with($data);
     $visitor = new Common\Output\Visitor($generatorMock, $valueObjectDispatcherMock);
     $visitor->visit($data);
 }
 /**
  * Assigns the content to the given section
  * this method overrides the current assigned section.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If user does not have access to view provided object
  *
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
  * @param \eZ\Publish\API\Repository\Values\Content\Section $section
  *
  * @todo In order to make the integration test for this method running, the
  *       countAssignedContents() method must be implemented. Otherwise this
  *       should work fine.
  */
 public function assignSection(ContentInfo $contentInfo, Section $section)
 {
     $inputMessage = $this->outputVisitor->visit(new RestContentMetadataUpdateStruct(array('sectionId' => $section->id)));
     $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Content');
     $inputMessage->headers['X-HTTP-Method-Override'] = 'PATCH';
     $this->client->request('POST', $contentInfo->id, $inputMessage);
     // Will throw exception on error, no return value for method
     // @todo: Deactivated due to missing implementation of visitor for
     // content on the server side.
     // Should be: $result = $this->inputDispatcher->parse( $response );
 }
 /**
  * Sets the object-state of a state group to $state for the given content.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the object state does not belong to the given group
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to change the object state
  *
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
  * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup
  * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState
  */
 public function setContentState(ContentInfo $contentInfo, ObjectStateGroup $objectStateGroup, ObjectState $objectState)
 {
     $inputMessage = $this->outputVisitor->visit(new ContentObjectStates(array($objectState)));
     $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('ContentObjectStates');
     $inputMessage->headers['X-HTTP-Method-Override'] = 'PATCH';
     // Should originally be PATCH, but PHP's shiny new internal web server
     // dies with it.
     $values = $this->requestParser->parse('object', $contentInfo->id);
     $result = $this->client->request('POST', $this->requestParser->generate('objectObjectStates', array('object' => $values['object'])), $inputMessage);
     $this->inputDispatcher->parse($result);
 }
 /**
  * Create a Content Type object.
  *
  * The content type is created in the state STATUS_DRAFT.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException In case when
  *         - array of content type groups does not contain at least one content type group
  *         - identifier or remoteId in the content type create struct already exists
  *         - there is a duplicate field identifier in the content type create struct
  *         - content type create struct does not contain at least one field definition create struct
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException
  *         if a field definition in the $contentTypeCreateStruct is not valid
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeCreateStruct $contentTypeCreateStruct
  * @param array $contentTypeGroups Required array of {@link ContentTypeGroup} to link type with (must contain one)
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft
  */
 public function createContentType(APIContentTypeCreateStruct $contentTypeCreateStruct, array $contentTypeGroups)
 {
     $inputMessage = $this->outputVisitor->visit($contentTypeCreateStruct);
     $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('ContentType');
     if (empty($contentTypeGroups)) {
         throw new InvalidArgumentException("Argument '\$contentTypeGroups' is invalid: Argument must contain at least one ContentTypeGroup");
     }
     /** @var $firstGroup \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup */
     /** @var $contentTypeGroups \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] */
     $firstGroup = array_pop($contentTypeGroups);
     $response = $this->client->request('POST', $this->requestParser->generate("grouptypes", $this->requestParser->parse("typegroup", $firstGroup->id)), $inputMessage);
     try {
         $contentType = $this->inputDispatcher->parse($response);
     } catch (ForbiddenException $e) {
         throw new InvalidArgumentException($e->getMessage(), $e->getCode());
     }
     foreach ($contentTypeGroups as $contentTypeGroup) {
         $this->assignContentTypeGroup($contentType, $contentTypeGroup);
     }
     return $this->completeContentType($contentType);
 }