PHP code example of basilicom / json-schema-request-validator-bundle

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

    

basilicom / json-schema-request-validator-bundle example snippets


$collection->addBundle(new JsonSchemaRequestValidatorBundle());



namespace AppBundle\Controller;

use Basilicom\JsonSchemaRequestValidator\Controller\JsonSchemaRequestValidationControllerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class TestingEndpointsController extends AbstractController implements JsonSchemaRequestValidationControllerInterface
{
    /**
     * @Route("/testing", methods={"POST"}, name="testing_post")
     *
     * @param Request $request
     *
     * @return JsonResponse
     */
    public function testingPost(Request $request): JsonResponse
    {
        return new JsonResponse(['success']);
    }
    
    /**
     * @Route("/testing", methods={"GET"}, name="testing_get")
     *
     * @param Request $request
     *
     * @return JsonResponse
     */
    public function testingGet(Request $request): JsonResponse
    {
        return new JsonResponse(['success']);
    }

    public function setJsonSchemaFilePathsInFilePathProvider(FilePathProvider $filePathProvider)
    {
        $filePathProvider->setIgnoreRouteName('testing_get', true);
        $filePathProvider->setJsonSchemaFilePathForRouteName('testing_post', __DIR__ . '/../Resources/jsonschemas/test.json');
    }
}