PHP code example of devouted / request-mapper

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

    

devouted / request-mapper example snippets


use RequestMapper\Attribute\FromHeader;
use RequestMapper\Attribute\FromPath;
use RequestMapper\Attribute\FromUploads;

class GetArticleQuery
{
    public function __construct(
        #[FromPath]
        public int $articleId,

        #[FromHeader(name: 'Accept-Language')]
        public string $language,
    ) {
    }
}

class UploadFileCommand
{
    public function __construct(
        #[FromPath]
        public int $visitId,

        #[FromUploads]
        public array $files = [],
    ) {
    }
}

use RequestMapper\Attribute\FromHeader;
use RequestMapper\Attribute\FromPath;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;

class ArticleController
{
    public function show(#[MapQueryString] GetArticleQuery $query): Response
    {
        // Works even when the query string is empty —
        // FromPath and FromHeader attributes are still resolved.
    }
}