定制 mattiabasone/fixed-width 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mattiabasone/fixed-width

Composer 安装命令:

composer require mattiabasone/fixed-width

包简介

Library for parsing/generating fixed width files

README 文档

README

Coverage Status

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-04-04