Skip to content

Commit

Permalink
Fix: As of PHP 5.4 you can also use the short array syntax, which rep…
Browse files Browse the repository at this point in the history
…lace array() with [] , and Fix comment style
  • Loading branch information
N3Cr0N committed Apr 12, 2019
1 parent 671ddf9 commit f67b538
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 95 deletions.
18 changes: 9 additions & 9 deletions application/third_party/MX/Base.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');

/* load MX core classes */
// load MX core classes
require_once __DIR__ .'/Lang.php';
require_once __DIR__ .'/Config.php';

Expand Down Expand Up @@ -41,20 +41,20 @@ class CI extends CI_Controller
{
public static $APP;

/**
* [__construct description]
*
* @method __construct
*/
/**
* [__construct description]
*
* @method __construct
*/
public function __construct()
{

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

global $LANG, $CFG;

/* re-assign language and config for modules */
// re-assign language and config for modules
if (! $LANG instanceof MX_Lang) {
$LANG = new MX_Lang;
}
Expand All @@ -66,5 +66,5 @@ public function __construct()
}
}

/* create the application object */
// create the application object
new CI;
8 changes: 4 additions & 4 deletions application/third_party/MX/Ci.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');

/* load MX core classes */
// load MX core classes
require_once __DIR__ .'/Lang.php';
require_once __DIR__ .'/Config.php';

Expand Down Expand Up @@ -48,12 +48,12 @@ class CI
public function __construct()
{

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

global $LANG, $CFG;

/* re-assign language and config for modules */
// re-assign language and config for modules
if (! $LANG instanceof MX_Lang) {
$LANG = new MX_Lang;
}
Expand All @@ -63,5 +63,5 @@ public function __construct()
}
}

/* create the application object */
// create the application object
new CI;
2 changes: 1 addition & 1 deletion application/third_party/MX/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function load($file = '', $use_sections = false, $fail_gracefully = false
}

