GitAttributesCommand

Class
extends BaseCommand
Final: Yes

Provides functionality to manage .gitattributes export-ignore rules.

Description

This command adds export-ignore entries for repository-only files and directories to keep them out of Composer package archives.

Attributes
#[AsCommand]
$name : 'gitattributes'
$description : 'Manages .gitattributes export-ignore rules for leaner package archives.'
$help : 'This command adds export-ignore entries for repository-only files and directories to keep them out of Composer package archives. ' . 'Only paths that exist in the repository are added, existing custom rules are preserved, and "extra.gitattributes.keep-in-export" paths stay in exported archives.'

Table of Contents

Interfaces

LoggerAwareCommandInterface

Defines the logger contract consumed by reusable command result helpers.

Constants

 = 'keep-in-export'
 = 'gitattributes'
 = 'no-export-ignore'
 = '.gitattributes'

Properties

Methods

__construct()

Creates a new GitAttributesCommand instance.

 : mixed
addJsonOption()

Adds the standard JSON output options to the current command.

 : static
configure()

Configures verification and interactive update modes.

 : void
execute()

Configures the current command.

 : int
isJsonOutput()

Determines whether JSON output was requested.

 : bool
isPrettyJsonOutput()

Determines whether pretty JSON output was requested.

 : bool
configuredKeepInExportPaths()

Resolves the consumer-defined paths that MUST stay in exported archives.

 : array<int, string>
failure()

Logs a failed command result and returns the failure exit code.

 : int
notice()

Logs an informational command message at notice level.

 : void
shouldWriteGitAttributes()

Prompts whether .gitattributes should be updated.

 : bool
success()

Logs a successful command result and returns the success exit code.

 : int
Constants

Constants

EXTRA_KEEP_IN_EXPORT

Private
private mixed EXTRA_KEEP_IN_EXPORT = 'keep-in-export'

EXTRA_NO_EXPORT_IGNORE

Private
private mixed EXTRA_NO_EXPORT_IGNORE = 'no-export-ignore'
Properties
Methods

__construct()

Public

Creates a new GitAttributesCommand instance.

public __construct(CandidateProviderInterface  $candidateProvider, ExistenceCheckerInterface  $existenceChecker, ExportIgnoreFilterInterface  $exportIgnoreFilter, MergerInterface  $merger, ReaderInterface  $reader, WriterInterface  $writer, ComposerJsonInterface  $composer, FilesystemInterface  $filesystem, FileDiffer  $fileDiffer, LoggerInterface  $logger) : mixed
Parameters
$candidateProvider : CandidateProviderInterface

Description

the candidate provider

$existenceChecker : ExistenceCheckerInterface

Description

the repository path existence checker

$exportIgnoreFilter : ExportIgnoreFilterInterface

Description

the configured candidate filter

$merger : MergerInterface

Description

the merger component

$reader : ReaderInterface

Description

the reader component

$writer : WriterInterface

Description

the writer component

$composer : ComposerJsonInterface

Description

the composer.json accessor

$filesystem : FilesystemInterface

Description

the filesystem component

$fileDiffer : FileDiffer
$logger : LoggerInterface

Description

the output-aware logger

addJsonOption()

Protected

Adds the standard JSON output options to the current command.

protected addJsonOption() : static
Return values
static

configure()

Protected

Configures verification and interactive update modes.

protected configure() : void

execute()

Protected

Configures the current command.

protected execute(InputInterface  $input, OutputInterface  $output) : int

Description

This method MUST define the name, description, and help text for the command.

Parameters
$input : InputInterface
$output : OutputInterface
Return values
int

isJsonOutput()

Protected

Determines whether JSON output was requested.

protected isJsonOutput(InputInterface  $input) : bool

Description

The pretty-json flag SHALL imply JSON output.

Parameters
$input : InputInterface
Return values
bool

isPrettyJsonOutput()

Protected

Determines whether pretty JSON output was requested.

protected isPrettyJsonOutput(InputInterface  $input) : bool
Parameters
$input : InputInterface
Return values
bool

configuredKeepInExportPaths()

Private

Resolves the consumer-defined paths that MUST stay in exported archives.

private configuredKeepInExportPaths() : array<int, string>

Description

The preferred configuration key is "extra.gitattributes.keep-in-export". The alternate "extra.gitattributes.no-export-ignore" key remains supported as a compatibility alias.

Return values
array<int, string>

Description

the configured keep-in-export paths

failure()

Private

Logs a failed command result and returns the failure exit code.

private failure( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string|null  $file = null][, int|null  $line = null]) : int
Parameters
$message : string

Description

the failure message

$input : InputInterface

Description

the originating command input

$context : array<string, mixed> = []

Description

optional extra log context

$file : string|null = null

Description

the related file path when known

$line : int|null = null

Description

the related line when known

Return values
int

notice()

Private

Logs an informational command message at notice level.

private notice( string  $message, InputInterface  $input[, array<string, mixed>  $context = []]) : void
Parameters
$message : string

Description

the notice message

$input : InputInterface

Description

the originating command input

$context : array<string, mixed> = []

Description

optional extra log context

shouldWriteGitAttributes()

Private

Prompts whether .gitattributes should be updated.

private shouldWriteGitAttributes( string  $targetPath) : bool
Parameters
$targetPath : string

Description

the target path that would be updated

Return values
bool

Description

true when the update SHOULD proceed

success()

Private

Logs a successful command result and returns the success exit code.

private success( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string  $logLevel = LogLevel::INFO]) : int
Parameters
$message : string

Description

the success message

$input : InputInterface

Description

the originating command input

$context : array<string, mixed> = []

Description

optional extra log context

$logLevel : string = LogLevel::INFO

Description

the PSR-3 log level used for the successful result

Return values
int