mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-28 04:58:46 +02:00
poc form SDK (symfony 6)
This commit is contained in:
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace Combodo\iTop\DI\Controller;
|
||||
|
||||
use Person;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
|
||||
use Combodo\iTop\DI\Services\Orm;
|
||||
|
||||
/**
|
||||
* Param converter test controller.
|
||||
@@ -28,21 +31,20 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
class ParamConverterTestController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @Route("/param_converter_test/{integer<\d+>}/{class<\w+>}", name="param_converter_test", methods={"GET"})
|
||||
* @ParamConverter("integer", options={"sanitization" : "integer"})
|
||||
* @ParamConverter("class", options={"sanitization" : "class"})
|
||||
*/
|
||||
public function convert(Request $request, string $integer, string $class) : Response
|
||||
#[Route('/param_converter_test/{id<\d+>}', name: 'param_converter_test', methods: ['GET'])]
|
||||
public function convert(Request $request,
|
||||
#[Orm(mapping: 'id')] Person $person,
|
||||
#[MapQueryParameter(filter: \FILTER_VALIDATE_INT)] int $age
|
||||
) : Response
|
||||
{
|
||||
return $this->json([
|
||||
$response = new JsonResponse([
|
||||
'sanitization' => [
|
||||
'integer' => $integer,
|
||||
'class' => $class,
|
||||
'name' => $person->GetName(),
|
||||
'age' => $age,
|
||||
]
|
||||
]);
|
||||
|
||||
$response->setEncodingOptions( $response->getEncodingOptions() | JSON_PRETTY_PRINT );
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user