Upgrade to KH 3.3.0

This commit is contained in:
Deon George
2012-11-22 14:25:06 +11:00
parent e5e67a59bb
commit 5bd1841571
1455 changed files with 114353 additions and 9466 deletions

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Arr extends Kohana_Arr {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Config extends Kohana_Config {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Config_File extends Kohana_Config_File {}

View File

@@ -0,0 +1,4 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Config_Group extends Kohana_Config_Group {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
abstract class Controller extends Kohana_Controller {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
abstract class Controller_Template extends Kohana_Controller_Template {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Cookie extends Kohana_Cookie {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Date extends Kohana_Date {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Debug extends Kohana_Debug {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Encrypt extends Kohana_Encrypt {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Feed extends Kohana_Feed {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class File extends Kohana_File {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Form extends Kohana_Form {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Fragment extends Kohana_Fragment {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTML extends Kohana_HTML {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
abstract class HTTP extends Kohana_HTTP {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception extends Kohana_HTTP_Exception {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_300 extends Kohana_HTTP_Exception_300 {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_301 extends Kohana_HTTP_Exception_301 {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_302 extends Kohana_HTTP_Exception_302 {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_303 extends Kohana_HTTP_Exception_303 {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_304 extends Kohana_HTTP_Exception_304 {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_305 extends Kohana_HTTP_Exception_305 {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_307 extends Kohana_HTTP_Exception_307 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_400 extends Kohana_HTTP_Exception_400 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_401 extends Kohana_HTTP_Exception_401 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_402 extends Kohana_HTTP_Exception_402 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_403 extends Kohana_HTTP_Exception_403 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_405 extends Kohana_HTTP_Exception_405 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_406 extends Kohana_HTTP_Exception_406 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_407 extends Kohana_HTTP_Exception_407 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_408 extends Kohana_HTTP_Exception_408 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_409 extends Kohana_HTTP_Exception_409 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_410 extends Kohana_HTTP_Exception_410 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_411 extends Kohana_HTTP_Exception_411 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_412 extends Kohana_HTTP_Exception_412 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_413 extends Kohana_HTTP_Exception_413 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_414 extends Kohana_HTTP_Exception_414 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_415 extends Kohana_HTTP_Exception_415 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_416 extends Kohana_HTTP_Exception_416 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_417 extends Kohana_HTTP_Exception_417 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_500 extends Kohana_HTTP_Exception_500 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_501 extends Kohana_HTTP_Exception_501 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_502 extends Kohana_HTTP_Exception_502 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_503 extends Kohana_HTTP_Exception_503 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_504 extends Kohana_HTTP_Exception_504 {}

View File

@@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_505 extends Kohana_HTTP_Exception_505 {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
abstract class HTTP_Exception_Expected extends Kohana_HTTP_Exception_Expected {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
abstract class HTTP_Exception_Redirect extends Kohana_HTTP_Exception_Redirect {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Header extends Kohana_HTTP_Header {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
interface HTTP_Message extends Kohana_HTTP_Message {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
interface HTTP_Request extends Kohana_HTTP_Request {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
interface HTTP_Response extends Kohana_HTTP_Response {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class I18n extends Kohana_I18n {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Inflector extends Kohana_Inflector {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana extends Kohana_Core {}

View File

@@ -1,11 +1,11 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Array helper.
*
* @package Kohana
* @category Helpers
* @author Kohana Team
* @copyright (c) 2007-2011 Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Arr {
@@ -24,7 +24,7 @@ class Kohana_Arr {
* // Returns FALSE
* Arr::is_assoc('foo', 'bar');
*
* @param array array to check
* @param array $array array to check
* @return boolean
*/
public static function is_assoc(array $array)
@@ -49,7 +49,7 @@ class Kohana_Arr {
* Arr::is_array('not an array!');
* Arr::is_array(Database::instance());
*
* @param mixed value to check
* @param mixed $value value to check
* @return boolean
*/
public static function is_array($value)
@@ -80,10 +80,10 @@ class Kohana_Arr {
* // Using an array of keys
* $colors = Arr::path($array, array('theme', '*', 'color'));
*
* @param array array to search
* @param mixed key path string (delimiter separated) or array of keys
* @param mixed default value if the path is not set
* @param string key path delimiter
* @param array $array array to search
* @param mixed $path key path string (delimiter separated) or array of keys
* @param mixed $default default value if the path is not set
* @param string $delimiter key path delimiter
* @return mixed
*/
public static function path($array, $path, $default = NULL, $delimiter = NULL)
@@ -239,8 +239,8 @@ class Kohana_Arr {
* // Fill an array with values 5, 10, 15, 20
* $values = Arr::range(5, 20);
*
* @param integer stepping
* @param integer ending number
* @param integer $step stepping
* @param integer $max ending number
* @return array
*/
public static function range($step = 10, $max = 100)
@@ -267,9 +267,9 @@ class Kohana_Arr {
* // Get the value "sorting" from $_GET, if it exists
* $sorting = Arr::get($_GET, 'sorting');
*
* @param array array to extract from
* @param string key name
* @param mixed default value
* @param array $array array to extract from
* @param string $key key name
* @param mixed $default default value
* @return mixed
*/
public static function get($array, $key, $default = NULL)
@@ -278,23 +278,27 @@ class Kohana_Arr {
}
/**
* Retrieves multiple keys from an array. If the key does not exist in the
* Retrieves multiple paths from an array. If the path does not exist in the
* array, the default value will be added instead.
*
* // Get the values "username", "password" from $_POST
* $auth = Arr::extract($_POST, array('username', 'password'));
*
* // Get the value "level1.level2a" from $data
* $data = array('level1' => array('level2a' => 'value 1', 'level2b' => 'value 2'));
* Arr::extract($data, array('level1.level2a', 'password'));
*
* @param array array to extract keys from
* @param array list of key names
* @param mixed default value
* @param array $array array to extract paths from
* @param array $paths list of path
* @param mixed $default default value
* @return array
*/
public static function extract($array, array $keys, $default = NULL)
public static function extract($array, array $paths, $default = NULL)
{
$found = array();
foreach ($keys as $key)
foreach ($paths as $path)
{
$found[$key] = isset($array[$key]) ? $array[$key] : $default;
Arr::set_path($found, $path, Arr::path($array, $path, $default));
}
return $found;
@@ -308,8 +312,8 @@ class Kohana_Arr {
*
* [!!] A list of arrays is an array that contains arrays, eg: array(array $a, array $b, array $c, ...)
*
* @param array list of arrays to check
* @param string key to pluck
* @param array $array list of arrays to check
* @param string $key key to pluck
* @return array
*/
public static function pluck($array, $key)
@@ -334,9 +338,9 @@ class Kohana_Arr {
* // Add an empty value to the start of a select list
* Arr::unshift($array, 'none', 'Select a value');
*
* @param array array to modify
* @param string array key name
* @param mixed array value
* @param array $array array to modify
* @param string $key array key name
* @param mixed $val array value
* @return array
*/
public static function unshift( array & $array, $key, $val)
@@ -349,30 +353,50 @@ class Kohana_Arr {
}
/**
* Recursive version of [array_map](http://php.net/array_map), applies the
* same callback to all elements in an array, including sub-arrays.
* Recursive version of [array_map](http://php.net/array_map), applies one or more
* callbacks to all elements in an array, including sub-arrays.
*
* // Apply "strip_tags" to every element in the array
* $array = Arr::map('strip_tags', $array);
*
* // Apply $this->filter to every element in the array
* $array = Arr::map(array(array($this,'filter')), $array);
*
* // Apply strip_tags and $this->filter to every element
* $array = Arr::map(array('strip_tags',array($this,'filter')), $array);
*
* [!!] Because you can pass an array of callbacks, if you wish to use an array-form callback
* you must nest it in an additional array as above. Calling Arr::map(array($this,'filter'), $array)
* will cause an error.
* [!!] Unlike `array_map`, this method requires a callback and will only map
* a single array.
*
* @param mixed callback applied to every element in the array
* @param array array to map
* @param mixed $callbacks array of callbacks to apply to every element in the array
* @param array $array array to map
* @param array $keys array of keys to apply to
* @return array
*/
public static function map($callback, $array)
public static function map($callbacks, $array, $keys = NULL)
{
foreach ($array as $key => $val)
{
if (is_array($val))
{
$array[$key] = Arr::map($callback, $val);
$array[$key] = Arr::map($callbacks, $array[$key]);
}
else
elseif ( ! is_array($keys) OR in_array($key, $keys))
{
$array[$key] = call_user_func($callback, $val);
if (is_array($callbacks))
{
foreach ($callbacks as $cb)
{
$array[$key] = call_user_func($cb, $array[$key]);
}
}
else
{
$array[$key] = call_user_func($callbacks, $array[$key]);
}
}
}
@@ -380,7 +404,10 @@ class Kohana_Arr {
}
/**
* Merges one or more arrays recursively and preserves all keys.
* Recursively merge two or more arrays. Values in an associative array
* overwrite previous values with the same key. Values in an indexed array
* are appended, but only when they do not already exist in the result.
*
* Note that this does not work the same as [array_merge_recursive](http://php.net/array_merge_recursive)!
*
* $john = array('name' => 'john', 'children' => array('fred', 'paul', 'sally', 'jane'));
@@ -392,65 +419,75 @@ class Kohana_Arr {
* // The output of $john will now be:
* array('name' => 'mary', 'children' => array('fred', 'paul', 'sally', 'jane'))
*
* @param array initial array
* @param array array to merge
* @param array ...
* @param array $array1 initial array
* @param array $array2,... array to merge
* @return array
*/
public static function merge(array $a1, array $a2)
public static function merge($array1, $array2)
{
$result = array();
for ($i = 0, $total = func_num_args(); $i < $total; $i++)
if (Arr::is_assoc($array2))
{
// Get the next array
$arr = func_get_arg($i);
// Is the array associative?
$assoc = Arr::is_assoc($arr);
foreach ($arr as $key => $val)
foreach ($array2 as $key => $value)
{
if (isset($result[$key]))
if (is_array($value)
AND isset($array1[$key])
AND is_array($array1[$key])
)
{
if (is_array($val) AND is_array($result[$key]))
$array1[$key] = Arr::merge($array1[$key], $value);
}
else
{
$array1[$key] = $value;
}
}
}
else
{
foreach ($array2 as $value)
{
if ( ! in_array($value, $array1, TRUE))
{
$array1[] = $value;
}
}
}
if (func_num_args() > 2)
{
foreach (array_slice(func_get_args(), 2) as $array2)
{
if (Arr::is_assoc($array2))
{
foreach ($array2 as $key => $value)
{
if (Arr::is_assoc($val))
if (is_array($value)
AND isset($array1[$key])
AND is_array($array1[$key])
)
{
// Associative arrays are merged recursively
$result[$key] = Arr::merge($result[$key], $val);
$array1[$key] = Arr::merge($array1[$key], $value);
}
else
{
// Find the values that are not already present
$diff = array_diff($val, $result[$key]);
// Indexed arrays are merged to prevent duplicates
$result[$key] = array_merge($result[$key], $diff);
}
}
else
{
if ($assoc)
{
// Associative values are replaced
$result[$key] = $val;
}
elseif ( ! in_array($val, $result, TRUE))
{
// Indexed values are added only if they do not yet exist
$result[] = $val;
$array1[$key] = $value;
}
}
}
else
{
// New values are added
$result[$key] = $val;
foreach ($array2 as $value)
{
if ( ! in_array($value, $array1, TRUE))
{
$array1[] = $value;
}
}
}
}
}
return $result;
return $array1;
}
/**
@@ -466,8 +503,8 @@ class Kohana_Arr {
* // The output of $array will now be:
* array('name' => 'jack', 'mood' => 'happy', 'food' => 'tacos')
*
* @param array master array
* @param array input arrays that will overwrite existing values
* @param array $array1 master array
* @param array $array2 input arrays that will overwrite existing values
* @return array
*/
public static function overwrite($array1, $array2)
@@ -501,7 +538,7 @@ class Kohana_Arr {
* // Get the result of the callback
* $result = call_user_func_array($func, $params);
*
* @param string callback string
* @param string $str callback string
* @return array function, params
*/
public static function callback($str)
@@ -550,22 +587,31 @@ class Kohana_Arr {
*
* [!!] The keys of array values will be discarded.
*
* @param array array to flatten
* @param array $array array to flatten
* @return array
* @since 3.0.6
*/
public static function flatten($array)
{
$is_assoc = Arr::is_assoc($array);
$flat = array();
foreach ($array as $key => $value)
{
if (is_array($value))
{
$flat += Arr::flatten($value);
$flat = array_merge($flat, Arr::flatten($value));
}
else
{
$flat[$key] = $value;
if ($is_assoc)
{
$flat[$key] = $value;
}
else
{
$flat[] = $value;
}
}
}
return $flat;

View File

@@ -0,0 +1,192 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Wrapper for configuration arrays. Multiple configuration readers can be
* attached to allow loading configuration from files, database, etc.
*
* Configuration directives cascade across config sources in the same way that
* files cascade across the filesystem.
*
* Directives from sources high in the sources list will override ones from those
* below them.
*
* @package Kohana
* @category Configuration
* @author Kohana Team
* @copyright (c) 2009-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Config {
// Configuration readers
protected $_sources = array();
// Array of config groups
protected $_groups = array();
/**
* Attach a configuration reader. By default, the reader will be added as
* the first used reader. However, if the reader should be used only when
* all other readers fail, use `FALSE` for the second parameter.
*
* $config->attach($reader); // Try first
* $config->attach($reader, FALSE); // Try last
*
* @param Kohana_Config_Source $source instance
* @param boolean $first add the reader as the first used object
* @return $this
*/
public function attach(Kohana_Config_Source $source, $first = TRUE)
{
if ($first === TRUE)
{
// Place the log reader at the top of the stack
array_unshift($this->_sources, $source);
}
else
{
// Place the reader at the bottom of the stack
$this->_sources[] = $source;
}
// Clear any cached _groups
$this->_groups = array();
return $this;
}
/**
* Detach a configuration reader.
*
* $config->detach($reader);
*
* @param Kohana_Config_Source $source instance
* @return $this
*/
public function detach(Kohana_Config_Source $source)
{
if (($key = array_search($source, $this->_sources)) !== FALSE)
{
// Remove the writer
unset($this->_sources[$key]);
}
return $this;
}
/**
* Load a configuration group. Searches all the config sources, merging all the
* directives found into a single config group. Any changes made to the config
* in this group will be mirrored across all writable sources.
*
* $array = $config->load($name);
*
* See [Kohana_Config_Group] for more info
*
* @param string $group configuration group name
* @return Kohana_Config_Group
* @throws Kohana_Exception
*/
public function load($group)
{
if ( ! count($this->_sources))
{
throw new Kohana_Exception('No configuration sources attached');
}
if (empty($group))
{
throw new Kohana_Exception("Need to specify a config group");
}
if ( ! is_string($group))
{
throw new Kohana_Exception("Config group must be a string");
}
if (strpos($group, '.') !== FALSE)
{
// Split the config group and path
list($group, $path) = explode('.', $group, 2);
}
if (isset($this->_groups[$group]))
{
if (isset($path))
{
return Arr::path($this->_groups[$group], $path, NULL, '.');
}
return $this->_groups[$group];
}
$config = array();
// We search from the "lowest" source and work our way up
$sources = array_reverse($this->_sources);
foreach ($sources as $source)
{
if ($source instanceof Kohana_Config_Reader)
{
if ($source_config = $source->load($group))
{
$config = Arr::merge($config, $source_config);
}
}
}
$this->_groups[$group] = new Config_Group($this, $group, $config);
if (isset($path))
{
return Arr::path($config, $path, NULL, '.');
}
return $this->_groups[$group];
}
/**
* Copy one configuration group to all of the other writers.
*
* $config->copy($name);
*
* @param string $group configuration group name
* @return $this
*/
public function copy($group)
{
// Load the configuration group
$config = $this->load($group);
foreach ($config->as_array() as $key => $value)
{
$this->_write_config($group, $key, $value);
}
return $this;
}
/**
* Callback used by the config group to store changes made to configuration
*
* @param string $group Group name
* @param string $key Variable name
* @param mixed $value The new value
* @return Kohana_Config Chainable instance
*/
public function _write_config($group, $key, $value)
{
foreach ($this->_sources as $source)
{
if ( ! ($source instanceof Kohana_Config_Writer))
{
continue;
}
// Copy each value in the config
$source->write($group, $key, $value);
}
return $this;
}
} // End Kohana_Config

View File

@@ -0,0 +1,15 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* File-based configuration reader. Multiple configuration directories can be
* used by attaching multiple instances of this class to [Config].
*
* @package Kohana
* @category Configuration
* @author Kohana Team
* @copyright (c) 2009-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Config_File extends Kohana_Config_File_Reader
{
// @see Kohana_Config_File_Reader
}

View File

@@ -1,33 +1,31 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php
/**
* File-based configuration reader. Multiple configuration directories can be
* used by attaching multiple instances of this class to [Config].
* used by attaching multiple instances of this class to [Kohana_Config].
*
* @package Kohana
* @category Configuration
* @author Kohana Team
* @copyright (c) 2009-2011 Kohana Team
* @copyright (c) 2009-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Config_File extends Config_Reader {
class Kohana_Config_File_Reader implements Kohana_Config_Reader {
/**
* @var string Configuration group name
* The directory where config files are located
* @var string
*/
protected $_configuration_group;
protected $_directory = '';
/**
* @var bool Has the config group changed?
* Creates a new file reader using the given directory as a config source
*
* @param string $directory Configuration directory to search
*/
protected $_configuration_modified = FALSE;
public function __construct($directory = 'config')
{
// Set the configuration directory name
$this->_directory = trim($directory, '/');
// Load the empty array
parent::__construct();
}
/**
@@ -35,18 +33,16 @@ class Kohana_Config_File extends Config_Reader {
*
* $config->load($name);
*
* @param string configuration group name
* @param array configuration array
* @return $this clone of the current object
* @param string $group configuration group name
* @return $this current object
* @uses Kohana::load
*/
public function load($group, array $config = NULL)
public function load($group)
{
$config = array();
if ($files = Kohana::find_file($this->_directory, $group, NULL, TRUE))
{
// Initialize the config array
$config = array();
foreach ($files as $file)
{
// Merge each file to the configuration array
@@ -54,7 +50,7 @@ class Kohana_Config_File extends Config_Reader {
}
}
return parent::load($group, $config);
return $config;
}
} // End Kohana_Config_File
} // End Kohana_Config

View File

@@ -0,0 +1,130 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* The group wrapper acts as an interface to all the config directives
* gathered from across the system.
*
* This is the object returned from Kohana_Config::load
*
* Any modifications to configuration items should be done through an instance of this object
*
* @package Kohana
* @category Configuration
* @author Kohana Team
* @copyright (c) 2012 Kohana Team
* @license http://kohanaphp.com/license
*/
class Kohana_Config_Group extends ArrayObject {
/**
* Reference the config object that created this group
* Used when updating config
* @var Kohana_Config
*/
protected $_parent_instance = NULL;
/**
* The group this config is for
* Used when updating config items
* @var string
*/
protected $_group_name = '';
/**
* Constructs the group object. Kohana_Config passes the config group
* and its config items to the object here.
*
* @param Kohana_Config $instance "Owning" instance of Kohana_Config
* @param string $group The group name
* @param array $config Group's config
*/
public function __construct(Kohana_Config $instance, $group, array $config = array())
{
$this->_parent_instance = $instance;
$this->_group_name = $group;
parent::__construct($config, ArrayObject::ARRAY_AS_PROPS);
}
/**
* Return the current group in serialized form.
*
* echo $config;
*
* @return string
*/
public function __toString()
{
return serialize($this->getArrayCopy());
}
/**
* Alias for getArrayCopy()
*
* @return array Array copy of the group's config
*/
public function as_array()
{
return $this->getArrayCopy();
}
/**
* Returns the config group's name
*
* @return string The group name
*/
public function group_name()
{
return $this->_group_name;
}
/**
* Get a variable from the configuration or return the default value.
*
* $value = $config->get($key);
*
* @param string $key array key
* @param mixed $default default value
* @return mixed
*/
public function get($key, $default = NULL)
{
return $this->offsetExists($key) ? $this->offsetGet($key) : $default;
}
/**
* Sets a value in the configuration array.
*
* $config->set($key, $new_value);
*
* @param string $key array key
* @param mixed $value array value
* @return $this
*/
public function set($key, $value)
{
$this->offsetSet($key, $value);
return $this;
}
/**
* Overrides ArrayObject::offsetSet()
* This method is called when config is changed via
*
* $config->var = 'asd';
*
* // OR
*
* $config['var'] = 'asd';
*
* @param string $key The key of the config item we're changing
* @param mixed $value The new array value
*/
public function offsetSet($key, $value)
{
$this->_parent_instance->_write_config($this->_group_name, $key, $value);
return parent::offsetSet($key, $value);
}
}

View File

@@ -0,0 +1,25 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Interface for config readers
*
* @package Kohana
* @category Configuration
* @author Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
interface Kohana_Config_Reader extends Kohana_Config_Source
{
/**
* Tries to load the specificed configuration group
*
* Returns FALSE if group does not exist or an array if it does
*
* @param string $group Configuration group
* @return boolean|array
*/
public function load($group);
}

View File

@@ -0,0 +1,14 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Base Config source Interface
*
* Used to identify either config readers or writers when calling [Kohana_Config::attach()]
*
* @package Kohana
* @category Configuration
* @author Kohana Team
* @copyright (c) 2012 Kohana Team
* @license http://kohanaphp.com/license
*/
interface Kohana_Config_Source {}

View File

@@ -0,0 +1,27 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Interface for config writers
*
* Specifies the methods that a config writer must implement
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaphp.com/license
*/
interface Kohana_Config_Writer extends Kohana_Config_Source
{
/**
* Writes the passed config for $group
*
* Returns chainable instance on success or throws
* Kohana_Config_Exception on failure
*
* @param string $group The config group
* @param string $key The config key to write to
* @param array $config The configuration to write
* @return boolean
*/
public function write($group, $key, $config);
}

View File

@@ -0,0 +1,145 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Abstract controller class. Controllers should only be created using a [Request].
*
* Controllers methods will be automatically called in the following order by
* the request:
*
* $controller = new Controller_Foo($request);
* $controller->before();
* $controller->action_bar();
* $controller->after();
*
* The controller action should add the output it creates to
* `$this->response->body($output)`, typically in the form of a [View], during the
* "action" part of execution.
*
* @package Kohana
* @category Controller
* @author Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
abstract class Kohana_Controller {
/**
* @var Request Request that created the controller
*/
public $request;
/**
* @var Response The response that will be returned from controller
*/
public $response;
/**
* Creates a new controller instance. Each controller must be constructed
* with the request object that created it.
*
* @param Request $request Request that created the controller
* @param Response $response The request's response
* @return void
*/
public function __construct(Request $request, Response $response)
{
// Assign the request to the controller
$this->request = $request;
// Assign a response to the controller
$this->response = $response;
}
/**
* Executes the given action and calls the [Controller::before] and [Controller::after] methods.
*
* Can also be used to catch exceptions from actions in a single place.
*
* 1. Before the controller action is called, the [Controller::before] method
* will be called.
* 2. Next the controller action will be called.
* 3. After the controller action is called, the [Controller::after] method
* will be called.
*
* @throws HTTP_Exception_404
* @return Response
*/
public function execute()
{
// Execute the "before action" method
$this->before();
// Determine the action to use
$action = 'action_'.$this->request->action();
// If the action doesn't exist, it's a 404
if ( ! method_exists($this, $action))
{
throw HTTP_Exception::factory(404,
'The requested URL :uri was not found on this server.',
array(':uri' => $this->request->uri())
)->request($this->request);
}
// Execute the action itself
$this->{$action}();
// Execute the "after action" method
$this->after();
// Return the response
return $this->response;
}
/**
* Automatically executed before the controller action. Can be used to set
* class properties, do authorization checks, and execute other custom code.
*
* @return void
*/
public function before()
{
// Nothing by default
}
/**
* Automatically executed after the controller action. Can be used to apply
* transformation to the response, add extra output, and execute
* other custom code.
*
* @return void
*/
public function after()
{
// Nothing by default
}
/**
* Issues a HTTP redirect.
*
* Proxies to the [HTTP::redirect] method.
*
* @param string $uri URI to redirect to
* @param int $code HTTP Status code to use for the redirect
* @throws HTTP_Exception
*/
public static function redirect($uri = '', $code = 302)
{
return HTTP::redirect($uri, $code);
}
/**
* Checks the browser cache to see the response needs to be returned,
* execution will halt and a 304 Not Modified will be sent if the
* browser cache is up to date.
*
* $this->check_cache(sha1($content));
*
* @param string $etag Resource Etag
* @return Response
*/
protected function check_cache($etag = NULL)
{
return HTTP::check_cache($this->request, $this->response, $etag);
}
} // End Controller

View File

@@ -1,11 +1,11 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Abstract controller class for automatic templating.
*
* @package Kohana
* @category Controller
* @author Kohana Team
* @copyright (c) 2008-2011 Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
abstract class Kohana_Controller_Template extends Controller {
@@ -25,13 +25,13 @@ abstract class Kohana_Controller_Template extends Controller {
*/
public function before()
{
parent::before();
if ($this->auto_render === TRUE)
{
// Load the template
$this->template = View::factory($this->template);
}
return parent::before();
}
/**
@@ -44,7 +44,7 @@ abstract class Kohana_Controller_Template extends Controller {
$this->response->body($this->template->render());
}
return parent::after();
parent::after();
}
} // End Controller_Template

View File

@@ -1,11 +1,11 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Cookie helper.
*
* @package Kohana
* @category Helpers
* @author Kohana Team
* @copyright (c) 2008-2011 Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Cookie {
@@ -48,8 +48,8 @@ class Kohana_Cookie {
* // Get the "theme" cookie, or use "blue" if the cookie does not exist
* $theme = Cookie::get('theme', 'blue');
*
* @param string cookie name
* @param mixed default value to return
* @param string $key cookie name
* @param mixed $default default value to return
* @return string
*/
public static function get($key, $default = NULL)
@@ -91,9 +91,9 @@ class Kohana_Cookie {
* // Set the "theme" cookie
* Cookie::set('theme', 'red');
*
* @param string name of cookie
* @param string value of cookie
* @param integer lifetime in seconds
* @param string $name name of cookie
* @param string $value value of cookie
* @param integer $expiration lifetime in seconds
* @return boolean
* @uses Cookie::salt
*/
@@ -122,7 +122,7 @@ class Kohana_Cookie {
*
* Cookie::delete('theme');
*
* @param string cookie name
* @param string $name cookie name
* @return boolean
* @uses Cookie::set
*/
@@ -140,8 +140,8 @@ class Kohana_Cookie {
*
* $salt = Cookie::salt('theme', 'red');
*
* @param string name of cookie
* @param string value of cookie
* @param string $name name of cookie
* @param string $value value of cookie
* @return string
*/
public static function salt($name, $value)

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Contains the most low-level helpers methods in Kohana:
*
@@ -10,23 +10,23 @@
* @package Kohana
* @category Base
* @author Kohana Team
* @copyright (c) 2008-2011 Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Core {
// Release version and codename
const VERSION = '3.1.3.1';
const CODENAME = 'araea';
const VERSION = '3.3.0';
const CODENAME = 'badius';
// Common environment type constants for consistency and convenience
const PRODUCTION = 1;
const STAGING = 2;
const TESTING = 3;
const DEVELOPMENT = 4;
const PRODUCTION = 10;
const STAGING = 20;
const TESTING = 30;
const DEVELOPMENT = 40;
// Security check that is added to all generated PHP files
const FILE_SECURITY = '<?php defined(\'SYSPATH\') or die(\'No direct script access.\');';
const FILE_SECURITY = '<?php defined(\'SYSPATH\') OR die(\'No direct script access.\');';
// Format of cache files: header, cache name, and data
const FILE_CACHE = ":header \n\n// :name\n\n:data\n";
@@ -36,11 +36,6 @@ class Kohana_Core {
*/
public static $environment = Kohana::DEVELOPMENT;
/**
* @var boolean True if Kohana is running from the command line
*/
public static $is_cli = FALSE;
/**
* @var boolean True if Kohana is running on windows
*/
@@ -51,11 +46,6 @@ class Kohana_Core {
*/
public static $magic_quotes = FALSE;
/**
* @var boolean Should errors and exceptions be logged
*/
public static $log_errors = FALSE;
/**
* @var boolean TRUE if PHP safe mode is on
*/
@@ -180,10 +170,12 @@ class Kohana_Core {
* `string` | cache_dir | Kohana's cache directory. Used by [Kohana::cache] for simple internal caching, like [Fragments](kohana/fragments) and **\[caching database queries](this should link somewhere)**. This has nothing to do with the [Cache module](cache). | `APPPATH."cache"`
* `integer` | cache_life | Lifetime, in seconds, of items cached by [Kohana::cache] | `60`
* `boolean` | errors | Should Kohana catch PHP errors and uncaught Exceptions and show the `error_view`. See [Error Handling](kohana/errors) for more info. <br /> <br /> Recommended setting: `TRUE` while developing, `FALSE` on production servers. | `TRUE`
* `boolean` | profile | Whether to enable the [Profiler](kohana/profiling). <br /> <br />Recommended setting: `TRUE` while developing, `FALSE` on production servers. | `TRUE` * `boolean` | caching | Cache file locations to speed up [Kohana::find_file]. This has nothing to do with [Kohana::cache], [Fragments](kohana/fragments) or the [Cache module](cache). <br /> <br /> Recommended setting: `FALSE` while developing, `TRUE` on production servers. | `FALSE`
* `boolean` | profile | Whether to enable the [Profiler](kohana/profiling). <br /> <br />Recommended setting: `TRUE` while developing, `FALSE` on production servers. | `TRUE`
* `boolean` | caching | Cache file locations to speed up [Kohana::find_file]. This has nothing to do with [Kohana::cache], [Fragments](kohana/fragments) or the [Cache module](cache). <br /> <br /> Recommended setting: `FALSE` while developing, `TRUE` on production servers. | `FALSE`
* `boolean` | expose | Set the X-Powered-By header
*
* @throws Kohana_Exception
* @param array Array of settings. See above.
* @param array $settings Array of settings. See above.
* @return void
* @uses Kohana::globals
* @uses Kohana::sanitize
@@ -225,6 +217,14 @@ class Kohana_Core {
set_error_handler(array('Kohana', 'error_handler'));
}
/**
* Enable xdebug parameter collection in development mode to improve fatal stack traces.
*/
if (Kohana::$environment == Kohana::DEVELOPMENT AND extension_loaded('xdebug'))
{
ini_set('xdebug.collect_params', 3);
}
// Enable the Kohana shutdown handler, which catches E_FATAL errors.
register_shutdown_function(array('Kohana', 'shutdown_handler'));
@@ -239,9 +239,6 @@ class Kohana_Core {
Kohana::$expose = (bool) $settings['expose'];
}
// Determine if we are running in a command line environment
Kohana::$is_cli = (PHP_SAPI === 'cli');
// Determine if we are running in a Windows environment
Kohana::$is_windows = (DIRECTORY_SEPARATOR === '\\');
@@ -325,18 +322,24 @@ class Kohana_Core {
}
// Determine if the extremely evil magic quotes are enabled
Kohana::$magic_quotes = (bool) get_magic_quotes_gpc();
Kohana::$magic_quotes = (version_compare(PHP_VERSION, '5.4') < 0 AND get_magic_quotes_gpc());
// Sanitize all request variables
$_GET = Kohana::sanitize($_GET);
$_POST = Kohana::sanitize($_POST);
$_COOKIE = Kohana::sanitize($_COOKIE);
// Load the logger
Kohana::$log = Log::instance();
// Load the logger if one doesn't already exist
if ( ! Kohana::$log instanceof Log)
{
Kohana::$log = Log::instance();
}
// Load the config
Kohana::$config = Config::instance();
// Load the config if one doesn't already exist
if ( ! Kohana::$config instanceof Config)
{
Kohana::$config = new Config;
}
}
/**
@@ -431,8 +434,8 @@ class Kohana_Core {
* - Strips slashes if magic quotes are enabled
* - Normalizes all newlines to LF
*
* @param mixed any variable
* @return mixed sanitized variable
* @param mixed $value any variable
* @return mixed sanitized variable
*/
public static function sanitize($value)
{
@@ -467,12 +470,14 @@ class Kohana_Core {
* naming conventions](kohana/conventions#class-names-and-file-location).
* See [Loading Classes](kohana/autoloading) for more information.
*
* Class names are converted to file names by making the class name
* lowercase and converting underscores to slashes:
*
* // Loads classes/my/class/name.php
* // Loads classes/My/Class/Name.php
* Kohana::auto_load('My_Class_Name');
*
* or with a custom directory:
*
* // Loads vendor/My/Class/Name.php
* Kohana::auto_load('My_Class_Name', 'vendor');
*
* You should never have to call this function, as simply calling a class
* will cause it to be called.
*
@@ -480,33 +485,65 @@ class Kohana_Core {
*
* spl_autoload_register(array('Kohana', 'auto_load'));
*
* @param string class name
* @param string $class Class name
* @param string $directory Directory to load from
* @return boolean
*/
public static function auto_load($class)
public static function auto_load($class, $directory = 'classes')
{
try
// Transform the class name according to PSR-0
$class = ltrim($class, '\\');
$file = '';
$namespace = '';
if ($last_namespace_position = strripos($class, '\\'))
{
// Transform the class name into a path
$file = str_replace('_', '/', strtolower($class));
if ($path = Kohana::find_file('classes', $file))
{
// Load the class file
require $path;
// Class has been found
return TRUE;
}
// Class is not in the filesystem
return FALSE;
$namespace = substr($class, 0, $last_namespace_position);
$class = substr($class, $last_namespace_position + 1);
$file = str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR;
}
catch (Exception $e)
$file .= str_replace('_', DIRECTORY_SEPARATOR, $class);
if ($path = Kohana::find_file($directory, $file))
{
Kohana_Exception::handler($e);
die;
// Load the class file
require $path;
// Class has been found
return TRUE;
}
// Class is not in the filesystem
return FALSE;
}
/**
* Provides auto-loading support of classes that follow Kohana's old class
* naming conventions.
*
* This is included for compatibility purposes with older modules.
*
* @param string $class Class name
* @param string $directory Directory to load from
* @return boolean
*/
public static function auto_load_lowercase($class, $directory = 'classes')
{
// Transform the class name into a path
$file = str_replace('_', DIRECTORY_SEPARATOR, strtolower($class));
if ($path = Kohana::find_file($directory, $file))
{
// Load the class file
require $path;
// Class has been found
return TRUE;
}
// Class is not in the filesystem
return FALSE;
}
/**
@@ -515,8 +552,8 @@ class Kohana_Core {
*
* Kohana::modules(array('modules/foo', MODPATH.'bar'));
*
* @param array list of module paths
* @return array enabled modules
* @param array $modules list of module paths
* @return array enabled modules
*/
public static function modules(array $modules = NULL)
{
@@ -539,7 +576,10 @@ class Kohana_Core {
else
{
// This module is invalid, remove it
unset($modules[$name]);
throw new Kohana_Exception('Attempted to load an invalid or missing module \':module\' at \':path\'', array(
':module' => $name,
':path' => Debug::path($path),
));
}
}
@@ -599,12 +639,12 @@ class Kohana_Core {
* // Returns an array of all the "mimes" configuration files
* Kohana::find_file('config', 'mimes');
*
* @param string directory name (views, i18n, classes, extensions, etc.)
* @param string filename with subdirectory
* @param string extension to search for
* @param boolean return an array of files?
* @return array a list of files when $array is TRUE
* @return string single file path
* @param string $dir directory name (views, i18n, classes, extensions, etc.)
* @param string $file filename with subdirectory
* @param string $ext extension to search for
* @param boolean $array return an array of files?
* @return array a list of files when $array is TRUE
* @return string single file path
*/
public static function find_file($dir, $file, $ext = NULL, $array = FALSE)
{
@@ -700,8 +740,8 @@ class Kohana_Core {
* // Find all view files.
* $views = Kohana::list_files('views');
*
* @param string directory name
* @param array list of paths to search
* @param string $directory directory name
* @param array $paths list of paths to search
* @return array
*/
public static function list_files($directory = NULL, array $paths = NULL)
@@ -781,7 +821,7 @@ class Kohana_Core {
*
* $foo = Kohana::load('foo.php');
*
* @param string
* @param string $file
* @return mixed
*/
public static function load($file)
@@ -789,48 +829,6 @@ class Kohana_Core {
return include $file;
}
/**
* Returns the configuration array for the requested group. See
* [configuration files](kohana/files/config) for more information.
*
* // Get all the configuration in config/database.php
* $config = Kohana::config('database');
*
* // Get only the default connection configuration
* $default = Kohana::config('database.default')
*
* // Get only the hostname of the default connection
* $host = Kohana::config('database.default.connection.hostname')
*
* @param string group name
* @return Config
*/
public static function config($group)
{
static $config;
if (strpos($group, '.') !== FALSE)
{
// Split the config group and path
list ($group, $path) = explode('.', $group, 2);
}
if ( ! isset($config[$group]))
{
// Load the config group into the cache
$config[$group] = Kohana::$config->load($group);
}
if (isset($path))
{
return Arr::path($config[$group], $path, NULL, '.');
}
else
{
return $config[$group];
}
}
/**
* Provides simple file-based caching for strings and arrays:
*
@@ -849,9 +847,9 @@ class Kohana_Core {
* [ref-var]: http://php.net/var_export
*
* @throws Kohana_Exception
* @param string name of the cache
* @param mixed data to cache
* @param integer number of seconds the cache is valid for
* @param string $name name of the cache
* @param mixed $data data to cache
* @param integer $lifetime number of seconds the cache is valid for
* @return mixed for getting
* @return boolean for setting
*/
@@ -937,9 +935,9 @@ class Kohana_Core {
* // Get "username" from messages/text.php
* $username = Kohana::message('text', 'username');
*
* @param string file name
* @param string key path to get
* @param mixed default value if the path does not exist
* @param string $file file name
* @param string $path key path to get
* @param mixed $default default value if the path does not exist
* @return string message string for the given path
* @return array complete message list, when no path is specified
* @uses Arr::merge
@@ -1027,7 +1025,7 @@ class Kohana_Core {
if (Kohana::$errors AND $error = error_get_last() AND in_array($error['type'], Kohana::$shutdown_errors))
{
// Clean the output buffer
ob_get_level() and ob_clean();
ob_get_level() AND ob_clean();
// Fake an exception for nice debugging
Kohana_Exception::handler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
@@ -1037,4 +1035,14 @@ class Kohana_Core {
}
}
/**
* Generates a version string based on the variables defined above.
*
* @return string
*/
public static function version()
{
return 'Kohana Framework '.Kohana::VERSION.' ('.Kohana::CODENAME.')';
}
} // End Kohana

View File

@@ -1,11 +1,11 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Date helper.
*
* @package Kohana
* @category Helpers
* @author Kohana Team
* @copyright (c) 2007-2011 Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Date {
@@ -44,9 +44,9 @@ class Kohana_Date {
* [!!] A list of time zones that PHP supports can be found at
* <http://php.net/timezones>.
*
* @param string timezone that to find the offset of
* @param string timezone used as the baseline
* @param mixed UNIX timestamp or date string
* @param string $remote timezone that to find the offset of
* @param string $local timezone used as the baseline
* @param mixed $now UNIX timestamp or date string
* @return integer
*/
public static function offset($remote, $local = NULL, $now = NULL)
@@ -83,10 +83,10 @@ class Kohana_Date {
*
* $seconds = Date::seconds(); // 01, 02, 03, ..., 58, 59, 60
*
* @param integer amount to increment each step by, 1 to 30
* @param integer start value
* @param integer end value
* @return array A mirrored (foo => foo) array from 1-60.
* @param integer $step amount to increment each step by, 1 to 30
* @param integer $start start value
* @param integer $end end value
* @return array A mirrored (foo => foo) array from 1-60.
*/
public static function seconds($step = 1, $start = 0, $end = 60)
{
@@ -110,8 +110,8 @@ class Kohana_Date {
* $minutes = Date::minutes(); // 05, 10, 15, ..., 50, 55, 60
*
* @uses Date::seconds
* @param integer amount to increment each step by, 1 to 30
* @return array A mirrored (foo => foo) array from 1-60.
* @param integer $step amount to increment each step by, 1 to 30
* @return array A mirrored (foo => foo) array from 1-60.
*/
public static function minutes($step = 5)
{
@@ -128,10 +128,10 @@ class Kohana_Date {
*
* $hours = Date::hours(); // 01, 02, 03, ..., 10, 11, 12
*
* @param integer amount to increment each step by
* @param boolean use 24-hour time
* @param integer the hour to start at
* @return array A mirrored (foo => foo) array from start-12 or start-23.
* @param integer $step amount to increment each step by
* @param boolean $long use 24-hour time
* @param integer $start the hour to start at
* @return array A mirrored (foo => foo) array from start-12 or start-23.
*/
public static function hours($step = 1, $long = FALSE, $start = NULL)
{
@@ -165,7 +165,7 @@ class Kohana_Date {
* $type = Date::ampm(12); // PM
* $type = Date::ampm(1); // AM
*
* @param integer number of the hour
* @param integer $hour number of the hour
* @return string
*/
public static function ampm($hour)
@@ -181,8 +181,8 @@ class Kohana_Date {
*
* $hour = Date::adjust(3, 'pm'); // 15
*
* @param integer hour to adjust
* @param string AM or PM
* @param integer $hour hour to adjust
* @param string $ampm AM or PM
* @return string
*/
public static function adjust($hour, $ampm)
@@ -215,9 +215,9 @@ class Kohana_Date {
*
* Date::days(4, 2010); // 1, 2, 3, ..., 28, 29, 30
*
* @param integer number of month
* @param integer number of year to check month, defaults to the current year
* @return array A mirrored (foo => foo) array of the days.
* @param integer $month number of month
* @param integer $year number of year to check month, defaults to the current year
* @return array A mirrored (foo => foo) array of the days.
*/
public static function days($month, $year = FALSE)
{
@@ -270,14 +270,14 @@ class Kohana_Date {
* // array(1 => 'Jan', 2 => 'Feb', ..., 12 => 'Dec')
*
* @uses Date::hours
* @param string The format to use for months
* @return array An array of months based on the specified format
* @param string $format The format to use for months
* @return array An array of months based on the specified format
*/
public static function months($format = NULL)
{
$months = array();
if ($format === DATE::MONTHS_LONG OR $format === DATE::MONTHS_SHORT)
if ($format === Date::MONTHS_LONG OR $format === Date::MONTHS_SHORT)
{
for ($i = 1; $i <= 12; ++$i)
{
@@ -299,8 +299,8 @@ class Kohana_Date {
*
* $years = Date::years(2000, 2010); // 2000, 2001, ..., 2009, 2010
*
* @param integer starting year (default is current year - 5)
* @param integer ending year (default is current year + 5)
* @param integer $start starting year (default is current year - 5)
* @param integer $end ending year (default is current year + 5)
* @return array
*/
public static function years($start = FALSE, $end = FALSE)
@@ -327,9 +327,9 @@ class Kohana_Date {
* $span = Date::span(60, 182, 'minutes,seconds'); // array('minutes' => 2, 'seconds' => 2)
* $span = Date::span(60, 182, 'minutes'); // 2
*
* @param integer timestamp to find the span of
* @param integer timestamp to use as the baseline
* @param string formatting string
* @param integer $remote timestamp to find the span of
* @param integer $local timestamp to use as the baseline
* @param string $output formatting string
* @return string when only a single output is requested
* @return array associative list of all outputs requested
*/
@@ -419,8 +419,8 @@ class Kohana_Date {
* however this parameter shouldn't be needed in normal usage and is only
* included for unit tests
*
* @param integer "remote" timestamp
* @param integer "local" timestamp, defaults to time()
* @param integer $timestamp "remote" timestamp
* @param integer $local_timestamp "local" timestamp, defaults to time()
* @return string
*/
public static function fuzzy_span($timestamp, $local_timestamp = NULL)
@@ -530,7 +530,7 @@ class Kohana_Date {
*
* $dos = Date::unix2dos($unix);
*
* @param integer UNIX timestamp
* @param integer $timestamp UNIX timestamp
* @return integer
*/
public static function unix2dos($timestamp = FALSE)
@@ -558,7 +558,7 @@ class Kohana_Date {
*
* $unix = Date::dos2unix($dos);
*
* @param integer DOS timestamp
* @param integer $timestamp DOS timestamp
* @return integer
*/
public static function dos2unix($timestamp = FALSE)
@@ -578,9 +578,10 @@ class Kohana_Date {
*
* $time = Date::formatted_time('5 minutes ago');
*
* @see http://php.net/manual/en/datetime.construct.php
* @param string datetime_str datetime string
* @param string timestamp_format timestamp format
* @link http://www.php.net/manual/datetime.construct
* @param string $datetime_str datetime string
* @param string $timestamp_format timestamp format
* @param string $timezone timezone identifier
* @return string
*/
public static function formatted_time($datetime_str = 'now', $timestamp_format = NULL, $timezone = NULL)
@@ -588,9 +589,13 @@ class Kohana_Date {
$timestamp_format = ($timestamp_format == NULL) ? Date::$timestamp_format : $timestamp_format;
$timezone = ($timezone === NULL) ? Date::$timezone : $timezone;
$time = new DateTime($datetime_str, new DateTimeZone(
$timezone ? $timezone : date_default_timezone_get()
));
$tz = new DateTimeZone($timezone ? $timezone : date_default_timezone_get());
$time = new DateTime($datetime_str, $tz);
if ($time->getTimeZone()->getName() !== $tz->getName())
{
$time->setTimeZone($tz);
}
return $time->format($timestamp_format);
}

View File

@@ -1,11 +1,11 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Contains debugging and dumping tools.
*
* @package Kohana
* @category Base
* @author Kohana Team
* @copyright (c) 2008-2011 Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaphp.com/license
*/
class Kohana_Debug {
@@ -17,8 +17,7 @@ class Kohana_Debug {
* // Displays the type and value of each variable
* echo Debug::vars($foo, $bar, $baz);
*
* @param mixed variable to debug
* @param ...
* @param mixed $var,... variable to debug
* @return string
*/
public static function vars()
@@ -43,24 +42,26 @@ class Kohana_Debug {
*
* Borrows heavily on concepts from the Debug class of [Nette](http://nettephp.com/).
*
* @param mixed variable to dump
* @param integer maximum length of strings
* @param mixed $value variable to dump
* @param integer $length maximum length of strings
* @param integer $level_recursion recursion limit
* @return string
*/
public static function dump($value, $length = 128)
public static function dump($value, $length = 128, $level_recursion = 10)
{
return Debug::_dump($value, $length);
return Debug::_dump($value, $length, $level_recursion);
}
/**
* Helper for Debug::dump(), handles recursion in arrays and objects.
*
* @param mixed variable to dump
* @param integer maximum length of strings
* @param integer recursion level (internal)
* @param mixed $var variable to dump
* @param integer $length maximum length of strings
* @param integer $limit recursion limit
* @param integer $level current recursion level (internal usage only!)
* @return string
*/
protected static function _dump( & $var, $length = 128, $level = 0)
protected static function _dump( & $var, $length = 128, $limit = 10, $level = 0)
{
if ($var === NULL)
{
@@ -144,7 +145,7 @@ class Kohana_Debug {
{
$output[] = "(\n$space$s*RECURSION*\n$space)";
}
elseif ($level < 5)
elseif ($level < $limit)
{
$output[] = "<span>(";
@@ -157,7 +158,7 @@ class Kohana_Debug {
$key = '"'.htmlspecialchars($key, ENT_NOQUOTES, Kohana::$charset).'"';
}
$output[] = "$space$s$key => ".Debug::_dump($val, $length, $level + 1);
$output[] = "$space$s$key => ".Debug::_dump($val, $length, $limit, $level + 1);
}
unset($var[$marker]);
@@ -194,7 +195,7 @@ class Kohana_Debug {
{
$output[] = "{\n$space$s*RECURSION*\n$space}";
}
elseif ($level < 10)
elseif ($level < $limit)
{
$output[] = "<code>{";
@@ -214,7 +215,7 @@ class Kohana_Debug {
$access = '<small>public</small>';
}
$output[] = "$space$s$access $key => ".Debug::_dump($val, $length, $level + 1);
$output[] = "$space$s$access $key => ".Debug::_dump($val, $length, $limit, $level + 1);
}
unset($objects[$hash]);
@@ -242,7 +243,7 @@ class Kohana_Debug {
* // Displays SYSPATH/classes/kohana.php
* echo Debug::path(Kohana::find_file('classes', 'kohana'));
*
* @param string path to debug
* @param string $file path to debug
* @return string
*/
public static function path($file)
@@ -278,9 +279,9 @@ class Kohana_Debug {
* // Highlights the current line of the current file
* echo Debug::source(__FILE__, __LINE__);
*
* @param string file to open
* @param integer line number to highlight
* @param integer number of padding lines
* @param string $file file to open
* @param integer $line_number line number to highlight
* @param integer $padding number of padding lines
* @return string source of file
* @return FALSE file is unreadable
*/
@@ -344,7 +345,7 @@ class Kohana_Debug {
* // Displays the entire current backtrace
* echo implode('<br/>', Debug::trace());
*
* @param string path to debug
* @param array $trace
* @return string
*/
public static function trace(array $trace = NULL)

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* The Encrypt library provides two-way encryption of text and binary strings
* using the [Mcrypt](http://php.net/mcrypt) extension, which consists of three
@@ -20,7 +20,7 @@
* @package Kohana
* @category Security
* @author Kohana Team
* @copyright (c) 2007-2011 Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Encrypt {
@@ -46,7 +46,7 @@ class Kohana_Encrypt {
*
* $encrypt = Encrypt::instance();
*
* @param string configuration group name
* @param string $name configuration group name
* @return Encrypt
*/
public static function instance($name = NULL)
@@ -60,7 +60,7 @@ class Kohana_Encrypt {
if ( ! isset(Encrypt::$instances[$name]))
{
// Load the configuration data
$config = Kohana::config('encrypt')->$name;
$config = Kohana::$config->load('encrypt')->$name;
if ( ! isset($config['key']))
{
@@ -91,9 +91,9 @@ class Kohana_Encrypt {
/**
* Creates a new mcrypt wrapper.
*
* @param string encryption key
* @param string mcrypt mode
* @param string mcrypt cipher
* @param string $key encryption key
* @param string $mode mcrypt mode
* @param string $cipher mcrypt cipher
*/
public function __construct($key, $mode, $cipher)
{
@@ -124,7 +124,7 @@ class Kohana_Encrypt {
* to convert it to a string. This string can be stored in a database,
* displayed, and passed using most other means without corruption.
*
* @param string data to be encrypted
* @param string $data data to be encrypted
* @return string
*/
public function encode($data)
@@ -179,7 +179,7 @@ class Kohana_Encrypt {
*
* $data = $encrypt->decode($data);
*
* @param string encoded string to be decrypted
* @param string $data encoded string to be decrypted
* @return FALSE if decryption fails
* @return string
*/

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_Exception extends Kohana_Kohana_Exception {}

View File

@@ -1,11 +1,11 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* RSS and Atom feed helper.
*
* @package Kohana
* @category Helpers
* @author Kohana Team
* @copyright (c) 2007-2011 Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Feed {
@@ -13,8 +13,8 @@ class Kohana_Feed {
/**
* Parses a remote feed into an array.
*
* @param string remote feed URL
* @param integer item limit to fetch
* @param string $feed remote feed URL
* @param integer $limit item limit to fetch
* @return array
*/
public static function parse($feed, $limit = 0)
@@ -30,10 +30,20 @@ class Kohana_Feed {
$error_level = error_reporting(0);
// Allow loading by filename or raw XML string
$load = (is_file($feed) OR Valid::url($feed)) ? 'simplexml_load_file' : 'simplexml_load_string';
if (Valid::url($feed))
{
// Use native Request client to get remote contents
$response = Request::factory($feed)->execute();
$feed = $response->body();
}
elseif (is_file($feed))
{
// Get file contents
$feed = file_get_contents($feed);
}
// Load the feed
$feed = $load($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
$feed = simplexml_load_string($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
// Restore error reporting
error_reporting($error_level);
@@ -42,7 +52,7 @@ class Kohana_Feed {
if ($feed === FALSE)
return array();
$namespaces = $feed->getNamespaces(true);
$namespaces = $feed->getNamespaces(TRUE);
// Detect the feed type. RSS 1.0/2.0 and Atom 1.0 are supported.
$feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry;
@@ -70,13 +80,12 @@ class Kohana_Feed {
/**
* Creates a feed from the given parameters.
*
* @param array feed information
* @param array items to add to the feed
* @param string define which format to use (only rss2 is supported)
* @param string define which encoding to use
* @param array $info feed information
* @param array $items items to add to the feed
* @param string $encoding define which encoding to use
* @return string
*/
public static function create($info, $items, $format = 'rss2', $encoding = 'UTF-8')
public static function create($info, $items, $encoding = 'UTF-8')
{
$info += array('title' => 'Generated Feed', 'link' => '', 'generator' => 'KohanaPHP');

View File

@@ -1,11 +1,11 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* File helper class.
*
* @package Kohana
* @category Helpers
* @author Kohana Team
* @copyright (c) 2007-2011 Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_File {
@@ -17,7 +17,7 @@ class Kohana_File {
*
* $mime = File::mime($file);
*
* @param string file name or path
* @param string $filename file name or path
* @return string mime type on success
* @return FALSE on failure
*/
@@ -66,14 +66,14 @@ class Kohana_File {
*
* $mime = File::mime_by_ext('png'); // "image/png"
*
* @param string extension: php, pdf, txt, etc
* @param string $extension php, pdf, txt, etc
* @return string mime type on success
* @return FALSE on failure
*/
public static function mime_by_ext($extension)
{
// Load all of the mime types
$mimes = Kohana::config('mimes');
$mimes = Kohana::$config->load('mimes');
return isset($mimes[$extension]) ? $mimes[$extension][0] : FALSE;
}
@@ -88,7 +88,7 @@ class Kohana_File {
public static function mimes_by_ext($extension)
{
// Load all of the mime types
$mimes = Kohana::config('mimes');
$mimes = Kohana::$config->load('mimes');
return isset($mimes[$extension]) ? ( (array) $mimes[$extension]) : array();
}
@@ -106,7 +106,7 @@ class Kohana_File {
// Fill the static array
if (empty($types))
{
foreach (Kohana::config('mimes') as $ext => $mimes)
foreach (Kohana::$config->load('mimes') as $ext => $mimes)
{
foreach ($mimes as $mime)
{
@@ -148,10 +148,9 @@ class Kohana_File {
*
* $count = File::split($file);
*
* @param string file to be split
* @param string directory to output to, defaults to the same directory as the file
* @param integer size, in MB, for each piece to be
* @return integer The number of pieces that were created
* @param string $filename file to be split
* @param integer $piece_size size, in MB, for each piece to be
* @return integer The number of pieces that were created
*/
public static function split($filename, $piece_size = 10)
{
@@ -204,9 +203,8 @@ class Kohana_File {
*
* $count = File::join($file);
*
* @param string split filename, without .000 extension
* @param string output filename, if different then an the filename
* @return integer The number of pieces that were joined.
* @param string $filename split filename, without .000 extension
* @return integer The number of pieces that were joined.
*/
public static function join($filename)
{

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Form helper class. Unless otherwise noted, all generated HTML will be made
* safe using the [HTML::chars] method. This prevents against simple XSS
@@ -8,7 +8,7 @@
* @package Kohana
* @category Helpers
* @author Kohana Team
* @copyright (c) 2007-2011 Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Form {
@@ -25,8 +25,8 @@ class Kohana_Form {
* // When "file" inputs are present, you must include the "enctype"
* echo Form::open(NULL, array('enctype' => 'multipart/form-data'));
*
* @param mixed form action, defaults to the current request URI, or [Request] class to use
* @param array html attributes
* @param mixed $action form action, defaults to the current request URI, or [Request] class to use
* @param array $attributes html attributes
* @return string
* @uses Request::instance
* @uses URL::site
@@ -40,10 +40,10 @@ class Kohana_Form {
$action = $action->uri();
}
if ($action === '')
if ( ! $action)
{
// Use only the base URI
$action = Kohana::$base_url;
// Allow empty form actions (submits back to the current url).
$action = '';
}
elseif (strpos($action, '://') === FALSE)
{
@@ -84,9 +84,9 @@ class Kohana_Form {
*
* echo Form::input('username', $username);
*
* @param string input name
* @param string input value
* @param array html attributes
* @param string $name input name
* @param string $value input value
* @param array $attributes html attributes
* @return string
* @uses HTML::attributes
*/
@@ -112,9 +112,9 @@ class Kohana_Form {
*
* echo Form::hidden('csrf', $token);
*
* @param string input name
* @param string input value
* @param array html attributes
* @param string $name input name
* @param string $value input value
* @param array $attributes html attributes
* @return string
* @uses Form::input
*/
@@ -130,9 +130,9 @@ class Kohana_Form {
*
* echo Form::password('password');
*
* @param string input name
* @param string input value
* @param array html attributes
* @param string $name input name
* @param string $value input value
* @param array $attributes html attributes
* @return string
* @uses Form::input
*/
@@ -148,8 +148,8 @@ class Kohana_Form {
*
* echo Form::file('image');
*
* @param string input name
* @param array html attributes
* @param string $name input name
* @param array $attributes html attributes
* @return string
* @uses Form::input
*/
@@ -165,10 +165,10 @@ class Kohana_Form {
*
* echo Form::checkbox('remember_me', 1, (bool) $remember);
*
* @param string input name
* @param string input value
* @param boolean checked status
* @param array html attributes
* @param string $name input name
* @param string $value input value
* @param boolean $checked checked status
* @param array $attributes html attributes
* @return string
* @uses Form::input
*/
@@ -179,7 +179,7 @@ class Kohana_Form {
if ($checked === TRUE)
{
// Make the checkbox active
$attributes['checked'] = 'checked';
$attributes[] = 'checked';
}
return Form::input($name, $value, $attributes);
@@ -191,10 +191,10 @@ class Kohana_Form {
* echo Form::radio('like_cats', 1, $cats);
* echo Form::radio('like_cats', 0, ! $cats);
*
* @param string input name
* @param string input value
* @param boolean checked status
* @param array html attributes
* @param string $name input name
* @param string $value input value
* @param boolean $checked checked status
* @param array $attributes html attributes
* @return string
* @uses Form::input
*/
@@ -205,7 +205,7 @@ class Kohana_Form {
if ($checked === TRUE)
{
// Make the radio active
$attributes['checked'] = 'checked';
$attributes[] = 'checked';
}
return Form::input($name, $value, $attributes);
@@ -216,10 +216,10 @@ class Kohana_Form {
*
* echo Form::textarea('about', $about);
*
* @param string textarea name
* @param string textarea body
* @param array html attributes
* @param boolean encode existing HTML characters
* @param string $name textarea name
* @param string $body textarea body
* @param array $attributes html attributes
* @param boolean $double_encode encode existing HTML characters
* @return string
* @uses HTML::attributes
* @uses HTML::chars
@@ -242,10 +242,10 @@ class Kohana_Form {
*
* [!!] Support for multiple selected options was added in v3.0.7.
*
* @param string input name
* @param array available options
* @param mixed selected option string, or an array of selected options
* @param array html attributes
* @param string $name input name
* @param array $options available options
* @param mixed $selected selected option string, or an array of selected options
* @param array $attributes html attributes
* @return string
* @uses HTML::attributes
*/
@@ -257,7 +257,7 @@ class Kohana_Form {
if (is_array($selected))
{
// This is a multi-select, god save us!
$attributes['multiple'] = 'multiple';
$attributes[] = 'multiple';
}
if ( ! is_array($selected))
@@ -302,7 +302,7 @@ class Kohana_Form {
if (in_array($_value, $selected))
{
// This option is selected
$option['selected'] = 'selected';
$option[] = 'selected';
}
// Change the option to the HTML string
@@ -325,7 +325,7 @@ class Kohana_Form {
if (in_array($value, $selected))
{
// This option is selected
$option['selected'] = 'selected';
$option[] = 'selected';
}
// Change the option to the HTML string
@@ -345,9 +345,9 @@ class Kohana_Form {
*
* echo Form::submit(NULL, 'Login');
*
* @param string input name
* @param string input value
* @param array html attributes
* @param string $name input name
* @param string $value input value
* @param array $attributes html attributes
* @return string
* @uses Form::input
*/
@@ -363,10 +363,10 @@ class Kohana_Form {
*
* echo Form::image(NULL, NULL, array('src' => 'media/img/login.png'));
*
* @param string input name
* @param string input value
* @param array html attributes
* @param boolean add index file to URL?
* @param string $name input name
* @param string $value input value
* @param array $attributes html attributes
* @param boolean $index add index file to URL?
* @return string
* @uses Form::input
*/
@@ -392,9 +392,9 @@ class Kohana_Form {
*
* echo Form::button('save', 'Save Profile', array('type' => 'submit'));
*
* @param string input name
* @param string input value
* @param array html attributes
* @param string $name input name
* @param string $body input value
* @param array $attributes html attributes
* @return string
* @uses HTML::attributes
*/
@@ -411,9 +411,9 @@ class Kohana_Form {
*
* echo Form::label('username', 'Username');
*
* @param string target input
* @param string label text
* @param array html attributes
* @param string $input target input
* @param string $text label text
* @param array $attributes html attributes
* @return string
* @uses HTML::attributes
*/

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* View fragment caching. This is primarily used to cache small parts of a view
* that rarely change. For instance, you may want to cache the footer of your
@@ -13,7 +13,7 @@
* @package Kohana
* @category Helpers
* @author Kohana Team
* @copyright (c) 2009-2011 Kohana Team
* @copyright (c) 2009-2012 Kohana Team
* @license http://kohanaframework.org/license
* @uses Kohana::cache
*/
@@ -39,8 +39,8 @@ class Kohana_Fragment {
*
* $key = Fragment::_cache_key('footer', TRUE);
*
* @param string fragment name
* @param boolean multilingual fragment support
* @param string $name fragment name
* @param boolean $i18n multilingual fragment support
* @return string
* @uses I18n::lang
* @since 3.0.4
@@ -69,9 +69,9 @@ class Kohana_Fragment {
* Fragment::save();
* }
*
* @param string fragment name
* @param integer fragment cache lifetime
* @param boolean multilingual fragment support
* @param string $name fragment name
* @param integer $lifetime fragment cache lifetime
* @param boolean $i18n multilingual fragment support
* @return boolean
*/
public static function load($name, $lifetime = NULL, $i18n = NULL)
@@ -134,8 +134,8 @@ class Kohana_Fragment {
*
* Fragment::delete($key);
*
* @param string fragment name
* @param boolean multilingual fragment support
* @param string $name fragment name
* @param boolean $i18n multilingual fragment support
* @return void
*/
public static function delete($name, $i18n = NULL)

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* HTML helper class. Provides generic methods for generating various HTML
* tags and making output HTML safe.
@@ -6,7 +6,7 @@
* @package Kohana
* @category Helpers
* @author Kohana Team
* @copyright (c) 2007-2011 Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_HTML {
@@ -46,6 +46,11 @@ class Kohana_HTML {
'disabled',
);
/**
* @var boolean use strict XHTML mode?
*/
public static $strict = TRUE;
/**
* @var boolean automatically target external URLs to a new window?
*/
@@ -57,8 +62,8 @@ class Kohana_HTML {
*
* echo HTML::chars($username);
*
* @param string string to convert
* @param boolean encode existing entities
* @param string $value string to convert
* @param boolean $double_encode encode existing entities
* @return string
*/
public static function chars($value, $double_encode = TRUE)
@@ -73,8 +78,8 @@ class Kohana_HTML {
*
* echo HTML::entities($username);
*
* @param string string to convert
* @param boolean encode existing entities
* @param string $value string to convert
* @param boolean $double_encode encode existing entities
* @return string
*/
public static function entities($value, $double_encode = TRUE)
@@ -88,17 +93,17 @@ class Kohana_HTML {
*
* echo HTML::anchor('/user/profile', 'My Profile');
*
* @param string URL or URI string
* @param string link text
* @param array HTML anchor attributes
* @param mixed protocol to pass to URL::base()
* @param boolean include the index page
* @param string $uri URL or URI string
* @param string $title link text
* @param array $attributes HTML anchor attributes
* @param mixed $protocol protocol to pass to URL::base()
* @param boolean $index include the index page
* @return string
* @uses URL::base
* @uses URL::site
* @uses HTML::attributes
*/
public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL, $index = FALSE)
public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL, $index = TRUE)
{
if ($title === NULL)
{
@@ -140,11 +145,11 @@ class Kohana_HTML {
*
* echo HTML::file_anchor('media/doc/user_guide.pdf', 'User Guide');
*
* @param string name of file to link to
* @param string link text
* @param array HTML anchor attributes
* @param mixed protocol to pass to URL::base()
* @param boolean include the index page
* @param string $file name of file to link to
* @param string $title link text
* @param array $attributes HTML anchor attributes
* @param mixed $protocol protocol to pass to URL::base()
* @param boolean $index include the index page
* @return string
* @uses URL::base
* @uses HTML::attributes
@@ -158,83 +163,25 @@ class Kohana_HTML {
}
// Add the file link to the attributes
$attributes['href'] = URL::base($protocol, $index).$file;
$attributes['href'] = URL::site($file, $protocol, $index);
return '<a'.HTML::attributes($attributes).'>'.$title.'</a>';
}
/**
* Generates an obfuscated version of a string. Text passed through this
* method is less likely to be read by web crawlers and robots, which can
* be helpful for spam prevention, but can prevent legitimate robots from
* reading your content.
*
* echo HTML::obfuscate($text);
*
* @param string string to obfuscate
* @return string
* @since 3.0.3
*/
public static function obfuscate($string)
{
$safe = '';
foreach (str_split($string) as $letter)
{
switch (rand(1, 3))
{
// HTML entity code
case 1:
$safe .= '&#'.ord($letter).';';
break;
// Hex character code
case 2:
$safe .= '&#x'.dechex(ord($letter)).';';
break;
// Raw (no) encoding
case 3:
$safe .= $letter;
}
}
return $safe;
}
/**
* Generates an obfuscated version of an email address. Helps prevent spam
* robots from finding email addresses.
*
* echo HTML::email($address);
*
* @param string email address
* @return string
* @uses HTML::obfuscate
*/
public static function email($email)
{
// Make sure the at sign is always obfuscated
return str_replace('@', '&#64;', HTML::obfuscate($email));
}
/**
* Creates an email (mailto:) anchor. Note that the title is not escaped,
* to allow HTML elements within links (images, etc).
*
* echo HTML::mailto($address);
*
* @param string email address to send to
* @param string link text
* @param array HTML anchor attributes
* @param string $email email address to send to
* @param string $title link text
* @param array $attributes HTML anchor attributes
* @return string
* @uses HTML::email
* @uses HTML::attributes
*/
public static function mailto($email, $title = NULL, array $attributes = NULL)
{
// Obfuscate email address
$email = HTML::email($email);
if ($title === NULL)
{
// Use the email address as the title
@@ -249,10 +196,10 @@ class Kohana_HTML {
*
* echo HTML::style('media/css/screen.css');
*
* @param string file name
* @param array default attributes
* @param mixed protocol to pass to URL::base()
* @param boolean include the index page
* @param string $file file name
* @param array $attributes default attributes
* @param mixed $protocol protocol to pass to URL::base()
* @param boolean $index include the index page
* @return string
* @uses URL::base
* @uses HTML::attributes
@@ -262,14 +209,14 @@ class Kohana_HTML {
if (strpos($file, '://') === FALSE)
{
// Add the base URL
$file = URL::base($protocol, $index).$file;
$file = URL::site($file, $protocol, $index);
}
// Set the stylesheet link
$attributes['href'] = $file;
// Set the stylesheet rel
$attributes['rel'] = 'stylesheet';
$attributes['rel'] = empty($attributes['rel']) ? 'stylesheet' : $attributes['rel'];
// Set the stylesheet type
$attributes['type'] = 'text/css';
@@ -282,10 +229,10 @@ class Kohana_HTML {
*
* echo HTML::script('media/js/jquery.min.js');
*
* @param string file name
* @param array default attributes
* @param mixed protocol to pass to URL::base()
* @param boolean include the index page
* @param string $file file name
* @param array $attributes default attributes
* @param mixed $protocol protocol to pass to URL::base()
* @param boolean $index include the index page
* @return string
* @uses URL::base
* @uses HTML::attributes
@@ -295,7 +242,7 @@ class Kohana_HTML {
if (strpos($file, '://') === FALSE)
{
// Add the base URL
$file = URL::base($protocol, $index).$file;
$file = URL::site($file, $protocol, $index);
}
// Set the script link
@@ -312,10 +259,10 @@ class Kohana_HTML {
*
* echo HTML::image('media/img/logo.png', array('alt' => 'My Company'));
*
* @param string file name
* @param array default attributes
* @param mixed protocol to pass to URL::base()
* @param boolean include the index page
* @param string $file file name
* @param array $attributes default attributes
* @param mixed $protocol protocol to pass to URL::base()
* @param boolean $index include the index page
* @return string
* @uses URL::base
* @uses HTML::attributes
@@ -325,7 +272,7 @@ class Kohana_HTML {
if (strpos($file, '://') === FALSE)
{
// Add the base URL
$file = URL::base($protocol, $index).$file;
$file = URL::site($file, $protocol, $index);
}
// Add the image link
@@ -340,7 +287,7 @@ class Kohana_HTML {
*
* echo '<div'.HTML::attributes($attrs).'>'.$content.'</div>';
*
* @param array attribute list
* @param array $attributes attribute list
* @return string
*/
public static function attributes(array $attributes = NULL)
@@ -374,10 +321,22 @@ class Kohana_HTML {
{
// Assume non-associative keys are mirrored attributes
$key = $value;
if ( ! HTML::$strict)
{
// Just use a key
$value = FALSE;
}
}
// Add the attribute value
$compiled .= ' '.$key.'="'.HTML::chars($value).'"';
// Add the attribute key
$compiled .= ' '.$key;
if ($value OR HTML::$strict)
{
// Add the attribute value
$compiled .= '="'.HTML::chars($value).'"';
}
}
return $compiled;

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Contains the most low-level helpers methods in Kohana:
*
@@ -11,7 +11,7 @@
* @category HTTP
* @author Kohana Team
* @since 3.1.0
* @copyright (c) 2008-2011 Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaphp.com/license
*/
abstract class Kohana_HTTP {
@@ -19,12 +19,69 @@ abstract class Kohana_HTTP {
/**
* @var The default protocol to use if it cannot be detected
*/
public static $protocol = 'http';
public static $protocol = 'HTTP/1.1';
/**
* @var The default protocol version to use if cannot be detected
* Issues a HTTP redirect.
*
* @param string $uri URI to redirect to
* @param int $code HTTP Status code to use for the redirect
* @throws HTTP_Exception
*/
public static $version = '1.1';
public static function redirect($uri = '', $code = 302)
{
$e = HTTP_Exception::factory($code);
if ( ! $e instanceof HTTP_Exception_Redirect)
throw new Kohana_Exception('Invalid redirect code \':code\'', array(
':code' => $code
));
throw $e->location($uri);
}
/**
* Checks the browser cache to see the response needs to be returned,
* execution will halt and a 304 Not Modified will be sent if the
* browser cache is up to date.
*
* @param Request $request Request
* @param Response $response Response
* @param string $etag Resource ETag
* @throws HTTP_Exception_304
* @return Response
*/
public static function check_cache(Request $request, Response $response, $etag = NULL)
{
// Generate an etag if necessary
if ($etag == NULL)
{
$etag = $response->generate_etag();
}
// Set the ETag header
$response->headers('etag', $etag);
// Add the Cache-Control header if it is not already set
// This allows etags to be used with max-age, etc
if ($response->headers('cache-control'))
{
$response->headers('cache-control', $response->headers('cache-control').', must-revalidate');
}
else
{
$response->headers('cache-control', 'must-revalidate');
}
// Check if we have a matching etag
if ($request->headers('if-none-match') AND (string) $request->headers('if-none-match') === $etag)
{
// No need to send data again
throw HTTP_Exception::factory(304)->headers('etag', $etag);
}
return $response;
}
/**
* Parses a HTTP header string into an associative array

View File

@@ -0,0 +1,72 @@
<?php defined('SYSPATH') OR die('No direct script access.');
abstract class Kohana_HTTP_Exception extends Kohana_Exception {
/**
* Creates an HTTP_Exception of the specified type.
*
* @param integer $code the http status code
* @param string $message status message, custom content to display with error
* @param array $variables translation variables
* @return HTTP_Exception
*/
public static function factory($code, $message = NULL, array $variables = NULL, Exception $previous = NULL)
{
$class = 'HTTP_Exception_'.$code;
return new $class($message, $variables, $previous);
}
/**
* @var int http status code
*/
protected $_code = 0;
/**
* @var Request Request instance that triggered this exception.
*/
protected $_request;
/**
* Creates a new translated exception.
*
* throw new Kohana_Exception('Something went terrible wrong, :user',
* array(':user' => $user));
*
* @param string $message status message, custom content to display with error
* @param array $variables translation variables
* @return void
*/
public function __construct($message = NULL, array $variables = NULL, Exception $previous = NULL)
{
parent::__construct($message, $variables, $this->_code, $previous);
}
/**
* Store the Request that triggered this exception.
*
* @param Request $request Request object that triggered this exception.
* @return Response
*/
public function request(Request $request = NULL)
{
if ($request === NULL)
return $this->_request;
$this->_request = $request;
return $this;
}
/**
* Generate a Response for the current Exception
*
* @uses Kohana_Exception::response()
* @return Response
*/
public function get_response()
{
return Kohana_Exception::response($this);
}
} // End Kohana_HTTP_Exception

View File

@@ -0,0 +1,10 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_300 extends HTTP_Exception_Redirect {
/**
* @var integer HTTP 300 Multiple Choices
*/
protected $_code = 300;
}

View File

@@ -0,0 +1,10 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_301 extends HTTP_Exception_Redirect {
/**
* @var integer HTTP 301 Moved Permanently
*/
protected $_code = 301;
}

View File

@@ -0,0 +1,10 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_302 extends HTTP_Exception_Redirect {
/**
* @var integer HTTP 302 Found
*/
protected $_code = 302;
}

View File

@@ -0,0 +1,10 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_303 extends HTTP_Exception_Redirect {
/**
* @var integer HTTP 303 See Other
*/
protected $_code = 303;
}

View File

@@ -0,0 +1,10 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_304 extends HTTP_Exception_Expected {
/**
* @var integer HTTP 304 Not Modified
*/
protected $_code = 304;
}

View File

@@ -0,0 +1,41 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_305 extends HTTP_Exception_Expected {
/**
* @var integer HTTP 305 Use Proxy
*/
protected $_code = 305;
/**
* Specifies the proxy to replay this request via
*
* @param string $location URI of the proxy
*/
public function location($uri = NULL)
{
if ($uri === NULL)
return $this->headers('Location');
$this->headers('Location', $uri);
return $this;
}
/**
* Validate this exception contains everything needed to continue.
*
* @throws Kohana_Exception
* @return bool
*/
public function check()
{
if ($location = $this->headers('location') === NULL)
throw new Kohana_Exception('A \'location\' must be specified for a redirect');
if (strpos($location, '://') === FALSE)
throw new Kohana_Exception('An absolute URI to the proxy server must be specified');
return TRUE;
}
}

View File

@@ -0,0 +1,10 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_307 extends HTTP_Exception_Redirect {
/**
* @var integer HTTP 307 Temporary Redirect
*/
protected $_code = 307;
}

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_400 extends HTTP_Exception {

View File

@@ -0,0 +1,38 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_401 extends HTTP_Exception_Expected {
/**
* @var integer HTTP 401 Unauthorized
*/
protected $_code = 401;
/**
* Specifies the WWW-Authenticate challenge.
*
* @param string $challenge WWW-Authenticate challenge (eg `Basic realm="Control Panel"`)
*/
public function authenticate($challenge = NULL)
{
if ($challenge === NULL)
return $this->headers('www-authenticate');
$this->headers('www-authenticate', $challenge);
return $this;
}
/**
* Validate this exception contains everything needed to continue.
*
* @throws Kohana_Exception
* @return bool
*/
public function check()
{
if ($this->headers('www-authenticate') === NULL)
throw new Kohana_Exception('A \'www-authenticate\' header must be specified for a HTTP 401 Unauthorized');
return TRUE;
}
}

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_402 extends HTTP_Exception {

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_403 extends HTTP_Exception {

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_404 extends HTTP_Exception {

View File

@@ -0,0 +1,41 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_405 extends HTTP_Exception_Expected {
/**
* @var integer HTTP 405 Method Not Allowed
*/
protected $_code = 405;
/**
* Specifies the list of allowed HTTP methods
*
* @param array $methods List of allowed methods
*/
public function allowed($methods)
{
if (is_array($methods))
{
$methods = implode(',', $methods);
}
$this->headers('allow', $methods);
return $this;
}
/**
* Validate this exception contains everything needed to continue.
*
* @throws Kohana_Exception
* @return bool
*/
public function check()
{
if ($location = $this->headers('allow') === NULL)
throw new Kohana_Exception('A list of allowed methods must be specified');
return TRUE;
}
}

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_406 extends HTTP_Exception {

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_407 extends HTTP_Exception {

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_408 extends HTTP_Exception {

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_409 extends HTTP_Exception {

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_410 extends HTTP_Exception {

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_411 extends HTTP_Exception {

View File

@@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_412 extends HTTP_Exception {

Some files were not shown because too many files have changed in this diff Show More