exsyst/normalizer-extra-bundle

Symfony 序列化器的美味甜点

0.4.5 2024-06-10 22:09 UTC

This package is auto-updated.

Last update: 2024-09-10 22:36:35 UTC


README

这是一个主要基于意见的包,旨在通过使用Symfony序列化器简化高效API服务器的创建,同时尽量保持轻量。

如何使用?

  1. 确保您有一个使用Serializer组件和Doctrine ORM的Symfony 3.*或4.*项目;
  2. 在您的项目中运行 composer require exsyst/normalizer-extra-bundle
  3. 在您的项目配置中添加一个部分以选择您想要使用的功能(见下文);
  4. 如果您想进一步自定义和/或扩展包的行为(文档将在以后提供);
  5. 开始(反)序列化吧!

功能和默认配置

默认启用的功能仅包括那些

  • 本身是无害的,或者;
  • 为完全不受支持的情况定义合理、无偏见的默认行为。
exsyst_normalizer_extra:
  features:
    # Makes $request->request able to access the request body in the
    # Content-Type: application/json, application/xml, application/x-yaml,
    # text/csv cases and/or others depending on serializer support.
    # Enabled by default.
    request_decoder: true

    # Parses a JSON document in a header named "Response-Shape",
    # into a request attribute named "shape", used so that the client
    # can filter out unneeded fields.
    # Enabled by default.
    response_shape_header: true

    # Allows a controller to return an object or null and have it
    # automatically turned into a Response.
    # Disabled by default.
    serializer_view_listener: false

    # Allows a controller to throw a HttpException and have it
    # automatically turned into a Response.
    # Disabled by default.
    serializer_exception_listener: false

  normalizers:
    # A normalizer geared towards Doctrine collections, which also
    # supports most iterables (though in a limited way).
    # Disabled by default.
    collection: false

    # A normalizer for PHP 8.1+ enums. It will normalize backed enum
    # cases into their values, and unit enum cases into their names.
    # Disabled by default.
    enum: false

    # A meta-normalizer that can generate fast normalizers for most
    # classes, and delegate to them.
    # Disabled by default.
    specializing: false
  options:
    # Always use a breadth-first normalization algorithm, that can
    # optimize initialization operations by batching them.
    # Some normalizers may be incompatible.
    # Disabled by default.
    implicit_breadth_first: false

    # When using the breadth-first normalization algorithm (see above),
    # only normalize each object once in each normalized graph.
    # An object that appears at several places will have its extra
    # properties merged into the first normalized instance, and the
    # other instances will be replaced by stubs.
    # Disabled by default.
    implicit_merge_objects: false

    # Automatically provides metadata consumers with information
    # obtained by using Symfony's PropertyInfo component and serializer
    # metadata, Doctrine's mappings, and attributes.
    # Enabled by default.
    auto_metadata: true

    # Parameters to use in the (de)serialization context of the services
    # defined by enabling the above features.
    # Null by default, which is treated the same as an empty mapping.
    default_context: ~
  unsafe_features:
    # Optimizes Doctrine collection initializations by batching them.
    # Disabled by default.
    collection_batching: false

    # Optimizes Doctrine entity proxy initializations by batching them.
    # Disabled by default.
    entity_batching: false