core/Kohana – Kohana API 2.3 Documentation

system/core/Kohana.php

Class: Kohana

final class Kohana

Provides Kohana-specific helper functions. This is where the magic happens!


Methods

Kohana :: setup

public static function setup

Sets up the PHP environment. Adds error/exception handling, output buffering, and adds an auto-loading method for loading classes.

This method is run immediately when this file is loaded, and is benchmarked as environment_setup.

For security, this function also destroys the $_REQUEST global variable. Using the proper global (GET, POST, COOKIE, etc) is inherently more secure. The recommended way to fetch a global variable is using the Input library.

See: http://www.php.net/globals

Return: void


Kohana :: instance

public static function instance

Loads the controller and initializes it. Runs the pre_controller, post_controller_constructor, and post_controller events. Triggers a system.404 event when the route cannot be mapped to a controller.

This method is benchmarked as controller_setup and controller_execution.

Return: object instance of controller


Kohana :: include_paths

public static function include_paths

Get all include paths. APPPATH is the first path, followed by module paths in the order they are configured, follow by the SYSPATH.

Parameters:

boolean process
(FALSE) re-process the include paths

Return: array


Kohana :: config

public static function config

Get a config item or group.

Parameters:

string key
item name
boolean slash
(FALSE) force a forward slash (/) at the end of the item
boolean required
(TRUE) is the item required?

Return: mixed


Kohana :: config_set

public static function config_set

Sets a configuration item, if allowed.

Parameters:

string key
config key string
string value
config value

Return: boolean


Kohana :: config_load

public static function config_load

Load a config file.

Parameters:

string name
config filename, without extension
boolean required
(TRUE) is the file required?

Return: array


Kohana :: config_clear

public static function config_clear

Clears a config group from the cached configuration.

Parameters:

string group
config group

Return: void


Kohana :: log

public static function log

Add a new message to the log.

Parameters:

string type
type of message
string message
message text

Return: void


Kohana :: log_save

public static function log_save

Save all currently logged messages.

Return: void


Kohana :: log_directory

public static function log_directory

Get or set the logging directory.

Parameters:

string dir
(NULL) new log directory

Return: string


Kohana :: cache

public static function cache

Load data from a simple cache file. This should only be used internally, and is NOT a replacement for the Cache library.

Parameters:

string name
unique name of cache
integer lifetime
expiration in seconds

Return: mixed


Kohana :: cache_save

public static function cache_save

Save data to a simple cache file. This should only be used internally, and is NOT a replacement for the Cache library.

Parameters:

string name
cache name
mixed data
data to cache
integer lifetime
expiration in seconds

Return: boolean


Kohana :: output_buffer

public static function output_buffer

Kohana output handler.

Parameters:

string output
current output buffer

Return: string


Kohana :: close_buffers

public static function close_buffers

Closes all open output buffers, either by flushing or cleaning all open buffers, including the Kohana output buffer.

Parameters:

boolean flush
(TRUE) disable to clear buffers, rather than flushing

Return: void


Kohana :: shutdown

public static function shutdown

Triggers the shutdown of Kohana by closing the output buffer, runs the system.display event.

Return: void


Kohana :: render

public static function render

Inserts global Kohana variables into the generated output and prints it.

Parameters:

string output
final output that will displayed

Return: void


Kohana :: show_404

public static function show_404

Displays a 404 page.

Parameters:

string page
(FALSE) URI of page
string template
(FALSE) custom template

Throws: Kohana_404_Exception

Return: void


Kohana :: exception_handler

public static function exception_handler

Dual-purpose PHP error and exception handler. Uses the kohana_error_page view to display the message.

Parameters:

integer or object exception
exception object or error code
string message
(NULL) error message
string file
(NULL) filename
integer line
(NULL) line number

Return: void


Kohana :: auto_load

public static function auto_load

Provides class auto-loading.

Parameters:

string class
name of class

Throws: Kohana_Exception

Return: bool


Kohana :: find_file

public static function find_file

Find a resource file in a given directory. Files will be located according to the order of the include paths. Configuration and i18n files will be returned in reverse order.

