Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SpdxLicenses.php

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

SpdxLicenses

Namespace

Composer\Spdx

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal