PHP code example of check24 / apitk-manipulation-bundle
1. Go to this page and download the library: Download check24/apitk-manipulation-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
check24 / apitk-manipulation-bundle example snippets
namespace MyApp\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class User
{
private $id;
/**
* @Assert\NotBlank()
*/
private $username;
/**
* @Assert\NotBlank()
* @Assert\Email()
*/
private $email;
/**
* @Assert\NotBlank()
*/
private $fullname;
// ...
}
namespace MyApp\Form\Type;
use MyApp\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UserV1Type extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('username', TextType::class)
->add('email', EmailType::class)
->add('fullname', TextType::class);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => User::class,
]
);
}
}
namespace MyApp\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
use MyApp\Entity\User;
use Shopping\ApiTKManipulationBundle\Annotation as Manipulation;
use Swagger\Annotations as SWG;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class UserV1Controller extends Controller
{
/**
* Create a new user.
*
* @Rest\Post("/v1/users/{id}")
* @Manipulation\Update("user", type=UserV1Type::class)
*
* @SWG\Tag(name="User")
*
* @param User $user
*
* @return Response
*/
public function postUserV1(User $user): Response
{
return new Response('', 200);
}
/**
* Update all properties of a given user.
*
* @Rest\Put("/v1/users/{id}")
* @Manipulation\Update("user", type=UserV1Type::class)
*
* @SWG\Tag(name="User")
*
* @param User $user
*
* @return Response
*/
public function putUserV1(User $user): Response
{
return new Response('', 200);
}
/**
* Partially update a users's properties.
*
* @Rest\Patch("/v1/users/{id}")
* @Manipulation\Update("user", type=UserV1Type::class)
*
* @SWG\Tag(name="User")
*
* @param User $user
*
* @return Response
*/
public function patchUserV1(User $user): Response
{
return new Response('', 200);
}
/**
* Remove a user.
*
* @Rest\Delete("/v1/user/{id}")
*
* @Manipulation\Delete("id", entity=User::class)
*
* @SWG\Tag(name="User")
*
* @return Response
*/
public function deleteUserV1(Response $response): Response
{
return $response;
}
}
use Shopping\ApiTKManipulationBundle\Annotation as Manipulation;
/**
* Partially update a users's properties.
*
* @Rest\Patch("/v1/users/{id}")
* @Manipulation\Update("user", type=UserV1Type::class)
*
* @SWG\Tag(name="User")
*
* @param User $user
*
* @return Response
*/
public function patchUserV1(User $user): Response
{
return new Response('', 200);
}
use Shopping\ApiTKManipulationBundle\Annotation as Manipulation;
/**
* Remove a user.
*
* @Rest\Delete("/v1/user/{id}")
*
* @Manipulation\Delete("id", entity=User::class)
*
* @SWG\Tag(name="User")
*
* @return Response
*/
public function deleteUserV1(Response $response): Response
{
return $response;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.