PHP code example of lsbproject / request-doc-bundle

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

    

lsbproject / request-doc-bundle example snippets


// config/bundles.php

return [
    // ...
    LSBProject\RequestDocBundle\LSBProjectRequestDocBundle::class => ['all' => true],
];

 declare(strict_types=1);

namespace App\DTO;

use App\Entity\TestEntity;
use App\Service\TestService;
use LSBProject\RequestBundle\Configuration as LSB;
use LSBProject\RequestBundle\Request\RequestInterface;
use OpenApi\Annotations as OA;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @OA\RequestBody(@OA\MediaType(mediaType="application/json"))
 */
class TestRequest implements RequestInterface
{
    /**
     * @Assert\NotBlank()
     * @Assert\Choice({"foo", "bar"})
     * @LSB\PropConverter(name="foo_bar")
     * @LSB\RequestStorage({LSB\RequestStorage::QUERY})
     * @OA\Property(description="Some awesome property")
     */
    public string $foo;

    /**
     * Some awesome title
     *
     * Interesting description
     *
     * @LSB\PropConverter("App\Service\TestService")
     * @LSB\RequestStorage({LSB\RequestStorage::BODY})
     */
    public TestService $service;

    /**
     * @LSB\RequestStorage({LSB\RequestStorage::QUERY})
     */
    public int $testId;

    /**
     * @Assert\NotBlank()
     * @LSB\RequestStorage({LSB\RequestStorage::BODY})
     */
    private bool $barBaz;

    /**
     * @LSB\Entity(options={"id": "test_id"})
     * @LSB\RequestStorage({LSB\RequestStorage::BODY})
     */
    public TestEntity $entity;

    /**
     * @LSB\Entity(expr="repository.find(id)", mapping={"id": "test_id"})
     * @LSB\RequestStorage({LSB\RequestStorage::BODY})
     */
    public TestEntity $entityB;

    /**
     * @LSB\Entity(options={"mapping": {"bar_baz": "text"}})
     * @LSB\RequestStorage({LSB\RequestStorage::BODY})
     */
    public TestEntity $entityC;

    /**
     * @LSB\PropConverter(isDto=true)
     * @LSB\RequestStorage({LSB\RequestStorage::QUERY})
     */
    public SubRequest $params;

    public function setBarBaz(bool $flag): void
    {
        $this->barBaz = $flag;
    }

    public function getBarBaz(): bool
    {
        return $this->barBaz;
    }
}

    /**
     * @Route("/123")
     */
    public function test(TestRequest $testRequest): Response
    {
        return new Response((string)$testRequest->params->subfoo);
    }