Skip to content

Generator

github-actions edited this page Apr 10, 2026 · 2 revisions

Generates LICENSE files from composer.json metadata.

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.


Methods

__construct

Creates a new Generator instance.

public __construct(\FastForward\DevTools\License\Reader $reader, \FastForward\DevTools\License\Resolver $resolver, \FastForward\DevTools\License\TemplateLoader $templateLoader, \FastForward\DevTools\License\PlaceholderResolver $placeholderResolver, \Symfony\Component\Filesystem\Filesystem $filesystem = new \Symfony\Component\Filesystem\Filesystem()): mixed

Parameters:

Parameter Type Description
$reader \FastForward\DevTools\License\Reader The reader for extracting metadata from composer.json
$resolver \FastForward\DevTools\License\Resolver The resolver for mapping license identifiers to templates
$templateLoader \FastForward\DevTools\License\TemplateLoader The loader for reading template files
$placeholderResolver \FastForward\DevTools\License\PlaceholderResolver The resolver for template placeholders
$filesystem \Symfony\Component\Filesystem\Filesystem The filesystem component for file operations

generate

Generates a LICENSE file at the specified path.

public generate(string $targetPath): string|null

Parameters:

Parameter Type Description
$targetPath string The full path where the LICENSE file should be written

Return Value:

The generated license content, or null if generation failed


hasLicense

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

public hasLicense(): bool

Return Value:

True if a supported license is defined, false otherwise


Clone this wiki locally