Writer

Class
implements WriterInterface
Read only: Yes Final: Yes

Persists normalized .gitattributes content.

Description

This writer SHALL align attribute declarations using the longest path spec, write the provided textual content to the target path, and MUST append a final trailing line feed for deterministic formatting.

Table of Contents

Interfaces

WriterInterface

Defines the contract for writing .gitattributes files to persistent storage.

Properties

 : Filesystem

Methods

 : mixed
write()

Writes the .gitattributes content to the specified filesystem path.

 : void
firstUnescapedWhitespacePosition()

Locates the first non-escaped whitespace separator in a line.

 : int|null
format()

Formats .gitattributes content with aligned attribute columns.

 : string
parseEntry()

Parses a .gitattributes entry into its path spec and attribute segment.

 : array{path_spec: string, attributes: string}|null
Properties

$filesystem

Private
private Filesystem $filesystem
Methods

__construct()

Public
public __construct(Filesystem  $filesystem) : mixed
Parameters
$filesystem : Filesystem

Description

the filesystem service responsible for writing the file

write()

Public

Writes the .gitattributes content to the specified filesystem path.

public write( string  $gitattributesPath, string  $content) : void
Parameters
$gitattributesPath : string

Description

The filesystem path to the .gitattributes file.

$content : string

Description

The merged .gitattributes content to persist.

firstUnescapedWhitespacePosition()

Private

Locates the first non-escaped whitespace separator in a line.

private firstUnescapedWhitespacePosition( string  $line) : int|null
Parameters
$line : string

Description

the line to inspect

Return values
int|null

format()

Private

Formats .gitattributes content with aligned attribute columns.

private format( string  $content) : string
Parameters
$content : string

Description

The merged .gitattributes content to normalize.

Return values
string

parseEntry()

Private

Parses a .gitattributes entry into its path spec and attribute segment.

private parseEntry( string  $line) : array{path_spec: string, attributes: string}|null
Parameters
$line : string

Description

The normalized .gitattributes line.

Return values
array{path_spec: string, attributes: string}|null