Download the PHP package check24/apitk-manipulation-bundle without Composer
On this page you can find all versions of the php package check24/apitk-manipulation-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package apitk-manipulation-bundle
apitk-manipulation-bundle
API Toolkit Bundle to handle POST, PUT, PATCH and DELETE methods.
Installation
Install the package via composer:
Usage
Example Classes
See the example
-Folder in this repository: https://github.com/alexdo/apitk-manipulation-bundle/tree/master/example
User entity
User FormType
Controller
Updating Entities (POST, PUT, PATCH)
Updating entites works by mapping request data to a form, validating it and then persisting the form's data to the Database via Doctrine.
You'll need:
- Doctrine Entity
- Form Type with data_class
- Controller Action
This will also auto-generate appropriate Swagger parameters. Usage of FOSRest bundle is optional. Controller methods look the same for POST and PUT.
The $user
parameter is an already updated version of the requested User. You can do anything you want with it:
Serialization, JSON encode, etc.
Internally, the Update
annotation fetches the default
EntityManager, gets the Repository and executes find($id)
on it. You can customize this in three ways:
-
If you'd like to use a different ORM connection than
default
, supply it viaentityManager
:This will cause the annotation to fetch the repository and entity from the "custom" EntityManager.
-
If you'd like to use a different Repository method than
find
, use themethodName
option: - If your path component is something different than
id
, eg.email
, you can supply the parameter to use via therequestParam
option:
Removing Entities (DELETE)
To remove an entity, add an action to your controller that uses the Delete
-Annotation.
@Manipulation\Delete("id", entity=User::class)
"id"
is the name of the path-component to get the ID fromentity=User::class
is the type of the entity to be removed
The $response
parameter is a HTTP 204-Response (No Content). You can just return it, or ignore
it and build one of your own.
Delete
will, by default, perform a hard delete by executing find($id)
on UserRepository
and then
removing the Entity via ObjectManager::remove
.
As with Update
, you can customize this behaviour:
-
If you'd like to perform a soft delete or other things instead, use the
methodName
option:This will cause the Annotation to call
DeleteRepository::deleteById(DeletionService $deletionService)
. TheDeletionService
allows you to access all request parameters. Perform anything you want to mark your Entity as deleted, eg. setting a deleted-Property from 0 to 1 and then flushing the EntityManager. -
If you'd like to use a different ORM connection than
default
, supply it viaentityManager
:This will cause the annotation to operate against the "custom" EntityManager.
All versions of apitk-manipulation-bundle with dependencies
check24/apitk-common-bundle Version ^2.2.0
doctrine/doctrine-bundle Version ^2.2
doctrine/orm Version ^2.5
doctrine/persistence Version ^2
nelmio/api-doc-bundle Version ^3.2
sensio/framework-extra-bundle Version ^5.2
symfony/config Version >= 5.3 <6.0
symfony/dependency-injection Version >= 5.3 <6.0
symfony/form Version >= 5.3 <6.0
symfony/framework-bundle Version >= 5.3 <6.0