当前位置: 首页>>代码示例>>PHP>>正文


PHP JSON::respond方法代码示例

本文整理汇总了PHP中JSON::respond方法的典型用法代码示例。如果您正苦于以下问题:PHP JSON::respond方法的具体用法?PHP JSON::respond怎么用?PHP JSON::respond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSON的用法示例。


在下文中一共展示了JSON::respond方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: is_numeric

<?php

Gatekeeper\Gatekeeper::authorizeTestApiAccess();
$code = !empty($_REQUEST['statusCode']) && is_numeric($_REQUEST['statusCode']) ? $_REQUEST['statusCode'] : 200;
$message = !empty($_REQUEST['statusMessage']) && preg_match('/^[a-zA-Z0-9 \\-]+$/', $_REQUEST['statusMessage']) ? $_REQUEST['statusMessage'] : 'OK';
header("HTTP/1.1 {$code} {$message}");
JSON::respond(array('success' => $code < 300, 'code' => $code, 'message' => $message));
开发者ID:jmealo,项目名称:Gatekeeper,代码行数:7,代码来源:status.php

示例2: array

Site::$autoPull = true;
$succeeded = array();
$failed = array();
foreach ($requestData['nodes'] as $updateData) {
    $Node = Site::resolvePath($updateData['path']);
    if ($Node->Collection->Site == 'Local') {
        $failed[] = array('path' => $updateData['path'], 'error' => 'CURRENT_IS_LOCAL', 'message' => 'Current node is local and blocks any remote updates');
        continue;
    }
    if ($Node->SHA1 != $updateData['localSHA1']) {
        $failed[] = array('path' => $updateData['path'], 'error' => 'LOCAL_SHA1_MISMATCH', 'message' => 'Current node\'s SHA1 hash does not match that which this update was requested for');
        continue;
    }
    if (empty($updateData['remoteSHA1'])) {
        $Node->delete();
    } else {
        $NewNode = Emergence::resolveFileFromParent($Node->Collection, $Node->Handle, true);
        if (!$NewNode) {
            $failed[] = array('path' => $updateData['path'], 'error' => 'DOWNLOAD_FAILED', 'message' => 'The remote file failed to download');
            continue;
        }
        if ($NewNode->SHA1 != $updateData['remoteSHA1']) {
            $NewNode->destroyRecord();
            $failed[] = array('path' => $updateData['path'], 'error' => 'REMOTE_SHA1_MISMATCH', 'message' => 'Downloaded node\'s SHA1 hash does not match that which this update was requested for');
            continue;
        }
    }
    $succeeded[] = $updateData['path'];
}
JSON::respond(array('succeeded' => $succeeded, 'failed' => $failed));
开发者ID:nbey,项目名称:Emergence-Skeleton,代码行数:30,代码来源:pull-remote-changes.php

示例3: searchRequest

 public static function searchRequest()
 {
     $GLOBALS['Session']->requireAccountLevel('Developer');
     set_time_limit(180);
     if (empty($_REQUEST['q'])) {
         return static::throwInvalidRequestError('q required');
     }
     $fileResults = DB::query('SELECT f.ID FROM (SELECT MAX(ID) AS ID FROM _e_files GROUP BY Handle, CollectionID) matches JOIN _e_files f USING(ID) WHERE f.Status = "Normal"');
     // open grep process
     $cmd = sprintf('xargs grep -nIP "%s" ', addslashes($_REQUEST['q']));
     $cwd = Site::$rootPath . '/data/';
     $grepProc = proc_open($cmd, array(0 => array('pipe', 'r'), 1 => array('pipe', 'w')), $pipes, $cwd);
     // pipe file list into xargs
     $filesCount = 0;
     while ($file = $fileResults->fetch_assoc()) {
         fwrite($pipes[0], $file['ID'] . PHP_EOL);
     }
     fclose($pipes[0]);
     // pipe results out
     $output = array();
     while (!feof($pipes[1])) {
         $line = trim($origLine = stream_get_line($pipes[1], 100000000, PHP_EOL));
         #            print "$origLine<hr>";
         $line = explode(':', $line, 3);
         if (count($line) === 3) {
             $file = SiteFile::getByID($line[0]);
             if (strlen($line[2]) > 255) {
                 $result = preg_match("/{$_REQUEST['q']}/", $line[2], $matches, PREG_OFFSET_CAPTURE);
                 $line[2] = substr(substr($line[2], max(0, $matches[0][1] - 50)), 0, 255);
             }
             if (!$file) {
                 Debug::dumpVar($line, true, 'no file');
             }
             $output[] = array('File' => $file ? $file->getData() : null, 'line' => $line[1], 'result' => trim($line[2]));
         }
     }
     fclose($pipes[1]);
     proc_close($grepProc);
     JSON::respond(array('success' => true, 'data' => $output));
 }
