Archived
1
0

Update to CodeIgniter 3.19

This commit is contained in:
Marcel
2018-12-29 16:16:49 +01:00
parent b036b4d36e
commit d09ee2788d
159 changed files with 2508 additions and 1910 deletions

View File

@@ -6,7 +6,7 @@
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
@@ -182,7 +182,7 @@ class CI_Loader {
* Loads and instantiates libraries.
* Designed to be called from application controllers.
*
* @param string $library Library name
* @param mixed $library Library name
* @param array $params Optional parameters to pass to the library class constructor
* @param string $object_name An optional object name to assign to
* @return object
@@ -226,7 +226,7 @@ class CI_Loader {
*
* Loads and instantiates models.
*
* @param string $model Model name
* @param mixed $model Model name
* @param string $name An optional object name to assign to
* @param bool $db_conn An optional database connection configuration to initialize
* @return object
@@ -303,6 +303,8 @@ class CI_Loader {
{
throw new RuntimeException($app_path."Model.php exists, but doesn't declare class CI_Model");
}
log_message('info', 'CI_Model class loaded');
}
elseif ( ! class_exists('CI_Model', FALSE))
{
@@ -317,6 +319,8 @@ class CI_Loader {
{
throw new RuntimeException($app_path.$class.".php exists, but doesn't declare class ".$class);
}
log_message('info', config_item('subclass_prefix').'Model class loaded');
}
}
@@ -350,7 +354,9 @@ class CI_Loader {
}
$this->_ci_models[] = $name;
$CI->$name = new $model();
$model = new $model();
$CI->$name = $model;
log_message('info', 'Model "'.get_class($model).'" initialized');
return $this;
}
@@ -486,7 +492,7 @@ class CI_Loader {
*/
public function view($view, $vars = array(), $return = FALSE)
{
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
}
// --------------------------------------------------------------------
@@ -519,19 +525,13 @@ class CI_Loader {
*/
public function vars($vars, $val = '')
{
if (is_string($vars))
{
$vars = array($vars => $val);
}
$vars = is_string($vars)
? array($vars => $val)
: $this->_ci_prepare_view_vars($vars);
$vars = $this->_ci_object_to_array($vars);
if (is_array($vars) && count($vars) > 0)
foreach ($vars as $key => $val)
{
foreach ($vars as $key => $val)
{
$this->_ci_cached_vars[$key] = $val;
}
$this->_ci_cached_vars[$key] = $val;
}
return $this;
@@ -591,15 +591,21 @@ class CI_Loader {
*/
public function helper($helpers = array())
{
foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
is_array($helpers) OR $helpers = array($helpers);
foreach ($helpers as &$helper)
{
$filename = basename($helper);
$filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename));
$filename = strtolower(preg_replace('#(_helper)?(\.php)?$#i', '', $filename)).'_helper';
$helper = $filepath.$filename;
if (isset($this->_ci_helpers[$helper]))
{
continue;
}
// Is this a helper extension request?
$ext_helper = config_item('subclass_prefix').$helper;
$ext_helper = config_item('subclass_prefix').$filename;
$ext_loaded = FALSE;
foreach ($this->_ci_helper_paths as $path)
{
@@ -934,18 +940,7 @@ class CI_Loader {
* the two types and cache them so that views that are embedded within
* other views can have access to these variables.
*/
if (is_array($_ci_vars))
{
foreach (array_keys($_ci_vars) as $key)
{
if (strncmp($key, '_ci_', 4) === 0)
{
unset($_ci_vars[$key]);
}
}
$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
}
empty($_ci_vars) OR $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
extract($this->_ci_cached_vars);
/*
@@ -1048,6 +1043,26 @@ class CI_Loader {
return $this->_ci_load_stock_library($class, $subdir, $params, $object_name);
}
// Safety: Was the class already loaded by a previous call?
if (class_exists($class, FALSE))
{
$property = $object_name;
if (empty($property))
{
$property = strtolower($class);
isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
}
$CI =& get_instance();
if (isset($CI->$property))
{
log_message('debug', $class.' class already loaded. Second attempt ignored.');
return;
}
return $this->_ci_init_library($class, '', $params, $object_name);
}
// Let's search for the requested library file and load it.
foreach ($this->_ci_library_paths as $path)
{
@@ -1058,27 +1073,8 @@ class CI_Loader {
}
$filepath = $path.'libraries/'.$subdir.$class.'.php';
// Safety: Was the class already loaded by a previous call?
if (class_exists($class, FALSE))
{
// Before we deem this to be a duplicate request, let's see
// if a custom object name is being supplied. If so, we'll
// return a new instance of the object
if ($object_name !== NULL)
{
$CI =& get_instance();
if ( ! isset($CI->$object_name))
{
return $this->_ci_init_library($class, '', $params, $object_name);
}
}
log_message('debug', $class.' class already loaded. Second attempt ignored.');
return;
}
// Does the file exist? No? Bummer...
elseif ( ! file_exists($filepath))
if ( ! file_exists($filepath))
{
continue;
}
@@ -1106,7 +1102,7 @@ class CI_Loader {
* @used-by CI_Loader::_ci_load_library()
* @uses CI_Loader::_ci_init_library()
*
* @param string $library Library name to load
* @param string $library_name Library name to load
* @param string $file_path Path to the library filename, relative to libraries/
* @param mixed $params Optional parameters to pass to the class constructor
* @param string $object_name Optional object name to assign to
@@ -1123,16 +1119,17 @@ class CI_Loader {
$prefix = config_item('subclass_prefix');
}
// Before we deem this to be a duplicate request, let's see
// if a custom object name is being supplied. If so, we'll
// return a new instance of the object
if ($object_name !== NULL)
$property = $object_name;
if (empty($property))
{
$CI =& get_instance();
if ( ! isset($CI->$object_name))
{
return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
}
$property = strtolower($library_name);
isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
}
$CI =& get_instance();
if ( ! isset($CI->$property))
{
return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
}
log_message('debug', $library_name.' class already loaded. Second attempt ignored.');
@@ -1154,10 +1151,8 @@ class CI_Loader {
{
return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
}
else
{
log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name);
}
log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name);
}
}
@@ -1175,10 +1170,8 @@ class CI_Loader {
$prefix = config_item('subclass_prefix');
break;
}
else
{
log_message('debug', $path.' exists, but does not declare '.$subclass);
}
log_message('debug', $path.' exists, but does not declare '.$subclass);
}
}
@@ -1376,17 +1369,32 @@ class CI_Loader {
// --------------------------------------------------------------------
/**
* CI Object to Array translator
* Prepare variables for _ci_vars, to be later extract()-ed inside views
*
* Takes an object as input and converts the class variables to
* an associative array with key/value pairs.
* Converts objects to associative arrays and filters-out internal
* variable names (i.e. keys prefixed with '_ci_').
*
* @param object $object Object data to translate
* @param mixed $vars
* @return array
*/
protected function _ci_object_to_array($object)
protected function _ci_prepare_view_vars($vars)
{
return is_object($object) ? get_object_vars($object) : $object;
if ( ! is_array($vars))
{
$vars = is_object($vars)
? get_object_vars($vars)
: array();
}
foreach (array_keys($vars) as $key)
{
if (strncmp($key, '_ci_', 4) === 0)
{
unset($vars[$key]);
}
}
return $vars;
}
// --------------------------------------------------------------------
@@ -1404,34 +1412,4 @@ class CI_Loader {
$CI =& get_instance();
return $CI->$component;
}
// --------------------------------------------------------------------
/**
* Prep filename
*
* This function prepares filenames of various items to
* make their loading more reliable.
*
* @param string|string[] $filename Filename(s)
* @param string $extension Filename extension
* @return array
*/
protected function _ci_prep_filename($filename, $extension)
{
if ( ! is_array($filename))
{
return array(strtolower(str_replace(array($extension, '.php'), '', $filename).$extension));
}
else
{
foreach ($filename as $key => $val)
{
$filename[$key] = strtolower(str_replace(array($extension, '.php'), '', $val).$extension);
}
return $filename;
}
}
}