kelsoncm/php-fwf

PHP library for reading, writing, and parsing Fixed Width Files (FWF)

Maintainers

Package info

github.com/fixed-width-file/php-fwf

pkg:composer/kelsoncm/php-fwf

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-07-20 20:51 UTC

This package is auto-updated.

Last update: 2026-07-21 14:26:25 UTC


README

php-fwf

License PHP FWF Compliance QA Coverage Docs pre-commit

php-fwf is a fast, type-safe PHP library for parsing, validating, and exporting Fixed Width Files (FWF).

It is part of the Fixed Width File Ecosystem and fully implements the fwf-compliance-tests v1.0.0 specification.

๐ŸŒŸ Key Features

  • Type-Safe Columns: CharColumn, RightCharColumn, PositiveIntegerColumn, PositiveDecimalColumn, DateColumn, TimeColumn, and DateTimeColumn.
  • Flexible Descriptors: Structured records with HeaderRowDescriptor, DetailRowDescriptor, and FooterRowDescriptor.
  • Multiple Output Renders: Export layout specifications to Markdown, ReStructuredText (RST), or HTML tables via RenderUtils.
  • Full Test Suite & Compliance: 100% compliant with fwf-compliance-tests v1.0.0.
  • Git Hooks Ready: Pre-configured pre-commit and pre-push hooks.

๐Ÿš€ Installation

Install via Composer:

composer require kelsoncm/php-fwf

๐Ÿ’ก Quickstart

<?php

use Kelsoncm\Fwf\Columns\CharColumn;
use Kelsoncm\Fwf\Columns\PositiveIntegerColumn;
use Kelsoncm\Fwf\Descriptors\DetailRowDescriptor;
use Kelsoncm\Fwf\Descriptors\FileDescriptor;
use Kelsoncm\Fwf\Readers\Reader;

// 1. Define columns
$nameCol = new CharColumn('name', 20, 'User Name');
$ageCol = new PositiveIntegerColumn('age', 3, 'Age in years');

// 2. Define row and file descriptors
$detail = new DetailRowDescriptor([$nameCol, $ageCol]);
$fileDescriptor = new FileDescriptor([$detail]);

// 3. Read fixed-width file content
$content = "KELSON MEDEIROS     045\nMARIA SILVA         030\n";
$reader = new Reader($content, $fileDescriptor, "\n");

foreach ($reader as $row) {
    echo "Name: {$row['name']} | Age: {$row['age']}\n";
}

๐Ÿ“– phpDocumentor & GitHub Pages

Generated documentation is ready for GitHub Pages publication in the docs/ directory:

๐Ÿงช Testing & Compliance

Run all unit tests and compliance checks using PHPUnit:

vendor/bin/phpunit

โš“ Pre-Commit & Pre-Push Setup

Set up pre-commit and pre-push hooks:

pre-commit install
pre-commit install --hook-type pre-push

Run checks manually:

pre-commit run --all-files

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.