From f67b538d0de7159cf8bb82be59556ee98995f8dd Mon Sep 17 00:00:00 2001 From: N3Cr0N Date: Fri, 12 Apr 2019 22:09:24 +0200 Subject: [PATCH] Fix: As of PHP 5.4 you can also use the short array syntax, which replace array() with [] , and Fix comment style --- application/third_party/MX/Base.php | 18 +++--- application/third_party/MX/Ci.php | 8 +-- application/third_party/MX/Config.php | 2 +- application/third_party/MX/Controller.php | 8 +-- application/third_party/MX/Loader.php | 68 +++++++++++------------ application/third_party/MX/Modules.php | 52 ++++++++--------- application/third_party/MX/Router.php | 30 +++++----- 7 files changed, 91 insertions(+), 95 deletions(-) diff --git a/application/third_party/MX/Base.php b/application/third_party/MX/Base.php index 5941c31..3ba27d4 100644 --- a/application/third_party/MX/Base.php +++ b/application/third_party/MX/Base.php @@ -1,6 +1,6 @@ config; if ($use_sections === true) { diff --git a/application/third_party/MX/Controller.php b/application/third_party/MX/Controller.php index 4d2a066..5535aa0 100644 --- a/application/third_party/MX/Controller.php +++ b/application/third_party/MX/Controller.php @@ -1,6 +1,6 @@ load = clone load_class('Loader'); $this->load->initialize($this); - /* autoload module items */ + // autoload module items $this->load->_autoloader($this->autoload); } diff --git a/application/third_party/MX/Loader.php b/application/third_party/MX/Loader.php index 4da29d1..fd1f904 100644 --- a/application/third_party/MX/Loader.php +++ b/application/third_party/MX/Loader.php @@ -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] @@ -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; @@ -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); } @@ -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); } @@ -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); @@ -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); @@ -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 @@ -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'); @@ -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; } @@ -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. @@ -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]); } } @@ -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) { @@ -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; } @@ -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); @@ -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); @@ -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); @@ -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'; diff --git a/application/third_party/MX/Modules.php b/application/third_party/MX/Modules.php index a32fc5b..ca8571a 100644 --- a/application/third_party/MX/Modules.php +++ b/application/third_party/MX/Modules.php @@ -4,12 +4,12 @@ global $CFG; -/* get module locations from config settings or use the default module location and offset */ -is_array(Modules::$locations = $CFG->item('modules_locations')) or Modules::$locations = array( +// get module locations from config settings or use the default module location and offset +is_array(Modules::$locations = $CFG->item('modules_locations')) or Modules::$locations = [ APPPATH.'modules/' => '../modules/', -); +]; -/* PHP5 spl_autoload */ +// PHP5 spl_autoload spl_autoload_register('Modules::autoload'); /** @@ -73,7 +73,7 @@ public static function run($module) if (method_exists($class, $method)) { ob_start(); $args = func_get_args(); - $output = call_user_func_array(array($class, $method), array_slice($args, 1)); + $output = call_user_func_array([$class, $method], array_slice($args, 1)); $buffer = ob_get_clean(); return $output ?? $buffer; } @@ -111,34 +111,34 @@ public static function load($module) } } - /* get the requested controller class name */ + // get the requested controller class name $alias = strtolower(basename($module)); - /* create or return an existing controller from the registry */ + // create or return an existing controller from the registry if (!isset(self::$registry[$alias])) { - // Backward function + // Backward function // 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 - /* find the controller */ + // find the controller list($class) = CI::$APP->router->locate(explode('/', $module)); } else { [$class] = CI::$APP->router->locate(explode('/', $module)); } - /* controller cannot be located */ + // controller cannot be located if (empty($class)) { return; } - /* set the module directory */ + // set the module directory $path = APPPATH.'controllers/'.CI::$APP->router->directory; - /* load the controller class */ + // load the controller class $class .= CI::$APP->config->item('controller_suffix'); self::load_file(ucfirst($class), $path); - /* create and register the new controller */ + // create and register the new controller $controller = ucfirst($class); self::$registry[$alias] = new $controller($params); } @@ -157,12 +157,12 @@ public static function load($module) */ public static function autoload($class) { - /* don't autoload CI_ prefixed classes or those using the config subclass_prefix */ + // don't autoload CI_ prefixed classes or those using the config subclass_prefix if (strstr($class, 'CI_') || strstr($class, config_item('subclass_prefix'))) { return; } - /* autoload Modular Extensions MX core classes */ + // autoload Modular Extensions MX core classes if (strstr($class, 'MX_')) { if (is_file($location = dirname(__FILE__).'/'.substr($class, 3).EXT)) { include_once $location; @@ -171,13 +171,13 @@ public static function autoload($class) show_error('Failed to load MX core class: '.$class); } - /* autoload core classes */ + // autoload core classes if (is_file($location = APPPATH.'core/'.ucfirst($class).EXT)) { include_once $location; return; } - /* autoload library classes */ + // autoload library classes if (is_file($location = APPPATH.'libraries/'.ucfirst($class).EXT)) { include_once $location; return; @@ -208,7 +208,7 @@ public static function load_file($file, $path, $type = 'other', $result = true) } include_once $location; } else { - /* load config or language array */ + // load config or language array include $location; if (! isset($$type) || ! is_array($$type)) { @@ -243,7 +243,7 @@ public static function find($file, $module, $base) $file_ext = pathinfo($file, PATHINFO_EXTENSION) ? $file : $file.EXT; $path = ltrim(implode('/', $segments).'/', '/'); - $module ? $modules[$module] = $path : $modules = array(); + $module ? $modules[$module] = $path : $modules = []; if (! empty($segments)) { $modules[array_shift($segments)] = ltrim(implode('/', $segments).'/', '/'); @@ -255,16 +255,16 @@ public static function find($file, $module, $base) if ($base === 'libraries/' || $base === 'models/') { if (is_file($fullpath.ucfirst($file_ext))) { - return array($fullpath, ucfirst($file)); + return [$fullpath, ucfirst($file)]; } - } elseif /* load non-class files */ + } elseif // load non-class files (is_file($fullpath.$file_ext)) { - return array($fullpath, $file); + return [$fullpath, $file]; } } } - return array(false, $file); + return [false, $file]; } /** @@ -279,7 +279,7 @@ public static function find($file, $module, $base) */ public static function parse_routes($module, $uri) { - /* load the route file */ + // load the route file if (! isset(self::$routes[$module])) { // Backward function // Before PHP 7.1.0, list() only worked on numerical arrays and assumes the numerical indices start at 0. @@ -302,7 +302,7 @@ public static function parse_routes($module, $uri) // Add http verb support for each module routing $http_verb = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli'; - /* parse module routes */ + // parse module routes foreach (self::$routes[$module] as $key => $val) { // Add http verb support for each module routing if (is_array($val)) { @@ -315,7 +315,7 @@ public static function parse_routes($module, $uri) } } - $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key); + $key = str_replace([':any', ':num'], ['.+', '[0-9]+'], $key); if (preg_match('#^'.$key.'$#', $uri)) { if (strpos($val, '$') !== false && strpos($key, '(') !== false) { diff --git a/application/third_party/MX/Router.php b/application/third_party/MX/Router.php index e54e1c7..8888c0b 100644 --- a/application/third_party/MX/Router.php +++ b/application/third_party/MX/Router.php @@ -1,6 +1,6 @@ translate_uri_dashes === true) { foreach (range(0, 2) as $v) { @@ -110,7 +110,7 @@ protected function _set_404override_controller() protected function _set_default_controller() { if (empty($this->directory)) { - /* set the default controller module path */ + // set the default controller module path $this->_set_module_path($this->default_controller); } @@ -148,27 +148,27 @@ public function locate($segments) // 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 - /* get the segments array elements */ + // get the segments array elements list($module, $directory, $controller) = array_pad($segments, 3, null); } else { [$module, $directory, $controller] = array_pad($segments, 3, null); } - /* check modules */ + // check modules foreach (Modules::$locations as $location => $offset) { - /* module exists? */ + // module exists? if (is_dir($source = $location.$module.'/controllers/')) { $this->module = $module; $this->directory = $offset.$module.'/controllers/'; - /* module sub-controller exists? */ + // module sub-controller exists? if ($directory) { - /* module sub-directory exists? */ + // module sub-directory exists? if (is_dir($source.$directory.'/')) { $source .= $directory.'/'; $this->directory .= $directory.'/'; - /* module sub-directory controller exists? */ + // module sub-directory controller exists? if ($controller) { if (is_file($source.ucfirst($controller).$ext)) { $this->located = 3; @@ -184,7 +184,7 @@ public function locate($segments) } } - /* module controller exists? */ + // module controller exists? if (is_file($source.ucfirst($module).$ext)) { $this->located = 1; return $segments; @@ -196,27 +196,27 @@ public function locate($segments) return; } - /* application sub-directory controller exists? */ + // application sub-directory controller exists? if ($directory) { if (is_file(APPPATH.'controllers/'.$module.'/'.ucfirst($directory).$ext)) { $this->directory = $module.'/'; return array_slice($segments, 1); } - /* application sub-sub-directory controller exists? */ + // application sub-sub-directory controller exists? if ($controller && is_file(APPPATH . 'controllers/' . $module . '/' . $directory . '/' . ucfirst($controller) . $ext)) { $this->directory = $module.'/'.$directory.'/'; return array_slice($segments, 2); } } - /* application controllers sub-directory exists? */ + // application controllers sub-directory exists? if (is_dir(APPPATH.'controllers/'.$module.'/')) { $this->directory = $module.'/'; return array_slice($segments, 1); } - /* application controller exists? */ + // application controller exists? if (is_file(APPPATH.'controllers/'.ucfirst($module).$ext)) { return $segments; } @@ -237,7 +237,7 @@ protected function _set_module_path(&$_route) $sgs = sscanf($_route, '%[^/]/%[^/]/%[^/]/%s', $module, $directory, $class, $method); // set the module/controller directory location if found - if ($this->locate(array($module, $directory, $class))) { + if ($this->locate([$module, $directory, $class])) { //reset to class/method switch ($sgs) { case 1: $_route = $module.'/index';