mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-04 07:12:48 -04:00
Enhance license handling (#4223)
- automate license updates - license text rendered in monospace font - removed old bower license generation code
This commit is contained in:
@@ -75,8 +75,9 @@ class Config extends Secure_Controller
|
||||
private function _licenses(): array //TODO: remove hungarian notation. Super long function. Perhaps we need to refactor out functions?
|
||||
{
|
||||
$i = 0;
|
||||
$bower = false;
|
||||
$composer = false;
|
||||
$npmProd = false;
|
||||
$npmDev = false;
|
||||
$license = [];
|
||||
|
||||
$license[$i]['title'] = 'Open Source Point Of Sale ' . config('App')->application_version;
|
||||
@@ -106,17 +107,20 @@ class Config extends Secure_Controller
|
||||
} else {
|
||||
$license[$i]['text'] = $license_text_file . ' file is missing';
|
||||
}
|
||||
} elseif ($fileinfo->getBasename() == 'bower.LICENSES') {
|
||||
// set a flag to indicate that the JS Plugin bower.LICENSES file is available and needs to be attached at the end
|
||||
$bower = true;
|
||||
} elseif ($fileinfo->getBasename() == 'composer.LICENSES') {
|
||||
// set a flag to indicate that the composer.LICENSES file is available and needs to be attached at the end
|
||||
$composer = true;
|
||||
} elseif ($fileinfo->getBasename() == 'npm-prod.LICENSES') {
|
||||
// set a flag to indicate that the npm-prod.LICENSES file is available and needs to be attached at the end
|
||||
$npmProd = true;
|
||||
} elseif ($fileinfo->getBasename() == 'npm-dev.LICENSES') {
|
||||
// set a flag to indicate that the npm-dev.LICENSES file is available and needs to be attached at the end
|
||||
$npmDev = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// attach the licenses from the LICENSES file generated by bower
|
||||
// attach the licenses from the LICENSES file generated by composer
|
||||
if ($composer) {
|
||||
++$i;
|
||||
$license[$i]['title'] = 'Composer Libraries';
|
||||
@@ -125,65 +129,63 @@ class Config extends Secure_Controller
|
||||
$file = file_get_contents('license/composer.LICENSES');
|
||||
$array = json_decode($file, true);
|
||||
|
||||
foreach ($array as $key => $val) {
|
||||
if (is_array($val) && $key == 'dependencies') {
|
||||
foreach ($val as $key1 => $val1) {
|
||||
if (is_array($val1)) {
|
||||
$license[$i]['text'] .= "component: $key1\n"; //TODO: Duplicated Code
|
||||
if (isset($array['dependencies'])) {
|
||||
foreach ($array['dependencies'] as $dependency => $details) {
|
||||
$license[$i]['text'] .= "library: $dependency\n";
|
||||
|
||||
foreach ($val1 as $key2 => $val2) {
|
||||
if (is_array($val2)) {
|
||||
$license[$i]['text'] .= "$key2: ";
|
||||
|
||||
foreach ($val2 as $key3 => $val3) {
|
||||
$license[$i]['text'] .= "$val3 ";
|
||||
}
|
||||
|
||||
$license[$i]['text'] .= "\n";
|
||||
} else {
|
||||
$license[$i]['text'] .= "$key2: $val2\n";
|
||||
}
|
||||
}
|
||||
|
||||
$license[$i]['text'] .= "\n";
|
||||
foreach ($details as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$license[$i]['text'] .= "$key: " . implode(' ', $value) . "\n";
|
||||
} else {
|
||||
$license[$i]['text'] .= "$key1: $val1\n";
|
||||
$license[$i]['text'] .= "$key: $value\n";
|
||||
}
|
||||
}
|
||||
|
||||
$license[$i]['text'] .= "\n";
|
||||
}
|
||||
$license[$i]['text'] = rtrim($license[$i]['text'], "\n");
|
||||
}
|
||||
}
|
||||
|
||||
// attach the licenses from the LICENSES file generated by bower
|
||||
if ($bower) {
|
||||
// attach the licenses from the LICENSES file generated by license-report
|
||||
if ($npmProd) {
|
||||
++$i;
|
||||
$license[$i]['title'] = 'JS Plugins';
|
||||
$license[$i]['title'] = 'NPM Production Libraries';
|
||||
$license[$i]['text'] = '';
|
||||
|
||||
$file = file_get_contents('license/bower.LICENSES');
|
||||
|
||||
$file = file_get_contents('license/npm-prod.LICENSES');
|
||||
$array = json_decode($file, true);
|
||||
|
||||
foreach ($array as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$license[$i]['text'] .= "component: $key\n"; //TODO: Duplicated Code.
|
||||
|
||||
foreach ($val as $key1 => $val1) {
|
||||
if (is_array($val1)) {
|
||||
$license[$i]['text'] .= "$key1: ";
|
||||
|
||||
foreach ($val1 as $key2 => $val2) {
|
||||
$license[$i]['text'] .= "$val2 ";
|
||||
}
|
||||
|
||||
$license[$i]['text'] .= '\n';
|
||||
} else {
|
||||
$license[$i]['text'] .= "$key1: $val1\n";
|
||||
}
|
||||
}
|
||||
|
||||
$license[$i]['text'] .= '\n';
|
||||
}
|
||||
|
||||
foreach ($array as $dependency) {
|
||||
$license[$i]['text'] .= "library: {$dependency['name']}\n";
|
||||
$license[$i]['text'] .= "authors: {$dependency['author']}\n";
|
||||
$license[$i]['text'] .= "website: {$dependency['homepage']}\n";
|
||||
$license[$i]['text'] .= "version: {$dependency['installedVersion']}\n";
|
||||
$license[$i]['text'] .= "license: {$dependency['licenseType']}\n";
|
||||
|
||||
$license[$i]['text'] .= "\n";
|
||||
}
|
||||
$license[$i]['text'] = rtrim($license[$i]['text'], "\n");
|
||||
}
|
||||
|
||||
if ($npmDev) {
|
||||
++$i;
|
||||
$license[$i]['title'] = 'NPM Development Libraries';
|
||||
$license[$i]['text'] = '';
|
||||
|
||||
$file = file_get_contents('license/npm-dev.LICENSES');
|
||||
$array = json_decode($file, true);
|
||||
|
||||
foreach ($array as $dependency) {
|
||||
$license[$i]['text'] .= "library: {$dependency['name']}\n";
|
||||
$license[$i]['text'] .= "authors: {$dependency['author']}\n";
|
||||
$license[$i]['text'] .= "website: {$dependency['homepage']}\n";
|
||||
$license[$i]['text'] .= "version: {$dependency['installedVersion']}\n";
|
||||
$license[$i]['text'] .= "license: {$dependency['licenseType']}\n";
|
||||
|
||||
$license[$i]['text'] .= "\n";
|
||||
}
|
||||
$license[$i]['text'] = rtrim($license[$i]['text'], "\n");
|
||||
}
|
||||
|
||||
return $license;
|
||||
|
||||
Reference in New Issue
Block a user