本文整理汇总了PHP中Service::returnError方法的典型用法代码示例。如果您正苦于以下问题:PHP Service::returnError方法的具体用法?PHP Service::returnError怎么用?PHP Service::returnError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Service
的用法示例。
在下文中一共展示了Service::returnError方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ucfirst
}
include_once $classfile;
$classname = ucfirst($type);
// class names start with uppercase
$class = new $classname($userID, $tenantID);
$id = 0;
if (isset($_GET["id"])) {
$id = $_GET["id"];
}
$parentid = Utility::getRequestVariable('parentid', 0);
$entity = '';
if ($id > 0) {
try {
$entity = $class->getEntity($id, $tenantID, $userID);
} catch (Exception $ex) {
Service::returnError($ex->getMessage());
}
}
?>
<form id="<?php
echo $type;
?>
Form" class="form-horizontal" action="<?php
echo $class->getDataServiceURL();
?>
" method="post" role="form">
<div class="edit">
<input type="hidden" id="<?php
echo $type;
?>
id" name="id" value="<?php
示例2: array
Service::returnError('Please specify a type');
}
$coretypes = array('tenant', 'tenantSetting', 'tenantProperty', 'category', 'menuItem', 'page', 'pageCollection', 'content', 'tenantContent', 'entityList', 'entityListItem', 'propertyBag');
if (!in_array($type, $coretypes, false) && !in_array($type, Application::$knowntypes, false)) {
// unrecognized type requested can't do much from here.
Service::returnError('Unknown type: ' . $type, 400, 'entityService?type=' . $type);
}
$classpath = dirname(__FILE__) . '/../classes/';
if (in_array($type, $coretypes, false)) {
// core types will be in core subfolder
$classpath = Config::$core_path . '/classes';
}
// include appropriate dataEntity class & then instantiate it
$classfile = $classpath . '/' . $type . '.php';
if (!file_exists($classfile)) {
Service::returnError('Internal error. Unable to process entity ' . $classfile, 400, 'entityService?type=' . $type);
}
include_once $classfile;
$classname = ucfirst($type);
// class names start with uppercase
$class = new $classname($userID, $tenantID);
$tab = '  ';
function stringValue($field)
{
if (sizeof($field) >= 3 && $field[2] == 0) {
return 'text';
} else {
if (sizeof($field) < 3 || !$field[2]) {
$length = 100;
} else {
$length = $field[2];
示例3: dirname
* get parameters are:
* collection: name of the pageCollection to update (e.g. 'home')
* pageid: id of the page
* sort: new sort/sequence number for the page
*/
include_once dirname(__FILE__) . '/../partials/pageCheck.php';
include_once dirname(__FILE__) . '/../classes/utility.php';
include_once dirname(__FILE__) . '/../classes/service.php';
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$collection = Utility::getRequestVariable("collection", "");
$pageid = Utility::getRequestVariable("pageid", "");
$sort = Utility::getRequestVariable("sort", "");
if ($collection == "") {
Service::returnError('collection parameter is required.');
}
if ($pageid == "") {
Service::returnError('pageid parameter is required.');
}
if ($sort == "") {
Service::returnError('sort parameter is required.');
}
if (!$user->hasRole('admin', $tenantID)) {
Service::returnError('Access denied.', 403);
}
$query = "call setPageSortOrderForCollection(" . Database::queryString($collection) . "," . Database::queryNumber($pageid) . "," . Database::queryNumber($sort) . "," . Database::queryNumber($tenantID) . ");";
Database::executeQuery($query);
$json = '{"success":true}';
Service::returnJSON($json);
} else {
Service::returnError('Unsupported HTTP method.');
}
示例4: json_encode
Utility::debug($type . ' updated.', 5);
$response = '{"id":' . json_encode($id) . "}";
header('Content-Type: application/json');
echo $response;
}
}
break;
default:
Service::returnError('Invalid action: ' . $action);
}
} elseif ($_SERVER['REQUEST_METHOD'] == "PUT") {
$reset = $_GET["reset"];
$id = $_GET["id"];
$class = new User($id, $tenantID);
if (!$user->userCanEdit($id, $class)) {
Service::returnError('Access denied.', 403);
}
if ($reset == "true") {
try {
$class = new User($id, $tenantID);
$class->resetPassword();
} catch (Exception $ex) {
header(' ', true, 500);
echo 'Unable to reset password:' . $ex->getMessage();
die;
}
}
} elseif ($_SERVER['REQUEST_METHOD'] == "DELETE") {
$id = Utility::getRequestVariable('id', 0);
if ($id == 0) {
header(' ', true, 400);
示例5: catch
// a list was requested here. Different handling than regular entity set
try {
$totalEntities = $class->getEntityCountForList($listId);
$entities = $class->getEntitiesFromList($listId, $numToReturn, $offset);
} catch (Exception $ex) {
$message = 'Unable to retrieve ' . $type . ' set count: ' . $ex->getMessage();
Service::returnError($message);
}
} else {
$totalEntities = $class->getEntityCount($_GET);
try {
// we pass the entire _GET collection in so object classes can extract relevant filters
$entities = $class->getEntities($_GET, $numToReturn, $offset);
} catch (Exception $ex) {
$message = 'Unable to retrieve ' . $type . ' set: ' . $ex->getMessage();
Service::returnError($message);
}
}
$addSequence = isset($_GET["sequence"]) && (strtolower($_GET["sequence"]) == "yes" || strtolower($_GET["sequence"]) == "true");
if ($addSequence) {
for ($i = 0; $i < count($entities); $i++) {
// computer nerds can suck it: you being numbering things with 1, not 0
$entities[$i]["sequence"] = $i + 1;
// but since nerds insist on making many things sequence with 0 as first element
// we'll include this just for them
$entities[$i]["sequence_zero"] = $i;
}
}
if (strtolower($descending) == 'true' || strtolower($descending) == 'yes') {
// reverse the sort order
$newentities = array();
示例6: dirname
include_once dirname(__FILE__) . '/../partials/pageCheck.php';
include_once dirname(__FILE__) . '/../classes/database.php';
include_once dirname(__FILE__) . '/../classes/utility.php';
include_once dirname(__FILE__) . '/../classes/service.php';
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$event = Utility::getRequestVariable('event', 'unknown event');
$entityType = Utility::getRequestVariable('entityType', 'unknown entity');
$entityId = Utility::getRequestVariable('entityId', 0);
$query = "INSERT INTO event (event,entityType,entityId,userId,sessionId,tenantId) values (";
$query .= Database::queryString($event);
$query .= ',' . Database::queryString($entityType);
$query .= ',' . Database::queryNumber($entityId);
$query .= ',' . Database::queryNumber($userID);
$query .= ',' . Database::queryString(session_id());
$query .= ',' . Database::queryNumber($tenantID);
$query .= ")";
$errorMsg = '';
try {
Database::executeQuery($query);
} catch (Exception $ex) {
$errorMsg = $ex->getMessage();
}
if (strlen($errorMsg) > 0) {
Service::returnError($errorMsg);
} else {
Service::returnJSON('{result: true}');
}
} else {
echo "Unsupported HTTP method.";
}
示例7: file_get_contents
$json = file_get_contents('php://input');
$data = json_decode($json);
$maxDetour = 25;
$numToReturn = 50;
if (array_key_exists('maxDetour', $data)) {
$maxDetour = $data->{'maxDetour'};
}
if (array_key_exists('return', $data)) {
$numToReturn = $data->{'return'};
}
$filter = '';
if (array_key_exists('categories', $data)) {
$filter = getFilter($data->{'categories'});
}
if (!array_key_exists('points', $data)) {
Service::returnError('An array of points must be posted to retrieve a route.');
}
$points = $data->{'points'};
$rows = array();
for ($i = 1; $i < count($points); $i++) {
Log::debug('Processing point #' . $i . ' ' . $points[$i]->lat . ', ' . $points[$i]->lng, 1);
$data = fetchData($points[$i - 1]->lat, $points[$i - 1]->lng, $points[$i]->lat, $points[$i]->lng, $maxDetour, $numToReturn, $filter, $tenantID, $userID);
while ($r = mysqli_fetch_assoc($data)) {
if (!alreadyInSet($rows, $r)) {
$rows[] = $r;
}
}
}
Log::debug('Before trimming, row count=' . count($rows), 1);
$set = "{\"locations\":" . json_encode($rows) . "}";
header("Access-Control-Allow-Origin: *");
示例8: curl_init
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
curl_setopt($ch, CURLOPT_VERBOSE, True);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: token ' . Config::$github_token));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_USERAGENT, 'Food Finder');
Utility::debug('Posting issue via cUrl (url=' . $url . ')', 1);
$response = curl_exec($ch);
$error = '';
if ($error = curl_error($ch)) {
Utility::debug('cUrl exception:' . $error, 9);
}
curl_close($ch);
if ($error) {
Service::returnError('Unable to post issue to GitHub: ' . $error, 500);
} else {
Utility::debug('Issue service call completed successfully.', 5);
$returnData = json_decode($response);
if (array_key_exists('number', $returnData)) {
$response = json_encode(array("id" => $returnData->{"number"}));
} else {
Service::returnError('Unable to log issue. Response from repositor: ' . $response);
}
//http_response_code(200);
Service::returnJSON($response);
}
} else {
Service::returnError('Unsupported method.', 400, 'issue');
}
示例9: catch
try {
$files[$i]["url"] = $cdn->putContent($sourcefile, $key, '');
$files[$i]["thumbnailurl"] = $cdn->putContent($sourcethumb, $thumbkey, '');
} catch (Exception $ex) {
Service::returnError('Unable to store file in CDN: ' . $ex->getMessage());
}
}
// 4. save metadata in DB
$media = new Media($userID, $tenantID);
foreach ($files as $file) {
$data = (object) $file;
try {
$mediaid = $media->addEntity($data);
} catch (Exception $e) {
Service::returnError('Unable to save media record:' . $e->getMessage());
}
if ($locationid > 0) {
$media->linkMediaToLocation($mediaid, $locationid);
}
}
// 5. build & return response
$output = array();
foreach ($files as $file) {
$set = array("name" => $file["name"], "url" => $file["url"]);
array_push($output, $set);
}
$response = json_encode($output);
Service::returnJSON($response);
} else {
Service::returnError('Method not supported.');
}
示例10: elseif
echo $response;
}
}
}
} elseif ($_SERVER['REQUEST_METHOD'] == "DELETE") {
$supportedtypes = array('media', 'tenantSetting', 'tenantProperty', 'menuItem', 'page');
if (!in_array($type, $supportedtypes, false)) {
// delete method not supported from all types
Service::returnError('Method not supported for type: ' . $type);
}
// retrive required parameters
$id = Utility::getRequestVariable('id', 0);
if ($id == 0) {
Service::returnError("id is required parameter and must be non-zero.");
}
try {
$result = $class->deleteEntity($id);
if (!$result) {
Service::returnError('Unable to delete requested ' . $type . '. Unknown error.');
}
} catch (Exception $ex) {
Service::returnError('Unable to delete requested ' . $type . '. ' . $ex->getMessage());
}
$set = json_encode(array('deleted' => $id));
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
echo $set;
} else {
header(' ', true, 400);
echo "Unsupported HTTP method.";
}
示例11: dirname
include dirname(__FILE__) . '/../partials/pageCheck.php';
include_once dirname(__FILE__) . '/../classes/propertyBag.php';
include_once dirname(__FILE__) . '/../classes/service.php';
include_once dirname(__FILE__) . '/../classes/utility.php';
if ($_SERVER['REQUEST_METHOD'] == "POST") {
// for now, must be an admin to access property bags: will have to update later if we being using propertyBags for things
// other than system/tenant settings
if (!$user->hasRole('admin', $tenantID)) {
Service::returnError('Access denied.', 403, 'propertyBag');
}
$json = file_get_contents('php://input');
$data = json_decode($json);
if (!$data || !array_key_exists('name', $data)) {
Service::returnError('PropertyBag name must be specified for an update.', 400, 'propertyBag Service');
}
if (!$data || !array_key_exists('properties', $data)) {
Service::returnError('PropertyBag properties must be specified for an update.', 400, 'propertyBag Service');
}
$bagName = $data->{"name"};
$properties = $data->{"properties"};
$propertyBag = new PropertyBag($userID, $tenantID);
foreach ($properties as $property => $value) {
$propertyBag->putProperty($bagName, $property, $value);
}
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
echo json_encode($properties);
} else {
Service::returnError('Method not supported.', 400, 'propertyBag');
}