ac / kalinka-bundle
为您的 Symfony2 应用提供灵活的授权
0.1.2
2014-04-02 14:23 UTC
Requires
- php: >=5.4.0
- ac/kalinka: ~0.1
- symfony/framework-bundle: ~2.2
- symfony/security: ~2.2
Requires (Dev)
- ac/model-traits: 0.1.0
- jms/serializer-bundle: 0.12.0
- sensio/framework-extra-bundle: ~2.2
- symfony/symfony: ~2.2
This package is not auto-updated.
Last update: 2024-09-23 14:59:57 UTC
README
Symfony2 绑定用于 Kalinka.
安装
- 在您的 `composer.json` 中添加
"ac/kalinka-bundle": "~0.1.0"
- 运行
composer update ac/kalinka
- 在您的
AppKernel
中实例化AC\KalinkaBundle\ACKalinkaBundle
- 配置此绑定,详情如下
配置
ac_kalinka: #default_authorizer: 'default' authorizers: default: authenticated_role: 'authenticated' #optional anonymous_role: 'anonymous' #optional roles: #map roles to actions and guard policies authenticated: document: read: 'allow' index: 'allow' anonymous: document: read: 'allow' teacher: system: foo: 'allow' document: index: 'allow' create: 'allow' read: 'allow' update: ['owner', 'unlocked'] delete: ['owner', 'unlocked'] admin: system: foo: 'allow' bar: 'allow' baz: 'allow' document: index: 'allow' create: 'allow' read: 'allow' update: 'allow' delete: 'allow' student: document: index: 'allow' read: 'allow'
服务
该绑定注册了 kalinka.authorizer
服务,您可以在您的应用程序中使用它
$document = //...get some document instance, however you do that $authorizer = $this->container->get('kalinka.authorizer'); if (!$authorizer->can('edit', 'document', $someDocument)) { throw new Exception('Computer says no. :('); }
要注册守卫,只需使用 kalinka.guard
标签,并指定守卫的域。例如
services: app.guard.document: class: ACME\AppBundle\Authorization\DocumentGuard tags: - { name: 'kalinka.guard', tag: 'document' }
如果您需要,也可以配置多个授权者。
#TODO: document said feature