本文整理汇总了PHP中JsonResponse类的典型用法代码示例。如果您正苦于以下问题:PHP JsonResponse类的具体用法?PHP JsonResponse怎么用?PHP JsonResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsonResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: json
/**
* @param array $data
* @param int $statusCode
* @return Response
*/
public static function json(array $data, $statusCode = 200)
{
$response = new JsonResponse();
$response->setContent(json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT));
$response->setHeader('Content-Type', 'application/json');
$response->setStatusCode($statusCode);
return $response;
}
示例2: areas
public function areas()
{
$areas = $this->dao->getAreas();
if ($areas->count() > 0) {
return $this->returnJson($areas);
}
$json = new JsonResponse();
return $json->response(false, "Nenhuma área encontrada!")->serialize();
}
示例3: getMenusAction
/**
* Get memus - Makes search bar work.
*/
public function getMenusAction()
{
$menusData = array();
$systemTableService = $this->get('SystemTableService');
$menus = $systemTableService->getMenus();
foreach ($menus as $menu) {
$menusData[] = array('id' => $menu->getId(), 'name' => $menu->getName());
}
$response = new JsonResponse();
$response->setData($menusData);
return $response;
}
示例4: updateCostosAction
public function updateCostosAction($id, $hash)
{
$today = new \DateTime();
if ($hash != md5($today->format('Y-m-d'))) {
$logger = $this->get('logger');
$logger->error('Access denied on updateCostosAction');
$returnJson = new JsonResponse();
$returnJson->setData(array('ok' => true));
return $returnJson;
}
$migrationService = $this->get('kinder.migrations');
$migrationService->updateCostos();
$returnJson = new JsonResponse();
$returnJson->setData(array('ok' => true));
return $returnJson;
}
示例5: datesIncluded
public static function datesIncluded()
{
if (!isset($_REQUEST[START_DATE], $_REQUEST[END_DATE])) {
echo JsonResponse::error("Incomplete request parameters!");
exit;
}
}
示例6: parseException
protected function parseException()
{
/** @var APIResponse $response */
$response = app(APIResponse::class);
$fe = FlattenException::create($e);
$data = env("APP_DEBUG", false) ? $fe->toArray() : ["message" => "whoops, something wrong."];
return JsonResponse::create($data, 500);
}
示例7: run
public function run(Request $request)
{
$queueRepository = \Contao\Doctrine\ORM\EntityHelper::getRepository('Avisota\\Contao:Queue');
$queueId = $request->get('id');
$queue = $queueRepository->find($queueId);
/** @var \Avisota\Contao\Entity\Queue $queue */
if (!$queue) {
header("HTTP/1.0 404 Not Found");
echo '<h1>404 Not Found</h1>';
exit;
}
$user = \BackendUser::getInstance();
$user->authenticate();
try {
return $this->execute($request, $queue, $user);
} catch (\Exception $exception) {
$response = new JsonResponse(array('error' => sprintf('%s in %s:%d', $exception->getMessage(), $exception->getFile(), $exception->getLine())), 500);
$response->prepare($request);
return $response;
}
}
示例8: recv
public function recv()
{
$rawResponse = '';
do {
$bytesRead = $this->clientSocket->read($buffer, 1024);
if ($bytesRead > 0) {
$rawResponse .= $buffer;
} else {
break;
}
} while ($rawResponse[strlen($rawResponse) - 1] != '\\n');
if ($rawResponse) {
return JsonResponse::parse($rawResponse);
}
return null;
}
示例9: JsonResponse
<?php
$jsonResponse = new JsonResponse();
if (RequestsPatterns::postParamsSetted(RequestsPatterns::$TITLE, 'subarea', 'year', 'publication_type')) {
if (RequestsPatterns::postParamsSent(RequestsPatterns::$TITLE, 'subarea', 'year', 'publication_type')) {
require_once 'File.php';
require_once 'PublicationController.php';
require_once 'Publication.php';
require_once 'Paper.php';
require_once 'PublicationDao.php';
require_once '../core/generics/SubArea.php';
//require_once '../core/generics/State.php';
require_once '../core/generics/PublicationType.php';
//$jsonResponse = new JsonResponse();
$file = $_FILES['Arquivo'];
$controller = new PublicationController(new PublicationDao(Connection::connect()));
$controller->setPath("../publicacao/");
$publicationType = new PublicationType(null, $_POST['publication_type']);
$publication = new Paper($_POST['title'], new SubArea(null, $_POST['subarea']), new File($file), null, date("Y-m-d"), null, $publicationType, $_POST['year']);
//print_r($jsonResponse->response(false, $publication->getTypeId())->withoutHeader()->serialize());
try {
$controller->savePaper($publication);
print_r($jsonResponse->response(true, "Arquivo enviado com sucesso!")->withoutHeader()->serialize());
} catch (Exception $err) {
print_r($jsonResponse->response(false, $err->getMessage())->withoutHeader()->serialize());
}
} else {
print_r($jsonResponse->response(false, "Todos os campos devem ser preenchidos e/ou marcados.")->withoutHeader()->serialize());
}
} else {
print_r($jsonResponse->response(false, "Parâmetros não configurados corretamente.")->withoutHeader()->serialize());
示例10: Copyright
<?php
/*
Oxygen Webhelp plugin
Copyright (c) 1998-2015 Syncro Soft SRL, Romania. All rights reserved.
Licensed under the terms stated in the license file EULA_Webhelp.txt
available in the base directory of this Oxygen Webhelp plugin.
*/
require_once 'init.php';
//$ses=Session::getInstance();
$toReturn = new JsonResponse();
if (isset($_POST['email']) && trim($_POST['email']) != '') {
// send email to support
$info['product'] = $_POST['product'];
$info['version'] = $_POST['version'];
$info['username'] = $_POST['userName'];
$info['email'] = $_POST['email'];
$user = new User($dbConnectionInfo);
$generateInfo = $user->generatePasswd($info);
$productTranslate = defined("__PRODUCT_NAME__") ? __PRODUCT_NAME__ : $info['product'];
if ($generateInfo['generated'] == "") {
// nu are email valid
$toReturn->set("success", "false");
$toReturn->set("message", Utils::translate('noEmailFound'));
//echo "No ";
} else {
if ($generateInfo['match']) {
// generated password
$template = new Template("./templates/" . __LANGUAGE__ . "/recover.html");
$confirmationMsg = $template->replace(array("username" => $info['username'], "password" => $generateInfo['generated'], "productName" => $productTranslate));
示例11: Copyright
<?php
/*
Oxygen Webhelp plugin
Copyright (c) 1998-2014 Syncro Soft SRL, Romania. All rights reserved.
Licensed under the terms stated in the license file EULA_Webhelp.txt
available in the base directory of this Oxygen Webhelp plugin.
*/
require_once "init.php";
$cfgFile = './config/config.php';
$cfgInstall = '../../install/';
$toReturn = new JsonResponse();
if (file_exists($cfgInstall)) {
$toReturn->set("installPresent", "true");
} else {
$toReturn->set("installPresent", "false");
}
if (file_exists($cfgFile) && filesize($cfgFile) > 0) {
$toReturn->set("configPresent", "true");
} else {
$toReturn->set("configPresent", "false");
}
echo $toReturn;
示例12: elseif
$toReturn->set("name", $ses->{$fullUser}->name);
$toReturn->set("userName", $ses->{$fullUser}->userName);
$toReturn->set("level", $ses->{$fullUser}->level);
} else {
if (strlen(trim($user->msg)) > 0) {
$toReturn->set("error", $user->msg);
}
}
echo $toReturn;
} elseif (isset($_POST['logOff']) && trim($_POST['logOff']) != '') {
$ses->errBag = null;
unset($ses->errBag);
unset($ses->{$fullUser});
// echo print_r($_POST,true);
} elseif (isset($_POST['check']) && trim($_POST['check']) != '') {
$toReturn = new JsonResponse();
$toReturn->set("isAnonymous", "false");
$toReturn->set("loggedIn", "false");
if (defined('__GUEST_POST__') && !__GUEST_POST__ && (isset($ses->{$fullUser}) && $ses->{$fullUser}->isAnonymous == 'true')) {
unset($ses->{$fullUser});
}
if (defined('__GUEST_POST__') && __GUEST_POST__ && !isset($ses->{$fullUser})) {
$user = new User($dbConnectionInfo);
// user not logged in and guest is allowed to post
if (!$user->initAnonymous()) {
$toReturn->set("isAnonymous", "false");
$toReturn->set("loggedIn", "false");
$toReturn->set("msg", "1");
$toReturn->set("msgType", "error");
} else {
// anonymous must be logged in
示例13: Copyright
<?php
/*
Oxygen Webhelp plugin
Copyright (c) 1998-2014 Syncro Soft SRL, Romania. All rights reserved.
Licensed under the terms stated in the license file EULA_Webhelp.txt
available in the base directory of this Oxygen Webhelp plugin.
*/
require_once 'init.php';
$toReturn = new JsonResponse();
if (isset($_POST['id']) && trim($_POST['id']) != '') {
$realId = base64_decode($_POST['id']);
//list($id,$date,$action,$newPassword) = explode("|", $realId);
$args = explode("|", $realId);
$id = $args[0];
$date = $args[1];
$action = "new";
$newPassword = "";
if (count($args) > 2) {
$action = $args[2];
$newPassword = $args[3];
}
$user = new User($dbConnectionInfo);
//echo "id=".$id." date=".$date;
$currentDate = date("Y-m-d G:i:s");
$days = Utils::getTimeDifference($currentDate, $date, 3);
if ($days > 7) {
$toReturn->set("error", true);
$toReturn->set("msg", "Confirmation code expired!");
} else {
示例14: toJson
/**
* Helper method to return a JSON response.
*
* @param mixed $data
* The data to return as the response.
* @param int $status
* The HTTP status code for this response.
*
* @return JsonResponse
*
*/
public function toJson($data, $status = 200)
{
return JsonResponse::create($data, $status);
}
示例15: array
function __Construct($dictionary)
{
parent::__Construct(get_class());
$categories = array();
$list = ServiceCategory::GetAll(array('partnerCode' => Application::PARTNER_CODE, 'parentId' => null), null, $dictionary->getCode());
foreach ($list as $category) {
$categories[] = $category->toArray(true);
}
$this->jsonData = array('categories' => $categories);
}