本文整理汇总了PHP中Util::output_errors_and_die方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::output_errors_and_die方法的具体用法?PHP Util::output_errors_and_die怎么用?PHP Util::output_errors_and_die使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Util
的用法示例。
在下文中一共展示了Util::output_errors_and_die方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_programming_language
function update_programming_language($pl_id, $request)
{
Authenticator::assert_manager($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale']);
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die('', 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data)) {
Util::output_errors_and_die('', 400);
}
$result = $model->edit_programming_language($pl_id, $input_data);
header('Content-Type: text/plain');
http_response_code($result ? 200 : 404);
die;
} catch (ConflictException $e) {
Util::output_errors_and_die($e->getMessage(), 409);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例2: test_auto_marking_sc
function test_auto_marking_sc($request)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale'], '/new-question/errors');
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die($msg->_('invalid-format'), 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data) || !isset($input_data['question']) || !isset($input_data['source-code']) || !is_string($input_data['source-code'])) {
Util::output_errors_and_die($msg->_('invalid-format'), 400);
}
$extra = !empty($input_data['extra']) ? $input_data['extra'] : [];
$qd = $input_data['question'];
set_empty_if_undefined($qd['type']);
if ($qd['type'] != 'source-code') {
Util::output_errors_and_die('', 400);
}
$q = new QuestionSC($qd, Question::FROM_USER, $extra);
$q->mark_automatically(array('source-code' => $input_data['source-code']), $log, $result);
http_response_code(200);
header('Content-Type: application/json');
echo my_json_encode($result);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例3: create_topic
function create_topic($request)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale']);
try {
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die('', 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data)) {
Util::output_errors_and_die('', 400);
}
$model = new Model();
if (!isset($input_data['name'])) {
$input_data['name'] = '';
}
$topic_id = $model->create_topic($input_data['name']);
if ($topic_id) {
http_response_code(201);
header('Content-Type: text/plain');
echo '/topics/' . $topic_id;
die;
} else {
Util::output_errors_and_die('', 400);
}
} catch (ConflictException $e) {
Util::output_errors_and_die($e->getMessage(), 409);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例4: test_auto_marking
function test_auto_marking($request)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale'], '/new-question/errors');
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die($msg->_('invalid-format'), 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data) || !isset($input_data['question']) || !isset($input_data['studentAnswer'])) {
Util::output_errors_and_die($msg->_('invalid-format'), 400);
}
$extra = !empty($input_data['extra']) ? $input_data['extra'] : [];
$qd = $input_data['question'];
set_empty_if_undefined($qd['type']);
if (!Validator::validate_question_type($qd['type'])) {
Util::output_errors_and_die($msg->_('invalid-type'), 400);
}
switch ($qd['type']) {
case 'short-answer':
$q = new QuestionSA($qd, Question::FROM_USER, $extra);
break;
case 'essay':
$q = new QuestionES($qd, Question::FROM_USER, $extra);
break;
case 'multiple-choice':
$q = new QuestionMC($qd, Question::FROM_USER, $extra);
break;
case 'matching':
$q = new QuestionMA($qd, Question::FROM_USER, $extra);
break;
case 'fitb-type':
$q = new QuestionFT($qd, Question::FROM_USER, $extra);
break;
case 'fitb-select':
$q = new QuestionFS($qd, Question::FROM_USER, $extra);
break;
case 'source-code':
$q = new QuestionSC($qd, Question::FROM_USER, $extra);
break;
}
http_response_code(200);
header('Content-Type: application/json');
$mark = $q->mark_automatically($input_data['studentAnswer'], $log);
foreach ($log as $i => $line) {
$log[$i] = $msg->_('/auto-marking/' . $line[0], $line[1]);
}
$log = implode('<br/>', $log);
echo my_json_encode(array('log' => $log, 'mark' => $mark));
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例5: create_session
function create_session($request)
{
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
switch ($content_type) {
case 'application/json':
$input_data = json_decode($raw_input, true);
break;
case 'application/x-www-form-urlencoded':
$input_data = array();
parse_str($raw_input, $input_data);
break;
default:
Util::output_errors_and_die('', 415);
}
if ($input_data === null) {
Util::output_errors_and_die('', 400);
}
set_empty_if_undefined($input_data['username_or_email']);
set_empty_if_undefined($input_data['password']);
$msg = new Messages($GLOBALS['locale'], '/signin');
try {
$model = new Model();
$user_data = $model->is_valid_user($input_data['username_or_email'], $input_data['password']);
if (!$user_data) {
Util::output_errors_and_die($msg->_('invalid-username-pw'), 403);
}
switch ($user_data['status']) {
case 'pending-activation':
Util::output_errors_and_die($msg->_('pending-activation'), 403);
break;
case 'pending-approval':
Util::output_errors_and_die($msg->_('pending-approval'), 403);
break;
case 'banned':
Util::output_errors_and_die($msg->_('banned'), 403);
break;
case 'active':
$token = generate_token($user_data);
$now = new DateTime('now');
$expires_at = clone $now;
$expires_at->add(new DateInterval('P7D'));
$model->insert_auth_token($user_data['user_id'], $token, $now, $expires_at);
http_response_code(201);
$output = array('token' => $token, 'expires_at' => $expires_at->format('Y-m-d H:i:s'));
setcookie('authToken', $token, $expires_at->getTimestamp(), '/', '', $secure = true, $httponly = true);
header('Content-Type: application/json');
echo my_json_encode($output);
die;
break;
}
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例6: assert_manager
public static function assert_manager($token)
{
$user_data = self::assert_user($token);
if ($user_data['role'] !== 'manager') {
$msg = new Messages($GLOBALS['locale']);
Util::output_errors_and_die($msg->_('/authentication/only-managers'), 403);
}
return $user_data;
}
示例7: create_user
function create_user($request)
{
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
switch ($content_type) {
case 'application/json':
$input_data = json_decode($raw_input, true);
break;
case 'application/x-www-form-urlencoded':
$input_data = array();
parse_str($raw_input, $input_data);
break;
default:
Util::output_errors_and_die('', 415);
}
if ($input_data === null) {
Util::output_errors_and_die('', 400);
}
$fields = array('full_name' => '', 'email' => '', 'gender' => '', 'birth_date' => '', 'username' => '', 'role' => '');
$user_data = array();
foreach ($fields as $f => $v) {
if (array_key_exists($f, $input_data)) {
if (!is_string($input_data[$f])) {
Util::output_errors_and_die('', 400);
}
$user_data[$f] = trim($input_data[$f]);
} else {
$user_data[$f] = '';
}
}
if (isset($input_data['password'])) {
if (!is_string($input_data['password'])) {
Util::output_errors_and_die('', 400);
}
$user_data['password'] = $input_data['password'];
}
set_empty_if_undefined($user_data['password']);
try {
$model = new Model();
$uid = $model->create_user($user_data);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (ConflictException $e) {
Util::output_errors_and_die($e->getMessage(), 409);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
if ($uid) {
http_response_code(201);
header('Content-Type: text/plain');
echo '/users/' . $uid;
die;
} else {
Util::output_errors_and_die('', 400);
}
}
示例8: create_question
function create_question($request, $assignment_id = null)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale']);
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die('', 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data)) {
Util::output_errors_and_die('', 400);
}
set_empty_if_undefined($input_data['type']);
if (!Validator::validate_question_type($input_data['type'])) {
Util::output_errors_and_die($msg->_('invalid-type'), 400);
}
switch ($input_data['type']) {
case 'short-answer':
$q = new QuestionSA($input_data, Question::FROM_USER);
break;
case 'essay':
$q = new QuestionES($input_data, Question::FROM_USER);
break;
case 'multiple-choice':
$q = new QuestionMC($input_data, Question::FROM_USER);
break;
case 'matching':
$q = new QuestionMA($input_data, Question::FROM_USER);
break;
case 'fitb-type':
$q = new QuestionFT($input_data, Question::FROM_USER);
break;
case 'fitb-select':
$q = new QuestionFS($input_data, Question::FROM_USER);
break;
case 'source-code':
$q = new QuestionSC($input_data, Question::FROM_USER);
break;
}
$qid = $model->create_question($q);
header('Content-Type: text/plain');
echo '/question_bank/questions/' . $qid;
http_response_code(201);
die;
} catch (ConflictException $e) {
Util::output_errors_and_die($e->getMessage(), 409);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例9: update_user
function update_user($username, $request)
{
$user_data = Authenticator::assert_manager($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale']);
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
switch ($content_type) {
case 'application/json':
$input_data = json_decode($raw_input, true);
break;
case 'application/x-www-form-urlencoded':
$input_data = array();
parse_str($raw_input, $input_data);
break;
default:
Util::output_errors_and_die('', 415);
}
if (empty($input_data)) {
Util::output_errors_and_die('', 400);
}
$changes = array();
foreach ($input_data as $f => $v) {
if (is_string($input_data[$f])) {
$changes[$f] = trim($input_data[$f]);
} else {
Util::output_errors_and_die('', 400);
}
}
if (isset($input_data['password'])) {
// don't trim
if (is_string($input_data['password'])) {
$changes['password'] = $input_data['password'];
} else {
Util::output_errors_and_die('', 400);
}
}
if ($model->update_user($username, $changes)) {
echo $user_data['username'] . ' -> ' . $username;
$model->insert_approvedby($user_data['username'], $username);
http_response_code(204);
die;
} else {
Util::output_errors_and_die('', 404);
}
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例10: test_question
function test_question($request)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale'], '/new-question/errors');
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die($msg->_('invalid-format'), 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data)) {
Util::output_errors_and_die($msg->_('invalid-format'), 400);
}
set_empty_if_undefined($input_data['type']);
if (!Validator::validate_question_type($input_data['type'])) {
Util::output_errors_and_die($msg->_('invalid-type'), 400);
}
switch ($input_data['type']) {
case 'short-answer':
$q = new QuestionSA($input_data, Question::FROM_USER);
break;
case 'essay':
$q = new QuestionES($input_data, Question::FROM_USER);
break;
case 'multiple-choice':
$q = new QuestionMC($input_data, Question::FROM_USER);
break;
case 'matching':
$q = new QuestionMA($input_data, Question::FROM_USER);
break;
case 'fitb-type':
$q = new QuestionFT($input_data, Question::FROM_USER);
break;
case 'fitb-select':
$q = new QuestionFS($input_data, Question::FROM_USER);
break;
case 'source-code':
$q = new QuestionSC($input_data, Question::FROM_USER);
break;
}
http_response_code(200);
header('Content-Type: application/json');
echo my_json_encode($q->to_auto_marking_test(true, true));
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例11: get_programming_languages
function get_programming_languages($request)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale']);
try {
$model = new Model();
$result = $model->get_programming_languages();
http_response_code(200);
header('Content-Type: application/json');
echo my_json_encode($result);
die;
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例12: delete_user
function delete_user($username, $request)
{
Authenticator::assert_manager($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale']);
try {
$model = new Model();
if ($model->delete_user($username)) {
http_response_code(204);
} else {
http_response_code(404);
}
die;
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例13: confirm_code
function confirm_code($request)
{
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'text/plain') {
Util::output_errors_and_die('', 415);
}
$code = trim($request->getBody());
try {
$model = new Model();
$status = $model->confirm_email($code);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
http_response_code(200);
echo $status;
die;
}
示例14: test_programming_language
function test_programming_language($request)
{
Authenticator::assert_manager($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale']);
try {
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die('', 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data)) {
Util::output_errors_and_die('', 400);
}
LanguageTest::test($input_data['file_name'], $input_data['extension'], $input_data['source_code'], $input_data['compiler_flags'], $input_data['check_command'], $input_data['compile_command'], $input_data['run_command'], $input_data['arguments'], $input_data['stdin']);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例15: delete_session
function delete_session($request)
{
if (isset($request->cookies['authToken'])) {
$token = $request->cookies['authToken'];
} else {
Util::output_errors_and_die('', 400);
}
try {
$model = new Model();
$result = $model->delete_auth_token($token);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
http_response_code($result ? 204 : 403);
setcookie('authToken', '', 0, '/', '', $secure = true, $httponly = true);
die;
}