PlaceholderResolver

Class
Final: Yes

Resolves placeholders in license templates with metadata values.

Description

This class replaces placeholders like {{ year }}, {{ author }}, {{ project }}, {{ organization }}, and {{ copyright_holder }} with values from metadata. Unresolved placeholders are removed and excess newlines are normalized.

Table of Contents

Interfaces

PlaceholderResolverInterface

Resolves placeholders in license templates with metadata values.

Methods

resolve()

Resolves placeholders in a license template with the provided metadata.

 : string
Methods

resolve()

Public

Resolves placeholders in a license template with the provided metadata.

public resolve( string  $template, array{year?: int, organization?: string, author?: string, project?: string}  $metadata) : string

Description

Supported placeholders:

  • {{ year }} - The copyright year (defaults to current year)
  • {{ organization }} - The organization or vendor name
  • {{ author }} - The primary author name or email
  • {{ project }} - The project/package name
  • {{ copyright_holder }} - Organization or author (organization takes precedence)

Unmatched placeholders are removed, and consecutive blank lines are normalized.

Parameters
$template : string

Description

The license template content with placeholders

$metadata : array{year?: int, organization?: string, author?: string, project?: string}

Description

The metadata values to use for replacement

Return values
string

Description

The template with all resolved placeholders