[CLI] Autoload bugs with load_class()
et-nik opened this issue · comments
Nikita commented
Bug 1. Application library autoload
If i will add in autoload custom library, then i will get error.
Example. I added to autoload application my library:
$autoload['libraries'] = array('gameap_hooks');
Then, i executed sprint command:
$ ./sprint forge model users
Invoked ModelGenerator
PHP Fatal error: Class 'CI_Gameap_hooks' not found in /home/nikita/Git/GameAP/upload/system/core/Common.php on line 208
PHP Stack trace:
PHP 1. {main}() /home/nikita/Git/GameAP/upload/index.php:0
PHP 2. require_once() /home/nikita/Git/GameAP/upload/index.php:332
PHP 3. call_user_func_array:{/home/nikita/Git/GameAP/upload/system/core/CodeIgniter.php:514}() /home/nikita/Git/GameAP/upload/system/core/CodeIgniter.php:514
PHP 4. Forge->_remap() /home/nikita/Git/GameAP/upload/system/core/CodeIgniter.php:514
PHP 5. call_user_func_array:{/home/nikita/Git/GameAP/upload/myth/CIModules/forge/controllers/Forge.php:57}() /home/nikita/Git/GameAP/upload/myth/CIModules/forge/controllers/Forge.php:57
PHP 6. Forge->run() /home/nikita/Git/GameAP/upload/myth/CIModules/forge/controllers/Forge.php:57
PHP 7. Myth\Forge\BaseGenerator->__construct() /home/nikita/Git/GameAP/upload/myth/CIModules/forge/controllers/Forge.php:158
PHP 8. Myth\Controllers\CLIController->__construct() /home/nikita/Git/GameAP/upload/myth/Forge/BaseGenerator.php:69
PHP 9. CI_Controller->__construct() /home/nikita/Git/GameAP/upload/myth/Controllers/CLIController.php:67
PHP 10. load_class() /home/nikita/Git/GameAP/upload/system/core/Controller.php:75
Fatal error: Class 'CI_Gameap_hooks' not found in /home/nikita/Git/GameAP/upload/system/core/Common.php on line 208
Call Stack:
0.0005 253672 1. {main}() /home/nikita/Git/GameAP/upload/index.php:0
0.0085 859560 2. require_once('/home/nikita/Git/GameAP/upload/system/core/CodeIgniter.php') /home/nikita/Git/GameAP/upload/index.php:332
0.1139 4326168 3. call_user_func_array:{/home/nikita/Git/GameAP/upload/system/core/CodeIgniter.php:514}() /home/nikita/Git/GameAP/upload/system/core/CodeIgniter.php:514
0.1139 4326720 4. Forge->_remap() /home/nikita/Git/GameAP/upload/system/core/CodeIgniter.php:514
0.1153 4436096 5. call_user_func_array:{/home/nikita/Git/GameAP/upload/myth/CIModules/forge/controllers/Forge.php:57}() /home/nikita/Git/GameAP/upload/myth/CIModules/forge/controllers/Forge.php:57
0.1153 4436728 6. Forge->run() /home/nikita/Git/GameAP/upload/myth/CIModules/forge/controllers/Forge.php:57
0.1178 4636080 7. Myth\Forge\BaseGenerator->__construct() /home/nikita/Git/GameAP/upload/myth/CIModules/forge/controllers/Forge.php:158
0.1178 4636080 8. Myth\Controllers\CLIController->__construct() /home/nikita/Git/GameAP/upload/myth/Forge/BaseGenerator.php:69
0.1178 4636080 9. CI_Controller->__construct() /home/nikita/Git/GameAP/upload/myth/Controllers/CLIController.php:67
0.1180 4638480 10. load_class() /home/nikita/Git/GameAP/upload/system/core/Controller.php:75
A PHP Error was encountered
Severity: Error
Message: Class 'CI_Gameap_hooks' not found
Filename: /home/nikita/Git/GameAP/upload/system/core/Common.php
Line Number: 208
Backtrace
It happens because code in CI_Controller constructor executed again.
At firts Gameap_hooks loaded via CI_Loader, next Gameap_hooks loaded via load_class() in Common.
Bug 2. Drivers autoload
If i will add driver to autoload:
$autoload['drivers'] = array('cache');
I will get error:
$ ./sprint forge model users
Invoked ModelGenerator
Unable to locate the specified class: Cache.php
It happens because code in CI_Controller constructor executed again.
Result is_loaded() after first execute CI_Controller constructor:
(
[benchmark] => Benchmark
[hooks] => Hooks
[config] => Config
[log] => Log
[utf8] => Utf8
[uri] => URI
[router] => Router
[output] => Output
[security] => Security
[input] => Input
[lang] => Lang
[loader] => Loader
[cache] => Cache
[gameap_hooks] => Gameap_hooks
)
After that, CI_Controller trying to load Cache library.