Skip to content

Commit

Permalink
Merge pull request #83 from ivantcholakov/development
Browse files Browse the repository at this point in the history
Solving the issue #82 - CI 2.x old class/file naming convention.
  • Loading branch information
goFrendiAsgard committed Nov 14, 2013
2 parents da9f947 + 6192704 commit fb16b2c
Show file tree
Hide file tree
Showing 15 changed files with 1,330 additions and 864 deletions.
411 changes: 411 additions & 0 deletions application/core/MY_CodeIgniter.php

Large diffs are not rendered by default.

145 changes: 1 addition & 144 deletions application/core/MY_Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,147 +254,4 @@ protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object
: new $name();
}

// Modified by Go Frendi Gunawan, 12-NOV-2013
/** Load a module model **/
public function model($model, $object_name = NULL, $connect = FALSE) {

if (is_array($model)) return $this->models($model);

($_alias = $object_name) OR $_alias = basename($model);

if (in_array($_alias, $this->_ci_models, TRUE))
return CI::$APP->$_alias;

/* check module */
list($path, $_model) = Modules::find(strtolower($model), $this->_module, 'models/');

if ($path == FALSE) {

/* check application & packages */
$this->__original_model($model, $object_name, $connect);

} else {

class_exists('CI_Model', FALSE) OR load_class('Model', 'core');

if ($connect !== FALSE AND ! class_exists('CI_DB', FALSE)) {
if ($connect === TRUE) $connect = '';
$this->database($connect, FALSE, TRUE);
}

Modules::load_file($_model, $path);

$model = ucfirst($_model);
CI::$APP->$_alias = new $model();

$this->_ci_models[] = $_alias;
}

return CI::$APP->$_alias;
}
public function __original_model($model, $name = '', $db_conn = FALSE)
{
if (empty($model))
{
return;
}
elseif (is_array($model))
{
foreach ($model as $key => $value)
{
is_int($key) ? $this->model($value, '', $db_conn) : $this->model($key, $value, $db_conn);
}
return;
}

$path = '';

// Is the model in a sub-folder? If so, parse out the filename and path.
if (($last_slash = strrpos($model, '/')) !== FALSE)
{
// The path is in front of the last slash
$path = substr($model, 0, ++$last_slash);

// And the model name behind it
$model = substr($model, $last_slash);
}

if (empty($name))
{
$name = $model;
}

if (in_array($name, $this->_ci_models, TRUE))
{
return;
}

$CI =& get_instance();
if (isset($CI->$name))
{
show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
}

if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE))
{
if ($db_conn === TRUE)
{
$db_conn = '';
}

$CI->load->database($db_conn, FALSE, TRUE);
}

if ( ! class_exists('CI_Model', FALSE))
{
load_class('Model', 'core');
}

/* ORIGINAL CODE:
$model = ucfirst(strtolower($model));
foreach ($this->_ci_model_paths as $mod_path)
{
if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
{
continue;
}
require_once($mod_path.'models/'.$path.$model.'.php');
$CI->$name = new $model();
$this->_ci_models[] = $name;
return;
}
*/

// MY BACKWARD COMPATIBLE CODE
$model = strtolower($model);

foreach ($this->_ci_model_paths as $mod_path)
{
if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
{
continue;
}

if(file_exists($mod_path.'models/'.$path.ucfirst($model).'.php')){
require_once($mod_path.'models/'.$path.ucfirst($model).'.php');
}else{
require_once($mod_path.'models/'.$path.$model.'.php');
}
$model = ucfirst($model);
$CI->$name = new $model();

$this->_ci_models[] = $name;
return;
}
// END OF MY BACKWARD COMPATIBLE CODE

// couldn't find the model
show_error('Unable to locate the model you have specified: '.$model);
}


}
}
2 changes: 1 addition & 1 deletion application/core/MY_Router.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,4 @@ protected function is_controller($base_path) {
return is_file($base_path.$ext) || is_file($base_path.'.php');
}

}
}
40 changes: 22 additions & 18 deletions application/third_party/MX/Base.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
* Modular Extensions - HMVC
*
* Adapted from the CodeIgniter Core Classes
* @link http://codeigniter.com
* @link http://codeigniter.com
*
* Description:
* This library extends the CodeIgniter CI_Controller class and creates an application
* object allowing use of the HMVC design pattern.
*
* Install this file as application/third_party/MX/Base.php
*
* @copyright Copyright (c) 2011 Wiredesignz
* @version 5.4
* @copyright Copyright (c) 2011 Wiredesignz
* @version 5.4
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -39,21 +39,25 @@
**/
class CI extends CI_Controller
{
public static $APP;

public function __construct() {

/* assign the application instance */
self::$APP = $this;

global $LANG, $CFG;

/* re-assign language and config for modules */
if ( ! ($LANG instanceof MX_Lang)) $LANG = new MX_Lang;
if ( ! ($CFG instanceof MX_Config)) $CFG = new MX_Config;

parent::__construct();
}
public static $APP;

public function __construct() {

/* assign the application instance */
self::$APP = $this;

global $LANG, $CFG;

/* re-assign language and config for modules */
// Modified by Ivan Tcholakov, 28-SEP-2012.
//if ( ! is_a($LANG, 'MX_Lang')) $LANG = new MX_Lang;
//if ( ! is_a($CFG, 'MX_Config')) $CFG = new MX_Config;
if ( @ ! is_a($LANG, 'MX_Lang')) $LANG = new MX_Lang;
if ( @ ! is_a($CFG, 'MX_Config')) $CFG = new MX_Config;
//

parent::__construct();
}
}

