本文整理汇总了PHP中errorResponse函数的典型用法代码示例。如果您正苦于以下问题:PHP errorResponse函数的具体用法?PHP errorResponse怎么用?PHP errorResponse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了errorResponse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
public function generate(Request $request)
{
$data = $request->all();
$validator = Validator::make($data, ['token' => 'required', 'number' => 'required']);
if ($validator->fails()) {
return validatorError($validator->errors());
}
$token = $this->getToken($data['token']);
if (!$token->owner->hasApiEnabled($this->api)) {
return errorResponse('api_disabled', 403);
}
if ($token == null) {
return errorResponse("token_invalid", 403);
}
if (!$token->enabled) {
return errorResponse("token_disabled", 403);
}
if (!$token->validDayLimit()) {
return errorResponse('day_limit_reached', 403);
}
if (!$token->validMonthLimit()) {
return errorResponse('month_limit_reached', 403);
}
$verification = Verification::create(['phone_number' => $data['number'], 'code' => $this->incrementalHash($this->api->configuration->token_length), 'expiration' => Carbon::now()->addMinutes($this->api->configuration->expiration)]);
$sms = $this->api->configuration->message_content;
$sms = str_replace("\\(code)", $verification->code, $sms);
$this->sendApiRequest($data['number'], $sms, $token->owner->id);
return successResponse('sent');
}
示例2: validateNotEmpty
function validateNotEmpty($string)
{
if (empty(trim($string))) {
errorResponse();
return false;
}
return true;
}
示例3: setMessageBody
/**
* Pulls posted values for all fields in $fields_req array.
* If a required field does not have a value, an error response is given.
*
* @param [Array] $fields_req a map of field name to required
*/
function setMessageBody($fields_req)
{
$message_body = "";
foreach ($fields_req as $name => $required) {
if ($required && empty($name)) {
errorResponse("{$name} is empty.");
} else {
$message_body .= ucfirst($name) . ": " . $_POST[$name] . "\n";
}
}
return $message_body;
}
示例4: constructMessageBody
/**
* Pulls posted values for all fields in $fields_req array.
* If a required field does not have a value, an error response is given.
*/
function constructMessageBody()
{
$fields_req = array("name" => true, "email" => true, "message" => true);
$message_body = "";
foreach ($fields_req as $name => $required) {
$postedValue = $_POST[$name];
if ($required && empty($postedValue)) {
errorResponse("{$name} is empty.");
} else {
$message_body .= ucfirst($name) . ": " . $postedValue . "\n";
}
}
return $message_body;
}
示例5: errorResponse
if (isset($_GET['current'])) {
$tripId = Trip::findCurrentTrip();
if (!$tripId) {
$tripId = '';
}
} else {
if (isset($_GET['tripId'])) {
$tripId = $_GET['tripId'];
}
}
if ($tripId === '') {
$response = errorResponse(RESPONSE_BAD_REQUEST);
} else {
$object = new Trip($tripId);
if ($object->getCreated() === null) {
$response = errorResponse(RESPONSE_NOT_FOUND);
} else {
$response = successResponse();
$response['tripId'] = $object->getTripId();
$response['created'] = $object->getCreated();
$response['updated'] = $object->getUpdated();
$response['name'] = $object->getName();
$response['description'] = $object->getDescription();
$response['bannerImg'] = $object->getBannerImg();
$response['startDate'] = $object->getStartDate();
$response['endDate'] = $object->getEndDate();
$response['active'] = $object->getActive();
$response['deleted'] = $object->getDeleted();
// Do NOT return the hash field on the GET service.
$journal = Journal::getFirstJournal($object->getTripId());
if ($journal !== null) {
示例6: errorResponse
if (isset($data['password'])) {
$password = $data['password'];
}
if ($userId === '' || $password === '') {
$response = errorResponse(RESPONSE_BAD_REQUEST);
} else {
$user = new User($userId);
if ($user->getCreated() === null) {
$response = errorResponse(RESPONSE_NOT_FOUND);
} else {
if ($user->checkPassword($password)) {
// password matches, need to allow for hash update (if hash
// algorithm changed, the new hash can only be stored in the
// database when we have the actual password, and only at login
// time do we have the actual password)
$user->updatePasswordHash($password);
$authId = Auth::generateAuthId();
$auth = new Auth($authId);
$auth->setUserId($userId);
$auth->save();
$response = successResponse();
$response['authId'] = $authId;
} else {
$response = errorResponse(RESPONSE_UNAUTHORIZED);
}
}
}
} else {
$response = errorResponse(RESPONSE_METHOD_NOT_ALLOWED, $_SERVER['REQUEST_METHOD']);
}
echo json_encode($response);
示例7: Cancellation
exit;
}
$email = Configuration::get($prefix . 'EMAIL');
$token = Configuration::get($prefix . 'TOKEN');
$cancellation = new Cancellation($email, $token);
$cancellation->enableSandBox(Configuration::get($prefix . 'SANDBOX'));
try {
$response = $cancellation->execute($id_transacao);
if ($response->transactionStatusId == 7 || $response->transactionStatusId == 6) {
updateOrder($id_pedido, $response);
writeHistory($id_pedido, $response);
}
} catch (ValidationException $e) {
die(errorResponse($e));
} catch (ConnectionException $e) {
die(errorResponse($e));
}
echo json_encode($response);
exit;
function errorResponse($e)
{
$erros = $e->getErrors();
if (!empty($erros)) {
return $e->getErrors()->list[0]->description;
}
}
function updateOrder($orderId, $response)
{
$order_state_id = (int) Configuration::get('PS_OS_BCASH_CANCELLED');
if ($response->transactionStatusId == 6) {
$order_state_id = (int) Configuration::get('PS_OS_BCASH_REFUNDED');
示例8: successResponse
$object->setAccess($data['access']);
}
if (isset($data['email'])) {
$object->setEmail($data['email']);
}
if (isset($data['notification'])) {
$object->setNotification($data['notification']);
}
if (isset($data['tempCode'])) {
$object->setTempCode($data['tempCode']);
}
if (isset($data['deleted'])) {
$object->setDeleted($data['deleted']);
}
if (isset($data['hash'])) {
$object->setHash($data['hash']);
}
if ($object->save()) {
$response = successResponse();
} else {
$response = errorResponse(RESPONSE_INTERNAL_ERROR);
}
} else {
$response = errorResponse(RESPONSE_BAD_REQUEST, 'Need user ID');
}
} else {
$response = errorResponse(RESPONSE_METHOD_NOT_ALLOWED);
}
}
}
echo json_encode($response);
示例9: TripAttribute
$name = $data['name'];
$object = new TripAttribute($tripId, $name);
if (isset($data['created'])) {
$object->setCreated($data['created']);
}
if (isset($data['updated'])) {
$object->setUpdated($data['updated']);
}
if (isset($data['value'])) {
$object->setValue($data['value']);
}
if (isset($data['deleted'])) {
$object->setDeleted($data['deleted']);
}
if (isset($data['hash'])) {
$object->setHash($data['hash']);
}
if ($object->save()) {
$response = successResponse();
} else {
$response = errorResponse(RESPONSE_INTERNAL_ERROR);
}
} else {
$response = errorResponse(RESPONSE_BAD_REQUEST);
}
} else {
$response = errorResponse(RESPONSE_BAD_REQUEST);
}
}
}
echo json_encode($response);
示例10: successResponse
$object->setUserId($data['userId']);
}
if (isset($data['journalDate'])) {
$object->setJournalDate($data['journalDate']);
}
if (isset($data['journalTitle'])) {
$object->setJournalTitle($data['journalTitle']);
}
if (isset($data['journalText'])) {
$object->setJournalText($data['journalText']);
}
if (isset($data['deleted'])) {
$object->setDeleted($data['deleted']);
}
if (isset($data['hash'])) {
$object->setHash($data['hash']);
}
if ($object->save()) {
$response = successResponse();
} else {
$response = errorResponse(RESPONSE_INTERNAL_ERROR);
}
} else {
$response = errorResponse(RESPONSE_BAD_REQUEST, 'tripId or journalId not set');
}
} else {
$response = errorResponse(RESPONSE_BAD_REQUEST, 'not GET or PUT response');
}
}
}
echo json_encode($response);
示例11: array_push
}
$step_array['step_progress'] = $step_progress_array;
}
}
array_push($steps_array, $step_array);
}
$task_array['steps'] = $steps_array;
array_push($tasks_array, $task_array);
}
$response_array = array("status" => "ok", "module_id" => $module_id, "tasks" => $tasks_array);
$response = json_encode($response_array);
} else {
$response = errorResponse("The module id provided is not valid");
}
} else {
$response = errorResponse("module_id is expected");
}
}
echo $response;
function taskByModuleId($module_id)
{
return getTaskByModuleId($module_id);
}
function getTaskByModuleId($module_id)
{
$sql = sprintf("SELECT t.task_id, name, brief_desc, t.desc, thumb_url FROM task t JOIN module_task mt ON t.task_id = mt.task_id WHERE module_id = %d", $module_id);
return executeSql($sql);
}
function taskProgressByTaskIdUserId($task_id, $user_id)
{
return getTaskProgressByTaskIdUserId($task_id, $user_id);
示例12: isset
$module_id = isset($module_id) ? $module_id : $_GET['module_id'];
$show_all_for_user = isset($show_all_for_user) ? $show_all_for_user : $_GET['show_all_for_user'];
$new_module = isset($new_module) ? $new_module : $_POST['new_module'];
$response = "";
if ($user_id && !$show_all_for_user) {
if (checkId($user_id)) {
$response = moduleByUserId($user_id);
} else {
$response = errorResponse("The user id provided is not valid");
}
} else {
if ($module_id) {
if (checkId($module_id)) {
$response = moduleByModuleId($module_id);
} else {
$response = errorResponse("The module id provided is not valid");
}
} else {
if ($new_module) {
$user_id = intval($_POST['user_id']);
$module_id = intval($_POST['module_id']);
$progress = checkString($_POST['progress']);
$is_complete = checkString($_POST['is_complete']);
$date_completed = checkString($_POST['date_completed']);
if (checkId($user_id) && checkId($module_id)) {
$response = moduleUserProgress($user_id, $module_id, $progress, $is_complete, $date_completed);
}
} else {
$response = allModules($user_id);
}
}
示例13: successResponse
$object->setUserId($data['userId']);
}
if (isset($data['referenceId'])) {
$object->setReferenceId($data['referenceId']);
}
if (isset($data['commentText'])) {
$object->setCommentText($data['commentText']);
}
if (isset($data['deleted'])) {
$object->setDeleted($data['deleted']);
}
if (isset($data['hash'])) {
$object->setHash($data['hash']);
}
if ($object->save()) {
$response = successResponse();
} else {
// @codeCoverageIgnoreStart
// cannot unit test database errors
$response = errorResponse(RESPONSE_INTERNAL_ERROR);
// @codeCoverageIgnoreEnd
}
} else {
$response = errorResponse(RESPONSE_BAD_REQUEST);
}
} else {
$response = errorResponse(RESPONSE_METHOD_NOT_ALLOWED, 'must be get or put');
}
}
}
echo json_encode($response);
示例14: isset
<?php
include_once "connect.php";
include_once "common.php";
$user_id = isset($user_id) ? $user_id : $_GET['user_id'];
$response = "";
if ($user_id) {
if (checkId($user_id)) {
$response = userById($user_id);
} else {
$response = errorResponse("The user id provided is not valid");
}
} else {
$response = errorResponse("The user id was not provided");
}
echo $response;
function userById($user_id)
{
$result = getUserById($user_id);
return formJson($result);
}
function getUserById($user_id)
{
$sql = sprintf("SELECT user_id, first_name, last_name, age, email, receive_notifications, is_new, lang_id FROM user WHERE user_id = '%d'", $user_id);
return executeSql($sql);
}
function formJson($result)
{
$users = array();
while ($item = mysql_fetch_array($result)) {
$user = array("user_id" => $item['user_id'], "first_name" => $item['first_name'], "last_name" => $item['last_name'], "age" => $item['age'], "email" => $item['email'], "receive_notifications" => $item['receive_notifications'], "is_new" => $item['is_new'], "lang_id" => $item['lang_id']);
示例15: sendSmsTemplate
public function sendSmsTemplate(Request $request)
{
$data = $request->all();
$validator = Validator::make($data, ['token' => 'required', 'template' => 'required', 'number' => 'required']);
if ($validator->fails()) {
return validatorError($validator->errors());
}
$token = $this->getToken($data['token']);
if ($token == null) {
return errorResponse("token_invalid", 403);
}
if (!$token->enabled) {
return errorResponse("token_disabled", 403);
}
if (!$token->validDayLimit()) {
return errorResponse('day_limit_reached', 403);
}
if (!$token->validMonthLimit()) {
return errorResponse('month_limit_reached', 403);
}
$template = SmsTemplate::where('sms_id', $data['template'])->first();
if ($template == null) {
return errorResponse('template_not_found', 404);
}
$forFill = $data;
unset($forFill['token']);
unset($forFill['template']);
$template->fillData($forFill);
$this->sendApiRequest($data['number'], $template->getFilled(), $token->owner->id);
return successResponse('sent');
}