gl3n / serialization-group-bundle
Provides a way to organize serialization groups through configuration
Installs: 8 299
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 2
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.4
- symfony/framework-bundle: ~2.6|~3.0
Requires (Dev)
- atoum/atoum: @stable
- phpspec/prophecy: ~1.0
This package is not auto-updated.
Last update: 2024-04-22 12:34:44 UTC
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 groupinclude
(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.