PHP code example of halloverden / symfony-request-entity-bundle
1. Go to this page and download the library: Download halloverden/symfony-request-entity-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/ */
halloverden / symfony-request-entity-bundle example snippets
// config/bundles.php
return [
// ...
HalloVerden\RequestEntityBundle\HalloVerdenRequestEntityBundle::class => ['all' => true],
];
namespace App\Entity\Requests;
use App\Entity\Yoo;
use HalloVerden\RequestEntityBundle\Requests\AbstractRequestEntity;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class TestRequest
*
* @package App\Entity\Requests
*
* @Serializer\ExclusionPolicy("ALL")
*/
class TestRequest extends AbstractRequestEntity {
/**
* @var array|null
*
* @Serializer\SerializedName("test")
* @Serializer\Type(name="array")
* @Serializer\Expose()
*/
private $test;
/**
* @var Yoo
*
* @Serializer\SerializedName("yoo")
* @Serializer\Type(name="App\Entity\Yoo")
* @Serializer\Expose()
*/
private $yoo;
/**
* @return array|null
*/
public function getTest(): ?array {
return $this->test;
}
/**
* @inheritDoc
*/
protected static function getRequestDataValidationFields(): array {
return [
'test' => [new Assert\Type(['type' => 'array']), new Assert\Count(['min' => 1])],
'yoo' => new Assert\Collection([
'fields' => [
'message' => [new Assert\Type(['type' => 'string']), new Assert\NotBlank()]
],
'allowMissingFields' => static::allowMissingFields(),
'allowExtraFields' => static::allowExtraFields()
])
];
}
}
namespace App\Controller;
use App\Entity\Requests\TestRequest;
use App\Response\TestResponse;
use HalloVerden\ResponseEntityBundle\Controller\AbstractResponseEntityController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class Test2Controller
*
* @package App\Controller
*
* @Route("/test2", methods={"POST"}, name="testpost")
*/
class Test2Controller extends AbstractResponseEntityController {
/**
* @ParamConverter("testRequest", converter="HalloVerden\RequestEntityBundle\ParamConverter\RequestEntityConverter", class="App\Entity\Requests\TestRequest")
*
* @param TestRequest $testRequest
*
* @return JsonResponse
*/
public function __invoke(TestRequest $testRequest): JsonResponse {
return $this->createJsonResponse(new TestResponse($testRequest->getTest()));
}
}