Allow setting suffix for licence name

This commit is contained in:
Joseph Bielawski
2023-09-05 20:05:09 +02:00
committed by Jerry Ma
parent 33798ff108
commit c0830a9e1f
2 changed files with 10 additions and 3 deletions

View File

@@ -90,8 +90,8 @@ class LicenseDumper
$licenses = [$licenses]; $licenses = [$licenses];
} }
foreach ($licenses as $license) { foreach ($licenses as $index => $license) {
yield match ($license['type']) { yield ($license['suffix'] ?? $index) => match ($license['type']) {
'text' => $license['text'], 'text' => $license['text'],
'file' => $this->loadSourceFile($source_name, $license['path'], Config::getSource($source_name)['path'] ?? null), 'file' => $this->loadSourceFile($source_name, $license['path'], Config::getSource($source_name)['path'] ?? null),
default => throw new RuntimeException('source [' . $source_name . '] license type is not allowed'), default => throw new RuntimeException('source [' . $source_name . '] license type is not allowed'),

View File

@@ -37,6 +37,7 @@ final class LicenseDumperTest extends TestCase
'license' => [ 'license' => [
'type' => 'text', 'type' => 'text',
'text' => 'license', 'text' => 'license',
'suffix' => 'zend',
], ],
], ],
]; ];
@@ -45,7 +46,7 @@ final class LicenseDumperTest extends TestCase
$dumper->addLibs(['fake_lib']); $dumper->addLibs(['fake_lib']);
$dumper->dump(self::DIRECTORY); $dumper->dump(self::DIRECTORY);
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt'); $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_zend.txt');
} }
public function testDumpWithMultipleLicenses(): void public function testDumpWithMultipleLicenses(): void
@@ -66,6 +67,11 @@ final class LicenseDumperTest extends TestCase
'type' => 'text', 'type' => 'text',
'text' => 'license', 'text' => 'license',
], ],
[
'type' => 'text',
'text' => 'license',
'suffix' => 'zend',
],
], ],
], ],
]; ];
@@ -76,5 +82,6 @@ final class LicenseDumperTest extends TestCase
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt'); $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt');
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_1.txt'); $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_1.txt');
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_zend.txt');
} }
} }