| Total Complexity | 74 |
| Total Lines | 611 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Loader often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Loader, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class Loader extends BaseClass { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * List of loaded resources |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | private $loaded = array(); |
||
| 37 | |||
| 38 | |||
| 39 | public function __construct() { |
||
| 47 | } |
||
| 48 | |||
| 49 | |||
| 50 | /** |
||
| 51 | * Load the model class |
||
| 52 | * |
||
| 53 | * @param string $class the class name to be loaded |
||
| 54 | * @param string $instance the name of the instance to use in super object |
||
| 55 | * |
||
| 56 | * @return void |
||
| 57 | */ |
||
| 58 | public function model($class, $instance = null) { |
||
| 59 | $class = str_ireplace('.php', '', $class); |
||
| 60 | $class = trim($class, '/\\'); |
||
| 61 | $file = ucfirst($class) . '.php'; |
||
| 62 | $this->logger->debug('Loading model [' . $class . '] ...'); |
||
| 63 | //************ |
||
| 64 | if (!$instance) { |
||
| 65 | $instance = $this->getModelLibraryInstanceName($class); |
||
| 66 | } |
||
| 67 | //**************** |
||
| 68 | if (isset($this->loaded[$instance])) { |
||
| 69 | $this->logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
||
| 70 | return; |
||
| 71 | } |
||
| 72 | $classFilePath = APPS_MODEL_PATH . $file; |
||
| 73 | //first check if this model is in the module |
||
| 74 | $this->logger->debug('Checking model [' . $class . '] from module list ...'); |
||
| 75 | //check if the request class contains module name |
||
| 76 | $moduleInfo = $this->getModuleInfoForModelLibrary($class); |
||
| 77 | $module = $moduleInfo['module']; |
||
| 78 | $class = $moduleInfo['class']; |
||
| 79 | |||
| 80 | $moduleModelFilePath = get_instance()->module->findModelFullPath($class, $module); |
||
| 81 | if ($moduleModelFilePath) { |
||
| 82 | $this->logger->info('Found model [' . $class . '] from module [' . $module . '], ' |
||
| 83 | . 'the file path is [' . $moduleModelFilePath . '] we will used it'); |
||
| 84 | $classFilePath = $moduleModelFilePath; |
||
| 85 | } else { |
||
| 86 | $this->logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
||
| 87 | } |
||
| 88 | $this->logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
||
| 89 | if (file_exists($classFilePath)) { |
||
| 90 | require_once $classFilePath; |
||
| 91 | if (class_exists($class)) { |
||
| 92 | $c = new $class(); |
||
| 93 | $obj = & get_instance(); |
||
| 94 | $obj->{$instance} = $c; |
||
| 95 | $this->loaded[$instance] = $class; |
||
| 96 | $this->logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
||
| 97 | } else { |
||
| 98 | show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
||
| 99 | } |
||
| 100 | } else { |
||
| 101 | show_error('Unable to find the model [' . $class . ']'); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | |||
| 106 | /** |
||
| 107 | * Load the library class |
||
| 108 | * |
||
| 109 | * @param string $class the library class name to be loaded |
||
| 110 | * @param string $instance the instance name to use in super object |
||
| 111 | * @param mixed $params the arguments to pass to the constructor |
||
| 112 | * |
||
| 113 | * @return void |
||
| 114 | */ |
||
| 115 | public function library($class, $instance = null, array $params = array()) { |
||
| 116 | $class = str_ireplace('.php', '', $class); |
||
| 117 | $class = trim($class, '/\\'); |
||
| 118 | $file = ucfirst($class) . '.php'; |
||
| 119 | $this->logger->debug('Loading library [' . $class . '] ...'); |
||
| 120 | if (!$instance) { |
||
| 121 | $instance = $this->getModelLibraryInstanceName($class); |
||
| 122 | } |
||
| 123 | if (isset($this->loaded[$instance])) { |
||
| 124 | $this->logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
||
| 125 | return; |
||
| 126 | } |
||
| 127 | $obj = & get_instance(); |
||
|
|
|||
| 128 | //Check and load Database library |
||
| 129 | if (strtolower($class) == 'database') { |
||
| 130 | $this->logger->info('This is the Database library ...'); |
||
| 131 | $this->loadDatabase(); |
||
| 132 | return; |
||
| 133 | } |
||
| 134 | $libraryFilePath = null; |
||
| 135 | $this->logger->debug('Check if this is a system library ...'); |
||
| 136 | if (file_exists(CORE_LIBRARY_PATH . $file)) { |
||
| 137 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
||
| 138 | $class = ucfirst($class); |
||
| 139 | $this->logger->info('This library is a system library'); |
||
| 140 | } else { |
||
| 141 | $this->logger->info('This library is not a system library'); |
||
| 142 | //first check if this library is in the module |
||
| 143 | $info = $this->getLibraryPathUsingModuleInfo($class); |
||
| 144 | $class = $info['class']; |
||
| 145 | $libraryFilePath = $info['path']; |
||
| 146 | } |
||
| 147 | if (!$libraryFilePath && file_exists(LIBRARY_PATH . $file)) { |
||
| 148 | $libraryFilePath = LIBRARY_PATH . $file; |
||
| 149 | } |
||
| 150 | $this->logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
||
| 151 | $this->loadLibrary($libraryFilePath, $class, $instance, $params); |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Load the helper |
||
| 156 | * |
||
| 157 | * @param string $function the helper name to be loaded |
||
| 158 | * |
||
| 159 | * @return void |
||
| 160 | */ |
||
| 161 | public function functions($function) { |
||
| 162 | $function = str_ireplace('.php', '', $function); |
||
| 163 | $function = trim($function, '/\\'); |
||
| 164 | $function = str_ireplace('function_', '', $function); |
||
| 165 | $file = 'function_' . $function . '.php'; |
||
| 166 | $this->logger->debug('Loading helper [' . $function . '] ...'); |
||
| 167 | if (isset($this->loaded['function_' . $function])) { |
||
| 168 | $this->logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
||
| 169 | return; |
||
| 170 | } |
||
| 171 | $functionFilePath = null; |
||
| 172 | //first check if this helper is in the module |
||
| 173 | $this->logger->debug('Checking helper [' . $function . '] from module list ...'); |
||
| 174 | $moduleInfo = $this->getModuleInfoForFunction($function); |
||
| 175 | $module = $moduleInfo['module']; |
||
| 176 | $function = $moduleInfo['function']; |
||
| 177 | if (!empty($moduleInfo['file'])) { |
||
| 178 | $file = $moduleInfo['file']; |
||
| 179 | } |
||
| 180 | $moduleFunctionPath = get_instance()->module->findFunctionFullPath($function, $module); |
||
| 181 | if ($moduleFunctionPath) { |
||
| 182 | $this->logger->info('Found helper [' . $function . '] from module [' . $module . '], ' |
||
| 183 | . 'the file path is [' . $moduleFunctionPath . '] we will used it'); |
||
| 184 | $functionFilePath = $moduleFunctionPath; |
||
| 185 | } else { |
||
| 186 | $this->logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
||
| 187 | } |
||
| 188 | if (!$functionFilePath) { |
||
| 189 | $functionFilePath = $this->getDefaultFilePathForFunctionLanguage($file, 'function'); |
||
| 190 | } |
||
| 191 | $this->logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
||
| 192 | if ($functionFilePath) { |
||
| 193 | require_once $functionFilePath; |
||
| 194 | $this->loaded['function_' . $function] = $functionFilePath; |
||
| 195 | $this->logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
||
| 196 | } else { |
||
| 197 | show_error('Unable to find helper file [' . $file . ']'); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Load the configuration file |
||
| 203 | * |
||
| 204 | * @param string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config |
||
| 205 | * |
||
| 206 | * @return void |
||
| 207 | */ |
||
| 208 | public function config($filename) { |
||
| 209 | $filename = str_ireplace('.php', '', $filename); |
||
| 210 | $filename = trim($filename, '/\\'); |
||
| 211 | $filename = str_ireplace('config_', '', $filename); |
||
| 212 | $file = 'config_' . $filename . '.php'; |
||
| 213 | $this->logger->debug('Loading configuration [' . $filename . '] ...'); |
||
| 214 | $configFilePath = CONFIG_PATH . $file; |
||
| 215 | //first check if this config is in the module |
||
| 216 | $this->logger->debug('Checking config [' . $filename . '] from module list ...'); |
||
| 217 | $moduleInfo = $this->getModuleInfoForConfig($filename); |
||
| 218 | $module = $moduleInfo['module']; |
||
| 219 | $filename = $moduleInfo['filename']; |
||
| 220 | $moduleConfigPath = get_instance()->module->findConfigFullPath($filename, $module); |
||
| 221 | if ($moduleConfigPath) { |
||
| 222 | $this->logger->info('Found config [' . $filename . '] from module [' . $module . '], ' |
||
| 223 | . 'the file path is [' . $moduleConfigPath . '] we will used it'); |
||
| 224 | $configFilePath = $moduleConfigPath; |
||
| 225 | } else { |
||
| 226 | $this->logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
||
| 227 | } |
||
| 228 | $this->logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
||
| 229 | $config = array(); |
||
| 230 | if (file_exists($configFilePath)) { |
||
| 231 | //note need use require instead of require_once |
||
| 232 | require $configFilePath; |
||
| 233 | if (!empty($config) && is_array($config)) { |
||
| 234 | get_instance()->config->setAll($config); |
||
| 235 | $this->logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
||
| 236 | $this->logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
||
| 237 | unset($config); |
||
| 238 | } |
||
| 239 | } else { |
||
| 240 | show_error('Unable to find config file [' . $configFilePath . ']'); |
||
| 241 | } |
||
| 242 | } |
||
| 243 | |||
| 244 | |||
| 245 | /** |
||
| 246 | * Load the language |
||
| 247 | * |
||
| 248 | * @param string $language the language name to be loaded |
||
| 249 | * |
||
| 250 | * @return void |
||
| 251 | */ |
||
| 252 | public function lang($language) { |
||
| 253 | $language = str_ireplace('.php', '', $language); |
||
| 254 | $language = trim($language, '/\\'); |
||
| 255 | $language = str_ireplace('lang_', '', $language); |
||
| 256 | $file = 'lang_' . $language . '.php'; |
||
| 257 | $this->logger->debug('Loading language [' . $language . '] ...'); |
||
| 258 | if (isset($this->loaded['lang_' . $language])) { |
||
| 259 | $this->logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
||
| 260 | return; |
||
| 261 | } |
||
| 262 | //get the current language |
||
| 263 | $appLang = $this->getAppLang(); |
||
| 264 | $languageFilePath = null; |
||
| 265 | //first check if this language is in the module |
||
| 266 | $this->logger->debug('Checking language [' . $language . '] from module list ...'); |
||
| 267 | $moduleInfo = $this->getModuleInfoForLanguage($language); |
||
| 268 | $module = $moduleInfo['module']; |
||
| 269 | $language = $moduleInfo['language']; |
||
| 270 | if (!empty($moduleInfo['file'])) { |
||
| 271 | $file = $moduleInfo['file']; |
||
| 272 | } |
||
| 273 | $moduleLanguagePath = get_instance()->module->findLanguageFullPath($language, $appLang, $module); |
||
| 274 | if ($moduleLanguagePath) { |
||
| 275 | $this->logger->info('Found language [' . $language . '] from module [' . $module . '], ' |
||
| 276 | . 'the file path is [' . $moduleLanguagePath . '] we will used it'); |
||
| 277 | $languageFilePath = $moduleLanguagePath; |
||
| 278 | } else { |
||
| 279 | $this->logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
||
| 280 | } |
||
| 281 | if (!$languageFilePath) { |
||
| 282 | $languageFilePath = $this->getDefaultFilePathForFunctionLanguage($file, 'language', $appLang); |
||
| 283 | } |
||
| 284 | $this->logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
||
| 285 | $this->loadLanguage($languageFilePath, $language); |
||
| 286 | } |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Load the library database with dependencies |
||
| 290 | */ |
||
| 291 | protected function loadDatabase() { |
||
| 292 | $connection = &class_loader('DatabaseConnection', 'classes/database'); |
||
| 293 | $config = $connection->getDatabaseConfigFromFile(); |
||
| 294 | $connection->setConfig($config); |
||
| 295 | $connection->connect(); |
||
| 296 | |||
| 297 | $obj = &get_instance(); |
||
| 298 | |||
| 299 | $db = & class_loader('Database', 'classes/database', $connection); |
||
| 300 | $queryResult = &class_loader('DatabaseQueryResult', 'classes/database'); |
||
| 301 | $queryRunner = &class_loader('DatabaseQueryRunner', 'classes/database', $connection); |
||
| 302 | $queryRunner->setQueryResult($queryResult); |
||
| 303 | $queryRunner->setBenchmark($obj->benchmark); |
||
| 304 | $db->setQueryRunner($queryRunner); |
||
| 305 | |||
| 306 | $queryBuilder = &class_loader('DatabaseQueryBuilder', 'classes/database', $connection); |
||
| 307 | $db->setQueryBuilder($queryBuilder); |
||
| 308 | |||
| 309 | $dbCache = &class_loader('DatabaseCache', 'classes/database'); |
||
| 310 | $db->setCache($dbCache); |
||
| 311 | $obj->database = $db; |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Return the current app language by default will use the value from cookie |
||
| 316 | * if can not found will use the default value from configuration |
||
| 317 | * @return string the app language like "en", "fr" |
||
| 318 | */ |
||
| 319 | protected function getAppLang() { |
||
| 320 | //determine the current language |
||
| 321 | $appLang = get_instance()->config->get('default_language'); |
||
| 322 | //if the language exists in the cookie use it |
||
| 323 | $cfgKey = get_instance()->config->get('language_cookie_name'); |
||
| 324 | $objCookie = & class_loader('Cookie'); |
||
| 325 | $cookieLang = $objCookie->get($cfgKey); |
||
| 326 | if ($cookieLang) { |
||
| 327 | $appLang = $cookieLang; |
||
| 328 | } |
||
| 329 | return $appLang; |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Return the default full file path for function, language |
||
| 334 | * @param string $file the filename |
||
| 335 | * @param string $type the type can be "function", "language" |
||
| 336 | * @param string $appLang the application language, only if type = "language" |
||
| 337 | * @return string|null the full file path |
||
| 338 | */ |
||
| 339 | protected function getDefaultFilePathForFunctionLanguage($file, $type, $appLang = null){ |
||
| 340 | $searchDir = null; |
||
| 341 | if ($type == 'function') { |
||
| 342 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
||
| 343 | } |
||
| 344 | else if ($type == 'language') { |
||
| 345 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
||
| 346 | $file = $appLang . DS . $file; |
||
| 347 | } |
||
| 348 | $fullFilePath = null; |
||
| 349 | foreach ($searchDir as $dir) { |
||
| 350 | $filePath = $dir . $file; |
||
| 351 | if (file_exists($filePath)) { |
||
| 352 | $fullFilePath = $filePath; |
||
| 353 | //is already found not to continue |
||
| 354 | break; |
||
| 355 | } |
||
| 356 | } |
||
| 357 | return $fullFilePath; |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Get the module using the attribute of super controller "moduleName" |
||
| 362 | * @param string|null $module the module if is not null will return it |
||
| 363 | * @return string|null |
||
| 364 | */ |
||
| 365 | protected function getModuleFromSuperController($module){ |
||
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Get the module information for the model and library to load |
||
| 375 | * @param string $class the full class name like moduleName/className, className, |
||
| 376 | * @return array the module information |
||
| 377 | * array( |
||
| 378 | * 'module'=> 'module_name' |
||
| 379 | * 'class' => 'class_name' |
||
| 380 | * ) |
||
| 381 | */ |
||
| 382 | protected function getModuleInfoForModelLibrary($class) { |
||
| 383 | $module = null; |
||
| 384 | $path = explode('/', $class); |
||
| 385 | if (count($path) >= 2 && in_array($path[0], get_instance()->module->getModuleList())) { |
||
| 386 | $module = $path[0]; |
||
| 387 | $class = ucfirst($path[1]); |
||
| 388 | } else { |
||
| 389 | $class = ucfirst($class); |
||
| 390 | } |
||
| 391 | $module = $this->getModuleFromSuperController($module); |
||
| 392 | return array( |
||
| 393 | 'class' => $class, |
||
| 394 | 'module' => $module |
||
| 395 | ); |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Get the module information for the function to load |
||
| 400 | * @param string $function the function name like moduleName/functionName, functionName, |
||
| 401 | * @return array the module information |
||
| 402 | * array( |
||
| 403 | * 'module'=> 'module_name' |
||
| 404 | * 'function' => 'function' |
||
| 405 | * 'file' => 'file' |
||
| 406 | * ) |
||
| 407 | */ |
||
| 408 | protected function getModuleInfoForFunction($function) { |
||
| 409 | $module = null; |
||
| 410 | $file = null; |
||
| 411 | //check if the request class contains module name |
||
| 412 | $path = explode('/', $function); |
||
| 413 | if (count($path) >= 2 && in_array($path[0], get_instance()->module->getModuleList())) { |
||
| 414 | $module = $path[0]; |
||
| 415 | $function = 'function_' . $path[1]; |
||
| 416 | $file = $path[0] . DS . $function . '.php'; |
||
| 417 | } |
||
| 418 | $module = $this->getModuleFromSuperController($module); |
||
| 419 | return array( |
||
| 420 | 'function' => $function, |
||
| 421 | 'module' => $module, |
||
| 422 | 'file' => $file |
||
| 423 | ); |
||
| 424 | } |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Get the module information for the language to load |
||
| 428 | * @param string $language the language name like moduleName/languageName, languageName, |
||
| 429 | * @return array the module information |
||
| 430 | * array( |
||
| 431 | * 'module'=> 'module_name' |
||
| 432 | * 'language' => 'language' |
||
| 433 | * 'file' => 'file' |
||
| 434 | * ) |
||
| 435 | */ |
||
| 436 | protected function getModuleInfoForLanguage($language) { |
||
| 437 | $module = null; |
||
| 438 | $file = null; |
||
| 439 | //check if the request class contains module name |
||
| 440 | $path = explode('/', $language); |
||
| 441 | if (count($path) >= 2 && in_array($path[0], get_instance()->module->getModuleList())) { |
||
| 442 | $module = $path[0]; |
||
| 443 | $language = 'lang_' . $path[1] . '.php'; |
||
| 444 | $file = $path[0] . DS . $language; |
||
| 445 | } |
||
| 446 | $module = $this->getModuleFromSuperController($module); |
||
| 447 | return array( |
||
| 448 | 'language' => $language, |
||
| 449 | 'module' => $module, |
||
| 450 | 'file' => $file |
||
| 451 | ); |
||
| 452 | } |
||
| 453 | |||
| 454 | |||
| 455 | /** |
||
| 456 | * Get the module information for the config to load |
||
| 457 | * @param string $filename the filename of the configuration file, |
||
| 458 | * @return array the module information |
||
| 459 | * array( |
||
| 460 | * 'module'=> 'module_name' |
||
| 461 | * 'filename' => 'filename' |
||
| 462 | * ) |
||
| 463 | */ |
||
| 464 | protected function getModuleInfoForConfig($filename) { |
||
| 465 | $module = null; |
||
| 466 | //check if the request class contains module name |
||
| 467 | $path = explode('/', $filename); |
||
| 468 | if (count($path) >= 2 && in_array($path[0], get_instance()->module->getModuleList())) { |
||
| 469 | $module = $path[0]; |
||
| 470 | $filename = $path[1] . '.php'; |
||
| 471 | } |
||
| 472 | $module = $this->getModuleFromSuperController($module); |
||
| 473 | return array( |
||
| 474 | 'filename' => $filename, |
||
| 475 | 'module' => $module |
||
| 476 | ); |
||
| 477 | } |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Get the name of model or library instance if is null |
||
| 481 | * @param string $class the class name to determine the instance |
||
| 482 | * @return string the instance name |
||
| 483 | */ |
||
| 484 | protected function getModelLibraryInstanceName($class) { |
||
| 485 | //for module |
||
| 486 | $instance = null; |
||
| 487 | $path = explode('/', $class); |
||
| 488 | if (count($path) >= 2) { |
||
| 489 | $instance = strtolower($path[1]); |
||
| 490 | } else { |
||
| 491 | $instance = strtolower($class); |
||
| 492 | } |
||
| 493 | return $instance; |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Get the library file path and class name using the module information |
||
| 498 | * @param string $class the class name |
||
| 499 | * @return array the library file path and class name |
||
| 500 | */ |
||
| 501 | protected function getLibraryPathUsingModuleInfo($class) { |
||
| 502 | $libraryFilePath = null; |
||
| 503 | $this->logger->debug('Checking library [' . $class . '] from module list ...'); |
||
| 504 | $moduleInfo = $this->getModuleInfoForModelLibrary($class); |
||
| 505 | $module = $moduleInfo['module']; |
||
| 506 | $class = $moduleInfo['class']; |
||
| 507 | $moduleLibraryPath = get_instance()->module->findLibraryFullPath($class, $module); |
||
| 508 | if ($moduleLibraryPath) { |
||
| 509 | $this->logger->info('Found library [' . $class . '] from module [' . $module . '], the ' |
||
| 510 | . 'file path is [' . $moduleLibraryPath . '] we will used it'); |
||
| 511 | $libraryFilePath = $moduleLibraryPath; |
||
| 512 | } else { |
||
| 513 | $this->logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
||
| 514 | } |
||
| 515 | return array( |
||
| 516 | 'path' => $libraryFilePath, |
||
| 517 | 'class' => $class |
||
| 518 | ); |
||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Load the library |
||
| 523 | * @param string $libraryFilePath the file path of the library to load |
||
| 524 | * @param string $class the class name |
||
| 525 | * @param string $instance the instance |
||
| 526 | * @param array $params the parameter to use |
||
| 527 | * @return void |
||
| 528 | */ |
||
| 529 | protected function loadLibrary($libraryFilePath, $class, $instance, $params = array()) { |
||
| 530 | if ($libraryFilePath) { |
||
| 531 | require_once $libraryFilePath; |
||
| 532 | if (class_exists($class)) { |
||
| 533 | $c = $params ? new $class($params) : new $class(); |
||
| 534 | $obj = & get_instance(); |
||
| 535 | $obj->{$instance} = $c; |
||
| 536 | $this->loaded[$instance] = $class; |
||
| 537 | $this->logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
||
| 538 | } else { |
||
| 539 | show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
||
| 540 | } |
||
| 541 | } else { |
||
| 542 | show_error('Unable to find library class [' . $class . ']'); |
||
| 543 | } |
||
| 544 | } |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Load the language |
||
| 548 | * @param string $languageFilePath the file path of the language to load |
||
| 549 | * @param string $language the language name |
||
| 550 | * @return void |
||
| 551 | */ |
||
| 552 | protected function loadLanguage($languageFilePath, $language) { |
||
| 553 | if ($languageFilePath) { |
||
| 554 | $lang = array(); |
||
| 555 | require_once $languageFilePath; |
||
| 556 | if (!empty($lang) && is_array($lang)) { |
||
| 557 | $this->logger->info('Language file [' . $languageFilePath . '] contains the ' |
||
| 558 | . 'valid languages keys add them to language list'); |
||
| 559 | //Note: may be here the class 'Lang' not yet loaded |
||
| 560 | $langObj = & class_loader('Lang', 'classes'); |
||
| 561 | $langObj->addLangMessages($lang); |
||
| 562 | //free the memory |
||
| 563 | unset($lang); |
||
| 564 | } |
||
| 565 | $this->loaded['lang_' . $language] = $languageFilePath; |
||
| 566 | $this->logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
||
| 567 | } else { |
||
| 568 | show_error('Unable to find language [' . $language . ']'); |
||
| 569 | } |
||
| 570 | } |
||
| 571 | |||
| 572 | /** |
||
| 573 | * Load the resources autoload array |
||
| 574 | * @param string $method this object method name to call |
||
| 575 | * @param array $resources the resource to load |
||
| 576 | * @return void |
||
| 577 | */ |
||
| 578 | protected function loadAutoloadResourcesArray($method, array $resources) { |
||
| 581 | } |
||
| 582 | } |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Get all the autoload using the configuration file |
||
| 586 | * @return array |
||
| 587 | */ |
||
| 588 | protected function getResourcesFromAutoloadConfig() { |
||
| 589 | $autoloads = array(); |
||
| 590 | $autoloads['config'] = array(); |
||
| 591 | $autoloads['languages'] = array(); |
||
| 592 | $autoloads['libraries'] = array(); |
||
| 593 | $autoloads['models'] = array(); |
||
| 594 | $autoloads['functions'] = array(); |
||
| 595 | //loading of the resources from autoload configuration file |
||
| 596 | if (file_exists(CONFIG_PATH . 'autoload.php')) { |
||
| 597 | $autoload = array(); |
||
| 598 | require CONFIG_PATH . 'autoload.php'; |
||
| 599 | if (!empty($autoload) && is_array($autoload)) { |
||
| 600 | $autoloads = array_merge($autoloads, $autoload); |
||
| 601 | unset($autoload); |
||
| 602 | } |
||
| 603 | } |
||
| 604 | //loading autoload configuration for modules |
||
| 605 | $modulesAutoloads = get_instance()->module->getModulesAutoloadConfig(); |
||
| 606 | if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) { |
||
| 607 | $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
||
| 608 | } |
||
| 609 | return $autoloads; |
||
| 610 | } |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Load the autoload configuration |
||
| 614 | * @return void |
||
| 615 | */ |
||
| 616 | protected function loadResourcesFromAutoloadConfig() { |
||
| 641 | } |
||
| 642 | } |
||
| 643 |