gb_admin::error_rsp PHP Method

error_rsp() static public method

static public error_rsp ( $msg, $status = '400 Bad Request', $content_type = 'text/plain; charset=utf-8', $exit = true )
    static function error_rsp($msg, $status = '400 Bad Request', $content_type = 'text/plain; charset=utf-8', $exit = true)
    {
        self::abrupt_rsp($status . "\n" . $msg . "\n", $status, $content_type, $exit);
    }

Usage Example

示例#1
0
ini_set('html_errors', '0');
require '../_base.php';
gb::authenticate();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    gb_admin::error_rsp('405 Method Not Allowed', '405 Method Not Allowed');
}
try {
    # parse input
    static $spec_fields = array('name' => '', 'version' => '(work)', 'commit' => 'bool(false)');
    static $state_fields = array('mimeType' => ':trim', 'title' => ':trim', 'slug' => ':trim', 'body' => '', 'tags' => '[]', 'categories' => '[]', 'published' => '@GBDateTime', 'author' => '@GBAuthor', 'commentsOpen' => 'bool', 'pingbackOpen' => 'bool', 'draft' => 'bool');
    $input = gb_input::process(array_merge($spec_fields, $state_fields));
    # find post
    $created = false;
    if ($input['name'] !== null) {
        if (!($post = GBPost::findByName($input['name'], $input['version']))) {
            gb_admin::error_rsp('Post ' . r($input['name']) . ' not found');
        }
    } else {
        $post = new GBPost();
        $created = true;
    }
    # set post state
    $modified_state = array();
    foreach ($state_fields as $k => $discard) {
        $v = $input[$k];
        if ($v !== null && $post->{$k} !== $v) {
            if ($k === 'body') {
                $post->setRawBody($v);
                $modified_state[$k] = $post->rawBody();
            } else {
                $post->{$k} = $v;