mattiabasone/fixed-width
Composer 安装命令:
composer require mattiabasone/fixed-width
包简介
Library for parsing/generating fixed width files
README 文档
README
This package provides some utilities for generating/parsing fixed-width (positional) files. This library is under development, use it in production at your own risk :D.
Installation
composer require mattiabasone/fixed-width
Usage
Given that sample object:
<?php namespace MyNameSpace; use MattiaBasone\FixedWidth\FixedWidth; class MyObject implements FixedWidth { public function __construct( #[FixedWidthProperty(from: 0, to: 9)] public string $name, #[FixedWidthProperty(from: 10, to: 19)] public string $surname, #[FixedWidthProperty(from: 20, to: 22)] public int $age ) { } }
You can pass this object to the serialize() method of the Serializer class.
<?php use MattiaBasone\FixedWidth\Serializer; use MyNameSpace\MyObject; $object = new MyObject("John", "Smith", "39"); echo (new Serializer())->serialize($object); // Prints // "John Smith 39 "
For deserialize a string into an object that implements FixedWidth interface and has properties with #[FixedWidthProperty]:
<?php use MattiaBasone\FixedWidth\Serializer; use MyNameSpace\MyObject; $object = "John Smith 39 "; var_dump((new Serializer())->deserialize($object, MyObject::class)); // Prints: // class MyObject#12 (3) { // public string $name => // string(4) "John" // public string $surname => // string(5) "Smith" // public int $age => // int(39) // }
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-04-04