本文整理汇总了PHP中Kohana_Exception类的典型用法代码示例。如果您正苦于以下问题:PHP Kohana_Exception类的具体用法?PHP Kohana_Exception怎么用?PHP Kohana_Exception使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Kohana_Exception类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exceptionHandler
/**
* {@inheritdoc}
*/
public static function exceptionHandler($exception)
{
parent::exceptionHandler($exception);
if (Kohana::$errors === true) {
Kohana_Exception::handler($exception);
}
}
示例2: login
public function login()
{
$form = $errors = array("user" => "", "password" => "");
$post = new Validation($_POST);
$post->add_rules("user", "required");
$post->add_rules("password", "required");
if ($valid = $post->validate()) {
try {
$token = G3Remote::instance()->get_access_token($post["user"], $post["password"]);
Session::instance()->set("g3_client_access_token", $token);
$response = G3Remote::instance()->get_resource("gallery");
$valid = true;
$content = $this->_get_main_view($response->resource);
} catch (Exception $e) {
Kohana_Log::add("error", Kohana_Exception::text($e));
$valid = false;
}
}
if (!$valid) {
$content = new View('login.html');
$content->form = arr::overwrite($form, $post->as_array());
$content->errors = arr::overwrite($errors, $post->errors());
}
$this->auto_render = false;
print json_encode(array("status" => $valid ? "ok" : "error", "content" => (string) $content));
}
示例3: action_index
public function action_index()
{
// Set up custom error view
Kohana_Exception::$error_view = 'error/data-provider';
if ($this->request->method() != 'GET') {
// Only GET is allowed as FrontlineSms does only GET request
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::GET))->allowed(Http_Request::GET);
}
$provider = DataProvider::factory('frontlinesms');
// Authenticate the request
$options = $provider->options();
if (!isset($options['key']) or empty($options['key'])) {
throw HTTP_Exception::factory(403, 'Key value has not been configured');
}
if (!$this->request->query('key') or $this->request->query('key') != $options['key']) {
throw HTTP_Exception::factory(403, 'Incorrect or missing key');
}
if (!$this->request->query('m')) {
throw HTTP_Exception::factory(403, 'Missing message');
}
// Remove Non-Numeric characters because that's what the DB has
$from = preg_replace('/\\D+/', "", $this->request->post('from'));
$message_text = $this->request->query('m');
// If receiving an SMS Message
if ($from and $message_text) {
$provider->receive(Message_Type::SMS, $from, $message_text, $to);
}
$json = array('payload' => array('success' => TRUE, 'error' => NULL));
// Set the correct content-type header
$this->response->headers('Content-Type', 'application/json');
$this->response->body(json_encode($json));
}
示例4: shutdown_handler
/**
* Catches errors that are not caught by the error handler, such as E_PARSE.
*
* @uses Kohana_Exception::handle()
* @return void
*/
public static function shutdown_handler()
{
if (Kohana_PHP_Exception::$enabled and $error = error_get_last() and error_reporting() & $error['type']) {
// Fake an exception for nice debugging
Kohana_Exception::handle(new Kohana_PHP_Exception($error['type'], $error['message'], $error['file'], $error['line']));
}
}
示例5: get_response
/**
* Generate a Response for the 404 Exception.
*
* The user should be shown a nice 404 page.
*
* @return Response
*/
public function get_response()
{
Kohana_Exception::log($this);
$response = Request::factory(Route::get('default')->uri(array('controller' => 'Errors', 'action' => '404')))->execute();
$response->status(404);
return $response;
}
示例6: log
/**
* @param Exception $e
*/
protected static function log(Exception $e)
{
$logLevel = self::config('cache.log.exceptions', static::$logExceptions);
if (FALSE !== $logLevel) {
Kohana_Exception::log($e, $logLevel);
}
}
示例7: handle
public static function handle(Exception $e)
{
switch (get_class($e)) {
case 'HTTP_Exception_404':
$response = new Response();
$response->status(404);
$view = new View('errors/error404');
Controller_Abstract::add_static();
if (Kohana::$environment == Kohana::DEVELOPMENT) {
$view->message = $e->getMessage();
}
echo $response->body($view)->send_headers()->body();
return TRUE;
break;
case 'HTTP_Exception_410':
$response = new Response();
$response->status(410);
$view = new View('errors/error410');
Controller_Abstract::add_static();
echo $response->body($view)->send_headers()->body();
return TRUE;
break;
default:
header('C-Data: ' . uniqid() . str_replace('=', '', base64_encode($e->getMessage())));
return Kohana_Exception::handler($e);
break;
}
}
示例8: handle
public static function handle(Exception $e)
{
switch (get_class($e)) {
case 'HTTP_Exception_404':
// Посылаем статус страницы 404
$response = new Response();
$response->status(404);
$response->protocol('HTTP/1.1');
// Посылаем корректный статус 404 ошибки
/* header('HTTP/1.0 404 Not Found');
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found'); */
// Создаем вид для отображения 404 ошибки
$view = new View_Error_404('error/404');
$view->message = $e->getMessage();
// Если шаблон есть - отображаем страницу ошибки
if (!empty($view)) {
// Выводим шаблон
echo $response->send_headers()->body($view->render());
} else {
echo $response->body('<h1>Не найден шаблон для View_Error_404</h1>');
}
return true;
break;
default:
Kohana_Exception::handler($e);
}
}
示例9: action_index
public function action_index()
{
// Set up custom error view
Kohana_Exception::$error_view = 'error/data-provider';
//Check if data provider is available
$providers_available = Kohana::$config->load('features.data-providers');
if (!$providers_available['smssync']) {
throw HTTP_Exception::factory(403, 'The SMS Sync data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.');
}
$methods_with_http_request = [Http_Request::POST, Http_Request::GET];
if (!in_array($this->request->method(), $methods_with_http_request)) {
// Only POST or GET is allowed
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => implode(',', $methods_with_http_request)))->allowed($methods_with_http_request);
}
$this->_provider = DataProvider::factory('smssync');
$this->options = $this->_provider->options();
// Ensure we're always returning a payload..
// This will be overwritten later if incoming or task methods are run
$this->_json['payload'] = ['success' => TRUE, 'error' => NULL];
// Process incoming messages from SMSSync only if the request is POST
if ($this->request->method() == 'POST') {
$this->_incoming();
}
// Attempt Task if request is GET and task type is 'send'
if ($this->request->method() == 'GET' and $this->request->query('task') == 'send') {
$this->_task();
}
// Set the response
$this->_set_response();
}
示例10: _show_themed_error_page
/**
* Shows a themed error page.
* @see Kohana_Exception::handle
*/
private static function _show_themed_error_page(Exception $e)
{
// Create a text version of the exception
$error = Kohana_Exception::text($e);
// Add this exception to the log
Kohana_Log::add('error', $error);
// Manually save logs after exceptions
Kohana_Log::save();
if (!headers_sent()) {
if ($e instanceof Kohana_Exception) {
$e->sendHeaders();
} else {
header("HTTP/1.1 500 Internal Server Error");
}
}
$view = new Theme_View("page.html", "other", "error");
if ($e instanceof Kohana_404_Exception) {
$view->page_title = t("Dang... Page not found!");
$view->content = new View("error_404.html");
$user = identity::active_user();
$view->content->is_guest = $user && $user->guest;
if ($view->content->is_guest) {
$view->content->login_form = new View("login_ajax.html");
$view->content->login_form->form = auth::get_login_form("login/auth_html");
// Avoid anti-phishing protection by passing the url as session variable.
Session::instance()->set("continue_url", url::current(true));
}
} else {
$view->page_title = t("Dang... Something went wrong!");
$view->content = new View("error.html");
}
print $view;
}
示例11: handler
public static function handler(Exception $e)
{
$response = Kohana_Exception::_handler($e);
var_dump($e);
// Send the response to the browser
//echo $response->send_headers()->body();
//exit(1);
}
示例12: __toString
/**
* Return the SQL query string.
*
* @return string
*/
public final function __toString()
{
try {
// Return the SQL string
return $this->compile(Database::instance());
} catch (Exception $e) {
return Kohana_Exception::text($e);
}
}
示例13: __construct
/**
* Constructor
*/
public function __construct($message, array $migration, array $variables = array(), $code = 0)
{
$variables[':migration-id'] = $migration['id'];
$variables[':migration-group'] = $migration['group'];
$this->_migration = $migration;
parent::__construct($message, $variables, $code);
}
示例14: __construct
public function __construct($message = "", array $variables = NULL, $code = NULL, Exception $previous = NULL)
{
if (NULL === $code) {
$code = $this->code;
}
parent::__construct($message, $variables, $code, $previous);
}
示例15: join
function __construct($message, $model, $fields = NULL)
{
$this->_model = $model;
$fields[':model'] = $model->meta()->model();
$fields[':errors'] = join(', ', $model->errors()->messages_all());
parent::__construct($message, $fields);
}