function SpdxLicenses::isValidLicenseString
Parameters
string $license:
Return value
bool
Throws
\RuntimeException
1 call to SpdxLicenses::isValidLicenseString()
- SpdxLicenses::validate in vendor/
composer/ spdx-licenses/ src/ SpdxLicenses.php
File
-
vendor/
composer/ spdx-licenses/ src/ SpdxLicenses.php, line 296
Class
Namespace
Composer\SpdxCode
private function isValidLicenseString($license) {
if (isset($this->licenses[strtolower($license)])) {
return true;
}
$licenses = $this->getLicensesExpression();
$exceptions = $this->getExceptionsExpression();
$regex = <<<REGEX
{
(?(DEFINE)
# idstring: 1*( ALPHA / DIGIT / - / . )
(?<idstring>[\\pL\\pN.-]{1,})
# license-id: taken from list
(?<licenseid>{<span class="php-variable">$licenses</span>})
# license-exception-id: taken from list
(?<licenseexceptionid>{<span class="php-variable">$exceptions</span>})
# license-ref: [DocumentRef-1*(idstring):]LicenseRef-1*(idstring)
(?<licenseref>(?:DocumentRef-(?&idstring):)?LicenseRef-(?&idstring))
# simple-expresssion: license-id / license-id+ / license-ref
(?<simple_expression>(?&licenseid)\\+? | (?&licenseid) | (?&licenseref))
# compound-expression: 1*(
# simple-expression /
# simple-expression WITH license-exception-id /
# compound-expression AND compound-expression /
# compound-expression OR compound-expression
# ) / ( compound-expression ) )
(?<compound_head>
(?&simple_expression) ( \\s+ WITH \\s+ (?&licenseexceptionid))?
| \\( \\s* (?&compound_expression) \\s* \\)
)
(?<compound_expression>
(?&compound_head) (?: \\s+ (?:AND|OR) \\s+ (?&compound_expression))?
)
# license-expression: 1*1(simple-expression / compound-expression)
(?<license_expression>(?&compound_expression) | (?&simple_expression))
) # end of define
^(NONE | NOASSERTION | (?&license_expression))\$
}xi
REGEX;
$match = preg_match($regex, $license);
if (0 === $match) {
return false;
}
if (false === $match) {
throw new \RuntimeException('Regex failed to compile/run.');
}
return true;
}