Skip to content

Instantly share code, notes, and snippets.

@ismail1432
Last active December 25, 2022 20:05
Show Gist options
  • Save ismail1432/27256d779a4151ee95dc4933e795fd73 to your computer and use it in GitHub Desktop.
Save ismail1432/27256d779a4151ee95dc4933e795fd73 to your computer and use it in GitHub Desktop.
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class UserAction
{
/**
* @Route("/users",
* name="get",
* methods="GET",
* defaults={
* "_validator": {
* "limit":"Positive"
* }
* })
*/
public function search(Request $request): Response
{
$errors = $request->attributes->get('_errors');
if ([] !== $errors) {
return new JsonResponse($this->formatError($errors), 400);
}
// boring stuff, fetch users...
return new JsonResponse($users, 201);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment