示例#1
0
 /**
  * Return a exception response.
  *
  * @return \Parest\Rest\Service\Http\Response
  */
 public function response()
 {
     $response = new Response();
     $response->setStatusCode($this->statusCode, $this->statusMessage);
     empty($this->code) and $this->code = $this->statusCode;
     empty($this->message) and $this->message = $this->statusMessage;
     $response->setContent(['code' => $this->code, 'message' => $this->message, 'description' => $this->description]);
     return $response;
 }
示例#2
0
 /**
  * Response Http OPTIONS method. Set the resource response to the client can use Http methods.
  *
  * @param string $childResourceName
  */
 public function options($childResourceName = '')
 {
     $options = [];
     $childResourceName = str_replace('-', '', ucwords($childResourceName));
     foreach (['get', 'post', 'put', 'patch', 'delete', 'head'] as $httpMethod) {
         $methodName = $childResourceName ? $httpMethod . $childResourceName : $httpMethod;
         if (is_callable(array($this, $methodName))) {
             $method = new ReflectionMethod($this, $methodName);
             $method->isPublic() and $options[] = strtoupper($httpMethod);
         }
     }
     $this->response->setContent($options);
 }
示例#3
0
 /**
  * Request the client sends authorization information.
  *
  * Call this method when a restful api client is not authorized.
  *
  * @todo
  * @param \Parest\Rest\Service\Http\Response $response
  * @param array                 $parameters
  */
 public function ask($response, $parameters = [])
 {
     $parameters = array_merge(['realm' => $this->_realm], $parameters);
     $response->setHeaderAppendParameters('WWW-Authenticate', $this->_authorizationType, $parameters);
 }