Classifies .gitignore entries as directory-oriented or file-oriented patterns.
Description
This classifier SHALL inspect a raw .gitignore entry and determine whether the entry expresses directory semantics or file semantics. Implementations MUST preserve deterministic classification for identical inputs. Blank entries and comment entries MUST be treated as file-oriented values to avoid incorrectly inferring directory intent where no effective pattern exists.
Interfaces
Constants
Methods
Classifies a .gitignore entry as either a directory or a file pattern.
Determines whether the given .gitignore entry represents a directory pattern.
Determines whether the given .gitignore entry represents a file pattern.
Represents a classification result indicating directory semantics.
private
mixed
DIRECTORY
=
'directory'
Description
This constant MUST be returned when an entry clearly targets a directory, such as entries ending with a slash or patterns that imply directory traversal.
Represents a classification result indicating file semantics.
private
mixed
FILE
=
'file'
Description
This constant MUST be returned when an entry does not clearly express directory semantics, including blank values and comment lines.
Classifies a .gitignore entry as either a directory or a file pattern.
public
classify(
string
$entry) : string
Description
The provided entry SHALL be normalized with trim() before any rule is evaluated. Empty entries and comment entries MUST be classified as files. Entries ending with "/" MUST be classified as directories. Patterns that indicate directory traversal or wildcard directory matching SHOULD also be classified as directories.
Parameters
$entry
:
string
Description
The raw .gitignore entry to classify.
Return values
Description
The classification result. The value MUST be either self::DIRECTORY or self::FILE.
Determines whether the given .gitignore entry represents a directory pattern.
public
isDirectory(
string
$entry) : bool
Description
This method MUST delegate the effective classification to classify() and SHALL return true only when the resulting classification is self::DIRECTORY.
Parameters
$entry
:
string
Description
The raw .gitignore entry to evaluate.
Return values
Description
true when the entry is classified as a directory pattern; otherwise, false
Determines whether the given .gitignore entry represents a file pattern.
public
isFile(
string
$entry) : bool
Description
This method MUST delegate the effective classification to classify() and SHALL return true only when the resulting classification is self::FILE.
Parameters
$entry
:
string
Description
The raw .gitignore entry to evaluate.
Return values
Description
true when the entry is classified as a file pattern; otherwise, false