Пример #1
0
 public function testLocationToStringReturnsHeaderFormattedString()
 {
     $this->markTestIncomplete('Location needs to be completed');
     $locationHeader = new Location();
     // @todo set some values, then test output
     $this->assertEmpty('Location: xxx', $locationHeader->toString());
 }
Пример #2
0
 public function testLocationCanSetAndAccessRelativeUri()
 {
     $locationHeader = Location::fromString('Location: /path/to');
     $uri = $locationHeader->uri();
     $this->assertInstanceOf('Zend\\Uri\\Http', $uri);
     $this->assertFalse($uri->isAbsolute());
     $this->assertEquals('/path/to', $locationHeader->getUri());
 }
 protected function addLocationHeader(MvcEvent $event)
 {
     $options = $event->getTarget()->getOptions();
     if ($property = $options->getProperty()) {
         $result = $event->getResult();
         $createdDocument = $result->getModel();
         $result->addHeader(Location::fromString('Location: ' . $event->getRequest()->getUri()->getPath() . '/' . $options->getModelManager()->getClassMetadata(get_class($createdDocument))->getFieldValue($createdDocument, $property)));
     }
     return $event->getResult();
 }
 /**
  * Checks the provided username and password against the AuthenticationService and
  * returns the active user
  *
  * @param  type                           $data
  * @return type
  * @throws Exception\LoginFailedException
  */
 public function create($data)
 {
     $authService = $this->options->getAuthenticationService();
     if ($authService->hasIdentity()) {
         $authService->logout();
     }
     $result = $authService->login($data[$this->options->getDataUsernameKey()], $data[$this->options->getDataPasswordKey()], isset($data[$this->options->getDataRememberMeKey()]) ? $data[$this->options->getDataRememberMeKey()] : false);
     if (!$result->isValid()) {
         throw new Exception\LoginFailedException(implode('. ', $result->getMessages()));
     }
     $this->response->getHeaders()->addHeader(Location::fromString('Location: ' . $this->request->getUri()->getPath()));
     return $this->model->setVariables($this->options->getSerializer()->toArray($result->getIdentity()));
 }
 public function patch($id, $data)
 {
     $documentManager = $this->options->getDocumentManager();
     $parts = explode('/', $id);
     $document = $parts[0];
     array_shift($parts);
     $deeperResource = $parts;
     $metadata = $documentManager->getClassMetadata($this->options->getDocumentClass());
     $patchedDocument = $this->doPatch($data, $document, $metadata, $deeperResource);
     if ($this->getEvent()->getRouteMatch()->getParam('surpressResponse')) {
         return $patchedDocument;
     }
     $this->flush();
     $patchedMetadata = $documentManager->getClassMetadata(get_class($patchedDocument));
     $newId = $patchedMetadata->reflFields[$patchedMetadata->identifier]->getValue($patchedDocument);
     if ($newId != $id) {
         $parts = explode('/', $this->request->getUri()->getPath());
         array_pop($parts);
         $location = implode('/', $parts) . '/' . $newId;
         $this->response->getHeaders()->addHeader(Location::fromString('Location: ' . $location));
     }
     $this->response->setStatusCode(204);
     return $this->response;
 }
 protected function getLocationHeader($event, $metadata, $document)
 {
     if ($property = $event->getTarget()->getOptions()->getProperty()) {
         $pieces = explode('/', $event->getRequest()->getUri()->getPath());
         array_pop($pieces);
         return Location::fromString('Location: ' . implode('/', $pieces) . '/' . $metadata->getFieldValue($document, $property));
     }
 }