-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolver.php
More file actions
86 lines (75 loc) · 2.56 KB
/
Resolver.php
File metadata and controls
86 lines (75 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types=1);
/**
* Fast Forward Development Tools for PHP projects.
*
* This file is part of fast-forward/dev-tools project.
*
* @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
* @license https://opensource.org/licenses/MIT MIT License
*
* @see https://github.com/php-fast-forward/
* @see https://github.com/php-fast-forward/dev-tools
* @see https://github.com/php-fast-forward/dev-tools/issues
* @see https://php-fast-forward.github.io/dev-tools/
* @see https://datatracker.ietf.org/doc/html/rfc2119
*/
namespace FastForward\DevTools\License;
/**
* Resolves license identifiers to their corresponding template filenames.
*
* This class maintains a mapping of supported open-source licenses to their
* template files and provides methods to check support and resolve licenses.
*/
final class Resolver implements ResolverInterface
{
private const array SUPPORTED_LICENSES = [
'MIT' => 'mit.txt',
'BSD-2-Clause' => 'bsd-2-clause.txt',
'BSD-3-Clause' => 'bsd-3-clause.txt',
'Apache-2.0' => 'apache-2.0.txt',
'Apache-2' => 'apache-2.0.txt',
'GPL-3.0-or-later' => 'gpl-3.0-or-later.txt',
'GPL-3.0' => 'gpl-3.0-or-later.txt',
'GPL-3+' => 'gpl-3.0-or-later.txt',
'LGPL-3.0-or-later' => 'lgpl-3.0-or-later.txt',
'LGPL-3.0' => 'lgpl-3.0-or-later.txt',
'LGPL-3+' => 'lgpl-3.0-or-later.txt',
'MPL-2.0' => 'mpl-2.0.txt',
'ISC' => 'isc.txt',
'Unlicense' => 'unlicense.txt',
];
/**
* Resolves a license identifier to its template filename.
*
* @param string|null $license The license identifier to resolve
*
* @return string|null The template filename if supported, or null if not
*/
public function resolve(?string $license): ?string
{
$normalized = $this->normalize($license);
if (null === $normalized) {
return null;
}
if (! isset(self::SUPPORTED_LICENSES[$normalized])) {
return null;
}
return self::SUPPORTED_LICENSES[$normalized];
}
/**
* Normalizes the license identifier for comparison.
*
* @param string|null $license The license identifier to normalize
*
* @return string|null The normalized license string, or null when unavailable
*/
private function normalize(?string $license): ?string
{
if (null === $license) {
return null;
}
$license = trim($license);
return '' === $license ? null : $license;
}
}