saeedncc/object-mapper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

saeedncc/object-mapper

最新稳定版本:v1.0.1

Composer 安装命令:

composer require saeedncc/object-mapper

包简介

object mapper for php from ymal file

README 文档

README

Installation

Require this package with composer using the following command:

composer require saeedncc/object-mapper

How to use

Define ymal file for custom object like this:

userinfo.yml

property: 
 - name: 'id'
   map: 'identify'
   type: 'integer'

 - name: 'frist_name'
   map: 'name'
   type: 'string'

 - name: 'last_name'
   map: 'lastname'
   type: 'string'
   
   
 - name: 'age'
   map: 'old'
   type: 'integer'
   
 - name: 'address'
   map: 'address'
   type: 'string'
   
 - name: 'info'
   map: 'information' 
   type: 'object'
   property:
    - name: 'mobile'
      map: 'mobilenumber'
      type: 'string'
      
    - name: 'tel'
      map: 'telphon'
      type: 'string'

    - name: 'email'
      map: 'mail'
      type: 'string'  

Get response json or xml from external api or other and convert to object

require 'vendor/autoload.php';

use \saeedncc\ObjectMapper\ObjectMapper;

$pathYmal='./yaml/userinfo.yml';

$xml = <<<XML
<?xml version='1.0'?> 
<document>
 <identify>125</identify>
 <name>tom</name>
 <lastname>jordan</lastname>
 <old>20</old>
 <address>north bahar st</address>
 <information>
	<mobilenumber>085236125</mobilenumber>
	<telphon>52634855</telphon>
	<mail>tom@gmail.com</mail>
 </information>
</document>
XML;


$object=ObjectMapper::map($pathYmal,$xml);

print_r($object);

stdClass Object
(
    [id] => 125
    [frist_name] => tom
    [last_name] => jordan
    [age] => 20
    [address] => north bahar st
    [info] => stdClass Object
        (
            [mobile] => 085236125
            [tel] => 52634855
            [email] => tom@gmail.com
        )

)

$json='{"identify":"125","name":"tom","lastname":"jordan","old":"20","address":"north bahar st","information":{"mobilenumber":"085236125","telphon":"52634855","mail":"tom@gmail.com"}}';


$object=ObjectMapper::map($pathYmal,$json);

print_r($object);

stdClass Object
(
    [id] => 125
    [frist_name] => tom
    [last_name] => jordan
    [age] => 20
    [address] => north bahar st
    [info] => stdClass Object
        (
            [mobile] => 085236125
            [tel] => 52634855
            [email] => tom@gmail.com
        )

)

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固