Skip to content

Commit

Permalink
Adapted core for HMVC support
Browse files Browse the repository at this point in the history
  • Loading branch information
dchill42 committed Aug 5, 2011
1 parent 254217a commit 2c35654
Show file tree
Hide file tree
Showing 11 changed files with 703 additions and 338 deletions.
112 changes: 74 additions & 38 deletions system/core/CodeIgniter.php
Expand Up @@ -128,17 +128,32 @@
*/
$EXT->_call_hook('pre_system');

/*
* ------------------------------------------------------
* Load the application root
* ------------------------------------------------------
*/

// Load the root class
require BASEPATH.'core/Root.php';

function &get_instance()
{
return CI_Root::get_instance();
}
$CI =& get_instance();

/*
* ------------------------------------------------------
* Instantiate the config class
* ------------------------------------------------------
*/
$CFG =& load_class('Config', 'core');
$CI->load_core('Config');

// Do we have any manually set config items in the index.php file?
if (isset($assign_to_config))
{
$CFG->_assign_to_config($assign_to_config);
$CI->config->_assign_to_config($assign_to_config);
}

/*
Expand All @@ -153,35 +168,35 @@
*
*/

$UNI =& load_class('Utf8', 'core');
$CI->load_core('Utf8');

/*
* ------------------------------------------------------
* Instantiate the URI class
* ------------------------------------------------------
*/
$URI =& load_class('URI', 'core');
$CI->load_core('URI');

/*
* ------------------------------------------------------
* Instantiate the routing class and set the routing
* ------------------------------------------------------
*/
$RTR =& load_class('Router', 'core');
$RTR->_set_routing();
$CI->load_core('Router');
$CI->router->_set_routing();

// Set any routing overrides that may exist in the main index file
if (isset($routing))
{
$RTR->_set_overrides($routing);
$CI->router->_set_overrides($routing);
}

/*
* ------------------------------------------------------
* Instantiate the output class
* ------------------------------------------------------
*/
$OUT =& load_class('Output', 'core');
$CI->load_core('Output');

/*
* ------------------------------------------------------
Expand All @@ -190,7 +205,7 @@
*/
if ($EXT->_call_hook('cache_override') === FALSE)
{
if ($OUT->_display_cache($CFG, $URI) == TRUE)
if ($CI->output->_display_cache($CI->config, $CI->uri) == TRUE)
{
exit;
}
Expand All @@ -201,51 +216,70 @@
* Load the security class for xss and csrf support
* -----------------------------------------------------
*/
$SEC =& load_class('Security', 'core');
$CI->load_core('Security');

/*
* ------------------------------------------------------
* Load the Input class and sanitize globals
* ------------------------------------------------------
*/
$IN =& load_class('Input', 'core');
$CI->load_core('Input');

/*
* ------------------------------------------------------
* Load the Language class
* ------------------------------------------------------
*/
$LANG =& load_class('Lang', 'core');
$CI->load_core('Lang');

/*
* ------------------------------------------------------
* Load the app controller and local controller
* Autoload libraries, etc.
* ------------------------------------------------------
*
*/
// Load the base controller class
require BASEPATH.'core/Controller.php';

function &get_instance()
{
return CI_Controller::get_instance();
}
$CI->load->ci_autoloader();

/*
* ------------------------------------------------------
* Load the local controller
* ------------------------------------------------------
*/

if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
// Load the Controller base class
require BASEPATH.'core/Controller.php';

// Load the Controller subclass, if found
$file = 'core/'.$CI->config->item('subclass_prefix').'Controller.php';
$packages = $CI->load->get_package_paths();
foreach ($packages as $path)
{
require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
if (file_exists($path.$file))
{
require $path.$file;
break;
}
}

// 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->fetch_directory().$RTR->fetch_class().'.php'))
$file = 'controllers/'.$CI->router->fetch_directory().$CI->router->fetch_class().'.php';
$found = FALSE;
foreach ($packages as $path)
{
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
if (file_exists($path.$file))
{
include($path.$file);
$found = TRUE;
break;
}
}

include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
if ( ! $found)
{
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}

// Set a mark point for benchmarking
$BM->mark('loading_time:_base_classes_end');
Expand All @@ -259,8 +293,8 @@ function &get_instance()
* loader class can be called via the URI, nor can
* controller functions that begin with an underscore
*/
$class = $RTR->fetch_class();
$method = $RTR->fetch_method();
$class = $CI->router->fetch_class();
$method = $CI->router->fetch_method();

if ( ! class_exists($class)
OR strncmp($method, '_', 1) == 0
Expand All @@ -285,7 +319,9 @@ function &get_instance()
// Mark a start point so we can benchmark the controller
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');

$CI = new $class();
$CI->routed = new $class();
$name = strtolower($class);
$CI->$name = $CI->routed;

/*
* ------------------------------------------------------
Expand All @@ -300,20 +336,20 @@ function &get_instance()
* ------------------------------------------------------
*/
// Is there a "remap" function? If so, we call it instead
if (method_exists($CI, '_remap'))
if (method_exists($CI->routed, '_remap'))
{
$CI->_remap($method, array_slice($URI->rsegments, 2));
$CI->routed->_remap($method, array_slice($CI->uri->rsegments, 2));
}
else
{
// is_callable() returns TRUE on some versions of PHP 5 for private and protected
// methods, so we'll use this workaround for consistent behavior
if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI->routed))))
{
// Check and see if we are using a 404 override and use it.
if ( ! empty($RTR->routes['404_override']))
if ( ! empty($CI->router->routes['404_override']))
{
$x = explode('/', $RTR->routes['404_override']);
$x = explode('/', $CI->router->routes['404_override']);
$class = $x[0];
$method = (isset($x[1]) ? $x[1] : 'index');
if ( ! class_exists($class))
Expand All @@ -324,8 +360,8 @@ function &get_instance()
}

include_once(APPPATH.'controllers/'.$class.'.php');
unset($CI);
$CI = new $class();
unset($CI->routed);
$CI->routed = new $class();
}
}
else
Expand All @@ -336,7 +372,7 @@ function &get_instance()

