Skip to content

Commit 632e7ba

Browse files
1.26 see README.md for a list of changes
1 parent 209d53a commit 632e7ba

File tree

4 files changed

+74
-45
lines changed

4 files changed

+74
-45
lines changed

AutoLoadOne.php

+42-38
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
*
4646
* @copyright Jorge Castro C. MIT License https://github.com/EFTEC/AutoLoadOne
4747
*
48-
* @version 1.25.1 2021-06-09
48+
* @version 1.26 2022-02-21
4949
* @noautoload
5050
*/
5151
class AutoLoadOne
5252
{
53-
const VERSION = '1.25.1';
53+
public const VERSION = '1.26';
5454

5555

5656
public $rooturl = '';
@@ -93,7 +93,7 @@ public function __construct()
9393
$this->rooturl = '.'; //getcwd(); // dirname($_SERVER['SCRIPT_FILENAME']);
9494
$this->t1 = microtime(true);
9595
$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
9797
$this->fileConfig = $this->dirNameLinux(getcwd()) . '/' . str_replace($this->extension, '.json', $this->fileConfig);
9898
}
9999

@@ -105,7 +105,7 @@ public function __construct()
105105
*
106106
* @return string
107107
*/
108-
public function dirNameLinux($url, $ifFullUrl = true)
108+
public function dirNameLinux($url, bool $ifFullUrl = true): string
109109
{
110110
$url = trim($url);
111111
$dir = ($ifFullUrl) ? dirname($url) : $url;
@@ -119,7 +119,8 @@ public function fixSeparator($fullUrl)
119119
return str_replace('\\', '/', $fullUrl); // replace windows path for linux path.
120120
}
121121

122-
public static function format($json, $unescapeUnicode, $unescapeSlashes)
122+
/** @noinspection PhpUnused */
123+
public static function format($json, $unescapeUnicode, $unescapeSlashes): string
123124
{
124125
$result = '';
125126
$pos = 0;
@@ -203,7 +204,7 @@ public static function format($json, $unescapeUnicode, $unescapeSlashes)
203204
return $result;
204205
}
205206

206-
public function init()
207+
public function init(): void
207208
{
208209
$this->log = '';
209210
$this->logStat = '';
@@ -219,7 +220,7 @@ public function init()
219220
}
220221
}
221222

222-
private function initSapi()
223+
private function initSapi(): void
223224
{
224225
global $argv;
225226
$v = $this::VERSION . ' (c) Jorge Castro';
@@ -274,7 +275,7 @@ private function initSapi()
274275
echo "------------------------------------------------------------------\n";
275276
}
276277

