PHP code example of ed.sukharev / request-headers-param-converter

1. Go to this page and download the library: Download ed.sukharev/request-headers-param-converter 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/ */

    

ed.sukharev / request-headers-param-converter example snippets


namespace App\Controller\Api;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

class ApiController
{
    /**
     * @Route("/", methods={"GET"})
     * @ParamConverter("XAuthenticatedUserId", class="int", isOptional=true, converter="request_header_converter")
     * @ParamConverter("ContentType", class="string", isOptional=false, converter="request_header_converter")
     * @ParamConverter("XRequireAuth", class="string", isOptional=false, converter="request_header_converter")
     */
    public function getUserInfo($xAuthenticatedUserId, $contentType, $xRequireAuth) {
        return new JsonResponse([
            'XAuthenticatedUserId' => $xAuthenticatedUserId,
            'ContentType' => $contentType,
            'XRequireAuth' => $xRequireAuth,
        ]);
    }
}