承接 vigihdev/serializer 相关项目开发

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

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

vigihdev/serializer

Composer 安装命令:

composer require vigihdev/serializer

包简介

A Symfony-inspired serializer library for PHP

README 文档

README

PHP Version License

Serializer Package

A simple, powerful JSON serializer library for PHP inspired by Symfony components. Transform JSON data into PHP objects with ease.

Installation

composer require vigihdev/serializer

Quick Start

use Serializer\Factory\JsonTransformerFactory;

// Transform JSON file to objects
$transformer = JsonTransformerFactory::create(YourDTO::class);
$objects = $transformer->transformWithFile('data.json');

// Or transform JSON string
$json = '{"name": "John", "age": 30}';
$object = $transformer->transformJson($json);

Features

  • ✅ Transform JSON to PHP objects
  • ✅ Handle both single objects and arrays
  • ✅ File-based and string-based transformation
  • ✅ Symfony Serializer integration
  • ✅ Proper error handling with custom exceptions
  • ✅ Type safety with PHP 8.1+ features

Usage Examples

Basic DTO

class UserDto
{
    public function __construct(
        public readonly string $name,
        public readonly int $age,
        public readonly string $email
    ) {}
}

Transform from File

$transformer = JsonTransformerFactory::create(UserDto::class);
$users = $transformer->transformWithFile('users.json');

foreach ($users as $user) {
    echo $user->name . ': ' . $user->email;
}

Transform from JSON String

$json = '{"name": "Alice", "age": 25, "email": "alice@example.com"}';
$user = $transformer->transformJson($json);

echo $user->name; // "Alice"

Error Handling

use Serializer\Exception\TransformerException;

try {
    $transformer->transformWithFile('invalid.json');
} catch (TransformerException $e) {
    echo "Error: " . $e->getMessage();
}

Requirements

  • PHP 8.1 or higher
  • Symfony Serializer Component

License

MIT License - feel free to use in your projects!

Simple · Fast · Reliable

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-28