Generates LICENSE files from composer.json metadata.
Description
This class orchestrates the license generation workflow:
- Reads metadata from composer.json via Reader
- Resolves the license identifier to a template filename
- Loads the license template content
- Resolves placeholders with metadata (year, author, project, organization)
- Writes the resulting LICENSE file to the target path
Generation is skipped if a LICENSE file already exists or if the license is not supported.
Interfaces
Properties
Methods
Creates a new Generator instance.
Generates a LICENSE file at the specified path.
Checks whether a supported license is present in composer.json.
private
Filesystem
$filesystem
=
new Filesystem()
private
PlaceholderResolverInterface
$placeholderResolver
private
ReaderInterface
$reader
private
ResolverInterface
$resolver
private
TemplateLoaderInterface
$templateLoader
Creates a new Generator instance.
public
__construct(ReaderInterface
$reader, ResolverInterface
$resolver, TemplateLoaderInterface
$templateLoader, PlaceholderResolverInterface
$placeholderResolver[, Filesystem
$filesystem = new Filesystem()]) : mixed
Parameters
Description
The reader for extracting metadata from composer.json
Description
The resolver for mapping license identifiers to templates
Description
The loader for reading template files
Description
The resolver for template placeholders
$filesystem
:
Filesystem
=
new Filesystem()
Description
The filesystem component for file operations
Generates a LICENSE file at the specified path.
public
generate(
string
$targetPath) : string|null
Parameters
$targetPath
:
string
Description
The full path where the LICENSE file should be written
Return values
Description
The generated license content, or null if generation failed
Checks whether a supported license is present in composer.json.
public
hasLicense() : bool
Return values
Description
True if a supported license is defined, false otherwise