/* create the application object */
Expand Down
41 changes: 25 additions & 16 deletions application/third_party/MX/Ci.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* Modular Extensions - HMVC
*
* Adapted from the CodeIgniter Core Classes
* @link http://codeigniter.com
* @link http://codeigniter.com
*
* Description:
* This library creates a CI class which allows the use of modules in an application.
*
* Install this file as application/third_party/MX/Ci.php
*
* @copyright Copyright (c) 2011 Wiredesignz
* @version 5.4
* @copyright Copyright (c) 2011 Wiredesignz
* @version 5.4
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -38,19 +38,28 @@
**/
class CI
{
public static $APP;

public function __construct() {

/* assign the application instance */
self::$APP = CI_Controller::get_instance();

global $LANG, $CFG;

/* re-assign language and config for modules */
if ( ! is_a($LANG, 'MX_Lang')) $LANG = new MX_Lang;
if ( ! is_a($CFG, 'MX_Config')) $CFG = new MX_Config;
}
public static $APP;

public function __construct() {

/* assign the application instance */
self::$APP = CI_Controller::get_instance();

global $LANG, $CFG;

/* re-assign language and config for modules */
// Modified by Ivan Tcholakov, 28-SEP-2012.
//if ( ! is_a($LANG, 'MX_Lang')) $LANG = new MX_Lang;
//if ( ! is_a($CFG, 'MX_Config')) $CFG = new MX_Config;
if ( @ ! is_a($LANG, 'MX_Lang')) $LANG = new MX_Lang;
if ( @ ! is_a($CFG, 'MX_Config')) $CFG = new MX_Config;
//
}

public function __call($method, $arguments)
{
return call_user_func_array($method, $arguments);
}
}

/* create the application object */
Expand Down
72 changes: 36 additions & 36 deletions application/third_party/MX/Config.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
* Modular Extensions - HMVC
*
* Adapted from the CodeIgniter Core Classes
* @link http://codeigniter.com
* @link http://codeigniter.com
*
* Description:
* This library extends the CodeIgniter CI_Config class
* and adds features allowing use of modules and the HMVC design pattern.
*
* Install this file as application/third_party/MX/Config.php
*
* @copyright Copyright (c) 2011 Wiredesignz
* @version 5.4
* @copyright Copyright (c) 2011 Wiredesignz
* @version 5.4
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -34,38 +34,38 @@
* THE SOFTWARE.
**/
class MX_Config extends CI_Config
{
public function load($file = 'config', $use_sections = FALSE, $fail_gracefully = FALSE, $_module = '') {

if (in_array($file, $this->is_loaded, TRUE)) return $this->item($file);
{
public function load($file = 'config', $use_sections = FALSE, $fail_gracefully = FALSE, $_module = '') {

$_module OR $_module = CI::$APP->router->fetch_module();
list($path, $file) = Modules::find($file, $_module, 'config/');

if ($path === FALSE) {
parent::load($file, $use_sections, $fail_gracefully);
return $this->item($file);
}

if ($config = Modules::load_file($file, $path, 'config')) {

/* reference to the config array */
$current_config =& $this->config;
if (in_array($file, $this->is_loaded, TRUE)) return $this->item($file);

if ($use_sections === TRUE) {

if (isset($current_config[$file])) {
$current_config[$file] = array_merge($current_config[$file], $config);
} else {
$current_config[$file] = $config;
}

} else {
$current_config = array_merge($current_config, $config);
}
$this->is_loaded[] = $file;
unset($config);
return $this->item($file);
}
}
}
$_module OR $_module = CI::$APP->router->fetch_module();
list($path, $file) = Modules::find($file, $_module, 'config/');

if ($path === FALSE) {
parent::load($file, $use_sections, $fail_gracefully);
return $this->item($file);
}

if ($config = Modules::load_file($file, $path, 'config')) {

/* reference to the config array */
$current_config =& $this->config;

if ($use_sections === TRUE) {

if (isset($current_config[$file])) {
$current_config[$file] = array_merge($current_config[$file], $config);
} else {
$current_config[$file] = $config;
}

} else {
$current_config = array_merge($current_config, $config);
}
$this->is_loaded[] = $file;
unset($config);
return $this->item($file);
}
}
}
Loading

0 comments on commit fb16b2c

Please sign in to comment.