Parameters:

string directory
directory to search in
string filename
filename to look for (including extension only if 4th parameter is TRUE)
boolean required
(FALSE) file required
string ext
(FALSE) file extension

Throws: Kohana_Exception if file is required and not found

Return:

  • array if the type is config, i18n or l10n
  • string if the file is found
  • FALSE if the file is not found

Kohana :: list_files

public static function list_files

Lists all files and directories in a resource path.

Parameters:

string directory
directory to search
boolean recursive
(FALSE) list all files to the maximum depth?
string path
(FALSE) full path to search (used for recursion, *never* set this manually)

Return: array filenames and directories


Kohana :: lang

public static function lang

Fetch an i18n language item.

Parameters:

string key
language key to fetch
array args
(array) additional information to insert into the line

Return: string i18n language string, or the requested key if the i18n item is not found


Kohana :: key_string

public static function key_string

Returns the value of a key, defined by a 'dot-noted' string, from an array.

Parameters:

array array
array to search
string keys
dot-noted string: foo.bar.baz

Return:

  • string if the key is found
  • void if the key is not found

Kohana :: key_string_set

public static function key_string_set

Sets values in an array by using a 'dot-noted' string.

Parameters:

array array
array to set keys in (reference)
string keys
dot-noted string: foo.bar.baz
fill
(NULL)

Return:

  • mixed fill value for the key
  • void

Kohana :: user_agent

public static function user_agent

Retrieves current user agent information: keys: browser, version, platform, mobile, robot, referrer, languages, charsets tests: is_browser, is_mobile, is_robot, accept_lang, accept_charset

Parameters:

string key
(string agent) key or test name
string compare
(NULL) used with "accept" tests: user_agent(accept_lang, en)

Return:

  • array languages and charsets
  • string all other keys
  • boolean all tests

Kohana :: debug

public static function debug

Quick debugging of any variable. Any number of parameters can be set.

Return: string


Kohana :: backtrace

public static function backtrace

Displays nice backtrace information.

Parameters:

array trace
backtrace generated by an exception or debug_backtrace

See: http://php.net/debug_backtrace

Return: string


Kohana :: internal_cache_save

public static function internal_cache_save

Saves the internal caches: configuration, include paths, etc.

Return: boolean


Class: Kohana_Exception

class Kohana_Exception extends Exception

Creates a generic i18n exception.


Methods

Kohana_Exception -> __construct

public function __construct

Set exception message.

Parameters:

string error
i18n language key for the message

Kohana_Exception -> __toString

public function __toString

Magic method for converting an object to a string.

Return: string i18n message


Kohana_Exception -> getTemplate

public function getTemplate

Fetch the template name.

Return: string


Kohana_Exception -> sendHeaders

public function sendHeaders

Sends an Internal Server Error header.

Return: void


Class: Kohana_User_Exception

class Kohana_User_Exception extends Kohana_Exception

Creates a custom exception.


Methods

Kohana_User_Exception -> __construct

public function __construct

Set exception title and message.

Parameters:

string title
exception title string
string message
exception message string
string template
(FALSE) custom error template

Kohana_User_Exception -> __toString

public function __toString

Magic method for converting an object to a string.

Return: string i18n message


Kohana_User_Exception -> getTemplate

public function getTemplate

Fetch the template name.

Return: string


Kohana_User_Exception -> sendHeaders

public function sendHeaders

Sends an Internal Server Error header.

Return: void


Class: Kohana_404_Exception

class Kohana_404_Exception extends Kohana_Exception

Creates a Page Not Found exception.


Methods

Kohana_404_Exception -> __construct

public function __construct

Set internal properties.

Parameters:

string page
(FALSE) URL of page
string template
(FALSE) custom error template

Kohana_404_Exception -> sendHeaders

public function sendHeaders

Sends "File Not Found" headers, to emulate server behavior.

Return: void


Kohana_404_Exception -> __toString

public function __toString

Magic method for converting an object to a string.

Return: string i18n message


Kohana_404_Exception -> getTemplate

public function getTemplate

Fetch the template name.

Return: string