开发者ID:Akujin,项目名称:emergence-skeleton-v2,代码行数:40,代码来源:EditorRequestHandler.class.php

示例4: ctype_digit

<?php

Gatekeeper\Gatekeeper::authorizeTestApiAccess();
$cacheSecs = !empty($_GET['secs']) && ctype_digit($_GET['secs']) ? $_GET['secs'] : 30;
header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $cacheSecs));
header('Cache-Control: max-age=' . $cacheSecs);
header('Pragma: cache');
JSON::respond(array('success' => true, 'foo' => 'bar', 'time' => date('Y-m-d H:i:s')));
开发者ID:jmealo,项目名称:Gatekeeper,代码行数:8,代码来源:cachable.php

示例5: is_numeric

<?php

Gatekeeper\Gatekeeper::authorizeTestApiAccess();
$delay = !empty($_REQUEST['delay']) && is_numeric($_REQUEST['delay']) ? $_REQUEST['delay'] : 5;
sleep($delay);
JSON::respond(array('success' => 200, 'delay' => $delay));
开发者ID:jmealo,项目名称:Gatekeeper,代码行数:6,代码来源:slow.php

示例6: is_array

        if (in_array($validHour, $hours)) {
            $where[] = "Site{$validHour} = 1";
        }
    }
}
// add features filter
if (!empty($_GET['features'])) {
    $validFeatures = ['TransportationProvided'];
    $features = is_array($_GET['features']) ? $_GET['features'] : [$_GET['features']];
    foreach ($validFeatures as $validFeature) {
        if (in_array($validFeature, $features)) {
            $where[] = "Site{$validFeature} = 1";
        }
    }
}
// calculate limit params
if (!empty($_GET['limit']) && ctype_digit($_GET['limit'])) {
    $limit = (int) $_GET['limit'];
} else {
    $limit = 25;
}
if (!empty($_GET['offset']) && ctype_digit($_GET['offset'])) {
    $offset = (int) $_GET['offset'];
} else {
    $offset = 0;
}
// execute query and print JSON response
#Debug::dumpVar($_GET, false, 'get');
#Debug::dumpVar($where, true, '$where');
JSON::respond(['results' => DB::allRecords('SELECT SQL_CALC_FOUND_ROWS ' . implode(',', $selectFields) . ' FROM Site' . ' WHERE SiteApproved = 1 AND (' . (count($where) ? implode(') AND (', $where) : '1') . ')' . " ORDER BY {$order}" . " LIMIT {$offset}, {$limit}"), 'limit' => $limit, 'offset' => $offset, 'total' => (int) DB::foundRows()]);
开发者ID:CfABrigadePhiladelphia,项目名称:asap-mobile,代码行数:30,代码来源:asap-search.php

示例7: throwAPIUnauthorizedError

 public static function throwAPIUnauthorizedError($message = 'You do not have authorization to access this resource')
 {
     header('HTTP/1.0 403 Forbidden');
     switch (static::getResponseMode()) {
         case 'json':
         default:
             JSON::respond(['success' => false, 'message' => $message]);
     }
 }
开发者ID:Akujin,项目名称:emergence-skeleton-v2,代码行数:9,代码来源:AbstractRequestHandler.php

示例8:

<?php

Gatekeeper\Gatekeeper::authorizeTestApiAccess();
JSON::respond($_COOKIE);
开发者ID:jmealo,项目名称:Gatekeeper,代码行数:4,代码来源:cookies.php


注:本文中的JSON::respond方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。