本文整理汇总了PHP中Kohana_Exception::response方法的典型用法代码示例。如果您正苦于以下问题:PHP Kohana_Exception::response方法的具体用法?PHP Kohana_Exception::response怎么用?PHP Kohana_Exception::response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kohana_Exception
的用法示例。
在下文中一共展示了Kohana_Exception::response方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_response
/**
* Generate a Response for the current Exception
*
* @uses Kohana_Exception::response()
* @return Response
*/
public function get_response()
{
$this->check();
// Use Kohana_Exception to get a response with a response body
$response = Kohana_Exception::response($this);
// Copy headers from $this->_response
$response->headers((array) $this->_response->headers());
// Add CORS Headers
$this->add_cors_headers($response);
return $response;
}
示例2: get_response
/**
* Generate a Response for the current Exception
*
* @uses Kohana_Exception::response()
* @return Response
*/
public function get_response()
{
if (!IN_PRODUCTION) {
return Kohana_Exception::response($this);
}
$code = $this->getCode();
try {
$view = View::factory('error/error');
$view->code = $code;
$response = Response::factory()->status($code)->body($view->render());
} catch (Exception $e) {
$response = Kohana_Exception::response($this);
}
return $response;
}
示例3: handler
public static function handler($e)
{
try {
Kohana_Exception::log($e);
if (PHP_SAPI == 'cli') {
$response = Kohana_Exception::text($e);
} else {
$response = Kohana_Exception::response($e);
}
echo $response;
exit(1);
} catch (Exception $e) {
ob_get_level() and ob_clean();
header('Content-Type: text/plain; charset=utf-8', TRUE, 500);
echo Kohana_Exception::text($e);
exit(1);
}
}
示例4: _handler
/**
* Exception handler, logs the exception and generates a Response object
* for display.
*
* @uses Kohana_Exception::response
*
* @param Exception $e
*
* @return Response
*/
public static function _handler(Exception $e)
{
try {
// Log the exception
Kohana_Exception::log($e);
// Generate the response
$response = Kohana_Exception::response($e);
return $response;
} catch (Exception $e) {
/**
* Things are going *really* badly for us, We now have no choice
* but to bail. Hard.
*/
// Clean the output buffer if one exists
ob_get_level() and ob_clean();
// Set the Status code to 500, and Content-Type to text/plain.
header('Content-Type: text/plain; charset=' . Kohana::$charset, true, 500);
echo Kohana_Exception::text($e);
exit(1);
}
}
示例5: get_response
/**
* Generate a Response for the current Exception
*
* @uses Kohana_Exception::response()
* @return Response
*/
public function get_response()
{
return Kohana_Exception::response($this);
}
示例6: _response
private function _response()
{
if (!isset(Response::$messages[$this->_response_httpCode])) {
$this->_response_httpCode = 400;
}
if ($this->responseAsJSON) {
if (!$this->isError()) {
// SUCCESS
$jsonData = $this->_response_data;
if (NULL !== $this->responseLocation) {
//$this->response->headers('Location', $this->responseLocation);
}
} else {
// ERROR
if ($this->_response_data instanceof Exception) {
$exception = $this->_response_data;
$message = $exception->getMessage();
if (!$exception instanceof RestfulAPI_Exception) {
$this->_response_httpCode = $exception->getCode();
}
} else {
$message = $this->_response_data;
}
if (!is_string($message)) {
$message = isset($exception) ? get_class($exception) : 'Undefined error';
}
$jsonData = $this->getErrorResponse($message, $this->_response_operationCode);
if (isset($this->_response_errors)) {
$errors = [];
foreach ((array) $this->_response_errors as $field => $error) {
$errors[] = ['key' => $field, 'description' => $error];
}
$jsonData['parameters'] = $errors;
}
}
$this->response->headers('cache-control', 'no-cache, no-store, max-age=0, must-revalidate');
$this->response->headers('content-type', 'application/json; charset=utf-8');
try {
$this->response->status($this->_response_httpCode);
} catch (Exception $e) {
$this->response->status(500);
$this->_response_operationCode = $this->_response_httpCode;
}
if (isset($exception)) {
$_traceType = RestfulAPI::config('onerror.debug.exception', 'string');
if ($_traceType) {
$this->setDebugData(['exception' => ['source' => self::exceptionString($exception), 'trace' => $_traceType !== 'array' ? $exception->getTraceAsString() : $exception->getTrace()]]);
}
}
try {
$this->setResponseBody($jsonData);
} catch (Exception $e) {
$exception = !isset($exception) ? $e : new Exception($e->getMessage(), $e->getCode(), $exception);
$this->response->status(500);
$this->setResponseBody(['message' => strtr('Error while formatting response:message', [':message' => !Helpers_Core::isProduction() ? ': ' . $e->getMessage() : '']), 'code' => 0]);
}
// LOGGING EXCEPTION
if (isset($exception)) {
$_logCodes = RestfulAPI::config('onerror.log.http_codes', []);
if (TRUE === $_logCodes || Helpers_Arr::inArray($this->response->status(), $_logCodes)) {
Kohana::$log->add($this->response->status() == 500 ? Log::ERROR : Log::INFO, self::exceptionString($exception), NULL, ['exception' => $exception]);
}
}
$this->response->send_headers(TRUE);
exit($this->response);
} else {
if ($this->isError()) {
if ($this->_response_data instanceof Exception) {
Kohana_Exception::response($this->_response_data);
}
throw HTTP_Exception::factory($this->_response_httpCode, '[ :errno ] :error', [':errno' => $this->_response_operationCode, ':error' => $this->_response_data]);
} else {
$this->response->body($this->_response_data);
}
}
}