2017 © Pedro PelĂĄez
 

library fixed-width

A library to parse and build fixed-width strings

image

axelero/fixed-width

A library to parse and build fixed-width strings

  • Tuesday, January 10, 2017
  • by fcamp
  • Repository
  • 5 Watchers
  • 1 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

FixedWidth

Latest Version on Packagist ![Software License][ico-license] Build Status ![Total Downloads][ico-downloads] Coverage Status, (*1)

A simple library to read and write fixed width file. It's a partial port from this python library, with the aim to be simple, stable and consistent., (*2)

Install

Via Composer, (*3)

``` bash $ composer require axelero/fixed-width, (*4)


## Usage You can read values from arbitrary strings: ``` php $config = [ 'a' => [ 'type' => 'string', 'start' => 3, 'length' => 10 ], // numeric indexes of the config array will be ignored [ 'type' => 'string', 'start' => 13, 'end' => 13 ], 'b' => [ 'type' => 'string', 'start' => 14, 'end' => 17 ] ]; $obj = new FixedWidth($config); $line = '12345678901234567890'; $record = $obj->readLine($line); // ['a' => '3456789012','b' => '4567',]

You can write arrays into fixed-width strings:, (*5)

$config = [
    'a' => [
        'type' => 'string',
        'start' => 1,
        'end' => 5
    ],
    'b' => [
        'type' => 'integer',
        'start' => 6,
        'end' => 10
    ]
];

$obj = new FixedWidth($config);

$data = ['a' => 'xxx', 'b' => 42];
$string = $obj->writeLine($data); // 'xxx  00042'

The possible configuration values for each field are:, (*6)

  • type: string|integer
  • alignment: left|right (defaults to left for string, right for integers)
  • padding: charachter to use to fill the missing space (defaults to '' for string, '0' for integers)
  • default: what to write when an array field is missing (defaults to '' for string, '0' for integers)

Testing

bash $ phpunit, (*7)

Contributing

You are welcome to send any PR. Please make sure the tests pass. Please try to keep the code PSR compliant (in the root of the project lies a .php_cs config file for that)., (*8)

Credits

License

The MIT License (MIT). Please see License File for more information., (*9)

The Versions

10/01 2017

dev-master

9999999-dev http://www.axelero.it

A library to parse and build fixed-width strings

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

09/01 2017

1.01

1.01.0.0 http://www.axelero.it

A library to parse and build fixed-width strings

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires