saraivadaniel/phpstring

通过填充属性类以字符串数据创建对象(jansenfelipe/phpstring 的分支)

v3.0.0 2023-05-13 16:11 UTC

This package is auto-updated.

Last update: 2024-09-13 19:00:13 UTC


README

Travis Latest Stable Version Total Downloads Latest Unstable Version MIT license

通过填充属性类以字符串数据创建对象(jansenfelipe/phpstring 的分支)

如何使用

添加库

$ composer require saraivadaniel/phpstring

在您的文件中添加 autoload.php

require_once 'vendor/autoload.php';  

添加注解

<?php

class Event
{
    /**
     * @Text(sequence=1, size=20)
     */
    public $name;

    /**
     * @Date(sequence=2, size=8, format="Ymd")
     */
    public $date;

    /**
     * @Numeric(sequence=3, size=6, decimals=2, decimal_separator="")
     */
    public $price;

    /**
     * @Text(sequence=4, size=100)
     */
    public $description;

}

字符串 -> 对象

$parser = new PHPString(Event::class);
$event = $parser->toObject("BH Bike Show        20160621002000Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce consequat augue at hendrerit posuere.");

echo $parser->getSize(); //output: 134

对象 <- 字符串

$parser = new PHPString(Event::class);

$event = new Event();
$event->name = 'Motocross Adventure';
$event->description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce consequat augue at hendrerit posuere.';
$event->date = Carbon::createFromFormat('Y-m-d', '2016-06-21');
$event->price = 1200.98;

$string = $parser->toString($event);

许可证

MIT 许可证 (MIT)