Documentation

Kohana
in package

FinalYes

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

$Id: Kohana.php 4372 2009-05-28 17:00:34Z ixmatus $

Tags
author

Kohana Team

copyright

(c) 2007-2008 Kohana Team

license

http://kohanaphp.com/license.html

Table of Contents

Properties

$enable_fatal_errors  : mixed
$has_error  : mixed
$instance  : mixed
$locale  : mixed
$output  : mixed
$user_agent  : mixed
$buffer_level  : mixed
$cache_lifetime  : mixed
$configuration  : mixed
$include_paths  : mixed
$internal_cache  : mixed
$internal_cache_path  : mixed
$write_cache  : mixed

Methods

backtrace()  : string
Displays nice backtrace information.
cache()  : mixed
Load data from a simple cache file. This should only be used internally, and is NOT a replacement for the Cache library.
cacheSave()  : bool
Save data to a simple cache file. This should only be used internally, and is NOT a replacement for the Cache library.
closeBuffers()  : void
Closes all open output buffers, either by flushing or cleaning, and stores the Kohana output buffer for display during shutdown.
closeConnection()  : void
Close the connection to the browser.
config()  : mixed
Get a config item or group.
configClear()  : void
Clears a config group from the cached configuration.
configInclude()  : array<string|int, mixed>|null
Load a kohana config file.
configLoad()  : array<string|int, mixed>
Load a config file.
configSet()  : bool
Sets a configuration item, if allowed.
debug()  : string
Quick debugging of any variable. Any number of parameters can be set.
disableCache()  : void
Disable the find-files and configuration caches This may be required if the caching is causing problems
errorHandler()  : bool
Converts PHP errors into {@see ErrorException}s
exceptionHandler()  : void
Exception handler.
findFile()  : array<string|int, mixed>|string|false
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.
handleFatalErrors()  : void
Convert fatal errors to error exceptions.
includePaths()  : array<string|int, mixed>
Get all include paths. APPPATH is the first path, followed by module paths in the order they are configured.
instance()  : object
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.
internalCacheSave()  : bool
Saves the internal caches: configuration, include paths, etc.
keyString()  : string|array<string|int, mixed>|null
Returns the value of a key, defined by a 'dot-noted' string, from an array.
keyStringSet()  : void
Sets values in an array by using a 'dot-noted' string.
lang()  : string|array<string|int, mixed>
Fetch an i18n language item.
listFiles()  : array<string|int, mixed>
Lists all files and directories in a resource path.
log()  : mixed
Deprecated.
logException()  : int
Log exceptions in the database
logRemoteException()  : bool
Log exceptions to a remote server.
outputBuffer()  : string
Kohana output handler. Called during ob_clean, ob_flush, and their variants.
render()  : void
Inserts global Kohana variables into the generated output and prints it.
run()  : void
Run the application.
setup()  : void
Sets up the PHP environment. Adds error/exception handling, output buffering, and adds an auto-loading method for loading classes.
show404()  : void
Displays a 404 page.
shutdown()  : void
Triggers the shutdown of Kohana by closing the output buffer + running display events.
userAgent()  : array<string|int, mixed>|string|bool|null
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
_obEndClean()  : bool
Ends the current output buffer with callback in mind PHP doesn't pass the output to the callback defined in ob_start() since 5.4

Properties

$enable_fatal_errors

public static mixed $enable_fatal_errors = \TRUE

$has_error

public static mixed $has_error = \FALSE

$instance

public static mixed $instance

$locale

public static mixed $locale

$output

public static mixed $output = ''

$user_agent

public static mixed $user_agent

$buffer_level

private static mixed $buffer_level

$cache_lifetime

private static mixed $cache_lifetime

$configuration

private static mixed $configuration

$include_paths

private static mixed $include_paths

$internal_cache

private static mixed $internal_cache = array()

$internal_cache_path

private static mixed $internal_cache_path

$write_cache

private static mixed $write_cache

Methods

backtrace()

Displays nice backtrace information.

public static backtrace(array<string|int, mixed> $trace) : string
Parameters
$trace : array<string|int, mixed>

backtrace generated by an exception or debug_backtrace

Tags
see
http://php.net/debug_backtrace
Return values
string

cache()

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

public static cache(string $name) : mixed
Parameters
$name : string

unique name of cache

cacheSave()

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

public static cacheSave(string $name, mixed $data) : bool
Parameters
$name : string

cache name

$data : mixed

data to cache

Return values
bool

closeBuffers()

Closes all open output buffers, either by flushing or cleaning, and stores the Kohana output buffer for display during shutdown.

public static closeBuffers([bool $flush = true ]) : void
Parameters
$flush : bool = true

disable to clear buffers, rather than flushing

closeConnection()

Close the connection to the browser.

public static closeConnection() : void

This sends a close header to the browser and disconnects FPM. Theoretically permitting a script to continue running in the background indefinitely.

However, once closed it cannot open again.

config()

Get a config item or group.

public static config(string $key[, bool $slash = false ][, bool $required = true ]) : mixed
Parameters
$key : string

item name

$slash : bool = false

force a forward slash (/) at the end of the item

$required : bool = true

is the item required?

configClear()

Clears a config group from the cached configuration.

public static configClear(string $group) : void
Parameters
$group : string

config group

configInclude()

Load a kohana config file.

public static configInclude(string $file[, string $name = 'config' ]) : array<string|int, mixed>|null

This assumes that the file will declare an array called named 'config' - or defined by the $name parameter.

Parameters
$file : string

absolute path to file

$name : string = 'config'

variable name

Return values
array<string|int, mixed>|null

configLoad()

Load a config file.

