本文整理汇总了PHP中Kohana_Log类的典型用法代码示例。如果您正苦于以下问题:PHP Kohana_Log类的具体用法?PHP Kohana_Log怎么用?PHP Kohana_Log使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Kohana_Log类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_detach_removes_log_writer_and_returns_this
/**
* When we call detach() we expect the specified log writer to be removed
*
* @test
* @covers Kohana_Log::detach
*/
public function test_detach_removes_log_writer_and_returns_this()
{
$logger = new Kohana_Log();
$writer = $this->getMockForAbstractClass('Kohana_Log_Writer');
$logger->attach($writer);
$this->assertSame($logger, $logger->detach($writer));
$this->assertAttributeSame(array(), '_writers', $logger);
}
示例2: __construct
public function __construct()
{
include Kohana::find_file('vendor', 'facebook/src/facebook');
// class setup
$this->_facebook = new Facebook(array('appId' => Kohana::config('facebook')->app_id, 'secret' => Kohana::config('facebook')->secret, 'cookie' => true));
$this->canvasUrl = Kohana::config('facebook')->canvas_url;
$this->scope = Kohana::config('facebook')->scope;
try {
$this->uid = $this->getUser();
if (Kohana::$profiling === TRUE) {
$benchmark = Profiler::start('Kohana_Facebook', 'facebook->api(/me)');
}
$this->_me = $this->_facebook->api('/me');
if (isset($benchmark)) {
// Stop the benchmark
Profiler::stop($benchmark);
}
} catch (FacebookApiException $e) {
$log = Kohana_Log::instance();
$log->write($e);
var_dump($e);
$this->redirectToLogin();
exit;
}
}
示例3: load_user
/**
* Make sure that we have a session and group_ids cached in the session.
*/
static function load_user()
{
try {
// Call IdentityProvider::instance() now to force the load of the user interface classes.
// We are about to load the active user from the session and which needs the user definition
// class, which can't be reached by Kohana's heiracrchical lookup.
IdentityProvider::instance();
$session = Session::instance();
if (!($user = $session->get("user"))) {
self::set_active_user($user = self::guest());
}
// The installer cannot set a user into the session, so it just sets an id which we should
// upconvert into a user.
// @todo set the user name into the session instead of 2 and then use it to get the user object
if ($user === 2) {
auth::login(IdentityProvider::instance()->admin_user());
}
if (!$session->get("group_ids")) {
$ids = array();
foreach ($user->groups() as $group) {
$ids[] = $group->id;
}
$session->set("group_ids", $ids);
}
} catch (Exception $e) {
// Log it, so we at least have so notification that we swallowed the exception.
Kohana_Log::add("error", "load_user Exception: " . $e->getMessage() . "\n" . $e->getTraceAsString());
try {
Session::instance()->destroy();
} catch (Exception $e) {
// We don't care if there was a problem destroying the session.
}
url::redirect(item::root()->abs_url());
}
}
示例4: _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;
}
示例5: __construct
/**
* Loads encryption configuration and validates the data.
*
* @param array|string custom configuration or config group name
* @throws Kohana_Exception
*/
public function __construct($config = FALSE)
{
if (!defined('MCRYPT_ENCRYPT')) {
throw new Kohana_Exception('To use the Encrypt library, mcrypt must be enabled in your PHP installation');
}
if (is_string($config)) {
$name = $config;
// Test the config group name
if (($config = Kohana::config('encryption.' . $config)) === NULL) {
throw new Kohana_Exception('The :name: group is not defined in your configuration.', array(':name:' => $name));
}
}
if (is_array($config)) {
// Append the default configuration options
$config += Kohana::config('encryption.default');
} else {
// Load the default group
$config = Kohana::config('encryption.default');
}
if (empty($config['key'])) {
throw new Kohana_Exception('To use the Encrypt library, you must set an encryption key in your config file');
}
// Find the max length of the key, based on cipher and mode
$size = mcrypt_get_key_size($config['cipher'], $config['mode']);
if (strlen($config['key']) > $size) {
// Shorten the key to the maximum size
$config['key'] = substr($config['key'], 0, $size);
}
// Find the initialization vector size
$config['iv_size'] = mcrypt_get_iv_size($config['cipher'], $config['mode']);
// Cache the config in the object
$this->config = $config;
Kohana_Log::add('debug', 'Encrypt Library initialized');
}
示例6: saveprefs
public function saveprefs()
{
// Save user preferences to the database.
// Prevent Cross Site Request Forgery
access::verify_csrf();
// Make sure the user filled out the form properly.
$form = $this->_get_admin_form();
if ($form->validate()) {
Kohana_Log::add("error", print_r($form, 1));
// Save settings to Gallery's database.
foreach (iptc::keys() as $keyword => $iptcvar) {
$checkbox = false;
for ($i = 0; $i < count($form->Global->{$keyword}); $i++) {
if ($form->Global->{$keyword}->value[$i] == $keyword) {
$checkbox = true;
}
}
module::set_var("iptc", "show_" . $keyword, $checkbox);
}
// Display a success message and redirect back to the TagsMap admin page.
message::success(t("Your settings have been saved."));
url::redirect("admin/iptc");
}
// Else show the page with errors
$view = new Admin_View("admin.html");
$view->content = new View("admin_iptc.html");
$view->content->iptc_form = $form;
print $view;
}
示例7: __construct
/**
* On first session instance creation, sets up the driver and creates session.
*
* @param string Force a specific session_id
*/
protected function __construct($session_id = NULL)
{
$this->input = Input::instance();
// This part only needs to be run once
if (Session::$instance === NULL) {
// Load config
Session::$config = Kohana::config('session');
// Makes a mirrored array, eg: foo=foo
Session::$protect = array_combine(Session::$protect, Session::$protect);
// Configure garbage collection
ini_set('session.gc_probability', (int) Session::$config['gc_probability']);
ini_set('session.gc_divisor', 100);
ini_set('session.gc_maxlifetime', Session::$config['expiration'] == 0 ? 86400 : Session::$config['expiration']);
// Create a new session
$this->create(NULL, $session_id);
if (Session::$config['regenerate'] > 0 and $_SESSION['total_hits'] % Session::$config['regenerate'] === 0) {
// Regenerate session id and update session cookie
$this->regenerate();
} else {
// Always update session cookie to keep the session alive
cookie::set(Session::$config['name'], $_SESSION['session_id'], Session::$config['expiration']);
}
// Close the session on system shutdown (run before sending the headers), so that
// the session cookie(s) can be written.
Event::add('system.shutdown', array($this, 'write_close'));
// Singleton instance
Session::$instance = $this;
}
Kohana_Log::add('debug', 'Session Library initialized');
}
示例8: item_created
/**
* Handle the creation of a new photo.
* @todo Get tags from the XMP and/or IPTC data in the image
*
* @param Item_Model $photo
*/
static function item_created($photo)
{
$tags = array();
if ($photo->is_photo()) {
$path = $photo->file_path();
$size = getimagesize($photo->file_path(), $info);
if (is_array($info) && !empty($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
if (!empty($iptc["2#025"])) {
foreach ($iptc["2#025"] as $tag) {
$tag = str_replace("", "", $tag);
foreach (explode(",", $tag) as $word) {
$word = trim($word);
if (function_exists("mb_detect_encoding") && mb_detect_encoding($word) != "UTF-8") {
$word = utf8_encode($word);
}
$tags[$word] = 1;
}
}
}
}
}
// @todo figure out how to read the keywords from xmp
foreach (array_keys($tags) as $tag) {
try {
tag::add($photo, $tag);
} catch (Exception $e) {
Kohana_Log::add("error", "Error adding tag: {$tag}\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
return;
}
示例9: 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));
}
示例10: rotate
/**
* Rotate an image. Valid options are degrees
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function rotate($input_file, $output_file, $options)
{
graphics::init_toolkit();
module::event("graphics_rotate", $input_file, $output_file, $options);
// BEGIN mod to original function
$image_info = getimagesize($input_file);
// [0]=w, [1]=h, [2]=type (1=GIF, 2=JPG, 3=PNG)
if (module::get_var("image_optimizer", "rotate_jpg") || $image_info[2] == 2) {
// rotate_jpg enabled, the file is a jpg. get args
$path = module::get_var("image_optimizer", "path_jpg");
$exec_args = " -rotate ";
$exec_args .= $options["degrees"] > 0 ? $options["degrees"] : $options["degrees"] + 360;
$exec_args .= " -copy all -optimize -outfile ";
// run it - from input_file to tmp_file
$tmp_file = image_optimizer::make_temp_name($output_file);
exec(escapeshellcmd($path) . $exec_args . escapeshellarg($tmp_file) . " " . escapeshellarg($input_file), $exec_output, $exec_status);
if ($exec_status || !filesize($tmp_file)) {
// either a blank/nonexistant file or an error - log an error and pass to normal function
Kohana_Log::add("error", "image_optimizer rotation failed on " . $output_file);
unlink($tmp_file);
} else {
// worked - move temp to output
rename($tmp_file, $output_file);
$status = true;
}
}
if (!$status) {
// we got here if we weren't supposed to use jpegtran or if jpegtran failed
// END mod to original function
Image::factory($input_file)->quality(module::get_var("gallery", "image_quality"))->rotate($options["degrees"])->save($output_file);
// BEGIN mod to original function
}
// END mod to original function
module::event("graphics_rotate_completed", $input_file, $output_file, $options);
}
示例11: gallery_shutdown
/**
* At this point, the output has been sent to the browser, so we can take some time
* to run a schedule task.
*/
static function gallery_shutdown()
{
try {
$schedule = ORM::factory("schedule")->where("next_run_datetime", "<=", time())->where("busy", "!=", 1)->order_by("next_run_datetime")->find_all(1);
if ($schedule->count()) {
$schedule = $schedule->current();
$schedule->busy = true;
$schedule->save();
try {
if (empty($schedule->task_id)) {
$task = task::start($schedule->task_callback);
$schedule->task_id = $task->id;
}
$task = task::run($schedule->task_id);
if ($task->done) {
$schedule->next_run_datetime += $schedule->interval;
$schedule->task_id = null;
}
$schedule->busy = false;
$schedule->save();
} catch (Exception $e) {
$schedule->busy = false;
$schedule->save();
throw $e;
}
}
} catch (Exception $e) {
Kohana_Log::add("error", (string) $e);
}
}
示例12: load_themes
/**
* Load the active theme. This is called at bootstrap time. We will only ever have one theme
* active for any given request.
*/
static function load_themes()
{
$input = Input::instance();
$path = $input->server("PATH_INFO");
if (empty($path)) {
$path = "/" . $input->get("kohana_uri");
}
$config = Kohana_Config::instance();
$modules = $config->get("core.modules");
self::$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7);
self::$site_theme_name = module::get_var("gallery", "active_site_theme");
if (self::$is_admin) {
// Load the admin theme
self::$admin_theme_name = module::get_var("gallery", "active_admin_theme");
array_unshift($modules, THEMEPATH . self::$admin_theme_name);
// If the site theme has an admin subdir, load that as a module so that
// themes can provide their own code.
if (file_exists(THEMEPATH . self::$site_theme_name . "/admin")) {
array_unshift($modules, THEMEPATH . self::$site_theme_name . "/admin");
}
} else {
// Admins can override the site theme, temporarily. This lets us preview themes.
if (identity::active_user()->admin && ($override = $input->get("theme"))) {
if (file_exists(THEMEPATH . $override)) {
self::$site_theme_name = $override;
} else {
Kohana_Log::add("error", "Missing override theme: '{$override}'");
}
}
array_unshift($modules, THEMEPATH . self::$site_theme_name);
}
$config->set("core.modules", $modules);
}
示例13: scan_php_file
static function scan_php_file($file, &$cache)
{
$code = file_get_contents($file);
$raw_tokens = token_get_all($code);
unset($code);
$tokens = array();
$func_token_list = array("t" => array(), "t2" => array());
$token_number = 0;
// Filter out HTML / whitespace, and build a lookup for global function calls.
foreach ($raw_tokens as $token) {
if (!is_array($token) || $token[0] != T_WHITESPACE && $token[0] != T_INLINE_HTML) {
if (is_array($token)) {
if ($token[0] == T_STRING && in_array($token[1], array("t", "t2"))) {
$func_token_list[$token[1]][] = $token_number;
}
}
$tokens[] = $token;
$token_number++;
}
}
unset($raw_tokens);
if (!empty($func_token_list["t"])) {
$errors = l10n_scanner::_parse_t_calls($tokens, $func_token_list["t"], $cache);
foreach ($errors as $line => $error) {
Kohana_Log::add("error", "Translation scanner error. " . "file: " . substr($file, strlen(DOCROOT)) . ", line: {$line}, context: {$error}");
}
}
if (!empty($func_token_list["t2"])) {
$errors = l10n_scanner::_parse_plural_calls($tokens, $func_token_list["t2"], $cache);
foreach ($errors as $line => $error) {
Kohana_Log::add("error", "Translation scanner error. " . "file: " . substr($file, strlen(DOCROOT)) . ", line: {$line}, context: {$error}");
}
}
}
示例14: __construct
/**
* @param resource from pg_query() or pg_get_result()
* @param string SQL used to create this result
* @param resource from pg_connect() or pg_pconnect()
* @param boolean|string
* @return void
*/
public function __construct($result, $sql, $link, $return_objects)
{
// PGSQL_COMMAND_OK <- SET client_encoding = 'utf8'
// PGSQL_TUPLES_OK <- SELECT table_name FROM information_schema.tables
// PGSQL_COMMAND_OK <- INSERT INTO pages (name) VALUES ('gone soon')
// PGSQL_COMMAND_OK <- DELETE FROM pages WHERE id = 2
// PGSQL_COMMAND_OK <- UPDATE pb_users SET company_id = 1
// PGSQL_FATAL_ERROR <- SELECT FROM pages
switch (pg_result_status($result)) {
case PGSQL_EMPTY_QUERY:
$this->total_rows = 0;
break;
case PGSQL_COMMAND_OK:
$this->total_rows = pg_affected_rows($result);
break;
case PGSQL_TUPLES_OK:
$this->total_rows = pg_num_rows($result);
break;
case PGSQL_COPY_OUT:
case PGSQL_COPY_IN:
Kohana_Log::add('debug', 'PostgreSQL COPY operations not supported');
break;
case PGSQL_BAD_RESPONSE:
case PGSQL_NONFATAL_ERROR:
case PGSQL_FATAL_ERROR:
throw new Database_Exception(':error [ :query ]', array(':error' => pg_result_error($result), ':query' => $sql));
}
$this->link = $link;
$this->result = $result;
$this->return_objects = $return_objects;
$this->sql = $sql;
}
示例15: __construct
/**
* Loads the configured driver and validates it.
*
* @param array|string custom configuration or config group name
* @return void
*/
public function __construct($config = FALSE)
{
if (is_string($config)) {
$name = $config;
// Test the config group name
if (($config = Kohana::config('cache.' . $config)) === NULL) {
throw new Cache_Exception('The :group: group is not defined in your configuration.', array(':group:' => $name));
}
}
if (is_array($config)) {
// Append the default configuration options
$config += Kohana::config('cache.default');
} else {
// Load the default group
$config = Kohana::config('cache.default');
}
// Cache the config in the object
$this->config = $config;
// Set driver name
$driver = 'Cache_' . ucfirst($this->config['driver']) . '_Driver';
// Load the driver
if (!Kohana::auto_load($driver)) {
throw new Cache_Exception('The :driver: driver for the :class: library could not be found', array(':driver:' => $this->config['driver'], ':class:' => get_class($this)));
}
// Initialize the driver
$this->driver = new $driver($this->config['params']);
// Validate the driver
if (!$this->driver instanceof Cache_Driver) {
throw new Cache_Exception('The :driver: driver for the :library: library must implement the :interface: interface', array(':driver:' => $this->config['driver'], ':library:' => get_class($this), ':interface:' => 'Cache_Driver'));
}
Kohana_Log::add('debug', 'Cache Library initialized');
}