PHP code example of mcc-api-tools / request-object-bundle

1. Go to this page and download the library: Download mcc-api-tools/request-object-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/ */

    

mcc-api-tools / request-object-bundle example snippets


   // config/bundles.php

   return [
       // ...
       MccApiTools\RequestObjectBundle\RequestObjectBundle::class => ['all' => true],
   ];
   

   // src/Request/CreateLocationRequest.php

   declare(strict_types=1);

   namespace App\Request;

   use MccApiTools\RequestObjectBundle\Model\AllowExtraAttributesInterface;
   use MccApiTools\RequestObjectBundle\Model\RequestObjectInterface;
   use Symfony\Component\Validator\Constraints as Assert;

   class CreateLocationRequest implements RequestObjectInterface, AllowExtraAttributesInterface
   {
       #[Assert\NotBlank(message: "The location name is ic float $longitude;
   }
   

   // src/Controller/LocationController.php

   declare(strict_types=1);

   namespace App\Controller;

   use App\Request\CreateLocationRequest;
   use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
   use Symfony\Component\HttpFoundation\Response;
   use Symfony\Component\Routing\Attribute\Route;

   class LocationController extends AbstractController
   {
       #[Route("/locations", methods: ["POST"])]
       public function create(CreateLocationRequest $request): Response
       {
           // Access request data via $request->name, $request->address, $request->latitude, $request->longitude

           // Logic for creating a location

           return new Response(null, 204);
       }
   }