承接 uuur86/dalue 相关项目开发

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

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

uuur86/dalue

Composer 安装命令:

composer require uuur86/dalue

包简介

PHP Data mapper.

README 文档

README

The Mapper class under the Dalue namespace offers a powerful and flexible method for data transformation and restructuring. This class allows you to create a new structure from a given data set, optionally performing transformations on the data in the process.

Getting Started

Before you begin using the Mapper class, ensure that the library containing the StrObj\StringObjects class is installed. The Mapper class utilizes the functionalities provided by this class for data access and manipulation.

Installation

First, install the required packages via Composer:

composer require uuur86/dalue:0.1.1-beta

Example Usage

Below is an example of how to use the Mapper class:

use Dalue\Mapper;
use StrObj\StringObjects;

// Sample data set
$data = new StringObjects([
    'user' => [
        'id' => 1,
        'name' => 'John Doe',
        'email' => 'john.doe@example.com',
        'details' => [
            'age' => 30,
            'city' => 'New York'
        ]
    ]
]);

// Defining the data structure we want to transform into.
$paths = [
    'userID' => '@data/user/id',
    'userName' => '@data/user/name',
    'userDetails' => [
        'userAge' => '@data/user/details/age',
        'userCity' => '@data/user/details/city'
    ]
];

// Using the Mapper::map function to perform the transformation.
$mappedData = Mapper::map($data, $paths);

print_r($mappedData);

Explanation

  1. Data Initialization:
    • A sample data set is created using the StringObjects class.
  2. Path Definition:
    • The structure we want to transform into is defined in the $paths array.
  3. Data Transformation:
    • The Mapper::map function is used to transform the data according to the defined paths.

Output

The above example will produce the following output:

Array
(
    [userID] => 1
    [userName] => John Doe
    [userDetails] => Array
        (
            [userAge] => 30
            [userCity] => New York
        )
)

Advanced Usage

You can also perform more complex transformations by incorporating custom functions in the mapping paths. Here is an example:

use Dalue\Mapper;
use StrObj\StringObjects;

$data = new StringObjects([
    'user' => [
        'id' => 1,
        'name' => 'John Doe',
        'email' => 'john.doe@example.com',
        'details' => [
            'age' => 30,
            'city' => 'New York'
        ]
    ]
]);

$paths = [
    'userID' => '@data/user/id',
    'userName' => '@data/user/name',
    'userEmail' => function($data) {
        return strtoupper($data->get('user.email'));
    },
    'userDetails' => [
        'userAge' => '@data/user/details/age',
        'userCity' => '@data/user/details/city',
        'description' => function($data) {
            return $data->get('user.details.age') . ' years old, lives in ' . $data->get('user.details.city');
        }
    ]
];

$mappedData = Mapper::map($data, $paths);

print_r($mappedData);

Output

The advanced example will produce the following output:

Array
(
    [userID] => 1
    [userName] => John Doe
    [userEmail] => JOHN.DOE@EXAMPLE.COM
    [userDetails] => Array
        (
            [userAge] => 30
            [userCity] => New York
            [description] => 30 years old, lives in New York
        )
)

LICENSE

This project is licensed under the GPL-3.0-or-later License. See the LICENSE file for more details.

AUTHOR

Uğur Biçer - @uuur86

CONTRIBUTING

If you want to contribute to this project, you can send pull requests. We expect all contributors to follow our Code of Conduct.

CONTACT

You can contact me via email: contact@codeplus.dev

BUGS

You can report bugs via GitHub issues.

SECURITY

If you find a security issue, please report it via email: contact@codeplus.dev

DONATE

If you want to support me, you can donate via GitHub sponsors: https://github.com/sponsors/uuur86

SEE ALSO

uuur86/dalue 适用场景与选型建议

uuur86/dalue 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 53 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 uuur86/dalue 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 uuur86/dalue 我们能提供哪些服务?
定制开发 / 二次开发

基于 uuur86/dalue 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2023-05-27