public static configLoad(string $name[, bool $required = true ]) : array<string|int, mixed>
Parameters
$name : string

config filename, without extension

$required : bool = true

is the file required?

Return values
array<string|int, mixed>

configSet()

Sets a configuration item, if allowed.

public static configSet(string $key, mixed $value) : bool
Parameters
$key : string

config key string

$value : mixed

config value

Return values
bool

debug()

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

public static debug(mixed ...$params) : string
Parameters
$params : mixed
Return values
string

disableCache()

Disable the find-files and configuration caches This may be required if the caching is causing problems

public static disableCache() : void

errorHandler()

Converts PHP errors into {@see ErrorException}s

public static errorHandler(int $errno, string $errmsg, string $file, int $line) : bool
Parameters
$errno : int

Error code

$errmsg : string

Error message

$file : string
$line : int
Tags
throws
ErrorException
Return values
bool

exceptionHandler()

Exception handler.

public static exceptionHandler(object $exception) : void
Parameters
$exception : object

exception object

findFile()

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.

public static findFile(string $directory, string $filename[, bool|false $required = false ][, string|false $ext = false ]) : array<string|int, mixed>|string|false
Parameters
$directory : string

directory to search in

$filename : string

filename to look for (without extension)

$required : bool|false = false

file required

$ext : string|false = false

file extension

Tags
throws
Kohana_Exception

if file is required and not found

Return values
array<string|int, mixed>|string|false —
  • array: if the type is config, i18n or l10n
  • string: if the file is found
  • false: if the file is not found

handleFatalErrors()

Convert fatal errors to error exceptions.

public static handleFatalErrors() : void

This is much like the error->exception helper above but fatal errors are not reported by the error handler. Instead they are caught during the shutdown event.

Enable/disable this with the $enable_fatal_errors static prop.

Tags
throws
ErrorException

includePaths()

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

public static includePaths([bool $process = false ]) : array<string|int, mixed>
Parameters
$process : bool = false

re-process the include paths

Return values
array<string|int, mixed>

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.

public static & instance() : object
Return values
object —

instance of controller

internalCacheSave()

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

public static internalCacheSave() : bool
Return values
bool

keyString()

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

public static keyString(array<string|int, mixed> $array, string $keys) : string|array<string|int, mixed>|null
Parameters
$array : array<string|int, mixed>

array to search

$keys : string

dot-noted string: foo.bar.baz

Return values
string|array<string|int, mixed>|null

keyStringSet()

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

public static keyStringSet(array<string|int, mixed>|object &$array, string $keys[, mixed $fill = null ]) : void
Parameters
$array : array<string|int, mixed>|object

array to set keys in (reference)

$keys : string

dot-noted string: foo.bar.baz

$fill : mixed = null

fill value for the key

lang()

Fetch an i18n language item.

public static lang(string $key, mixed ...$args) : string|array<string|int, mixed>
Parameters
$key : string

language key to fetch

$args : mixed

additional information to insert into the line

Return values
string|array<string|int, mixed> —

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

listFiles()

Lists all files and directories in a resource path.

public static listFiles(string $directory[, bool $recursive = false ][, string|false $path = false ]) : array<string|int, mixed>
Parameters
$directory : string

directory to search

$recursive : bool = false

list all files to the maximum depth?

$path : string|false = false

full path to search (used for recursion, never set this manually)

Return values
array<string|int, mixed> —

filenames and directories

log()

Deprecated.

public static log(mixed $type, mixed $message) : mixed

This function has been removed, and it's signature has been left for compatibilty only.

Parameters
$type : mixed
$message : mixed

logException()

Log exceptions in the database

public static logException(Throwable $exception[, bool $caught = true ]) : int
Parameters
$exception : Throwable

Exception or error to log

$caught : bool = true
Return values
int —

Record ID

logRemoteException()

Log exceptions to a remote server.

public static logRemoteException(Throwable $exception[, int $log_id = 0 ][, null|string $category = null ]) : bool
Parameters
$exception : Throwable
$log_id : int = 0
$category : null|string = null
Return values
bool

outputBuffer()

Kohana output handler. Called during ob_clean, ob_flush, and their variants.

public static outputBuffer(string $output) : string
Parameters
$output : string

current output buffer

Return values
string

render()

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

public static render(string $output) : void
Parameters
$output : string

final output that will displayed

run()

Run the application.

public static run() : void

This executes controller instance and runs shutdown events.

setup()

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

public static setup() : void

For security, this function also destroys the $_REQUEST global variable. Using the proper global (GET, POST, COOKIE, etc) is inherently more secure.

Tags
see
http://www.php.net/globals

show404()

Displays a 404 page.

public static show404([string|false|EventInterface $page = false ]) : void
Parameters
$page : string|false|EventInterface = false

URI of page

Tags
throws
Kohana_404_Exception

shutdown()

Triggers the shutdown of Kohana by closing the output buffer + running display events.

public static shutdown() : void

userAgent()

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

public static userAgent([string $key = 'agent' ][, string $compare = null ]) : array<string|int, mixed>|string|bool|null
Parameters
$key : string = 'agent'

key or test name

$compare : string = null

used with "accept" tests: userAgent(accept_lang, en)

Return values
array<string|int, mixed>|string|bool|null —
  • array: languages and charsets
  • string: all other keys
  • boolean: all tests
  • null: invalid key or test

_obEndClean()

Ends the current output buffer with callback in mind PHP doesn't pass the output to the callback defined in ob_start() since 5.4

protected static _obEndClean([callable|null $callback = null ]) : bool
Parameters
$callback : callable|null = null
Return values
bool
On this page

Search results