本文整理汇总了PHP中Symfony\Component\HttpFoundation\JsonResponse::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonResponse::setContent方法的具体用法?PHP JsonResponse::setContent怎么用?PHP JsonResponse::setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\JsonResponse
的用法示例。
在下文中一共展示了JsonResponse::setContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: defaultAction
static function defaultAction(Request $request, Service $service, $repositoryName)
{
$repository = $service->getRepository($repositoryName);
if ($repository) {
$response = new JsonResponse();
$etag = md5($repository->getLastModifiedDate());
$response->setEtag($etag);
if ($response->isNotModified($request)) {
$response->send();
return $response;
}
$result = [];
$result['content'] = [];
foreach ($repository->getContentTypeDefinitions() as $definition) {
$result['content'][$definition->getName()]['title'] = $definition->getTitle() ? $definition->getTitle() : $definition->getName();
$result['content'][$definition->getName()]['lastchange_content'] = $repository->getLastModifiedDate($definition->getName());
$result['content'][$definition->getName()]['lastchange_cmdl'] = 0;
// TODO
}
$response->setContent(json_encode($result, JSON_PRETTY_PRINT));
$response->setEtag($etag);
$response->setPublic();
return $response;
}
}
示例2: indexAction
public function indexAction()
{
$util = new Util();
//$key = $request->query->get('key',0);
$vvaList = $this->getDoctrine()->getRepository('IglesysGeneralBundle:ValorVariable')->findAll();
$response = new JsonResponse();
$response->setContent($util->getSerialize($vvaList));
return $response;
}
示例3: getEventCategoriesAction
/**
* @Route("/upcoming")
*/
public function getEventCategoriesAction(Request $request)
{
$events = $this->get('event_manager')->getUpcomingEvents();
$serializer = $this->get('jms_serializer');
$jsonContent = $serializer->serialize($events, 'json');
$response = new JsonResponse();
$response->setContent($jsonContent);
return $response;
}
示例4: conversationShowAction
/**
*
* @param User $mainUser
* @param User $secendaryUser
* @param Request $request
*
* @ParamConverter("mainUser", class="AppBundle:User", options={"id" = "mainUserId"})
* @ParamConverter("secendaryUser", class="AppBundle:User", options={"id" = "secendaryUserId"})
*/
public function conversationShowAction(User $mainUser, User $secendaryUser, Request $request)
{
$repo = $this->getDoctrine()->getRepository('AppBundle:Message');
$order = $request->query->get('order', 'desc');
$messages = $repo->getConversation($mainUser, $secendaryUser, $order);
$serializer = $this->get('serializer');
$response = new JsonResponse();
$response->setContent($serializer->serialize($messages, 'json', array('groups' => array('main'))));
return $response;
}
示例5: monitorAction
/**
* method checks if there are jobs which are enabled but did not return 0 on last execution or are locked.<br>
* if a match is found, HTTP status 417 is sent along with an array which contains name, return code and locked-state.
* if no matches found, HTTP status 200 is sent with an empty array
*
* @return JsonResponse
*/
public function monitorAction()
{
$scheduledCommands = $this->getMonitoringData();
$failed = $this->monitorService->processCommandsJSON($scheduledCommands);
$status = count($failed) > 0 ? Response::HTTP_EXPECTATION_FAILED : Response::HTTP_OK;
$response = new JsonResponse();
$response->setContent(json_encode($failed));
$response->setStatusCode($status);
return $response;
}
示例6: getEventCategoriesAction
/**
* @Route("/")
*/
public function getEventCategoriesAction(Request $request)
{
$repository = $this->getDoctrine()->getRepository('AppBundle:EventCategory');
$categories = $repository->findAll();
$serializer = $this->get('jms_serializer');
$jsonContent = $serializer->serialize($categories, 'json');
$response = new JsonResponse();
$response->setContent($jsonContent);
return $response;
}
示例7: subjectAction
public function subjectAction($name)
{
$url = "/subject?name=" . $name;
$response = $this->request($url);
$responseBodyJson = $response->getBody();
$serializer = $this->get('serializer');
$responseBody = $serializer->deserialize($responseBodyJson, 'array', 'json');
//$responseBody = json_decode($responseBodyJson, true);
$preferredNames = array();
foreach ($responseBody as $element) {
if (isset($element["@graph"])) {
if (isset($element["@graph"][0]["@type"])) {
$types = $element["@graph"][0]["@type"];
$geographicNameIdentifierFound = false;
$territoryOrAdministrativeUnitIdenitifierFound = false;
if (is_array($types)) {
foreach ($types as $type) {
if ($type == "http://d-nb.info/standards/elementset/gnd#PlaceOrGeographicName") {
$geographicNameIdentifierFound = true;
continue;
}
if ($type == "http://d-nb.info/standards/elementset/gnd#TerritorialCorporateBodyOrAdministrativeUnit") {
$territoryOrAdministrativeUnitIdenitifierFound = true;
}
}
} else {
// not necessary to check here?
}
if ($geographicNameIdentifierFound && $territoryOrAdministrativeUnitIdenitifierFound) {
if (isset($element["@graph"][0]["preferredNameForThePlaceOrGeographicName"])) {
if (is_array($element["@graph"][0]["preferredNameForThePlaceOrGeographicName"])) {
foreach ($element["@graph"][0]["preferredNameForThePlaceOrGeographicName"] as $name) {
$name = addslashes(trim($name));
if (!in_array($name, $preferredNames)) {
$preferredNames[] = $name;
}
}
} else {
$this->getLogger()->debug("Possible preferred Names: " . $element["@graph"][0]["preferredNameForThePlaceOrGeographicName"]);
$singleName = addslashes(trim($element["@graph"][0]["preferredNameForThePlaceOrGeographicName"]));
if (!in_array($singleName, $preferredNames)) {
$preferredNames[] = $singleName;
}
}
}
}
}
}
}
//Lipsk
$jsonResponse = new JsonResponse();
$jsonResponse->setContent($serializer->serialize($preferredNames, 'json'));
return $jsonResponse;
}
示例8: findPossibleRelativesAction
public function findPossibleRelativesAction($ID)
{
$this->getLogger()->info("FindPossibleRelativesAction called: " . $ID);
$em = $this->get('doctrine')->getManager('final');
$possibleRelatives = $this->get('possible_relatives_finder.service')->findPossibleRelatives($em, $ID);
$serializer = $this->container->get('serializer');
$json = $serializer->serialize($possibleRelatives, 'json');
$response = new JsonResponse();
$response->setContent($json);
return $response;
}
示例9: getJSONResponse
public function getJSONResponse($obj)
{
if (get_class($obj) == self::PERSON_CLASS) {
//$this->LOGGER->debug("PERSON: " . $obj . " has Sources: " . count($obj->getSources()));
}
$serializer = $this->container->get('serializer');
$json = $serializer->serialize($obj, 'json');
$response = new JsonResponse();
$response->setContent($json);
return $response;
}
示例10: directIdAction
public function directIdAction($ID)
{
$relationShipLoader = $this->get('relationship_loader.service');
$em = $this->get('doctrine')->getManager('new');
$relatives = $relationShipLoader->loadOnlyDirectRelatives($em, $ID);
$serializer = $this->container->get('serializer');
$json = $serializer->serialize($relatives, 'json');
$response = new JsonResponse();
$response->setContent($json);
return $response;
}
示例11: deleteAction
public function deleteAction($id)
{
$util = new Util();
//$key = $request->query->get('key',0);
$valorVariable = $this->getDoctrine()->getRepository('IglesysGeneralBundle:ValorVariable')->find($id);
if (!$valorVariable) {
throw $this->createNotFoundException('No se encuentra el registro solicitado.');
}
$response = new JsonResponse();
$response->setContent($util->getSerialize($valorVariable));
return $response;
}
示例12: coletaAction
public function coletaAction(Request $request)
{
$logger = $this->get('logger');
$status = $request->getContent();
$em = $this->getDoctrine()->getManager();
$dados = json_decode($status, true);
if (empty($dados)) {
$logger->error("JSON INVÁLIDO!!!!!!!!!!!!!!!!!!! Erro na COLETA");
// Retorna erro se o JSON for inválido
$error_msg = '{
"message": "JSON Inválido",
"codigo": 1
}';
$response = new JsonResponse();
$response->setStatusCode('500');
$response->setContent($error_msg);
return $response;
}
$computador = $this->getComputador($dados, $request);
if (empty($computador)) {
// Se não identificar o computador, manda para o getUpdate
$logger->error("Computador não identificado no getConfig. Necessário executar getUpdate");
$error_msg = '{
"message": "Computador não identificado",
"codigo": 2
}';
$response = new JsonResponse();
$response->setStatusCode('500');
$response->setContent($error_msg);
return $response;
}
//Verifica se a coleta foi forçada
if ($computador->getForcaColeta() == 'true') {
$computador->setForcaColeta('false');
$this->getDoctrine()->getManager()->persist($computador);
$this->getDoctrine()->getManager()->flush();
}
$result1 = $this->setHardware($dados['hardware'], $computador);
$result2 = $this->setSoftware($dados['software'], $computador);
$response = new JsonResponse();
if ($result1 && $result2) {
$response->setStatusCode('200');
} else {
$response->setStatusCode('500');
}
return $response;
}
示例13: loadPersonListAction
public function loadPersonListAction()
{
$content = $this->get("request")->getContent();
if (!empty($content)) {
$serializer = $this->get('serializer');
$personIds = $serializer->deserialize($content, 'array', 'json');
$personData = $this->loadPersonData($personIds);
$json = $serializer->serialize($personData, 'json');
$jsonResponse = new JsonResponse();
$jsonResponse->setContent($json);
return $jsonResponse;
} else {
$response = new Response();
$response->setContent("Missing Content.");
$response->setStatusCode("406");
return $response;
}
}
示例14: findPossibleRelativesAction
public function findPossibleRelativesAction($database, $OID)
{
$em = null;
if ($database == 'final') {
$em = $this->get('doctrine')->getManager('final');
} else {
if ($database == 'new') {
$em = $this->get('doctrine')->getManager('new');
} else {
throw new Exception("Invalid database");
}
}
$possibleRelatives = $this->get('possible_relatives_finder.service')->findPossibleRelatives($em, $OID);
$serializer = $this->container->get('serializer');
$json = $serializer->serialize($possibleRelatives, 'json');
$response = new JsonResponse();
$response->setContent($json);
return $response;
}
示例15: getUserByIdAction
/**
* @Route("/api/users/get/", name="api_get_user_by_id")
* @Template()
*/
public function getUserByIdAction()
{
$data = array();
$request = $this->getRequest();
$encoders = array(new JsonEncoder());
$normalizers = array(new GetSetMethodNormalizer());
$serializer = new Serializer($normalizers, $encoders);
// checking if was a post request
if ($request->isMethod('POST')) {
// getting post data
$post_data = $request->request->all();
$em = $this->getDoctrine()->getManager();
$user_repository = $em->getRepository('Proethos2ModelBundle:User');
$data = $user_repository->find($post_data['id']);
}
$jsonContent = $serializer->serialize($data, 'json');
var_dump($jsonContent);
$response = new JsonResponse();
$response->setContent($jsonContent);
return $response;
}