用于构建有效的自动引据数据格式ADF/XML引据的库。

0.3.0 2024-08-14 13:09 UTC

This package is auto-updated.

Last update: 2024-09-19 13:53:08 UTC


README

PHP库,用于构建有效的自动引据数据格式ADF/XML引据。

支持

功能

  • 完整的ADF实现
  • 验证标签和属性(可选)
  • 自定义标签和属性
  • 通过关联数组、对象或JSON进行数据输入
  • 尝试将日期转换为ISO 8601:1988
  • namephoneprospectvehicle的默认属性

安装

使用Composer将SendADF包含到您的项目中

composer require carmelosantana/sendadf

要求

使用方法

基本引据

示例引据表示符合ADF规范所需的最小数据。

$adf = ( new CarmeloSantana\SendAdf\SendAdf() )
    ->addProspect( 'new' )
    ->addRequestdate( '2/9/2020 6:26PM' )
    ->addVehicle( [
        'year' => 1999,
        'make' => 'Chevrolet',
        'model' => 'Blazer'
    ], 'buy', 'used' )
    ->addCustomer()
        ->addContact()
            ->addName( 'John Doe' )
            ->addPhone( '393-999-3922' )
    ->addVendor()
        ->addContact()
            ->addName( 'Acura of Bellevue' );

输出

无制表符的基本输出。

echo $adf->getXml();
<?xml version="1.0" encoding="UTF-8"?>
<?adf version="1.0"?>
<adf><prospect status="new"><requestdate>2020-02-09T18:26:00-05:00</requestdate><vehicle interest="buy" status="used"><year>1999</year><make>Chevrolet</make><model>Blazer</model></vehicle><customer><contact><name part="full" type="individual">John Doe</name><phone type="voice" time="nopreference">393-999-3922</phone></contact></customer><vendor><contact><name part="full" type="individual">Acura of Bellevue</name></contact></vendor></prospect></adf>

格式化输出。

echo $adf->getPrettyPrintXML();
<?xml version="1.0" encoding="UTF-8"?>
<?adf version="1.0"?>
<adf>
  <prospect status="new">
    <requestdate>2020-02-09T18:26:00-05:00</requestdate>
    <vehicle interest="buy" status="used">
      <year>1999</year>
      <make>Chevrolet</make>
      <model>Blazer</model>
    </vehicle>
    <customer>
      <contact>
        <name part="full" type="individual">John Doe</name>
        <phone type="voice" time="nopreference">393-999-3922</phone>
      </contact>
    </customer>
    <vendor>
      <contact>
        <name part="full" type="individual">Acura of Bellevue</name>
      </contact>
    </vendor>
  </prospect>
</adf>

默认值

如果没有提供,则添加默认属性值。这是为了符合ADF标准。

$adf = ( new CarmeloSantana\SendAdf\SendAdf() )
    ->addRequestdate()
    ->addVehicle( [
        'year' => 2020,
        'make' => 'Chevrolet',
        'model' => 'Blazer'
    ] )
    ->addCustomer()
        ->addContact()
            ->addName( 'John Doe' )
            ->addPhone( '393-999-3922' );

echo $adf->getPrettyPrintXML();
<?xml version="1.0" encoding="UTF-8"?>
<?adf version="1.0"?>
<adf>
  <prospect status="new">
    <requestdate>2021-02-09T19:32:16-05:00</requestdate>
    <vehicle interest="buy" status="new">
      <year>1999</year>
      <make>Chevrolet</make>
      <model>Blazer</model>
    </vehicle>
    <customer>
      <contact>
        <name part="full" type="individual">John Doe</name>
        <phone type="voice" time="nopreference">393-999-3922</phone>
      </contact>
    </customer>
  </prospect>
</adf>
  • prospect标签以状态new打开,而不调用addProspect
  • 如果没有提供,则使用addRequestdate当前服务器时间作为requestdate的默认值。
  • 提供name部分和类型。
  • 提供phone类型和时间。

可以通过使用如示例3中所示的使用addProspectparent_nodeaddNode来避免默认值。

示例1所示发送空值也可以禁用这些属性。

示例

示例1

  • 开始所需的最少内容

示例2

  • 包含所有元素和属性示例的完整文档

示例3

  • 避免默认值
  • 手动打开和关闭节点

示例4

  • 禁用验证
  • 自定义标签和属性

示例5

  • 通过arraysobjectsJSON进行数据输入

支持

Discord上提供社区支持。

资金

如果您发现此项目有用或将其用于商业环境,请考虑今天通过以下任一选项进行捐赠。

变更日志

  • 0.3.0 - 2024年8月6日
    • 修复psr-4命名空间
    • 更新所有方法从下划线到camelCase
    • 更新PHP要求

许可证

代码受MIT许可,文档受CC BY-SA 4.0许可。