// Call the requested method.
// Any URI segments present (besides the class/function) will be passed to the method for convenience
call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
call_user_func_array(array(&$CI->routed, $method), array_slice($CI->uri->rsegments, 2));
}


Expand All @@ -357,7 +393,7 @@ function &get_instance()
*/
if ($EXT->_call_hook('display_override') === FALSE)
{
$OUT->_display();
$CI->output->_display();
}

/*
Expand All @@ -379,4 +415,4 @@ function &get_instance()


/* End of file CodeIgniter.php */
/* Location: ./system/core/CodeIgniter.php */
/* Location: ./system/core/CodeIgniter.php */
59 changes: 40 additions & 19 deletions system/core/Controller.php
Expand Up @@ -5,7 +5,7 @@
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @author Darren Hill <dchill42@gmail.com>, St. Petersburg College
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
Expand All @@ -18,47 +18,68 @@
/**
* CodeIgniter Application Controller Class
*
* This class object is the super class that every library in
* CodeIgniter will be assigned to.
* This class object is the base class that connects each controller to the root object
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author ExpressionEngine Dev Team
* @author Darren Hill <dchill42@gmail.com>, St. Petersburg College
* @link http://codeigniter.com/user_guide/general/controllers.html
*/
class CI_Controller {

private static $instance;
protected $CI = NULL;

/**
* Constructor
*/
public function __construct()
{
self::$instance =& $this;

// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
foreach (is_loaded() as $var => $class)
$this->CI = $this->get_instance();
log_message('debug', 'Controller Class Initialized');
}

/**
* Get magic method
*
* Exposes root object members
* @param string member name
* @return mixed
*/
public function __get($key)
{
if (isset($this->CI->$key))
{
$this->$var =& load_class($class);
return $this->CI->$key;
}
}

$this->load =& load_class('Loader', 'core');

$this->load->set_base_classes()->ci_autoloader();

log_message('debug', "Controller Class Initialized");
/**
* Isset magic method
*
* Tests root object member existence
* @param string member name
* @return boolean
*/
public function __isset($key)
{
return isset($this->CI->$key);
}

/**
* Get instance
*
* Returns reference to root object
*
* @return object Root instance
*/
public static function &get_instance()
{
return self::$instance;
// Return root instance
return CI_Root::get_instance();
}
}
// END Controller class

/* End of file Controller.php */
/* Location: ./system/core/Controller.php */
/* Location: ./system/core/Controller.php */
9 changes: 4 additions & 5 deletions system/core/Input.php
Expand Up @@ -47,20 +47,19 @@ class CI_Input {
*/
public function __construct()
{
log_message('debug', "Input Class Initialized");
log_message('debug', 'Input Class Initialized');

$this->_allow_get_array = (config_item('allow_get_array') === TRUE);
$this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
$this->_enable_csrf = (config_item('csrf_protection') === TRUE);

global $SEC;
$this->security =& $SEC;
$CI =& get_instance();
$this->security =& $CI->security;

// Do we need the UTF-8 class?
if (UTF8_ENABLED === TRUE)
{
global $UNI;
$this->uni =& $UNI;
$this->uni =& $CI->utf8;
}

// Sanitize global arrays
Expand Down

0 comments on commit 2c35654

Please sign in to comment.