Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating CI3 and accounting for new Ucfirst rule #54

Merged
merged 2 commits into from
Jul 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
12 changes: 8 additions & 4 deletions system/core/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@ function &get_instance()
// Load the local application controller
// Note: The Router class automatically validates the controller path using the router->_validate_request().
// If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
if ( ! file_exists(APPPATH.'controllers/'.$RTR->directory.$RTR->class.'.php'))
$class = ucfirst($RTR->class);
if ( ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))
{
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}

include(APPPATH.'controllers/'.$RTR->directory.$RTR->class.'.php');
include(APPPATH.'controllers/'.$RTR->directory.$class.'.php');

// Set a mark point for benchmarking
$BM->mark('loading_time:_base_classes_end');
Expand All @@ -257,9 +258,8 @@ function &get_instance()
*
* None of the methods in the app controller or the
* loader class can be called via the URI, nor can
* controller functions that begin with an underscore.
* controller methods that begin with an underscore.
*/
$class = $RTR->class;
$method = $RTR->method;

if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
Expand All @@ -271,6 +271,8 @@ function &get_instance()
$method = 'index';
}

$class = ucfirst($class);

if ( ! class_exists($class, FALSE))
{
if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
Expand Down Expand Up @@ -309,6 +311,8 @@ function &get_instance()
$method = 'index';
}

$class = ucfirst($class);

if ( ! class_exists($class, FALSE))
{
if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
Expand Down
112 changes: 55 additions & 57 deletions system/core/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ class CI_Loader {
*/
protected $_ci_helper_paths = array(APPPATH, BASEPATH);

/**
* List of loaded base classes
*
* @var array
*/
protected $_base_classes = array(); // Set by the controller class

/**
* List of cached variables
*
Expand Down Expand Up @@ -120,6 +113,8 @@ class CI_Loader {
'user_agent' => 'agent'
);

// --------------------------------------------------------------------

/**
* Class constructor
*
Expand All @@ -129,7 +124,8 @@ class CI_Loader {
*/
public function __construct()
{
$this->_ci_ob_level = ob_get_level();
$this->_ci_ob_level = ob_get_level();
$this->_ci_classes =& is_loaded();

log_message('debug', 'Loader Class Initialized');
}
Expand All @@ -147,7 +143,6 @@ public function __construct()
*/
public function initialize()
{
$this->_base_classes =& is_loaded();
$this->_ci_autoloader();
}

Expand All @@ -165,7 +160,7 @@ public function initialize()
*/
public function is_loaded($class)
{
return isset($this->_ci_classes[$class]) ? $this->_ci_classes[$class] : FALSE;
return array_search(ucfirst($class), $this->_ci_classes, TRUE);
}

// --------------------------------------------------------------------
Expand All @@ -183,7 +178,11 @@ public function is_loaded($class)
*/
public function library($library = '', $params = NULL, $object_name = NULL)
{
if (is_array($library))
if (empty($library))
{
return;
}
elseif (is_array($library))
{
foreach ($library as $class)
{
Expand All @@ -193,11 +192,6 @@ public function library($library = '', $params = NULL, $object_name = NULL)
return;
}

if ($library === '' OR isset($this->_base_classes[$library]))
{
return;
}

if ($params !== NULL && ! is_array($params))
{
$params = NULL;
Expand Down Expand Up @@ -261,33 +255,32 @@ public function model($model, $name = '', $db_conn = FALSE)
show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
}

$model = strtolower($model);

foreach ($this->_ci_model_paths as $mod_path)
if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE))
{
if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
if ($db_conn === TRUE)
{
continue;
$db_conn = '';
}

if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE))
{
if ($db_conn === TRUE)
{
$db_conn = '';
}
$CI->load->database($db_conn, FALSE, TRUE);
}

$CI->load->database($db_conn, FALSE, TRUE);
}
if ( ! class_exists('CI_Model', FALSE))
{
load_class('Model', 'core');
}

$model = ucfirst(strtolower($model));

if ( ! class_exists('CI_Model', FALSE))
foreach ($this->_ci_model_paths as $mod_path)
{
if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
{
load_class('Model', 'core');
continue;
}

require_once($mod_path.'models/'.$path.$model.'.php');

$model = ucfirst($model);
$CI->$name = new $model();
$this->_ci_models[] = $name;
return;
Expand Down Expand Up @@ -1118,30 +1111,35 @@ protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object

// Set the variable name we will assign the class to
// Was a custom class name supplied? If so we'll use it
$class = strtolower($class);

if ($object_name === NULL)
if (empty($object_name))
{
$classvar = isset($this->_ci_varmap[$class]) ? $this->_ci_varmap[$class] : $class;
$object_name = strtolower($class);
if (isset($this->_ci_varmap[$object_name]))
{
$object_name = $this->_ci_varmap[$object_name];
}
}
else

// Don't overwrite existing properties
$CI =& get_instance();
if (isset($CI->$object_name))
{
$classvar = $object_name;
if ($CI->$object_name instanceof $name)
{
log_message('debug', $class." has already been instantiated as '".$object_name."'. Second attempt aborted.");
return;
}

show_error("Resource '".$object_name."' already exists and is not a ".$class." instance.");
}

// Save the class name and object name
$this->_ci_classes[$class] = $classvar;
$this->_ci_classes[$object_name] = $class;

// Instantiate the class
$CI =& get_instance();
if ($config !== NULL)
{
$CI->$classvar = new $name($config);
}
else
{
$CI->$classvar = new $name();
}
$CI->$object_name = isset($config)
? new $name($config)
: new $name();
}

