happyr/api-bundle

适用于大多数Happyr项目的API功能

安装量: 24,336

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 2

开放问题: 1

类型:symfony-bundle

0.5.1 2018-10-10 13:44 UTC

This package is auto-updated.

Last update: 2024-08-27 06:02:51 UTC


README

Latest Version Software License Build Status Code Coverage Quality Score Total Downloads

安装

在你的项目根目录下运行以下命令,假设你的项目已设置composer

composer require happyr/api-bundle

将bundle添加到app/AppKernel.php

$bundles = [
    // ...
    new Happyr\ApiBundle\HappyrApiBundle(),
];

安全

Wsse内置,默认可启用/禁用。

要启用和配置它,在config.yml中添加

happyr_api:
    wsse:
        user_provider: "security.user.provider.concrete.in_memory"
        cache_service: "cache.provider.redis"
        lifetime: 300
        debug: false # Set to true to disable WSSE completely. You will always be authenticated. 

并在security.yml中配置存储用户信息的提供者,如下所示

security:
    providers:
        in_memory:
            memory:
                users:
                    username:
                        password: password
                        roles: ['ROLE_API_USER']

在security.yml的firewalls下添加一个新的防火墙,如下所示

security:
    firewalls:
        main:
            pattern:   ^/api/
            stateless: true
            wsse:      true

异常监听器

异常监听器默认启用。它将捕获未捕获的异常并返回格式化的JSON响应。

以下是一个示例配置

happyr_api:
  exception_listener:
    enabled: false # disables response listener 
    path_prefix: '/api/' # path prefix to enable listener on. By default its enabled for any path