定制 gl3n/serialization-group-bundle 二次开发

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

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

gl3n/serialization-group-bundle

最新稳定版本:1.0.1

Composer 安装命令:

composer require gl3n/serialization-group-bundle

包简介

Provides a way to organize serialization groups through configuration

README 文档

README

SerializationGroupBundle provides a way to organize serialization groups through configuration.

It is useful to use with Symfony Serializer component or JMS Serializer.

1. Installation

Install the bundle through composer, then add it to your AppKernel.php file :

$bundles = array(
    // ...
    new Gl3n\SerializationGroupBundle\Gl3nSerializationGroupBundle(),
);

2. Configuration

Here is a sample configuration :

gl3n_serialization_group:
    groups:
        group2:
            roles: [ROLE_USER]
        group3:
            roles: [ROLE_ADMIN]
            include: [group2]
        group4:
            roles: [ROLE_SUPER_ADMIN]
            include: [group1, group3]

You can fill on each group :

  • roles (optional) : an array of security roles allowed to use this group
  • include (optional) : an array of included groups

3. Usage

Call the serialization group resolver (gl3n_serialization_group.resolver) in order to get the built groups list.

For example, with the previous sample configuration :

// Resolving group1 returns ['group1']
$groups = $resolver->resolve('group1');

// Resolving group3 returns ['group2', 'group3']
$groups = $resolver->resolve('group3');

// Resolving group4 returns ['group1', 'group2', 'group3', 'group4']
$groups = $resolver->resolve('group4');

3.1. Authorization checker

Security roles are checked during resolution. If user has not the required role a Symfony\Component\Security\Core\Exception\AccessDeniedException is thrown.

3.2. Example

You can organise entity serialization groups by size (small, medium, large) and serialize several entities at once like that :

# config.yml
gl3n_serialization_group:
    groups:
        book_M:
            roles: [ROLE_USER]
            include: [book_S, author_S]
        book_L:
            roles: [ROLE_ADMIN]
            include: [book_M, author_M]
        author_M:
            include: [author_S]

In this example, a book has one or many authors.

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-03-12