/** * 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; }
/** * 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); }
/** * 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); }