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. Uses the central Template Engine and VariablesFactory to map out the substitutions
  4. 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
generateContent()

Generates license content without writing it to disk.

 : string|null
Properties

$clock

Private
private ClockInterface $clock

$renderer

Private
private Environment $renderer
Methods

__construct()

Public

Creates a new Generator instance.

public __construct(ResolverInterface  $resolver, ComposerJsonInterface  $composer, ClockInterface  $clock, Environment  $renderer, FilesystemInterface  $filesystem) : mixed
Parameters
$resolver : ResolverInterface

Description

The resolver for mapping license identifiers to templates

$composer : ComposerJsonInterface
$clock : ClockInterface
$renderer : Environment
$filesystem : FilesystemInterface

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

generateContent()

Public

Generates license content without writing it to disk.

public generateContent() : string|null
Return values
string|null

Description

the generated license content, or null if generation failed