// --------------------------------------------------------------------
Expand Down Expand Up @@ -1198,6 +1196,15 @@ protected function _ci_autoloader()
}
}

// Autoload drivers
if (isset($autoload['drivers']))
{
foreach ($autoload['drivers'] as $item)
{
$this->driver($item);
}
}

// Load libraries
if (isset($autoload['libraries']) && count($autoload['libraries']) > 0)
{
Expand All @@ -1215,15 +1222,6 @@ protected function _ci_autoloader()
}
}

// Autoload drivers
if (isset($autoload['drivers']))
{
foreach ($autoload['drivers'] as $item)
{
$this->driver($item);
}
}

// Autoload models
if (isset($autoload['model']))
{
Expand Down
8 changes: 3 additions & 5 deletions system/core/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ protected function _validate_request($segments)
return $segments;
}

$test = ($this->translate_uri_dashes === TRUE)
? str_replace('-', '_', $segments[0]) : $segments[0];
$test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]);

// Does the requested controller exist in the root folder?
if (file_exists(APPPATH.'controllers/'.$test.'.php'))
Expand All @@ -286,8 +285,7 @@ protected function _validate_request($segments)
$this->set_directory(array_shift($segments));
if (count($segments) > 0)
{
$test = ($this->translate_uri_dashes === TRUE)
? str_replace('-', '_', $segments[0]) : $segments[0];
$test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]);

// Does the requested controller exist in the sub-directory?
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$test.'.php'))
Expand All @@ -307,7 +305,7 @@ protected function _validate_request($segments)
{
// Is the method being specified in the route?
$segments = explode('/', $this->default_controller);
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$segments[0].'.php'))
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($segments[0]).'.php'))
{
$this->directory = '';
}
Expand Down
2 changes: 1 addition & 1 deletion system/helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ function &_get_validation_object()
// We set this as a variable since we're returning by reference.
$return = FALSE;

if (FALSE !== ($object = $CI->load->is_loaded('form_validation')))
if (FALSE !== ($object = $CI->load->is_loaded('Form_validation')))
{
if ( ! isset($CI->$object) OR ! is_object($CI->$object))
{
Expand Down
3 changes: 2 additions & 1 deletion system/libraries/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function __construct($config = array())

isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix'];

if (isset($config['backup']) && in_array('cache_'.$config['backup'], $this->valid_drivers))
if (isset($config['backup']) && in_array($config['backup'], $this->valid_drivers))
{
$this->_backup_driver = $config['backup'];
}
Expand All @@ -123,6 +123,7 @@ public function __construct($config = array())
else
{
// Backup is supported. Set it to primary.
log_message('debug', 'Cache adapter "'.$this->_adapter.'" is unavailable. Falling back to "'.$this->_backup_driver.'" backup adapter.');
$this->_adapter = $this->_backup_driver;
}
}
Expand Down
4 changes: 2 additions & 2 deletions system/libraries/Form_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)

// If the field is blank, but NOT required, no further tests are necessary
$callback = FALSE;
if ( ! in_array('required', $rules) && $postdata === NULL)
if ( ! in_array('required', $rules) && ($postdata === NULL OR $postdata === ''))
{
// Before we bail out, does the rule contain a callback?
if (preg_match('/(callback_\w+(\[.*?\])?)/', implode(' ', $rules), $match))
Expand All @@ -598,7 +598,7 @@ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
}

// Isset Test. Typically this rule will only apply to checkboxes.
if ($postdata === NULL && $callback === FALSE)
if (($postdata === NULL OR $postdata === '') && $callback === FALSE)
{
if (in_array('isset', $rules, TRUE) OR in_array('required', $rules))
{
Expand Down
4 changes: 2 additions & 2 deletions system/libraries/Javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function error($element = 'this', $js = '')
*/
public function focus($element = 'this', $js = '')
{
return $this->js->__add_event($element, $js);
return $this->js->_focus($element, $js);
}

// --------------------------------------------------------------------
Expand All @@ -189,7 +189,7 @@ public function focus($element = 'this', $js = '')
*/
public function hover($element = 'this', $over = '', $out = '')
{
return $this->js->__hover($element, $over, $out);
return $this->js->_hover($element, $over, $out);
}

// --------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions system/libraries/Javascript/Jquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,6 @@ protected function _add_event($element, $js, $event)
if (is_array($js))
{
$js = implode("\n\t\t", $js);

}

$event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n";
Expand All @@ -937,7 +936,7 @@ protected function _add_event($element, $js, $event)
* Compile
*
* As events are specified, they are stored in an array
* This funciton compiles them all for output on a page
* This function compiles them all for output on a page
*
* @param string $view_var
* @param bool $script_tags
Expand Down
19 changes: 15 additions & 4 deletions system/libraries/User_agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,24 @@ public function is_mobile($key = NULL)
*/
public function is_referral()
{
if (empty($_SERVER['HTTP_REFERER']))
static $result;

if ( ! isset($result))
{
return FALSE;
if (empty($_SERVER['HTTP_REFERER']))
{
$result = FALSE;
}
else
{
$referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$own_host = parse_url(config_item('base_url'), PHP_URL_HOST);

$result = ($referer_host && $referer_host !== $own_host);
}
}

$referer = parse_url($_SERVER['HTTP_REFERER']);
return ! (empty($referer['host']) && strpos(config_item('base_url'), $referer['host']) !== FALSE);
return $result;
}

// --------------------------------------------------------------------
Expand Down
Loading