45
45
*
46
46
* @copyright Jorge Castro C. MIT License https://github.com/EFTEC/AutoLoadOne
47
47
*
48
- * @version 1.25.1 2021-06-09
48
+ * @version 1.26 2022-02-21
49
49
* @noautoload
50
50
*/
51
51
class AutoLoadOne
52
52
{
53
- const VERSION = '1.25.1 ' ;
53
+ public const VERSION = '1.26 ' ;
54
54
55
55
56
56
public $ rooturl = '' ;
@@ -93,7 +93,7 @@ public function __construct()
93
93
$ this ->rooturl = '. ' ; //getcwd(); // dirname($_SERVER['SCRIPT_FILENAME']);
94
94
$ this ->t1 = microtime (true );
95
95
$ tmpArr = explode ('/ ' , $ _SERVER ['SCRIPT_FILENAME ' ]); // it always returns with linux separators.
96
- $ this ->fileConfig = end ($ tmpArr ); // the config name shares the same name than the php but with extension .json
96
+ $ this ->fileConfig = end ($ tmpArr ); // the config name shares the same name as the php but with extension .json
97
97
$ this ->fileConfig = $ this ->dirNameLinux (getcwd ()) . '/ ' . str_replace ($ this ->extension , '.json ' , $ this ->fileConfig );
98
98
}
99
99
@@ -105,7 +105,7 @@ public function __construct()
105
105
*
106
106
* @return string
107
107
*/
108
- public function dirNameLinux ($ url , $ ifFullUrl = true )
108
+ public function dirNameLinux ($ url , bool $ ifFullUrl = true ): string
109
109
{
110
110
$ url = trim ($ url );
111
111
$ dir = ($ ifFullUrl ) ? dirname ($ url ) : $ url ;
@@ -119,7 +119,8 @@ public function fixSeparator($fullUrl)
119
119
return str_replace ('\\' , '/ ' , $ fullUrl ); // replace windows path for linux path.
120
120
}
121
121
122
- public static function format ($ json , $ unescapeUnicode , $ unescapeSlashes )
122
+ /** @noinspection PhpUnused */
123
+ public static function format ($ json , $ unescapeUnicode , $ unescapeSlashes ): string
123
124
{
124
125
$ result = '' ;
125
126
$ pos = 0 ;
@@ -203,7 +204,7 @@ public static function format($json, $unescapeUnicode, $unescapeSlashes)
203
204
return $ result ;
204
205
}
205
206
206
- public function init ()
207
+ public function init (): void
207
208
{
208
209
$ this ->log = '' ;
209
210
$ this ->logStat = '' ;
@@ -219,7 +220,7 @@ public function init()
219
220
}
220
221
}
221
222
222
- private function initSapi ()
223
+ private function initSapi (): void
223
224
{
224
225
global $ argv ;
225
226
$ v = $ this ::VERSION . ' (c) Jorge Castro ' ;
@@ -274,7 +275,7 @@ private function initSapi()
274
275
echo "------------------------------------------------------------------ \n" ;
275
276
}
276
277
277
- private function getAllParametersCli ()
278
+ private function getAllParametersCli (): void
278
279
{
279
280
$ this ->rooturl = $ this ->fixSeparator ($ this ->getParameterCli ('folder ' ));
280
281
$ this ->fileGen = $ this ->fixSeparator ($ this ->getParameterCli ('filegen ' ));
@@ -296,7 +297,7 @@ private function getAllParametersCli()
296
297
*
297
298
* @return string
298
299
*/
299
- private function getParameterCli ($ key , $ default = '' )
300
+ private function getParameterCli ($ key , string $ default = '' ): string
300
301
{
301
302
global $ argv ;
302
303
$ p = array_search ('- ' . $ key , $ argv , true );
@@ -313,12 +314,12 @@ private function getParameterCli($key, $default = '')
313
314
return '' ;
314
315
}
315
316
316
- private function removeTrailSlash ($ txt )
317
+ private function removeTrailSlash ($ txt ): string
317
318
{
318
319
return rtrim ($ txt , '/ \\' );
319
320
}
320
321
321
- private function initWeb ()
322
+ private function initWeb (): void
322
323
{
323
324
@ob_start ();
324
325
// Not in cli-mode
@@ -377,7 +378,7 @@ private function initWeb()
377
378
/**
378
379
* @return bool
379
380
*/
380
- private function loadParam ()
381
+ private function loadParam (): bool
381
382
{
382
383
if (!_AUTOLOAD_SAVEPARAM ) {
383
384
return false ;
@@ -396,7 +397,7 @@ private function loadParam()
396
397
}
397
398
$ this ->addLog ('Reading the configuration using the old method ' . $ this ->fileConfig . ' (you could delete this file) ' , 'error ' );
398
399
$ param = json_decode ($ oldMethod , true );
399
- $ param = isset ( $ param ['local ' ]) ? $ param [ ' local ' ] : null ;
400
+ $ param = $ param ['local ' ] ?? null ;
400
401
} else {
401
402
$ a1 += strlen ('/* -- CONFIG START HERE -- ' );
402
403
$ a2 = strpos ($ fullPHP , '-- CONFIG END HERE -- ' , $ a1 );
@@ -426,7 +427,7 @@ private function loadParam()
426
427
* @param mixed $txt The message to show
427
428
* @param string $type =['error','warning','info','success','stat','statinfo','staterror'][$i]
428
429
*/
429
- public function addLog ($ txt , $ type = '' )
430
+ public function addLog ($ txt , string $ type = '' ): void
430
431
{
431
432
if (PHP_SAPI === 'cli ' ) {
432
433
$ txt = str_replace (array ('<b> ' , '<i> ' , '</b> ' , '</i> ' ), array ("\033[1m " , "\033[4m " , "\033[0m " , "\033[0m " ), $ txt );
@@ -487,7 +488,7 @@ public function addLog($txt, $type = '')
487
488
*
488
489
* @return string
489
490
*/
490
- private function cleanInputFolder ($ value )
491
+ private function cleanInputFolder ($ value ): string
491
492
{
492
493
// remove windows line carriage
493
494
// remove previous ,\n if any and converted into \n. It avoids duplicate ,,\n
@@ -497,20 +498,20 @@ private function cleanInputFolder($value)
497
498
return str_replace (array ("\r\n" , ", \n" , "\n" , '\\, ' , '/, ' ), array ("\n" , "\n" , ", \n" , ', ' , ', ' ), $ value );
498
499
}
499
500
500
- public function process ()
501
+ public function process (): void
501
502
{
502
503
$ this ->rooturl = $ this ->fixSeparator ($ this ->rooturl );
503
504
$ this ->fileGen = $ this ->fixSeparator ($ this ->fileGen );
504
505
if ($ this ->rooturl ) {
505
506
$ this ->baseGen = $ this ->dirNameLinux ($ this ->fileGen . '/ ' . $ this ->getFileName ());
506
- list ( $ files , $ json) = $ this ->listFolderFiles ($ this ->rooturl );
507
+ [ $ files , $ json] = $ this ->listFolderFiles ($ this ->rooturl );
507
508
$ filesAbsolute = array_fill (0 , count ($ files ), false );
508
509
$ jsonAbsolute = array_fill (0 , count ($ json ), false );
509
510
510
511
$ extPathArr = explode (', ' , $ this ->externalPath );
511
512
foreach ($ extPathArr as $ ep ) {
512
513
$ ep = $ this ->dirNameLinux ($ ep , false );
513
- list ( $ files2 , $ json2) = $ this ->listFolderFiles ($ ep );
514
+ [ $ files2 , $ json2] = $ this ->listFolderFiles ($ ep );
514
515
foreach ($ json2 as $ newJson ) {
515
516
$ json [] = $ newJson ;
516
517
$ jsonAbsolute [] = true ;
@@ -715,7 +716,7 @@ public function process()
715
716
*
716
717
* @return string
717
718
*/
718
- public function getFileName ()
719
+ public function getFileName (): string
719
720
{
720
721
if (strpos ($ this ->savefileName , '.php ' ) === false ) {
721
722
return $ this ->savefileName . $ this ->extension ;
@@ -724,15 +725,15 @@ public function getFileName()
724
725
return $ this ->savefileName ;
725
726
}
726
727
727
- public function listFolderFiles ($ dir )
728
+ public function listFolderFiles ($ dir ): array
728
729
{
729
730
$ arr = [];
730
731
$ json = [];
731
732
$ this ->listFolderFilesAlt ($ dir , $ arr , $ json );
732
733
return [$ arr , $ json ];
733
734
}
734
735
735
- public function listFolderFilesAlt ($ dir , &$ list , &$ json )
736
+ public function listFolderFilesAlt ($ dir , &$ list , &$ json ): array
736
737
{
737
738
if ($ dir === '' ) {
738
739
return [];
@@ -790,10 +791,7 @@ public function parseJSONFile($filename)
790
791
echo "Error in $ filename \n" ;
791
792
die (1 );
792
793
}
793
- if (isset ($ tokens ['autoload ' ]['files ' ])) {
794
- return $ tokens ['autoload ' ]['files ' ];
795
- }
796
- return [];
794
+ return $ tokens ['autoload ' ]['files ' ] ?? [];
797
795
}
798
796
799
797
public function genPath ($ path )
@@ -833,7 +831,7 @@ public function genPath($path)
833
831
*
834
832
* @return array
835
833
*/
836
- public function parsePHPFile ($ filename , &$ runMe )
834
+ public function parsePHPFile ($ filename , string &$ runMe ): array
837
835
{
838
836
$ runMe = '' ;
839
837
$ r = [];
@@ -921,7 +919,7 @@ public function parsePHPFile($filename, &$runMe)
921
919
*
922
920
* @return bool
923
921
*/
924
- private function inExclusion ($ path , $ exclusions )
922
+ private function inExclusion (string $ path , array $ exclusions ): bool
925
923
{
926
924
foreach ($ exclusions as $ ex ) {
927
925
if ($ ex != '' ) {
@@ -946,12 +944,12 @@ private function inExclusion($path, $exclusions)
946
944
return false ;
947
945
}
948
946
949
- public function startwith ($ string , $ test )
947
+ public function startwith ($ string , $ test ): bool
950
948
{
951
949
return strpos ($ string , $ test ) === 0 ;
952
950
}
953
951
954
- public function endswith ($ string , $ test )
952
+ public function endswith ($ string , $ test ): bool
955
953
{
956
954
$ strlen = strlen ($ string );
957
955
$ testlen = strlen ($ test );
@@ -1089,10 +1087,16 @@ function autoloadone_exception_handler($exception) {
1089
1087
$r .= "Trace:\n";
1090
1088
foreach ($exception->getTrace() as $error) {
1091
1089
// we remove all trace pointing to this file.
1092
- if (isset($error['file']) && strpos($error['file'], __FILE__) === false) {
1093
- $r .= $error['file'] . '[' . $error['line'] . ']' . ' function:' . @$error['function'] . '('
1094
- .( is_array(@$error['args']) ? @implode(',', @$error['args']) . ')' : @$error['args'])
1095
- . "\n";
1090
+ if (isset($error['file'])) {
1091
+ if(strpos($error['file'], __FILE__) === false) {
1092
+ $r .= @$error['file'] . '[' . @$error['line'] . ']' . ' function:' . @$error['function'] . '('
1093
+ .( is_array(@$error['args']) ? @implode(',', @$error['args']) . ')' :@$error['args'])
1094
+ . "\n";
1095
+ } else {
1096
+ $r .= '(nofile)' . '[' . @$error['line'] . ']' . ' function:' . @$error['function'] . '('
1097
+ .( is_array(@$error['args']) ? @implode(',', @$error['args']) . ')' :@$error['args'])
1098
+ . "\n";
1099
+ }
1096
1100
}
1097
1101
}
1098
1102
}
@@ -1209,7 +1213,7 @@ function autoloadone_exception_handler($exception) {
1209
1213
return $ template ;
1210
1214
}
1211
1215
1212
- private function createArrayPHP ($ array )
1216
+ private function createArrayPHP ($ array ): string
1213
1217
{
1214
1218
$ result = '' ;
1215
1219
foreach ($ array as $ k => $ v ) {
@@ -1230,7 +1234,7 @@ private function createArrayPHP($array)
1230
1234
*
1231
1235
* @return array
1232
1236
*/
1233
- public function compress (&$ paths )
1237
+ public function compress (array &$ paths ): array
1234
1238
{
1235
1239
if (!$ this ->compression ) {
1236
1240
return [];
@@ -1312,7 +1316,7 @@ private function saveParam()
1312
1316
return @file_put_contents ($ this ->savefileName , $ txt );
1313
1317
}
1314
1318
1315
- private function evaluation ($ percentage )
1319
+ private function evaluation ($ percentage ): string
1316
1320
{
1317
1321
switch (true ) {
1318
1322
case $ percentage === 0 :
@@ -1329,7 +1333,7 @@ private function evaluation($percentage)
1329
1333
return 'The worst ' ;
1330
1334
}
1331
1335
1332
- public function render ()
1336
+ public function render (): void
1333
1337
{
1334
1338
if ($ this ->debugMode ) {
1335
1339
ob_clean ();
@@ -1669,7 +1673,7 @@ public function render()
1669
1673
}
1670
1674
}
1671
1675
1672
- public function bootstrapcss ()
1676
+ public function bootstrapcss (): string
1673
1677
{
1674
1678
return <<<BOOTS
1675
1679
<style>
0 commit comments