PHP code example of iwf-web / json-request-check-bundle

1. Go to this page and download the library: Download iwf-web/json-request-check-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/ */

    

iwf-web / json-request-check-bundle example snippets


// config/bundles.php
return [
    // ...
    IWF\JsonRequestCheckBundle\IWFJsonRequestCheckBundle::class => ['all' => true],
];



namespace App\Controller\Api;

use IWF\JsonRequestCheckBundle\Attribute\JsonRequestCheck;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

class ApiController extends AbstractController
{
    #[Route('/api/endpoint', methods: [Request::METHOD_POST])]
    #[JsonRequestCheck(maxJsonContentSize: 1024)] // Limits to 1KB for this route
    public function apiEndpoint(Request $request): object
    {
        // Your code here...
        return $this->json(['status' => 'success']);
    }
}
bash
tools/php-cs-fixer fix --dry-run --diff
bash
tools/php-cs-fixer fix
bash
tools/phpstan analyse
bash
tools/phpstan analyse --generate-baseline
bash
# Check code style
tools/php-cs-fixer fix --dry-run --diff

# Run static analysis
tools/phpstan analyse

# If everything passes, fix code style
tools/php-cs-fixer fix