本文整理汇总了PHP中Kohana_Exception::text方法的典型用法代码示例。如果您正苦于以下问题:PHP Kohana_Exception::text方法的具体用法?PHP Kohana_Exception::text怎么用?PHP Kohana_Exception::text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kohana_Exception
的用法示例。
在下文中一共展示了Kohana_Exception::text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _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;
}
示例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: __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);
}
}
示例4: log
/**
* 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);
}
示例5: handler
/**
* Inline exception handler, displays the error message, source of the
* exception, and the stack trace of the error.
*
* @uses Kohana_Exception::text
* @param object exception object
* @return boolean
*/
public static function handler(Exception $e)
{
try {
// Get the exception information
$type = get_class($e);
$code = $e->getCode();
$message = $e->getMessage();
$file = $e->getFile();
$line = $e->getLine();
// Create a text version of the exception
$error = Kohana_Exception::text($e);
if (is_object(Kohana::$log)) {
// Add this exception to the log
Kohana::$log->add(Log::ERROR, $error);
// Make sure the logs are written
Kohana::$log->write();
}
if (Kohana::$is_cli) {
// Just display the text of the exception
echo "\n{$error}\n";
return TRUE;
}
if ($e instanceof ErrorException) {
if (isset(Kohana_Exception::$php_errors[$code])) {
// Use the human-readable error name
$code = Kohana_Exception::$php_errors[$code];
}
}
if (!headers_sent()) {
Request::$current->response()->status($code);
Request::$current->response()->headers('Content-Type', 'text/plain; charset=' . Kohana::$charset);
Request::$current->response()->send_headers();
}
if (Kohana::$environment === Kohana::DEVELOPMENT) {
echo $error;
} else {
echo $message;
}
return TRUE;
} catch (Exception $e) {
// Clean the output buffer if one exists
ob_get_level() and ob_clean();
// Make sure the proper content type is sent with a 500 status
header('Content-Type: text/plain; charset=' . Kohana::$charset, TRUE, 500);
// Display the exception message
if (Kohana::$environment === Kohana::DEVELOPMENT) {
echo Kohana_Exception::text($e), "\n";
} else {
echo $e->getMessage(), "\n";
}
// Exit with an error status
// exit(1);
}
}
示例6: _get
/**
* Get from GeoNames by geonameId
*
* @static
* @param integer $id
* @return array
*/
private static function _get($id, $lang = 'en')
{
$url = Kohana::$config->load('geo.base_url') . '/get?geonameId=' . (int) $id . '&lang=' . $lang . '&style=full';
try {
$xml = new SimpleXMLElement($url, null, true);
Kohana::$log->add(Log::DEBUG, 'GeoNames OK: ' . $url);
return $xml;
} catch (Exception $e) {
Kohana::$log->add(Log::ERROR, 'GeoNames failed: ' . $url . ' - ' . Kohana_Exception::text($e));
return false;
}
}
示例7: execute
public function execute()
{
// try
$options = isset($this->options) ? $this->options->as_array(FALSE) : array();
$options['task'] = $this->task;
$success = FALSE;
try {
// create minion task
$minion = Minion_Task::factory($options);
// validate options here, to handle invalid tasks
$validation = Validation::factory($minion->get_options());
$validation = $minion->build_validation($validation);
if (!$validation->check()) {
$errors = $validation->errors(TRUE);
$error = array_shift($errors);
// don't execute task, log validation error
Kohana::$log->add(Log::ERROR, 'Task of id: :id and type: :type failed validation: ":msg"', array(':id' => (string) $this->_id, ':type' => (string) $this->task, ':msg' => $error));
// no need to retry
$this->try = $this->max_tries;
$this->message = $error;
} else {
$minion->execute();
$success = TRUE;
}
} catch (Exception $e) {
$error = Kohana_Exception::text($e);
Kohana::$log->add(Log::ERROR, 'Task :id failed on try: :try with message :msg', array(':id' => (string) $this->_id, ':msg' => $error, ':try' => $this->try));
$this->message = $error;
}
if ($success) {
// success, delete task
$this->delete();
} else {
$this->status = 'failed';
if ($this->try < $this->max_tries) {
// requeue
$this->status = 'queued';
$this->update();
} else {
if ($this->keep_failed) {
$this->update();
} else {
$this->delete();
}
}
}
Kohana::$log->write();
return $success;
}
示例8: _handler
public static function _handler(Exception $e)
{
if (method_exists($e, 'get_response')) {
return $e->get_response();
}
/**
* 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);
}
示例9: log
/**
* Logs an exception.
*
* @uses Kohana_Exception::text
* @param Exception $e
* @param int $level
* @return void
*/
public static function log(Exception $e, $level = Log::EMERGENCY)
{
if (is_object(Kohana::$log)) {
// Create a text version of the exception
$error = Kohana_Exception::text($e);
// add url to error
$error .= "\n on " . URL::current();
if (isset($_SERVER['HTTP_REFERER'])) {
$error .= "\n from " . $_SERVER['HTTP_REFERER'];
}
// Add this exception to the log
Kohana::$log->add($level, $error, NULL, array('exception' => $e));
// Make sure the logs are written
Kohana::$log->write();
}
}
开发者ID:yubinchen18,项目名称:A-basic-website-project-for-a-company-using-the-MVC-pattern-in-Kohana-framework,代码行数:24,代码来源:Exception.php
示例10: loop
public function loop(array $config)
{
if ($this->_auto_terminate && memory_get_usage() > $this->_auto_terminate) {
Kohana::$log->add(Log::WARNING, "Queue autoterminating. Memory usage (:usage bytes) higher than limit (:limit bytes).", array(":usage" => memory_get_usage(), ":limit" => $this->_auto_terminate));
return FALSE;
} else {
if (count($this->_pids) < $this->_max_tasks) {
try {
// find next task
$task = Mango::factory('task')->get_next();
} catch (MongoException $e) {
Kohana::$log->add(Log::ERROR, Kohana_Exception::text($e));
Kohana::$log->add(Log::ERROR, 'Error loading next task. Exiting');
return FALSE;
}
if ($task->loaded()) {
// Write log to prevent memory issues
Kohana::$log->write();
// close all database connections before forking
foreach (MangoDB::$instances as $instance) {
$instance->disconnect();
}
$pid = pcntl_fork();
if ($pid == -1) {
// error forking
Kohana::$log->add(Log::ERROR, 'Queue. Could not spawn child task process.');
Kohana::$log->write();
exit;
} else {
if ($pid) {
// parent process
$this->_pids[$pid] = time();
} else {
// child process
$task->execute();
exit(0);
}
}
}
}
}
return TRUE;
}
示例11: kandler
/**
* Inline exception handler.
*
* @param Exception exception object
* @return string
* @uses Arr::get
* @uses Kohana::find_file
* @uses Kohana_Exception::handler
* @uses Kohana_Exception::text
*/
function kandler(Exception $e)
{
try {
// Get error code
$code = $e->getCode();
// Retrieve Kandler's config
$config = Kohana::$config->load('kandler');
// Use views defined by user or use default
$view = Arr::get($config->errors, $code, $code);
// Create path to error view
$path = $config->path . DIRECTORY_SEPARATOR . $view;
if (Kohana::find_file('views', $path)) {
// Set an exception view
Kohana_Exception::$error_view = $path;
}
// Handle an exception using Kohana's handler
Kohana_Exception::handler($e);
} catch (Exception $e) {
return Kohana_Exception::text($e);
}
}
示例12: handler
public static function handler(Exception $e)
{
/*
* In development, use the in-built Kohana
* exception handler to display and log the
* exception/error.
*/
if (Kohana::$environment >= Kohana::DEVELOPMENT) {
Kohana_Exception::handler($e);
} else {
try {
$exception_text = Kohana_Exception::text($e);
// Log the error
Kohana::$log->add(Log::ERROR, $exception_text);
// Email the error
if (class_exists('Email')) {
$email_subject = Kohana::$config->load('error.website.name') . ' Error';
$email_message = $exception_text;
$email_from = Kohana::$config->load('error.email.from');
foreach ('error.email.to' as $email_to) {
Email::send($email_to, $email_from, $email_subject, $email_mesage);
}
} else {
Kohana::$log->add(Log::NOTICE, 'Email module not installed, errors can not be sent.');
}
// Show an error page
$action = $e instanceof HTTP_Exception ? $e->getCode() : 500;
$post = array('message' => $e->getMessage(), 'requested_url' => Request::$current ? Request::$current->uri() : 'Unknown');
echo Request::factory(Route::get('error-handler')->uri(array('action' => $action)))->method(Request::POST)->post($post)->execute()->send_headers()->body();
} catch (Exception $e) {
// Clean the output buffer if one exists
ob_get_level() and ob_clean();
// Display the exception text
echo Kohana_Exception::text($e);
// Exit with an error status
exit(1);
}
}
}
示例13: response
public static function response($e)
{
try {
$class = get_class($e);
$code = $e->getCode();
$message = $e->getMessage();
$file = $e->getFile();
$line = $e->getLine();
$trace = $e->getTrace();
if ($e instanceof ErrorException) {
if (isset(Kohana_Exception::$php_errors[$code])) {
$code = Kohana_Exception::$php_errors[$code];
}
}
$response = View::factory(Kohana_Exception::$error_view, get_defined_vars());
return $response;
} 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);
}
}
示例14: action_index
public function action_index()
{
$post = $this->request->current()->post();
$group = Arr::get($post, 'group');
$album_id = (int) Arr::get($post, 'album');
$items = Arr::get($post, 'items');
$operation = Arr::get($post, 'operation');
$album_orm = ORM::factory('photo_Album')->where('group', '=', $group)->and_where('id', '=', $album_id)->find();
if (!$album_orm->loaded() or !$this->acl->is_allowed($this->user, $album_orm, 'edit')) {
throw new HTTP_Exception_404();
}
if (empty($items) or !is_array($items) or empty($operation)) {
throw new HTTP_Exception_404();
}
try {
$this->_group_operation_move($operation, $items, $album_orm);
} catch (Exception $e) {
$code = $e->getCode();
$this->response->status(ctype_digit($code) ? $code : 500)->body(Kohana_Exception::text($e));
return;
}
$this->response->body('OK');
}
示例15: __toString
public function __toString()
{
try {
// Return the SQL string
return $this->compile();
} catch (Exception $e) {
return Kohana_Exception::text($e);
}
}