277-
private function getAllParametersCli()
278+
private function getAllParametersCli(): void
278279
{
279280
$this->rooturl = $this->fixSeparator($this->getParameterCli('folder'));
280281
$this->fileGen = $this->fixSeparator($this->getParameterCli('filegen'));
@@ -296,7 +297,7 @@ private function getAllParametersCli()
296297
*
297298
* @return string
298299
*/
299-
private function getParameterCli($key, $default = '')
300+
private function getParameterCli($key, string $default = ''): string
300301
{
301302
global $argv;
302303
$p = array_search('-' . $key, $argv, true);
@@ -313,12 +314,12 @@ private function getParameterCli($key, $default = '')
313314
return '';
314315
}
315316

316-
private function removeTrailSlash($txt)
317+
private function removeTrailSlash($txt): string
317318
{
318319
return rtrim($txt, '/\\');
319320
}
320321

321-
private function initWeb()
322+
private function initWeb(): void
322323
{
323324
@ob_start();
324325
// Not in cli-mode
@@ -377,7 +378,7 @@ private function initWeb()
377378
/**
378379
* @return bool
379380
*/
380-
private function loadParam()
381+
private function loadParam(): bool
381382
{
382383
if (!_AUTOLOAD_SAVEPARAM) {
383384
return false;
@@ -396,7 +397,7 @@ private function loadParam()
396397
}
397398
$this->addLog('Reading the configuration using the old method ' . $this->fileConfig . ' (you could delete this file)', 'error');
398399
$param = json_decode($oldMethod, true);
399-
$param = isset($param['local']) ? $param['local'] : null;
400+
$param = $param['local'] ?? null;
400401
} else {
401402
$a1 += strlen('/* -- CONFIG START HERE --');
402403
$a2 = strpos($fullPHP, '-- CONFIG END HERE -- ', $a1);
@@ -426,7 +427,7 @@ private function loadParam()
426427
* @param mixed $txt The message to show
427428
* @param string $type =['error','warning','info','success','stat','statinfo','staterror'][$i]
428429
*/
429-
public function addLog($txt, $type = '')
430+
public function addLog($txt, string $type = ''): void
430431
{
431432
if (PHP_SAPI === 'cli') {
432433
$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 = '')
487488
*
488489
* @return string
489490
*/
490-
private function cleanInputFolder($value)
491+
private function cleanInputFolder($value): string
491492
{
492493
// remove windows line carriage
493494
// remove previous ,\n if any and converted into \n. It avoids duplicate ,,\n
@@ -497,20 +498,20 @@ private function cleanInputFolder($value)
497498
return str_replace(array("\r\n", ",\n", "\n", '\\,', '/,'), array("\n", "\n", ",\n", ',', ','), $value);
498499
}
499500

500-
public function process()
501+
public function process(): void
501502
{
502503
$this->rooturl = $this->fixSeparator($this->rooturl);
503504
$this->fileGen = $this->fixSeparator($this->fileGen);
504505
if ($this->rooturl) {
505506
$this->baseGen = $this->dirNameLinux($this->fileGen . '/' . $this->getFileName());
506-
list($files, $json) = $this->listFolderFiles($this->rooturl);
507+
[$files, $json] = $this->listFolderFiles($this->rooturl);
507508
$filesAbsolute = array_fill(0, count($files), false);
508509
$jsonAbsolute = array_fill(0, count($json), false);
509510

510511
$extPathArr = explode(',', $this->externalPath);
511512
foreach ($extPathArr as $ep) {
512513
$ep = $this->dirNameLinux($ep, false);
513-
list($files2, $json2) = $this->listFolderFiles($ep);
514+
[$files2, $json2] = $this->listFolderFiles($ep);
514515
foreach ($json2 as $newJson) {
515516
$json[] = $newJson;
516517
$jsonAbsolute[] = true;
@@ -715,7 +716,7 @@ public function process()
715716
*
716717
* @return string
717718
*/
718-
public function getFileName()
719+
public function getFileName(): string
719720
{
720721
if (strpos($this->savefileName, '.php') === false) {
721722
return $this->savefileName . $this->extension;
@@ -724,15 +725,15 @@ public function getFileName()
724725
return $this->savefileName;
725726
}
726727

727-
public function listFolderFiles($dir)
728+
public function listFolderFiles($dir): array
728729
{
729730
$arr = [];
730731
$json = [];
731732
$this->listFolderFilesAlt($dir, $arr, $json);
732733
return [$arr, $json];
733734
}
734735

735-
public function listFolderFilesAlt($dir, &$list, &$json)
736+
public function listFolderFilesAlt($dir, &$list, &$json): array
736737
{
737738
if ($dir === '') {
738739
return [];
@@ -790,10 +791,7 @@ public function parseJSONFile($filename)
790791
echo "Error in $filename\n";
791792
die(1);
792793
}
793-
if (isset($tokens['autoload']['files'])) {
794-
return $tokens['autoload']['files'];
795-
}
796-
return [];
794+
return $tokens['autoload']['files'] ?? [];
797795
}
798796

799797
public function genPath($path)
@@ -833,7 +831,7 @@ public function genPath($path)
833831
*
834832
* @return array
835833
*/
836-
public function parsePHPFile($filename, &$runMe)
834+
public function parsePHPFile($filename, string &$runMe): array
837835
{
838836
$runMe = '';
839837
$r = [];
@@ -921,7 +919,7 @@ public function parsePHPFile($filename, &$runMe)
921919
*
922920
* @return bool
923921
*/
924-
private function inExclusion($path, $exclusions)
922+
private function inExclusion(string $path, array $exclusions): bool
925923
{
926924
foreach ($exclusions as $ex) {
927925
if ($ex != '') {
@@ -946,12 +944,12 @@ private function inExclusion($path, $exclusions)
946944
return false;
947945
}
948946

949-
public function startwith($string, $test)
947+
public function startwith($string, $test): bool
950948
{
951949
return strpos($string, $test) === 0;
952950
}
953951

954-
public function endswith($string, $test)
952+
public function endswith($string, $test): bool
955953
{
956954
$strlen = strlen($string);
957955
$testlen = strlen($test);
@@ -1089,10 +1087,16 @@ function autoloadone_exception_handler($exception) {
10891087
$r .= "Trace:\n";
10901088
foreach ($exception->getTrace() as $error) {
10911089
// 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+
}
10961100
}
10971101
}
10981102
}
@@ -1209,7 +1213,7 @@ function autoloadone_exception_handler($exception) {
12091213
return $template;
12101214
}
12111215

1212-
private function createArrayPHP($array)
1216+
private function createArrayPHP($array): string
12131217
{
12141218
$result = '';
12151219
foreach ($array as $k => $v) {
@@ -1230,7 +1234,7 @@ private function createArrayPHP($array)
12301234
*
12311235
* @return array
12321236
*/
1233-
public function compress(&$paths)
1237+
public function compress(array &$paths): array
12341238
{
12351239
if (!$this->compression) {
12361240
return [];
@@ -1312,7 +1316,7 @@ private function saveParam()
13121316
return @file_put_contents($this->savefileName, $txt);
13131317
}
13141318

1315-
private function evaluation($percentage)
1319+
private function evaluation($percentage): string
13161320
{
13171321
switch (true) {
13181322
case $percentage === 0:
@@ -1329,7 +1333,7 @@ private function evaluation($percentage)
13291333
return 'The worst';
13301334
}
13311335

1332-
public function render()
1336+
public function render(): void
13331337
{
13341338
if ($this->debugMode) {
13351339
ob_clean();
@@ -1669,7 +1673,7 @@ public function render()
16691673
}
16701674
}
16711675

1672-
public function bootstrapcss()
1676+
public function bootstrapcss(): string
16731677
{
16741678
return <<<BOOTS
16751679
<style>

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ reads the composer.json files once.
571571

572572
## Version
573573

574+
* 1.26 2022-02-21
575+
* [fix] compatibility with PHP 8.1.
576+
* Raising the compatibility with php 7.1.5 and higher. If you want to use an old version, then you can use 1.25.1
577+
* Adding AutoLoadOne as a composer's binary file.
574578
* 1.25.1 2021-06-09
575579
* [fix] in autoloadone_exception_handler when the arguments of the error is not an array but a string.
576580
* 1.25 2021-04-17

autoloadone

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (isset($GLOBALS['_composer_autoload_path'])) {
5+
define('PHPUNIT_COMPOSER_INSTALL', $GLOBALS['_composer_autoload_path']);
6+
unset($GLOBALS['_composer_autoload_path']);
7+
} else {
8+
foreach ([__DIR__ . '/../../../autoload.php',
9+
__DIR__ . '/../../vendor/autoload.php',
10+
__DIR__ . '/../vendor/autoload.php',
11+
__DIR__ . '/vendor/autoload.php'] as $file) {
12+
if (file_exists($file)) {
13+
define('PHPUNIT_COMPOSER_INSTALL', $file);
14+
break;
15+
}
16+
}
17+
unset($file);
18+
}
19+
if (!defined('_AUTOLOAD_ONLYCLI')) {
20+
define('_AUTOLOAD_ONLYCLI', true);
21+
}
22+
23+
include_once 'AutoLoadOne.php';

composer.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
"name": "Jorge Patricio Castro Castillo",
1212
"email": "[email protected]"
1313
}],
14-
"config": {
15-
"platform": {
16-
"php": "5.6"
17-
}
18-
},
1914
"require": {
2015
"ext-json": "*",
21-
"php":">=5.6"
16+
"php":">=7.2.5"
2217
},
18+
"bin": [
19+
"autoloadone"
20+
],
2321
"archive": {
2422
"exclude": ["/examples"]
2523
}
26-
}
24+
}

0 commit comments

Comments
 (0)