Designation: <item> — static property/method; # <item> — protected property/method
Tests if an array is associative or or not.
Gets a value from an array using a dot separated path.
// Get the value of $array['foo']['bar']
$value = Arr::path($array, 'foo.bar');
Fill an array with a range of numbers.
Retreive a single key from an array. If the key does not exist in the array, the default value will be returned instead.
Retrieves multiple keys from an array. If the key does not exist in the array, the default value will be added instead.
Binary search algorithm.
Adds a value to the beginning of an associative array.
Merges one or more arrays recursively and preserves all keys. Note that this does not work the same the PHP function array_merge_recursive()!
Overwrites an array with values from input array(s). Non-existing keys will not be appended!
Creates a callable function and parameter list from a string representation. Note that this function does not validate the callback string.
// Get the callback function and parameters
list($func, $params) = Arr::callback('Foo::bar(apple,orange)');
// Get the result of the callback
$result = call_user_func_array($func, $params);
Returns one or more command-line options. Options are specified using standard CLI syntax:
php index.php --option "value"
Automatically executed before the controller action.
Automatically executed after the controller action.
Gets the value of a signed cookie. Cookies without signatures will not be returned. If the cookie signature is present, but invalid, the cookie will be deleted.
Sets a signed cookie. Note that all cookie values must be strings and no automatic serialization will be performed!
Deletes a cookie by making the value NULL and expiring it.
Generates a salt string for a cookie based on the name and value.
Returns the offset (in seconds) between two time zones.
Number of seconds in a minute, incrementing by a step.
Number of minutes in an hour, incrementing by a step.
Number of hours in a day.
Returns AM or PM, based on a given hour.
Adjusts a non-24-hour number into a 24-hour number.
Number of days in month.
Number of months in a year
Returns an array of years between a starting and ending year. Uses the current year +/- 5 as the max/min.
Returns time difference between two timestamps, in human readable format.
Returns the difference between a time and now in a "fuzzy" way.
Converts a UNIX timestamp to DOS format.
Converts a DOS timestamp to UNIX format.
Returns a singleton instance of Encrypt. An encryption key must be provided, but default configuration settings will be applied:
"nofb" mode, produces short output with high entropy and supports IV "rijndael-128" (128-bit AES) cipher, the industry standard
Encrypts a string and returns an encrypted string that can be decoded.
Decrypts an encoded string back to its original value.
Parses a remote feed into an array.
Creates a feed from the given parameters.
Attempt to get the mime type from a file. This method is horribly unreliable, due to PHP being horribly unreliable when it comes to determining the mime type of a file.
Return the mime type of an extension.
Split a file into pieces matching a specific size.
Join a split file into a whole file.
Generates an opening HTML form tag.
Creates the closing form tag.
Creates a form input. If no type is specified, a "text" type input will be returned.
Creates a hidden form input.
Creates a password form input.
Creates a file upload form input.
Creates a checkbox form input.
Creates a radio form input.
Creates a textarea form input.
Creates a select form input.
Creates a submit form input.
Creates a button form input. Note that the body of a button is NOT escaped, to allow images and other HTML to be used.
Creates a form label.
Load a fragment from cache and display it. Multiple fragments can be nested.
Saves a fragment in the cache.
Delete a cached fragment.
Convert special characters to HTML entities.
Create HTML link anchors. Note that the title is not escaped, to allow HTML elements within links (images, etc).
Creates an HTML anchor to a file. Note that the title is not escaped, to allow HTML elements within links (images, etc).
Generates an obfuscated version of an email address.
Creates an email anchor. Note that the title is not escaped, to allow HTML elements within links (images, etc).
Creates a style sheet link.
Creates a script link.
Creates a image link.
Compiles an array of HTML attributes into an attribute string.
Get and set the target language.
Returns translation of a string. If no translation exists, the original string will be returned.
Returns the translation table for a given language.
Checks if a word is defined as uncountable.
Makes a plural word singular.
Makes a singular word plural.
Makes a phrase camel case.
Makes a phrase underscored instead of spaced.
Makes an underscored or dashed phrase human-readable.
Query the configuration table for all values for this group and unserialize each of the values.
Overload setting offsets to insert or update the database values as changes occur.
Return the raw array that is being used for this object.
Get a variable from the configuration or return the default value.
Sets a value in the configuration array.
Overload setting offsets to insert or update the database values as changes occur.
Merge all of the configuration files in this group.
Return the raw array that is being used for this object.
Get a variable from the configuration or return the default value.
Sets a value in the configuration array.
Loads a configuration group.
Return the raw array that is being used for this object.
Get a variable from the configuration or return the default value.
Sets a value in the configuration array.
Get the singleton instance of Kohana_Config.
Attach a configuration reader.
Detaches a configuration reader.
Load a configuration group. Searches the readers in order until the group is found. If the group does not exist, an empty configuration array will be loaded using the first reader.
Copy one configuration group to all of the other readers.
Initializes the environment:
Any of the global settings can be set here:
| Type | Setting | Description | Default Value |
|---|---|---|---|
boolean |
errors | use internal error and exception handling? | TRUE |
boolean |
profile | do internal benchmarking? | TRUE |
boolean |
caching | cache the location of files between requests? | FALSE |
string |
charset | character set used for all input and output | "utf-8" |
string |
base_url | set the base URL for the application | "/" |
string |
index_file | set the index.php file name | "index.php" |
string |
cache_dir | set the cache directory path | APPPATH."cache" |
Cleans up the environment:
Recursively sanitizes an input variable:
Provides auto-loading support of Kohana classes, as well as transparent extension of classes that have a _Core suffix.
Class names are converted to file names by making the class name lowercase and converting underscores to slashes:
// Loads classes/my/class/name.php
Kohana::auto_load('My_Class_Name');
Changes the currently enabled modules. Module paths may be relative or absolute, but must point to a directory:
Kohana::modules(array('modules/foo', MODPATH.'bar'));
Returns the the currently active include paths, including the application and system paths.
Finds the path of a file by directory, filename, and extension. If no extension is given, the default EXT extension will be used.
When searching the "config" or "i18n" directory, an array of files will be returned. These files will return arrays which must be merged together.
// Returns an absolute path to views/template.php
Kohana::find_file('views', 'template');
// Returns an absolute path to media/css/style.css
Kohana::find_file('media', 'css/style', 'css');
// Returns an array of all the "mimes" configuration file
Kohana::find_file('config', 'mimes');
Recursively finds all of the files in the specified directory.
$views = Kohana::list_files('views');
Loads a file within a totally empty scope and returns the output:
$foo = Kohana::load('foo.php');
Creates a new configuration object for the requested group.
Provides simple file-based caching for strings and arrays:
// Set the "foo" cache
Kohana::cache('foo', 'hello, world');
// Get the "foo" cache
$foo = Kohana::cache('foo');
All caches are stored as PHP code, generated with var_export. Caching objects may not work as expected. Storing references or an object or array that has recursion will cause an E_FATAL.
Get a message from a file. Messages are arbitary strings that are stored in the messages/ directory and reference by a key. Translation is not performed on the returned values.
// Get "username" from messages/text.php
$username = Kohana::message('text', 'username');
PHP error handler, converts all errors into ErrorExceptions. This handler respects error_reporting settings.
Inline exception handler, displays the error message, source of the exception, and the stack trace of the error.
Catches errors that are not caught by the error handler, such as E_PARSE.
Get a single line of text representing the exception:
Error [ Code ]: Message ~ File [ Line ]
Returns an HTML string of debugging information about any number of variables, each wrapped in a "pre" tag:
// Displays the type and value of each variable
echo Kohana::debug($foo, $bar, $baz);
Returns an HTML string of information about a single variable.
Borrows heavily on concepts from the Debug class of Nette.
Helper for Kohana::dump(), handles recursion in arrays and objects.
Removes application, system, modpath, or docroot from a filename, replacing them with the plain text equivalents. Useful for debugging when you want to display a shorter path.
// Displays SYSPATH/classes/kohana.php
echo Kohana::debug_path(Kohana::find_file('classes', 'kohana'));
Returns an HTML string, highlighting a specific line of a file, with some number of lines padded above and below.
// Highlights the current line of the current file
echo Kohana::debug_source(__FILE__, __LINE__);
Returns an array of HTML strings that represent each step in the backtrace.
// Displays the entire current backtrace
echo implode('<br/>', Kohana::trace());
Writes each of the messages into the log file.
Write an array of messages.
Get the singleton instance of this class and enable writing at shutdown.
Attaches a log writer.
Detaches a log writer.
Adds a message to the log.
Write and clear all of the messages.
Initializes the environment:
Any of the global settings can be set here:
| Type | Setting | Description | Default Value |
|---|---|---|---|
boolean |
errors | use internal error and exception handling? | TRUE |
boolean |
profile | do internal benchmarking? | TRUE |
boolean |
caching | cache the location of files between requests? | FALSE |
string |
charset | character set used for all input and output | "utf-8" |
string |
base_url | set the base URL for the application | "/" |
string |
index_file | set the index.php file name | "index.php" |
string |
cache_dir | set the cache directory path | APPPATH."cache" |
Cleans up the environment:
Recursively sanitizes an input variable:
Provides auto-loading support of Kohana classes, as well as transparent extension of classes that have a _Core suffix.
Class names are converted to file names by making the class name lowercase and converting underscores to slashes:
// Loads classes/my/class/name.php
Kohana::auto_load('My_Class_Name');
Changes the currently enabled modules. Module paths may be relative or absolute, but must point to a directory:
Kohana::modules(array('modules/foo', MODPATH.'bar'));
Returns the the currently active include paths, including the application and system paths.
Finds the path of a file by directory, filename, and extension. If no extension is given, the default EXT extension will be used.
When searching the "config" or "i18n" directory, an array of files will be returned. These files will return arrays which must be merged together.
// Returns an absolute path to views/template.php
Kohana::find_file('views', 'template');
// Returns an absolute path to media/css/style.css
Kohana::find_file('media', 'css/style', 'css');
// Returns an array of all the "mimes" configuration file
Kohana::find_file('config', 'mimes');
Recursively finds all of the files in the specified directory.
$views = Kohana::list_files('views');
Loads a file within a totally empty scope and returns the output:
$foo = Kohana::load('foo.php');
Creates a new configuration object for the requested group.
Provides simple file-based caching for strings and arrays:
// Set the "foo" cache
Kohana::cache('foo', 'hello, world');
// Get the "foo" cache
$foo = Kohana::cache('foo');
All caches are stored as PHP code, generated with var_export. Caching objects may not work as expected. Storing references or an object or array that has recursion will cause an E_FATAL.
Get a message from a file. Messages are arbitary strings that are stored in the messages/ directory and reference by a key. Translation is not performed on the returned values.
// Get "username" from messages/text.php
$username = Kohana::message('text', 'username');
PHP error handler, converts all errors into ErrorExceptions. This handler respects error_reporting settings.
Inline exception handler, displays the error message, source of the exception, and the stack trace of the error.
Catches errors that are not caught by the error handler, such as E_PARSE.
Get a single line of text representing the exception:
Error [ Code ]: Message ~ File [ Line ]
Returns an HTML string of debugging information about any number of variables, each wrapped in a "pre" tag:
// Displays the type and value of each variable
echo Kohana::debug($foo, $bar, $baz);
Returns an HTML string of information about a single variable.
Borrows heavily on concepts from the Debug class of Nette.
Helper for Kohana::dump(), handles recursion in arrays and objects.
Removes application, system, modpath, or docroot from a filename, replacing them with the plain text equivalents. Useful for debugging when you want to display a shorter path.
// Displays SYSPATH/classes/kohana.php
echo Kohana::debug_path(Kohana::find_file('classes', 'kohana'));
Returns an HTML string, highlighting a specific line of a file, with some number of lines padded above and below.
// Highlights the current line of the current file
echo Kohana::debug_source(__FILE__, __LINE__);
Returns an array of HTML strings that represent each step in the backtrace.
// Displays the entire current backtrace
echo implode('<br/>', Kohana::trace());
Create a new model instance.
Returns the English ordinal suffix (th, st, nd, etc) of a number.
Locale-aware number formatting.
Starts a new benchmark and returns a unique token.
Stops a benchmark.
Deletes a benchmark.
Returns all the benchmark tokens by group and name as an array.
Gets the min, max, average and total of a set of tokens as an array.
Gets the total execution time and memory usage of a benchmark as a list.
Gets the total application run time and memory usage.
Returns the output of a remote URL.
Returns the status code for a URL.
Main request singleton instance. If no URI is provided, the URI will be automatically detected using PATH_INFO, REQUEST_URI, or PHP_SELF.
Creates a new request object for the given URI.
Returns information about the client user agent.
Returns the accepted content types. If a specific type is defined, the quality of that type will be returned.
Returns the accepted languages. If a specific language is defined, the quality of that language will be returned. If the language is not accepted, FALSE will be returned.
Returns the accepted encodings. If a specific encoding is defined, the quality of that encoding will be returned. If the encoding is not accepted, FALSE will be returned.
Parses an accept header and returns an array (type => quality) of the accepted types, ordered by quality.
Generates a relative URI for the current route.
Retrieves a value from the route parameters.
Sends the response status and all set headers.
Redirects as the request response.
Send file download as the response. All execution will be halted when this method is called! Use TRUE for the filename to send the current response as the file content. The third parameter allows the following options to be set:
| Type | Option | Description | Default Value |
|---|---|---|---|
boolean |
inline | Display inline instead of download | FALSE |
string |
mime_type | Manual mime type | Automatic |
Processes the request, executing the controller. Before the routed action is run, the before() method will be called, which allows the controller to overload the action based on the request parameters. After the action is run, the after() method will be called, for post-processing.
By default, the output from the controller is captured and returned, and no headers are sent.
Generate ETag Generates an ETag from the response ready to be returned
Check Cache Checks the browser cache to see the response needs to be returned
Stores a named route and returns it.
Retrieves a named route.
Retrieves all named routes.
Get the name of a route.
Saves or loads the route cache.
Provides default values for keys when they are not present. The default action will always be "index" unless it is overloaded here.
$route->defaults(array('controller' => 'welcome', 'action' => 'index'));
Tests if the route matches a given URI. A successful match will return all of the routed parameters as an array. A failed match will return boolean FALSE.
// This route will only match if the <controller>, <action>, and <id> exist
$params = Route::factory('<controller>/<action>/<id>', array('id' => '\d+'))
->matches('users/edit/10');
// The parameters are now: controller = users, action = edit, id = 10
This method should almost always be used within an if/else block:
if ($params = $route->matches($uri))
{
// Parse the parameters
}
Generates a URI for the current route based on the parameters given.
Returns the compiled regular expression for the route. This translates keys and optional groups to a proper PCRE regular expression.
Remove XSS from user input.
Remove image tags from a string.
Remove PHP tags from a string.
Loads the raw session data string and returns it.
Generate a new session id and return it.
Writes the current session.
Destroys the current session.
Creates a singleton session of the given type. Some session types (native, database) also support restarting a session by passing a session id as the second parameter.
Returns the current session array.
Get a variable from the session array.
Set a variable in the session array.
Removes a variable in the session array.
Loads the session data.
Generates a new session id and returns it.
Sets the last_active timestamp and saves the session.
Destroy the current session.
Loads the raw session data string and returns it.
Generate a new session id and return it.
Writes the current session.
Destroys the current session.
Creates a singleton session of the given type. Some session types (native, database) also support restarting a session by passing a session id as the second parameter.
Returns the current session array.
Get a variable from the session array.
Set a variable in the session array.
Removes a variable in the session array.
Loads the session data.
Generates a new session id and returns it.
Sets the last_active timestamp and saves the session.
Destroy the current session.
Creates a singleton session of the given type. Some session types (native, database) also support restarting a session by passing a session id as the second parameter.
Returns the current session array.
Get a variable from the session array.
Set a variable in the session array.
Removes a variable in the session array.
Loads the session data.
Generates a new session id and returns it.
Sets the last_active timestamp and saves the session.
Destroy the current session.
Loads the raw session data string and returns it.
Generate a new session id and return it.
Writes the current session.
Destroys the current session.
Limits a phrase to a given number of words.
Limits a phrase to a given number of characters.
Alternates between two or more strings.
Generates a random string of a given type and length.
Reduces multiple slashes in a string to single slashes.
Replaces the given words with a string.
Finds the text that is similar between a set of words.
Converts text email addresses and anchors into links.
Converts text anchors into links.
Converts text email addresses into links.
Automatically applies
<
p> and
markup to text. Basically nl2br() on steroids.
Returns human readable sizes.
Prevents widow words by inserting a non-breaking space between the last two words.
Save an uploaded file to a new location. If no filename is provided, the original filename will be used, with a unique prefix added.
This method should be used after validating the $_FILES array:
if ($validate->check())
{
// Upload is valid, save it
Upload::save($_FILES['file']);
}
Tests if upload data is valid, even if no file was uploaded.
$validate->add_rule('file', 'Upload::valid')
Tests if a successful upload has been made.
$validate->add_rule('file', 'Upload::not_empty');
Test if an uploaded file is an allowed file type, by extension.
$validate->add_rule('file', 'Upload::type', array(array('jpg', 'png', 'gif')));
Validation rule to test if an uploaded file is allowed by file size. File sizes are defined as: SB, where S is the size (1, 15, 300, etc) and B is the byte modifier: (B)ytes, (K)ilobytes, (M)egabytes, (G)igabytes.
// Uploaded file must be 1MB or less
$validate->add_rule('file', 'Upload::size', array('1M'))
Gets the base URL to the application. To include the current protocol, use TRUE. To specify a protocol, provide the protocol as a string.
Fetches an absolute site URL based on a URI segment.
Merges the current GET parameters with an array of new or overloaded parameters and returns the resulting query string.
Convert a phrase to a URL-safe title. Note that non-ASCII characters should be transliterated before using this function.
Recursively cleans arrays, objects, and strings. Removes ASCII control codes and converts to the requested charset while silently discarding incompatible characters.
Tests whether a string contains only 7-bit ASCII bytes. This is used to determine when to use native functions or UTF-8 functions.
Strips out device control codes in the ASCII range.
Strips out all non-7bit ASCII bytes.
Replaces special/accented UTF-8 characters by ASCII-7 'equivalents'.
Returns the length of the given string.
Finds position of first occurrence of a UTF-8 string.
Finds position of last occurrence of a char in a UTF-8 string.
Returns part of a UTF-8 string.
Replaces text within a portion of a UTF-8 string.
Makes a UTF-8 string lowercase.
Makes a UTF-8 string uppercase.
Makes a UTF-8 string's first character uppercase.
Makes the first character of every word in a UTF-8 string uppercase.
Case-insensitive UTF-8 string comparison.
Returns a string or an array with all occurrences of search in subject (ignoring case) and replaced with the given replace value.
Note: This function is very slow compared to the native version.
Case-insenstive UTF-8 version of strstr. Returns all of input string from the first occurrence of needle to the end.
Finds the length of the initial segment matching mask.
Finds the length of the initial segment not matching mask.
Pads a UTF-8 string to a certain length with another string.
Converts a UTF-8 string to an array.
Reverses a UTF-8 string.
Strips whitespace (or other UTF-8 characters) from the beginning and end of a string.
Strips whitespace (or other UTF-8 characters) from the beginning of a string.
Strips whitespace (or other UTF-8 characters) from the end of a string.
Returns the unicode ordinal for a character.
Takes an UTF-8 string and returns an array of ints representing the Unicode characters. Astral planes are supported i.e. the ints in the output can be > 0xFFFF. Occurrances of the BOM are ignored. Surrogates are not allowed.
The Original Code is Mozilla Communicator client code. The Initial Developer of the Original Code is Netscape Communications Corporation. Portions created by the Initial Developer are Copyright (C) 1998 the Initial Developer. Ported to PHP by Henri Sivonen hsivonen@iki.fi, see http://hsivonen.iki.fi/php-utf8/ Slight modifications to fit with phputf8 library by Harry Fuecks hfuecks@gmail.com
Takes an array of ints representing the Unicode characters and returns a UTF-8 string. Astral planes are supported i.e. the ints in the input can be > 0xFFFF. Occurrances of the BOM are ignored. Surrogates are not allowed.
The Original Code is Mozilla Communicator client code. The Initial Developer of the Original Code is Netscape Communications Corporation. Portions created by the Initial Developer are Copyright (C) 1998 the Initial Developer. Ported to PHP by Henri Sivonen hsivonen@iki.fi, see http://hsivonen.iki.fi/php-utf8/ Slight modifications to fit with phputf8 library by Harry Fuecks hfuecks@gmail.com.
Creates a new Validation instance.
Checks if a field is not empty.
Checks a field against a regular expression.
Checks that a field is long enough.
Checks that a field is short enough.
Checks that a field is exactly the right length.
Check an email address for correct format.
Validate the domain of an email address by checking if the domain has a valid MX record.
Validate a URL.
Validate an IP.
Validates a credit card number using the Luhn (mod10) formula.
Checks if a phone number is valid.
Tests if a string is a valid date string.
Checks whether a string consists of alphabetical characters only.
Checks whether a string consists of alphabetical characters and numbers only.
Checks whether a string consists of alphabetical characters, numbers, underscores and dashes only.
Checks whether a string consists of digits only (no dots or dashes).
Checks whether a string is a valid number (negative and decimal numbers allowed).
Uses {@link http://www.php.net/manual/en/function.localeconv.php locale conversion} to allow decimal point to be locale specific.
Tests if a number is within a range.
Checks if a string is a proper decimal format. Optionally, a specific number of digits can be checked too.
Checks if a string is a proper hexadecimal HTML color value. The validation is quite flexible as it does not require an initial "#" and also allows for the short notation using only three instead of six hexadecimal characters.
Returns the array representation of the current object.
Sets or overwrites the label name for a field.
Sets labels using an array.
Overwrites or appends filters to a field. Each filter will be executed once. All rules must be valid callbacks.
// Run trim() on all fields
$validation->filter(TRUE, 'trim');
Add filters using an array.
Overwrites or appends rules to a field. Each rule will be executed once. All rules must be string names of functions method names.
// The "username" must not be empty and have a minimum length of 4
$validation->rule('username', 'not_empty')
->rule('username', 'min_length', array(4));
Add rules using an array.
Adds a callback to a field. Each callback will be executed only once. No extra parameters can be passed as the format for callbacks is predefined as (Validate $array, $field, array $errors).
// The "username" must be checked with a custom method
$validation->callback('username', array($this, 'check_username'));
To add a callback to every field already set, use TRUE for the field name.
Add callbacks using an array.
Executes all validation filters, rules, and callbacks. This should typically be called within an in/else block.
if ($validation->check())
{
// The data is valid, do something here
}
Add an error to a field.
Returns the error messages. If no file is specified, the error message will be the name of the rule that failed. When a file is specified, the message will be loaded from "field/rule", or if no rule-specific message exists, "field/default" will be used. If neither is set, the returned message will be "file/field/rule".
By default all messages are translated using the default language. A string can be used as the second parameter to specified the language that the message was written in.
// Get errors from messages/forms/login.php
$errors = $validate->errors('forms/login');
Checks if a field matches the value of another field.
Returns a new View object.
Captures the output that is generated when a view is included. The view data will be extracted to make local variables. This method is static to prevent object scope resolution.
Sets a global variable, similar to the set() method.
Assigns a global variable by reference, similar to the bind() method.
Sets the view filename.
Assigns a variable by name. Assigned values will be available as a variable within the view file:
// This value can be accessed as $foo within the view
$view->set('foo', 'my value');
You can also use an array to set several values at once:
// Create the values $food and $beverage in the view
$view->set(array('food' => 'bread', 'beverage' => 'water'));
Assigns a value by reference. The benefit of binding is that values can be altered without re-setting them. It is also possible to bind variables before they have values. Assigned values will be available as a variable within the view file:
// This reference can be accessed as $ref within the view
$view->bind('ref', $bar);
Renders the view object to a string. Global and local data are merged and extracted to create local variables within the view file.
Note: Global variables with the same key name as local variables will be overwritten by the local variable.