willdurand/BazingaHateoasBundle — pull request #30 by kleiram (2014-07-16 11:13:42+00:00)
Title: New expression language function: is_granted

Using the `is_granted` expression language function allows users to check permissions for the active user while describing the HATEOAS serialization properties, i.e.:

```php
/**
* @Hateoas\Relation(
* "delete",
* href = @Hateoas\Route(
* "post_delete",
* parameters = { "id" = "expr(object.getId())" }
* ),
* exclusion = @Hateoas\Exclusion(
* excludeIf = "expr(not is_granted(['ROLE_ADMIN'])"
* )
* )
*/
class Post
{
// ...
}
```

It is also possible to pass the object to the `is_granted` function:

```php
/**
* @Hateoas\Relation(
* "delete",
* href = @Hateoas\Route(
* "post_delete",
* parameters = { "id" = "expr(object.getId())" }
* ),
* exclusion = @Hateoas\Exclusion(
* excludeIf = "expr(not is_granted(['ROLE_ADMIN', object])"
* )
* )
*/
class Post
{
// ...
}
```