定制 didix16/php-apidataobject 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

didix16/php-apidataobject

Composer 安装命令:

composer require didix16/php-apidataobject

包简介

A simple library that allows easy handle incoming data from any sources (specially from API sources) and put data in a fashion way which is more practical to access it like an array or object. It allows to implement a DTO very fast.

README 文档

README

A simple library that allows easy handle incoming data from any sources (specially from API sources) and put data in a fashion way which is more practical to access it like an array or object. It allows to implement a DTO very fast.

Content

What is an ApiDataObject

It is just a class that can handle incoming data from API sources in JSON format or any other format and structure them in memory to easy handling like an associative array and/or general object.

To pass data into this class, first it should be a simple PHP associative array or plain PHP std object.

It can be created by using JSON string text.

Installation

composer require didix16/php-apidataobject

Usage

class ApiPlatformDataObject extends ApiDataObject {}

...

class AWebHookProcessor {

    /**
     * @var array|object
     */
    $data;

    public function process()
    {
        $apiData = new ApiPlatformDataObject($this->data);

        /**
         * data = 
         * [
         *  'property1' => 'value1',
         *  'property2' => 'value2',
         *  'property3' => 'value3',
         *  'property4' => 'value4',
         * ...
         * ]
         */

        /**
         * Different accessors
         */
        $apiData['property1'];
        $apiData->property1;
        $apiData->property1();

        /**
         * Different setters
         */
        $apiData['property1'] = 'value5';
        $apiData->property1 = 'value5';

        // chainable setter properties
        $apiData
        ->property1('value5')
        ->property2('value6')
        ...
    }

    public function processJson(string $json)
    {
        $apiData = ApiPlatformDataObject::fromJson($json);

        /**
         * Different accessors
         */
        $apiData['property1'];
        $apiData->property1;
        $apiData->property1();

        /**
         * Different setters
         */
        $apiData['property1'] = 'value5';
        $apiData->property1 = 'value5';

        // chainable setter properties
        $apiData
        ->property1('value5')
        ->property2('value6')
        ...

    }
}

See also

  • php-apidatamapper - A DTO library that allows map incoming API data to any of your entities/models by using a simple filed mapping language.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固