if ($config = Modules::load_file($file, $path, 'config')) {
/* reference to the config array */
// reference to the config array
$current_config =& $this->config;

if ($use_sections === true) {
Expand Down
8 changes: 4 additions & 4 deletions application/third_party/MX/Controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');

/** load the CI class for Modular Extensions **/
// load the CI class for Modular Extensions
require_once __DIR__ .'/Base.php';

/**
Expand Down Expand Up @@ -38,7 +38,7 @@
**/
class MX_Controller
{
public $autoload = array();
public $autoload = [];

/**
* [__construct description]
Expand All @@ -51,11 +51,11 @@ public function __construct()
log_message('debug', $class.' MX_Controller Initialized');
Modules::$registry[strtolower($class)] = $this;

/* copy a loader instance and initialize */
// copy a loader instance and initialize
$this->load = clone load_class('Loader');
$this->load->initialize($this);

/* autoload module items */
// autoload module items
$this->load->_autoloader($this->autoload);
}

Expand Down
68 changes: 32 additions & 36 deletions application/third_party/MX/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class MX_Loader extends CI_Loader
{
protected $_module;

public $_ci_plugins = array();
public $_ci_cached_vars = array();
public $_ci_plugins = [];
public $_ci_cached_vars = [];

/**
* [Initialize the loader variables]
Expand All @@ -51,14 +51,14 @@ class MX_Loader extends CI_Loader
*/
public function initialize($controller = null)
{
/* set the module name */
// set the module name
$this->_module = CI::$APP->router->fetch_module();

if ($controller instanceof MX_Controller) {
/* reference to the module controller */
// reference to the module controller
$this->controller = $controller;

/* references to ci loader variables */
// references to ci loader variables
foreach (get_class_vars('CI_Loader') as $var => $val) {
if ($var !== '_ci_ob_level') {
$this->$var =& CI::$APP->load->$var;
Expand All @@ -67,11 +67,11 @@ public function initialize($controller = null)
} else {
parent::initialize();

/* autoload module items */
$this->_autoloader(array());
// autoload module items
$this->_autoloader([]);
}

/* add this module path to the loader variables */
// add this module path to the loader variables
$this->_add_module_paths($this->_module);
}

Expand All @@ -89,7 +89,7 @@ public function _add_module_paths($module = '')
}

foreach (Modules::$locations as $location => $offset) {
/* only add a module path if it exists */
// only add a module path if it exists
if (is_dir($module_path = $location.$module.'/') && ! in_array($module_path, $this->_ci_model_paths)) {
array_unshift($this->_ci_model_paths, $module_path);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ public function database($params = '', $return = false, $query_builder = null)
*
* @return [type] [description]
*/
public function helper($helper = array())
public function helper($helper = [])
{
if (is_array($helper)) {
return $this->helpers($helper);
Expand Down Expand Up @@ -186,7 +186,7 @@ public function helper($helper = array())
*
* @return [type] [description]
*/
public function helpers($helpers = array())
public function helpers($helpers = [])
{
foreach ($helpers as $_helper) {
$this->helper($_helper);
Expand Down Expand Up @@ -264,7 +264,7 @@ public function library($library, $params = null, $object_name = null)
[$path, $_library] = Modules::find($library, $this->_module, 'libraries/');
}

/* load library config file as params */
// load library config file as params
if ($params === null) {

// Backward function
Expand Down Expand Up @@ -335,14 +335,14 @@ public function model($model, $object_name = null, $connect = false)
// Before PHP 7.1.0, list() only worked on numerical arrays and assumes the numerical indices start at 0.
if (version_compare(phpversion(), '7.1', '<')) {
// php version isn't high enough
/* check module */
// check module
list($path, $_model) = Modules::find(strtolower($model), $this->_module, 'models/');
} else {
[$path, $_model] = Modules::find(strtolower($model), $this->_module, 'models/');
}

if ($path === false) {
/* check application & packages */
// check application & packages
parent::model($model, $object_name, $connect);
} else {
class_exists('CI_Model', false) or load_class('Model', 'core');
Expand Down Expand Up @@ -398,7 +398,7 @@ public function module($module, $params = null)
}

$_alias = strtolower(basename($module));
CI::$APP->$_alias = Modules::load(array($module => $params));
CI::$APP->$_alias = Modules::load([$module => $params]);
return $this;
}

Expand Down Expand Up @@ -484,7 +484,7 @@ public function plugins($plugins)
*
* @return [type] [description]
*/
public function view($view, $vars = array(), $return = false)
public function view($view, $vars = [], $return = false)
{
// Backward function
// Before PHP 7.1.0, list() only worked on numerical arrays and assumes the numerical indices start at 0.
Expand All @@ -496,14 +496,14 @@ public function view($view, $vars = array(), $return = false)
}

if ($path != false) {
$this->_ci_view_paths = array($path => true) + $this->_ci_view_paths;
$this->_ci_view_paths = [$path => true] + $this->_ci_view_paths;
$view = $_view;
}

if (method_exists($this, '_ci_object_to_array')) {
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
return $this->_ci_load(['_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return]);
} else {
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
return $this->_ci_load(['_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return]);
}
}

Expand Down Expand Up @@ -551,7 +551,7 @@ public function _ci_load($_ci_data)
if (isset($_ci_view)) {
$_ci_path = '';

/* add file extension if not provided */
// add file extension if not provided
$_ci_file = pathinfo($_ci_view, PATHINFO_EXTENSION) ? $_ci_view : $_ci_view.EXT;

foreach ($this->_ci_view_paths as $path => $cascade) {
Expand Down Expand Up @@ -624,7 +624,7 @@ public function _autoloader($autoload)
} else {
[$path, $file] = Modules::find('constants', $this->_module, 'config/');
}
/* module constants file */
// module constants file
if ($path !== false) {
include_once $path.$file.EXT;
}
Expand All @@ -638,18 +638,18 @@ public function _autoloader($autoload)
[$path, $file] = Modules::find('autoload', $this->_module, 'config/');
}

/* module autoload file */
// module autoload file
if ($path !== false) {
$autoload = array_merge(Modules::load_file($file, $path, 'autoload'), $autoload);
}
}

/* nothing to do */
// nothing to do
if (count($autoload) === 0) {
return;
}

/* autoload package paths */
// autoload package paths
if (isset($autoload['packages'])) {
foreach ($autoload['packages'] as $package_path) {
$this->add_package_path($package_path);
Expand All @@ -663,8 +663,8 @@ public function _autoloader($autoload)
}
}

/* autoload helpers, plugins, languages */
foreach (array('helper', 'plugin', 'language') as $type) {
// autoload helpers, plugins, languages
foreach (['helper', 'plugin', 'language'] as $type) {
if (isset($autoload[$type])) {
foreach ($autoload[$type] as $item) {
$this->$type($item);
Expand All @@ -679,32 +679,28 @@ public function _autoloader($autoload)
}
}

/* autoload database & libraries */
// autoload database & libraries
if (isset($autoload['libraries'])) {
if (!$db = CI::$APP->config->item('database') && in_array('database', $autoload['libraries'])) {
$this->database();

$autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
$autoload['libraries'] = array_diff($autoload['libraries'], ['database']);
}





/* autoload libraries */
// autoload libraries
foreach ($autoload['libraries'] as $library => $alias) {
is_int($library) ? $this->library($alias) : $this->library($library, null, $alias);
}
}

/* autoload models */
// autoload models
if (isset($autoload['model'])) {
foreach ($autoload['model'] as $model => $alias) {
is_int($model) ? $this->model($alias) : $this->model($model, $alias);
}
}

/* autoload module controllers */
// autoload module controllers
if (isset($autoload['modules'])) {
foreach ($autoload['modules'] as $controller) {
($controller != $this->_module) && $this->module($controller);
Expand All @@ -713,5 +709,5 @@ public function _autoloader($autoload)
}
}

/** load the CI class for Modular Separation **/
// load the CI class for Modular Separation
(class_exists('CI', false)) or require_once __DIR__ .'/Ci.php';
Loading

0 comments on commit f67b538

Please sign in to comment.