定制 sapphire/mapper 二次开发

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

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

sapphire/mapper

Composer 安装命令:

composer require sapphire/mapper

包简介

Mapper library written in PHP for AWS DynamoDB

README 文档

README

sapphire logo

PHP Class Mapper for AWS DynamoDB

This library converts your PHP class with the help of PHP attributes to the array structure needed to work with AWS DynamoDB.

Example

Your class:

#[DynamoObject(tableName: "products")]
class Product
{
    #[DynamoField(type: DynamoType::STRING)]
    private string $id;

    #[DynamoField(type: DynamoType::STRING)]
    public string $name;

    #[DynamoField(type: DynamoType::NUMBER)]
    public float $price;

    #[DynamoField(type: DynamoType::LIST)]
    public array $tags = [];

    public function __construct()
    {
        $this->id = uniqid();
    }

    public function getId(): string
    {
        return $this->id;
    }
}

Usage of the mapper:

$product = new Product();
$product->name = "Dominator 2025";
$product->price = 13.37;
$product->tags = ["top seller", "hot", 2025];

$mapper = new DynamoMapper();

$item = $mapper->toPutItem($product);

Result:

// The $item looks like this:
array:2 [
  "TableName" => "products"
  "Item" => array:4 [
    "id" => array:1 [
      "S" => "6857e3326fdc2"
    ]
    "name" => array:1 [
      "S" => "Dominator 2025"
    ]
    "price" => array:1 [
      "N" => "13.37"
    ]
    "tags" => array:1 [
      "L" => array:3 [
        0 => array:1 [
          "S" => "top seller"
        ]
        1 => array:1 [
          "S" => "hot"
        ]
        2 => array:1 [
          "N" => "2025"
        ]
      ]
    ]
  ]
]

Installation

composer req <todo>

Run tests

Unit tests:

composer test:unit

Feature/Integration tests:

composer test:feature

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-22