承接 sarphp/return-data-format 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

sarphp/return-data-format

Composer 安装命令:

composer require sarphp/return-data-format

包简介

PHP Return Data Format - This used to making good format of return data for web application

README 文档

README

This php package help to format return data of any kind of methond. If anyone need to return data with some specific(Array, Json, Serialize) format, they can use it.

Example

class Examples
{
    function __construct() {
    }
    function getData(){
        $data = [
            [
                'id' => 1, 
                'name' => 'Jon D',            
            ],
            [
                'id' => 2, 
                'name' => 'Michel N',            
            ]
        ];
        $apiKey = "Aie"; 
        
        return \ReturnDataFormat\Response::success()->message('Data saved successfully!')
                                                     ->data($data)
                                                     ->apiKey($apiKey);
                                                     // Anything you can add here will be in array 
    }
}

$obj = new Examples();
$data = $obj->getData();
print_r($data->toArray()); 
print_r($data->toJson()); 
print_r($data->toSerialize()) ;

Output

## ARRAY
Array
(
    [result] => 1
    [message] => Data saved successfully!
    [data] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [name] => Jon D
                )

            [1] => Array
                (
                    [id] => 2
                    [name] => Michel N
                )

        )

    [apiKey] => Aie
)
## JSON
{"result":true,"message":"Data saved successfully!","data":[{"id":1,"name":"Jon D"},{"id":2,"name":"Michel N"}],"apiKey":"Aie"}

## Serialize 
a:4:{s:6:"result";b:1;s:7:"message";s:24:"Data saved successfully!";s:4:"data";a:2:{i:0;a:2:{s:2:"id";i:1;s:4:"name";s:5:"Jon D";}i:1;a:2:{s:2:"id";i:2;s:4:"name";s:8:"Michel N";}}s:6:"apiKey";s:3:"Aie";}

So there is not limitation to add index to array, whenever you want anything you can just add \ReturnDataFormat\Response::success()->ANY_INDEX(ASSIGN_DATA)->ANY_INDEX(ASSIGN_DATA) .. .. So it very flexiblie to use in any kind of functions.

Installation

php composer.phar sarphp/return-data-format

OR 

composer require sarphp/return-data-format

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固