/** * 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); }
/** * {@inheritdoc} */ public static function exceptionHandler($exception) { parent::exceptionHandler($exception); if (Kohana::$errors === true) { Kohana_Exception::handler($exception); } }
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)); }
public function __construct($message = "", array $variables = NULL, $code = NULL, Exception $previous = NULL) { if (NULL === $code) { $code = $this->code; } parent::__construct($message, $variables, $code, $previous); }
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); }
/** * Constructs a new exception for the specified model * * @param string $alias The alias to use when looking for error messages * @param Validation $object The Validation object of the model * @param string $message The error message * @param array $values The array of values for the error message * @param integer $code The error code for the exception * * @return void */ public function __construct($alias, Validation $object, $message = 'Failed to validate array', array $values = null, $code = 0, Exception $previous = null) { $this->_alias = $alias; $this->_objects['_object'] = $object; $this->_objects['_has_many'] = false; parent::__construct($message, $values, $code, $previous); }
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)); }
/** * Constructs a new exception for the specified model * * @param string $alias The alias to use when looking for error messages * @param Validation $object The Validation object of the model * @param string $message The error message * @param array $values The array of values for the error message * @param integer $code The error code for the exception * @return void */ public function __construct($alias, Validation $object, $message = 'Failed to validate array', array $values = NULL, $code = 0) { $this->_alias = $alias; $this->_objects['_object'] = $object; $this->_objects['_has_many'] = FALSE; parent::__construct($message, $values, $code); }
/** * 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'])); } }
/** * 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; }
/** * @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); } }
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; } }
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); } }
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(); }
/** * 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; }
function __construct($sender, $method, array $args = NULL) { $this->args = $args; $this->sender = $sender; $fields[':sender'] = get_class($sender); $fields[':method'] = $this->method = $method; parent::__construct('Object :sender does not have a method :method', $fields); }
public function __construct($status = 404, $message = NULL, array $values = NULL, $code = 0) { $this->_status = $status; if (!$message) { $message = arr::get(Request::$messages, $status); } parent::__construct($message, $values, $code); }
/** * Set internal properties. * * @param string URI of page * @param string custom error template */ public function __construct($page = NULL) { if ($page === NULL) { // Use the complete URI $page = Router::$complete_uri; } parent::__construct('The page you requested, %page%, could not be found.', array('%page%' => $page)); }
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); }
/** * 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); } }
/** * Magically converts mod view object to string. * * @return string */ public function __toString() { try { return $this->render(false, array($this, 'wrap')); } catch (Exception $e) { Kohana_Exception::handle($e); return ''; } }
/** * {@inheritdoc} */ public static function exceptionHandler($exception) { $session = Session::instance(); $session_data = $session->as_array(); parent::notifyException($exception, $session_data); if (Kohana::$errors === true) { Kohana_Exception::handler($exception); } }
/** * String representation of the exception * * @return string */ public function __toString() { if (version_compare(PHP_VERSION, '5.3.0', '<')) { if (null !== ($e = $this->getPrevious())) { return $e->__toString() . "\n\nNext " . parent::__toString(); } } return parent::__toString(); }
public function __construct($message = "", array $variables = NULL, $code = 0, Exception $previous = NULL, $data = array()) { if ($data and !is_array($data)) { $data = json_decode($data, TRUE); } parent::__construct($message, $variables, $code, $previous, $data); if (is_array($data)) { $this->data = $data; } }
/** * Generates a Response for all Exceptions without a specific override * * @return Response */ public function get_response() { // Log the exception Kohana_Exception::log($this); $response = Response::factory(); $view = Swiftriver::get_base_error_view(); $view->content = View::factory('pages/errors/404')->set('page', $this->request()->uri()); $response->body($view->render()); return $response; }
/** * Creates a new translated exception. * * throw new Kohana_Exception('Something went terrible wrong, :user', * array(':user' => $user)); * * @param string status message, custom content to display with error * @param array translation variables * @param integer the http status code * @return void */ public function __construct($message = NULL, array $variables = NULL, $code = 0) { if ($code == 0) { $code = $this->_code; } if (!isset(Response::$messages[$code])) { throw new Kohana_Exception('Unrecognized HTTP status code: :code . Only valid HTTP status codes are acceptable, see RFC 2616.', array(':code' => $code)); } parent::__construct($message, $variables, $code); }
public function __toString() { try { return (string) $this->render(); } catch (Exception $e) { // Display the exception message Kohana_Exception::handler($e); return ''; } }
public function get_response() { Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { return parent::get_response(); } else { $response = Response::factory()->status(401)->headers('Location', URL::site('/')); return $response; } }
public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); $params = array('code' => $this->getCode(), 'message' => rawurlencode($this->getMessage()), 'response' => NULL, 'errors' => $this->_errors); try { return json_encode($params); } catch (Exception $e) { return parent::get_response(); } }
/** * Logs with an arbitrary level. * * @param string $level a PSR LogLevel constant * @param string $message * @param array $context * * @return null */ public function log($level, $message, array $context = array()) { $level = $this->convert_psr_to_kohana_level($level); if ($exception = $this->get_exception_from_context($context)) { $message .= \PHP_EOL . \Kohana_Exception::text($exception); } elseif ($message instanceof \Exception) { $context['exception'] = $message; $message = \Kohana_Exception::text($message); } $this->log->add($level, $message, array(), $context); }