happyr / api-bundle
适用于大多数Happyr项目的API功能
0.5.1
2018-10-10 13:44 UTC
Requires
- php: ^7.0
- league/fractal: ^0.16.0
- psr/cache: ^1.0
- symfony/framework-bundle: ^3.3 || ^4.0
- symfony/http-foundation: ^3.3 || ^4.0
- symfony/security-bundle: ^3.3 || ^4.0
- symfony/validator: ^3.3 || ^4.0
Requires (Dev)
README
安装
在你的项目根目录下运行以下命令,假设你的项目已设置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