本文整理汇总了PHP中Symfony\Component\HttpFoundation\JsonResponse::create方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonResponse::create方法的具体用法?PHP JsonResponse::create怎么用?PHP JsonResponse::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\JsonResponse
的用法示例。
在下文中一共展示了JsonResponse::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: contactSendAction
public function contactSendAction(Request $request)
{
$contact = $request->get('email');
$message = \Swift_Message::newInstance()->setSubject('CONSULTA WEB')->setFrom($contact['userEmail'], $contact['name'])->setTo('odiseo.team@gmail.com')->setBody($contact['body'], 'text/html');
$this->get('mailer')->send($message);
return JsonResponse::create(array());
}
示例2: getTagAction
public function getTagAction(Request $request)
{
$q = $request->get('q');
$em = $this->getDoctrine()->getManager();
$result = $em->getRepository('AcmeBlogBundle:Tag')->findTagsByName($q);
return JsonResponse::create($result);
}
示例3: obtenerDatosPanillaNormal
public function obtenerDatosPanillaNormal($central_id, $planilla_id)
{
$planilla = Planilla::find($planilla_id);
$planilla['tipo'] = 'normal';
$planilla->load('viaje.conductor', 'central.ciudad.departamento');
return JsonResponse::create($planilla);
}
示例4: testCreate
public function testCreate()
{
$response = JsonResponse::create(array('foo' => 'bar'), 204);
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $response);
$this->assertEquals('{"foo":"bar"}', $response->getContent());
$this->assertEquals(204, $response->getStatusCode());
}
示例5: wrapResponse
public function wrapResponse($response)
{
if (!$response instanceof Response) {
$response = is_scalar($response) ? Response::create($response) : JsonResponse::create($response);
}
return $response;
}
示例6: __invoke
public function __invoke(\Exception $e, $code)
{
$error = array("code" => $e->getCode(), "message" => $e->getMessage());
if ($this->app["debug"]) {
$error["trace"] = $e->getTraceAsString();
}
return JsonResponse::create($error);
}
示例7: start
/**
* @param Request $request
* The request that resulted in an AuthenticationException
*
* @param AuthenticationException $authException
* The exception that started the authentication process
*
* @return Response
*/
public function start(Request $request, AuthenticationException $authException = null)
{
$responseData = ['error' => 'Unauthorized'];
if (!is_null($authException)) {
$responseData['details'] = $authException->getMessage();
}
return JsonResponse::create($responseData, 401);
}
示例8: testHandlingNonIlluminateResponseErrorResponses
public function testHandlingNonIlluminateResponseErrorResponses()
{
$response = JsonResponse::create(['format' => 'json'], 500);
$formatted = $this->formatter->formatResult($response);
$this->assertJsonResponse($formatted, 500);
$response = Response::create('<html>', 500);
$formatted = $this->formatter->formatResult($response);
$this->assertNormalResponse($formatted, 500);
}
示例9: stationStateAction
/**
* @Route("/stationstate")
* @Method("GET")
*/
public function stationStateAction()
{
$repository = $this->getDoctrine()->getRepository('StationMapping:StationState');
$data = $repository->findLastSnapshot();
return JsonResponse::create(array_map(function (StationState $stationState) {
$station = $stationState->getStation();
return array('name' => $station->getName(), 'id' => $station->getId(), 'statusCode' => $stationState->getStatusCode(), 'availableBikes' => $stationState->getAvailableBikes(), 'freeSlots' => $stationState->getFreeSlots(), 'latitude' => $station->getLatitude(), 'longitude' => $station->getLongitude());
}, $data));
}
示例10: getUserByIdAction
/**
* @param $id
* @return Response
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
* @ApiDoc(
* resource=true,
* description="get user by id"
* )
* @Get("/public/user/get/{id}", defaults={"id" = null})
*/
public function getUserByIdAction($id)
{
$em = $this->getDoctrine()->getManager();
$user = $em->find('OjsUserBundle:User', $id);
if ($user) {
return JsonResponse::create(['id' => $id, 'text' => $user->getUsername() . " <" . $user->getEmail() . '>']);
}
throw new NotFoundHttpException();
}
示例11: connect
public function connect(Application $app)
{
// Creates a new controller based on the default route
$controllers = $app['controllers_factory'];
$controllers->post('/json', function (Request $request, Application $app) {
if ($request->request->has('email')) {
$email = new EmailAddress($request->request->get('email'));
} else {
$email = null;
}
$selection = $request->request->get('selection');
$include = $request->request->get('include');
$command = new ExportEventsAsJsonLD(new EventExportQuery($request->request->get('query')), $email, $selection, $include);
/** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
$commandBus = $app['event_command_bus'];
$commandId = $commandBus->dispatch($command);
return JsonResponse::create(['commandId' => $commandId]);
});
$controllers->post('/csv', function (Request $request, Application $app) {
if ($request->request->has('email')) {
$email = new EmailAddress($request->request->get('email'));
} else {
$email = null;
}
$selection = $request->request->get('selection');
$include = $request->request->get('include');
$command = new ExportEventsAsCSV(new EventExportQuery($request->request->get('query')), $email, $selection, $include);
/** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
$commandBus = $app['event_command_bus'];
$commandId = $commandBus->dispatch($command);
return JsonResponse::create(['commandId' => $commandId]);
});
$controllers->post('/ooxml', function (Request $request, Application $app) {
if ($request->request->has('email')) {
$email = new EmailAddress($request->request->get('email'));
} else {
$email = null;
}
$selection = $request->request->get('selection');
$include = $request->request->get('include');
$command = new ExportEventsAsOOXML(new EventExportQuery($request->request->get('query')), $email, $selection, $include);
/** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
$commandBus = $app['event_command_bus'];
$commandId = $commandBus->dispatch($command);
return JsonResponse::create(['commandId' => $commandId]);
});
$controllers->post('/pdf', function (Request $request, Application $app) {
$deserializer = new ExportEventsAsPDFJSONDeserializer();
$command = $deserializer->deserialize(new String($request->getContent()));
/** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
$commandBus = $app['event_command_bus'];
$commandId = $commandBus->dispatch($command);
return JsonResponse::create(['commandId' => $commandId]);
});
return $controllers;
}
示例12: handle
public function handle(Request $request)
{
// Fetch client_id from authenticated token.
$clientId = $this->checkClientId();
// Check refresh_token, then fetch username and scope.
list($username, $scope) = $this->checkRefreshToken($request, $clientId);
// Generate access_token, store to backend and set token response.
$parameters = $this->tokenTypeHandlerFactory->getTokenTypeHandler()->createAccessToken($clientId, $username, $scope);
return JsonResponse::create($parameters, 200, ['Cache-Control' => 'no-store', 'Pragma' => 'no-cache']);
}
示例13: setStatusAjaxAction
public function setStatusAjaxAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$objLoan = $em->getRepository('DataBundle:Loan')->find($request->get('id'));
$status = (int) $request->get('status');
/* @var $objLoan \DataBundle\Entity\Loan */
$objLoan->setStatus($status);
$em->flush();
return \Symfony\Component\HttpFoundation\JsonResponse::create(array('status' => 'success', 'new_status_label' => $objLoan->getStatusLabel(), 'message' => 'Pożyczka o ID równym ' . $objLoan->getId() . ' zmieniła status na ' . $objLoan->getStatusLabel()));
}
示例14: searchunread
/**
* Action for route /markpostunread/searchunread
*
* Returns the text for the 'Unread posts' search link in JSON
*/
public function searchunread()
{
// Don't allow usage if default behaviour is selected
if ($this->core->cfg('unread_posts_link') == 0) {
throw new \phpbb\exception\http_exception(403, 'NOT_AUTHORISED');
}
$response = array('search_unread' => $this->core->get_search_unread_text());
$headers = array('Cache-Control' => 'no-cache', 'Pragma' => 'no-cache', 'Expires' => '0');
return JsonResponse::create($response, 200, $headers);
}
示例15: getUser
/**
* @return JsonResponse
*/
public function getUser()
{
$user = null;
$minimalUserInfo = $this->userSessionService->getMinimalUserInfo();
if (is_null($minimalUserInfo)) {
return new Response('No active user.', Response::HTTP_NOT_FOUND);
}
$user = $this->userService->getUser($minimalUserInfo->getId());
return JsonResponse::create()->setData($user)->setPrivate();
}