Generator

Class
implements GeneratorInterface
Read only: Yes Final: Yes

Generates LICENSE files from composer.json metadata.

Description

This class orchestrates the license generation workflow:

  1. Reads metadata from composer.json via Reader
  2. Resolves the license identifier to a template filename
  3. Loads the license template content
  4. Resolves placeholders with metadata (year, author, project, organization)
  5. 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.

Table of Contents

Interfaces

GeneratorInterface

Generates LICENSE files from composer.json metadata.

Properties

Methods

__construct()

Creates a new Generator instance.

 : mixed
generate()

Generates a LICENSE file at the specified path.

 : string|null
hasLicense()

Checks whether a supported license is present in composer.json.

 : bool
Properties

$filesystem

Private
private Filesystem $filesystem = new Filesystem()
Methods

__construct()

Public

Creates a new Generator instance.

public __construct(ReaderInterface  $reader, ResolverInterface  $resolver, TemplateLoaderInterface  $templateLoader, PlaceholderResolverInterface  $placeholderResolver[, Filesystem  $filesystem = new Filesystem()]) : mixed
Parameters
$reader : ReaderInterface

Description

The reader for extracting metadata from composer.json

$resolver : ResolverInterface

Description

The resolver for mapping license identifiers to templates

$templateLoader : TemplateLoaderInterface

Description

The loader for reading template files

$placeholderResolver : PlaceholderResolverInterface

Description

The resolver for template placeholders

$filesystem : Filesystem = new Filesystem()

Description

The filesystem component for file operations

generate()

Public

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
string|null

Description

The generated license content, or null if generation failed

hasLicense()

Public

Checks whether a supported license is present in composer.json.

public hasLicense() : bool
Return values
bool

Description

True if a supported license is defined, false otherwise