mementohub/data 问题修复 & 功能扩展

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

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

mementohub/data

Composer 安装命令:

composer require mementohub/data

包简介

Map arrays into Data Transfer Objects

README 文档

README

A lightweight package that enables casting multidimensional arrays to objects and vice versa.

Installation

You can install the package via composer:

composer require mementohub/data

Usage

Defining a Data Class

To define a data class, create a class that extends Mementohub\Data\Data and add properties to it.

<?php

namespace App\Data;

use Mementohub\Data\Data;

class User extends Data
{
    public function __construct(
        public readonly string $name,
        public readonly string $email,
        public readonly DateTimeImmutable $birthday,
        /** @var Team[] */
        public readonly array $teams
    ) {}
}

class Team extends Data
{
    public function __construct(
        public readonly string $name,
        public readonly string $description,
    ) {}
}

Parsing into Data

To parse an array into a data class, use the from method.

$user = User::from([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'birthday' => '2023-01-01',
    'teams' => [
        [
            'name' => 'Team 1',
            'description' => 'Description 1',
        ],
        [
            'name' => 'Team 2',
            'description' => 'Description 2',
        ],
    ],
]);

Transforming to Array

To transform a data class to an array, use the toArray method.

$array = $user->toArray();

Inspiration

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-26