Skip to content

Latest commit

 

History

History
61 lines (39 loc) · 2.31 KB

File metadata and controls

61 lines (39 loc) · 2.31 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

DcfParser (makowskid/dcfparser) is a minimal PHP library for parsing Debian Control Files (DCF format). It has zero production dependencies and optional Laravel integration via service provider auto-discovery.

  • PHP requirement: ^8.2
  • Namespace: makowskid\DcfParser\

Commands

# Run tests
composer test

# Install dependencies
composer install

# Static analysis (PHPStan level 8)
composer analyse

# Code style check
composer cs-check

# Code style fix
composer cs-fix

Architecture

The library consists of four classes:

  1. src/DcfParser.php - The core parser. Public methods:

    • parseFile(string $path): array — reads a DCF file, returns first stanza as associative array with lowercased keys
    • parseFileAll(string $path): array — reads a DCF file, returns all stanzas
    • parseString(string $content): array — parses DCF string, returns first stanza
    • parseStringAll(string $content): array — parses DCF string, returns all stanzas

    Internally uses file_get_contents and a shared parseLines() method. Handles multi-line continuation values, comment lines (#), Windows line endings, and blank-line stanza separators. Throws DcfParserException on errors.

  2. src/Exception/DcfParserException.php - Runtime exception for parse/file errors.

  3. src/ServiceProviders/DcfParserServiceProvider.php - Laravel service provider. Registers DcfParser as a singleton bound to the 'dcfparser' key. Auto-discovered by Laravel via composer.json extras.

  4. src/Facades/DcfParserFacade.php - Laravel facade accessor for 'dcfparser'.

DCF Format

Reference: https://www.debian.org/doc/debian-policy/ch-controlfields.html

  • Key-value pairs separated by first : on the line
  • Continuation lines start with whitespace and append to the previous key's value
  • Keys are case-insensitive (normalized to lowercase in output)
  • Blank lines separate stanzas (paragraphs)
  • Comment lines starting with # are skipped

Testing

PHPUnit 12 with comprehensive tests in tests/DcfParserTest.php. Covers single/multi stanza parsing, error cases, edge cases (comments, Windows line endings, empty values, colons in values), and file I/O.