Download the PHP package wizzaq/rest-bundle without Composer
On this page you can find all versions of the php package wizzaq/rest-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wizzaq/rest-bundle
More information about wizzaq/rest-bundle
Files in wizzaq/rest-bundle
Package rest-bundle
Short Description Wizzaq RestBundle
License MIT
Homepage https://github.com/wizzaq/rest-bundle
Informations about the package rest-bundle
Wizzaq Rest Bundle
Rest bundle what you always looked for.
Usage
- ProcessForm argument
- Protocols
ProcessForm argument
Wraps typical form handling to more clean code of action.
Configuration
Simple example
Simple example of typical controller.
All options
A number of options are available on the ProcessForm attribute to
control behavior:
form:string(required)Form type class name to process
mapEntity:null|bool(default:null)If not null, then strictly notify
ProcessFormResolveruse or notEntityValueResolverto resolve value before process by form.
Iffalse, thennullwill be used as initial value to create form.
Ifnull, thenProcessFormResolverwill try to guess it. Can be useful if action supports create and edit at once.:warning: We recommend you always specify this option explicitly.
submit:bool(defaultfalse)If true, then
$form->submit($data, false)(yes, with$clearMissing=false) will we used instead of default$form->handleRequest($request)
throwOnNotValid:bool(defaulttrue)By default
ProcessFormResolverthrowingFormValidationExceptionif validation failing.Set
throwOnNotValidtofalseif you want to process not valid form inside action.Processed form available by
Inherited from MapEntity:
idIf an
idoption is configured and matches a route parameter, then the resolver will find by the primary key
mappingConfigures the properties and values to use with the
findOneBy()method: the key is the route placeholder name and the value is the Doctrine property name
excludeConfigures the properties that should be used in the
findOneBy()method by excluding one or more properties so that not all are used
stripNullIf true, then when
findOneBy()is used, any values that arenullwill not be used for the query.
objectManagerBy default, the
EntityValueResolveruses the default object manager, but you can configure this
evictCacheIf true, forces Doctrine to always fetch the entity from the database instead of cache.
disabledIf true, the
ProcessFormResolverwill not try to replace the argument.
resolverBy default
ProcessFormResolverwill be used to resolve argument, but you can configure this
How it works.
ProcessForm argument extends MapEntity and using EntityValueResolver to find existing entity exactly as described in their doc.
After ProcessFormResolver creating form with parameters:
- with object (or
null) returned fromEntityValueResolveras$data - current
methodof form will be replaced with actual method from$request, if method is notGET
and processing it according defined options.
If form valid it returns processed data from form.
if not, then it throws FormValidationException or returns found object if throwOnNotValid is false
Protocols
While developing an API we all have main listener to decode payload from JSON and put it back into request to process like:
or you decoding it every time in actions :thinking:
Now you can use WizzaqRestBundle to automate it by two ways:
:warning: Protocols handling enabled by default config
-
Simple add
_rest: trueto route default options inconfig/routes.yaml: - Use
Restargument. Can be applied to class or method:
Configuration options
Full configuration options:
Rest argument options
routes:null|string|arrayApply only to defined routes
protocol:?stringProtocol name to use
responseSection:?stringOnly defined section of returned result will be used as response
responseSerializationGroups:null|string|arrayPass defined serialization groups to serializer when serialize response by protocol
Create own protocol
If you want to create you own protocol just implement Wizzaq\RestBundle\Protocol\NamedProtocolInterface and it will be tagged as protocol by autoconfiguration
Or implement Wizzaq\RestBundle\Protocol\ProtocolInterface and tag service manually with alias attribute:
Then you can disable unnecessary default protocol:
Bonus
CircularReferenceHandler
Lost CircularReferenceHandler for Symfony Serializer.
All versions of rest-bundle with dependencies
ext-json Version *
symfony/cache Version ^6.0
symfony/config Version ^6.0
symfony/dependency-injection Version ^6.0
symfony/framework-bundle Version ^6.0
symfony/polyfill-php81 Version 1.x-dev