From js is jquery, and php?
But now I have a question with frameworks, they provide ready-made solutions, or the need to connect.
From js is jquery, and php?
For example, such a commonplace as form validation: I have my own achievements and I can use them, but they are far from ideal.
/**
* @Route("/profile/{id}", name="getProfile")
* @Method({"GET"})
* @param Request $request
* @return JsonResponse
*/
public function getProfileAction(Request $request): JsonResponse
{
try {
$id = $request->attributes->get('id');
if (is_null($id)) {
return new JsonResponse("Param 'id' is required", JsonResponse::HTTP_BAD_REQUEST);
} elseif (!is_string($id)) {
return new JsonResponse("Param 'id' must be string", JsonResponse::HTTP_BAD_REQUEST);
} elseif (!ctype_digit($id)) {
return new JsonResponse("Param 'id' must be digit", JsonResponse::HTTP_BAD_REQUEST);
}
// Business logic here
return new JsonResponse();
} catch (\Throwable $exception) {
return new JsonResponse($exception->getMessage(), JsonResponse::HTTP_BAD_REQUEST);
}
}
try {
$id = $request->attributes->get('id');
Assert::assert($id, 'id')->notNull()->string()->digit();
} catch (\Throwable $exception) {
return new JsonResponse($exception->getMessage(), JsonResponse::HTTP_BAD_REQUEST);
}
try {
// Business logic here
return new JsonResponse();
} catch (\Throwable $exception) {
return new JsonResponse($exception->getMessage(), JsonResponse::HTTP_BAD_REQUEST);
}
Is there such a tried and tested solution in the frameworks, they give something other than "frame"?
And why is there no popular libraries for php?
Find more questions by tags PHP