Resolver

Class
implements ResolverInterface
Final: Yes

Resolves license identifiers to their corresponding template filenames.

Description

This class maintains a mapping of supported open-source licenses to their template files and provides methods to check support and resolve licenses.

Table of Contents

Interfaces

ResolverInterface

Resolves license identifiers to their corresponding template filenames.

Constants

 = ['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']

Methods

isSupported()

Checks whether the given license identifier is supported.

 : bool
resolve()

Resolves a license identifier to its template filename.

 : string|null
normalize()

Normalizes the license identifier for comparison.

 : string
Constants

Constants

SUPPORTED_LICENSES

Private
private mixed 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']
Methods

isSupported()

Public

Checks whether the given license identifier is supported.

public isSupported( string  $license) : bool

Description

The check is case-insensitive and handles common license variants.

Parameters
$license : string

Description

The license identifier to check

Return values
bool

Description

True if the license is supported, false otherwise

resolve()

Public

Resolves a license identifier to its template filename.

public resolve( string  $license) : string|null
Parameters
$license : string

Description

The license identifier to resolve

Return values
string|null

Description

The template filename if supported, or null if not

normalize()

Private

Normalizes the license identifier for comparison.

private normalize( string  $license) : string
Parameters
$license : string

Description

The license identifier to normalize

Return values
string

Description

The normalized license string