77
88 abstract class Main
99 {
10+ /**
11+ * Use same version as Composer configuration
12+ *
13+ * @var string
14+ */
1015 const PHP_MIN_VERSION = '7.1.0 ' ;
1116
1217 /**
@@ -15,45 +20,73 @@ abstract class Main
1520 protected $ _CONFIG ;
1621
1722 /**
18- * @var bool
23+ * @var bool|int
1924 */
2025 protected $ _debug = false ;
2126
2227 /**
23- * @var bool
28+ * @var bool|int
2429 */
2530 protected $ _addonDebug = false ;
2631
2732 /**
28- * @var bool
33+ * @var bool|int
2934 */
3035 protected $ _applicationDebug = false ;
3136
3237
33- public function __construct ($ configFilename )
38+ /**
39+ * @param string|array|Core\Config $configuration
40+ * @return $this
41+ */
42+ public function __construct ($ configuration )
3443 {
3544 set_error_handler (array (static ::class, 'errorHandler ' ));
3645
37- if (version_compare (PHP_VERSION , self ::PHP_MIN_VERSION ) === -1 ) {
46+ if (! C \Tools:: isPharRunning () && version_compare (PHP_VERSION , self ::PHP_MIN_VERSION ) === -1 ) {
3847 throw new Exception ("Version PHP inférieure à " .self ::PHP_MIN_VERSION .", PHP " .self ::PHP_MIN_VERSION ." min requis " , E_USER_ERROR );
3948 }
4049
4150 $ this ->_initDebug ();
4251
43- $ this ->_CONFIG = C \Config::getInstance ();
44- $ this ->_CONFIG ->loadConfigurations ($ configFilename , false );
52+ if ($ configuration instanceof C \Config) {
53+ $ this ->_CONFIG = $ configuration ;
54+ }
55+ else {
56+ $ this ->_CONFIG = C \Config::getInstance ();
57+ $ this ->_CONFIG ->loadConfigurations ($ configuration , false );
58+ }
4559 }
4660
4761 protected function _initDebug ()
4862 {
4963 $ debug = getenv ('PHPCLI_DEBUG ' );
50- $ this ->_debug = ( mb_strtolower ( $ debug ) === " true " || $ debug === 1 );
64+ $ this ->_setDebug ( $ this -> _debug , $ debug );
5165
5266 $ debug = getenv ('PHPCLI_ADDON_DEBUG ' );
53- $ this ->_addonDebug = ( mb_strtolower ( $ debug ) === " true " || $ debug === 1 );
67+ $ this ->_setDebug ( $ this -> _addonDebug , $ debug );
5468
5569 $ debug = getenv ('PHPCLI_APPLICATION_DEBUG ' );
56- $ this ->_applicationDebug = (mb_strtolower ($ debug ) === "true " || $ debug === 1 );
70+ $ this ->_setDebug ($ this ->_applicationDebug , $ debug );
71+ }
72+
73+ protected function _setDebug (&$ attribute , $ debug )
74+ {
75+ switch (mb_strtolower ($ debug ))
76+ {
77+ case 'on ' :
78+ case 'yes ' :
79+ case 'true ' : {
80+ $ attribute = true ;
81+ break ;
82+ }
83+ default :
84+ {
85+ if (C \Tools::is ('int&&>0 ' , $ debug )) {
86+ $ attribute = (int ) $ debug ;
87+ }
88+ }
89+ }
5790 }
5891
5992 protected function _throwException (Exception $ exception )
0 commit comments