rtablada / ibm-data-struct
用于创建字符串长度数据结构并与IBM服务通信的快速库
dev-master
2014-02-12 16:04 UTC
This package is not auto-updated.
Last update: 2024-09-24 02:31:39 UTC
README
在与基于IBM的Web服务通信时,您可能需要创建由不同长度字符串表示的数据结构。记住字符串长度和不同要求,并从各种输入创建这些数据结构可能会有些繁琐。
此库提供了一个简单的API,以可管理和可配置的方式创建这些结构。
安装
您可以使用composer安装此库,并需要rtablada/ibm-data-struct
。
使用
要创建数据结构并获取字符串表示,只需传递一组输入值和规则来创建结构即可。将按照顺序解析规则以创建字符串。如果规则未定义为映射,则将使用默认的长度变更。
$values = [ 'name_long' => 'Ryan Tablada', 'name_short' => 'Ryan Tablada', ]; $rules = [ 'name_short' => 22, // Pad length to take up 22 chars 'name_long' => ['length' => 10], // Trim to 10 chars ]; $structure = new Rtablada\IbmDataStruct\IbmStructBuilder($values, $rules); $stringValue = (string) $structure; $stringValue = $structure->getString();