ramasdev/simple-collection-transformer 问题修复 & 功能扩展

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

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

ramasdev/simple-collection-transformer

最新稳定版本:1.0.1

Composer 安装命令:

composer require ramasdev/simple-collection-transformer

包简介

Simple data to Laravel collection transformer.

README 文档

README

Simple data to Laravel collection transformer, don't write Collection transformers anymore!

  • Lets you utilize filters through callback function.

Install

composer require ramasdev/simple-collection-transformer

Usage

Create DTO/Model class and provide collection class through attributes to which need to transform:

use Ramasdev\SimpleCollectionTransformer\Attributes\CollectionAttribute;
use Ramasdev\SimpleCollectionTransformer\Tests\Unit\Data\Collections\ChannelCollection;

#[CollectionAttribute(ChannelCollection::class)]
class Channel
{
    public function __construct(
        private string $channelId,
        private string $channelType,
        private Carbon $lastRegistration
    ) {
    }

    public function getChannelId(): string
    {
        return $this->channelId;
    }

    public function getChannelType(): string
    {
        return $this->channelType;
    }

    public function getLastRegistration(): Carbon
    {
        return $this->lastRegistration;
    }
}

Transform to collection with filters:

use Ramasdev\SimpleCollectionTransformer\CollectionTransformer;

$actualCollection = $this->collectionTransformer->transform($data, function ($item) {
    if ($item['channel_id'] === 'b') {
        return false;
    }

    return new Channel($item['channel_id'], $item['channel_type'], new Carbon($item['last_registration']));
}); // Returns ChannelCollection

You can utilize it with you deserializer component also, for example:

use Ramasdev\SimpleCollectionTransformer\CollectionTransformer;

$actualCollection = $this->collectionTransformer->transform($data, function ($item) {
    return $this->decoder->decodeArray((array) $item, Channel::class);
}); // Returns ChannelCollection

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固