sitnikovik/array-to-object-serializer 问题修复 & 功能扩展

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

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

sitnikovik/array-to-object-serializer

最新稳定版本:v1.0.2

Composer 安装命令:

composer require sitnikovik/array-to-object-serializer

包简介

Tool to convert your class nested with anothers to associative array

README 文档

README

Tool to convert your class nested with others to associative array

How to use

Just run:

// Array to convert
$array = [
    "name" => "csgo",
    'players' => [
        [
            "name" => "bonnie",
            "health" => 100,
            "weapon" => [
                "name" => "m4a1",
                "ammo" => 30,
            ],
        ],
        [
            "name" => "klyde",
            "health" => 100,
            "weapon" => [
                "name" => "ak47",
                "ammo" => 30,
            ],
        ],
    ],
];

// Convert array to object with one step
$object = \Sitnikovik\ArrayToObjectSerializer\ArrayToObject::serialize($array, "needed_class_name_with_namespace");

How to specify object

You have to create object with properties annotated with @ToObject for each property you want to convert.

Note: You have to specify full class name with namespace in @ToObject annotation without use statement and ::class syntax cause of current version is adapted for PHP 7.3 and higher.

use Sitnikovik\ArrayToObjectSerializer\ToObject;

class Game
{
    /**
     * @var string
     */
    public $name;

    /**
     * @var Player[]
     *
     * @ToObject(Sitnikovik\ArrayToObjectSerializer\Mock\Player)
     */
    public $players = [];
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-11