PHP code example of paveldanilin / request-body-bundle

1. Go to this page and download the library: Download paveldanilin/request-body-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/ */

    

paveldanilin / request-body-bundle example snippets


/**
 * @Route("/users", methods={"POST"})
 *
 * @RequestBody
 *
 * @param User $user
 * @return Response
 */
public function createUser(User $user): Response
{
    return new Response();
}

/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user")
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}

/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user", deserializationContext={"someAttribute"="value"})
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}

/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user", deserializationError="Bad DTO")
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}

class User
{
    /**
     * @Assert\NotBlank(allowNull=false)
     * @Assert\Type(type="string")
     *
     * @var string
     */
    public $name;
}

/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user", validationGroups={})
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}

/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user", validationGroups={"edit"})
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}