定制 smartgroup/smart-serializer 二次开发

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

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

smartgroup/smart-serializer

最新稳定版本:2.0.0

Composer 安装命令:

composer require smartgroup/smart-serializer

包简介

Smart-serializer is a tiny library which allows to serialize PHP objects. It supports routes, translations and nested objects of Symfony.

README 文档

README

It's the tiny library which can be used in any of PHP projects, however it was designed mainly to support Symfony projects (Symfony 6 and above).

How to install

Call following command to add it to your project:

composer require smartgroup/smart-serializer

How to use

This library is easy to use. For the entity or object which needs to be serialized, just annotate it's properties or methods with Snapshot annotation.

class Photo
{
    #[Snapshot]
    private ?int $id;

    #[Snapshot]
    private string $locale = 'pl';

    #[Snapshot(isObject: true)]
    private PhotoGallery $photoGallery;

    #[Snapshot]
    private string $title;
    
    private string $slug;
}

Having the code above you will receive a serialized object, which contains fields which are annotated. To receive the serialized object just call:

$serializedObject = Serializer::getSnapshot($photoObject, true);

Snapshot annotation options

Annotating the object with Snapshot annotation, you have following options:

  • isObject - field is an object which should be serialized as well
  • isDate - object is a date
  • dateFormat - if object is a date you can specify the output format of date, by default it is 'Y-m-d H:i:s'
  • fieldName - by default name of the value is the field name, but you can overwrite the name by putting value here
  • isRoute - it will parse the value to extract the real route using symfony/router (it requires to pass symfony/router interface to getSnapshot method)
  • isCollection - it will extract the value as the serialized collection
  • translate - it will translate the value using symfony/translate (it requires to pass symfony/translate interface to getSnapshot method)

Contributing

This project is maintained by a community of developers. Contributions are welcome and appreciated. You can find Jodit on GitHub; feel free to start an issue or create a pull requests: https://github.com/mtulikowski/smart-serializer

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固