當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::setBody方法代碼示例

本文整理匯總了PHP中Response::setBody方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::setBody方法的具體用法?PHP Response::setBody怎麽用?PHP Response::setBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Response的用法示例。


在下文中一共展示了Response::setBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: checkConnection

 /**
  * check database connection based on provided setting
  */
 public function checkConnection()
 {
     $success = false;
     $message = '';
     $config = $this->getPostConfiguration();
     try {
         $this->makeConnection($config);
         /**
          * Just trying to show tables with current connection
          */
         switch ($config['driver']) {
             case 'mysql':
                 $tables = Capsule::select('show tables');
                 break;
             case 'sqlite':
                 $tables = Capsule::select("SELECT * FROM sqlite_master WHERE type='table'");
                 break;
             case 'sqlsrv':
                 $tables = Capsule::select("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'");
                 break;
             case 'pgsql':
                 $tables = Capsule::select("SELECT * FROM pg_catalog.pg_tables");
                 break;
         }
         $success = true;
         $message = 'Successfully connected!';
     } catch (Exception $e) {
         $success = false;
         $message = $e->getMessage();
     }
     Response::headers()->set('Content-Type', 'application/json');
     Response::setBody(json_encode(array('success' => $success, 'message' => $message, 'config' => $config)));
 }
開發者ID:lupuxyz,項目名稱:SlimStarter,代碼行數:36,代碼來源:InstallController.php

示例2: dispatch

 public static function dispatch()
 {
     $url = new Url();
     $uri = $url->getPath();
     foreach (array_reverse(self::$routes, true) as $route => $class) {
         if (preg_match("~^{$route}\$~", $uri, $params)) {
             Router::$current = $class;
             $return = call_user_func_array(array('Controller', 'dispatch'), array_merge(array($class), array_slice($params, 1)));
             if (!(false === $return)) {
                 $vars = get_class_vars($class);
                 $type = 'text/html';
                 if (isset($vars['type'])) {
                     $type = $vars['type'];
                 }
                 # PHP >= 5.3
                 # if ( isset($class::$type) )
                 #     $type = $class::$type;
                 //Response::setHeader('Content-Type', 'application/xhtml+xml');
                 Response::setHeader('Content-Type', "{$type};charset=UTF-8");
                 Response::setBody($class, $return);
                 return;
             }
             Router::$current = null;
         }
     }
     if (Response::getHttpResponseCode() == 200) {
         $class = 'Error404';
         $return = Controller::dispatch($class);
         Response::setHeader('Content-Type', 'text/html;charset=UTF-8');
         Response::setBody($class, $return);
         //Response::setHeader('HTTP/1.0 404 Not Found');
         //Response::setHttpResponseCode(404);
         //Response::setBody('404', 'Error 404');
     }
 }
開發者ID:joksnet,項目名稱:php-old,代碼行數:35,代碼來源:Router.php

示例3: respond

 /**
  * Sets the response body and status code header
  *
  * @param mixed $data
  * @param integer $status
  * @return void
  */
 protected function respond($data, $status = null)
 {
     if ($this->performedRespond) {
         throw new DoubleRespond();
     }
     $this->response->setStatus(!empty($status) ? $status : $this->status);
     $this->response->setBody($data);
     $this->performedRespond = true;
 }
開發者ID:vincenta,項目名稱:stato,代碼行數:16,代碼來源:Controller.php

示例4: response

 public function response($code = 200, $headers = array())
 {
     $response = new Response();
     $body = json_encode(['success' => $this->success, 'data' => $this->data]);
     $defaultOptions = ['Content-Type' => 'application/json', 'Content-Length' => strlen($body)];
     $finalHeaders = array_merge($defaultOptions, $headers);
     $response->setHeaders($finalHeaders);
     $response->setBody($body);
     $response->respondWith($code);
     return $response;
 }
開發者ID:tailored-tunes,項目名稱:http-response-adapters,代碼行數:11,代碼來源:JsonResponse.php

示例5: ConvertCurlResponse

 private function ConvertCurlResponse($response, $ch)
 {
     $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     $header = substr($response, 0, $header_size);
     $body = substr($response, $header_size);
     $r = new Response();
     $r->setHeaders($this->http_parse_headers($header));
     $r->setHttpCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
     $r->setBody($body);
     return $r;
 }
開發者ID:sstretten,項目名稱:phpcurl,代碼行數:11,代碼來源:Worker.php

示例6: error

 public static function error($errno)
 {
     if (isset(self::$errors[$errno])) {
         Response::setHeader('Status', self::$errors[$errno]['Status']);
         if (isset(self::$errors[$errno]['Class'])) {
             self::instance(self::$errors[$errno]['Class']);
         } else {
             Response::setHeader('Content-Type', 'text/plain');
             Response::setBody(self::$errors[$errno]['Status']);
         }
     }
 }
開發者ID:joksnet,項目名稱:php-old,代碼行數:12,代碼來源:Web.php

示例7: testToString

    function testToString()
    {
        $response = new Response(200, ['Content-Type' => 'text/xml']);
        $response->setBody('foo');
        $expected = <<<HI
HTTP/1.1 200 OK
Content-Type: text/xml

foo
HI;
        $this->assertEquals($expected, (string) $response);
    }
開發者ID:sebbie42,項目名稱:casebox,代碼行數:12,代碼來源:ResponseTest.php

示例8: Auth

function Auth()
{
    if (!Sentry::check()) {
        if (Request::isAjax()) {
            Response::headers()->set('Content-Type', 'application/json');
            Response::setBody(json_encode(array('success' => false, 'message' => 'Session expired or unauthorized access.', 'code' => 401)));
            App::stop();
        } else {
            $redirect = Request::getResourceUri();
            Response::redirect(App::urlFor('login') . '?redirect=' . base64_encode($redirect));
        }
    }
}
開發者ID:acmadi,項目名稱:slimapp,代碼行數:13,代碼來源:filters.php

示例9: outputError

 public static function outputError($exception)
 {
     if (PHP_SAPI == 'cli') {
         echo $exception->getMessage() . "\nFile: " . $exception->getFile() . ' on line ' . $exception->getLine() . "\n\n" . $exception->getTraceAsString() . "\n";
         // exit with an error code
         exit(1);
     }
     // Write the error to log file
     @error_log('Error 404 Page Not Found: ' . $_SERVER['REQUEST_URI']);
     $response = new Response();
     $response->setStatusCode(404);
     $response->setBody(Controller::outputError('errors/404', ['message' => $exception->getMessage()]));
     return $response;
 }
開發者ID:finzaiko,項目名稱:Panada,代碼行數:14,代碼來源:HttpException.php

示例10: testSend

 /**
  * @runInSeparateProcess
  *
  * Unfortunately we have no way of testing if the HTTP response code got
  * changed.
  */
 function testSend()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('XDebug needs to be installed for this test to run');
     }
     $response = new Response(204, ['Content-Type', 'text/xml']);
     $response->setBody('foo');
     ob_start();
     Sapi::sendResponse($response);
     $headers = xdebug_get_headers();
     $result = ob_get_clean();
     header_remove();
     $this->assertEquals(["0: Content-Type", "1: text/xml"], $headers);
     $this->assertEquals('foo', $result);
 }
開發者ID:LukasReschke,項目名稱:sabre-http,代碼行數:21,代碼來源:SapiTest.php

示例11: doExecute

 private function doExecute($curlHandle, Request $request)
 {
     curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10);
     curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curlHandle, CURLOPT_HEADER, true);
     curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array('Accept: ' . $request->getHttpAccept()));
     $res = curl_exec($curlHandle);
     $info = curl_getinfo($curlHandle);
     $response = new Response();
     $response->setStatus($info['http_code']);
     if (false !== $res) {
         $response->setHeaders(substr($res, 0, $info['header_size']));
         $response->setBody(substr($res, -$info['download_content_length']));
     }
     return $response;
 }
開發者ID:karamani,項目名稱:beresta,代碼行數:16,代碼來源:RestClient.php

示例12: checkConnection

 /**
  * check database connection based on provided setting
  */
 public function checkConnection()
 {
     $success = false;
     $message = '';
     $config = $this->getPostConfiguration();
     try {
         $this->makeConnection($config);
         $tables = Capsule::select('show tables');
         $success = true;
         $message = 'Successfully connected!';
     } catch (Exception $e) {
         $success = false;
         $message = $e->getMessage();
     }
     Response::headers()->set('Content-Type', 'application/json');
     Response::setBody(json_encode(array('success' => $success, 'message' => $message, 'config' => $config)));
 }
開發者ID:acmadi,項目名稱:SlimStarter,代碼行數:20,代碼來源:InstallController.php

示例13: testSend

 /**
  * @runInSeparateProcess
  *
  * Unfortunately we have no way of testing if the HTTP response code got
  * changed.
  */
 function testSend()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('XDebug needs to be installed for this test to run');
     }
     $response = new Response(204, ['Content-Type' => 'text/xml;charset=UTF-8']);
     // Second Content-Type header. Normally this doesn't make sense.
     $response->addHeader('Content-Type', 'application/xml');
     $response->setBody('foo');
     ob_start();
     Sapi::sendResponse($response);
     $headers = xdebug_get_headers();
     $result = ob_get_clean();
     header_remove();
     $this->assertEquals(["Content-Type: text/xml;charset=UTF-8", "Content-Type: application/xml"], $headers);
     $this->assertEquals('foo', $result);
 }
開發者ID:MetallianFR68,項目名稱:myroundcube,代碼行數:23,代碼來源:SapiTest.php

示例14: outputError

 public static function outputError($message = null, $file = false, $line = false, $trace = false)
 {
     // Message for log
     $errorMessage = 'Error ' . $message . ' in ' . $file . ' line: ' . $line;
     // Write the error to log file
     @error_log($errorMessage);
     // Just output the error if the error source for view file or if in cli mode.
     if (PHP_SAPI == 'cli') {
         exit($errorMessage);
     }
     $code = [];
     if (!$file) {
         goto constructViewData;
     }
     $fileString = file_get_contents($file);
     $arrLine = explode("\n", $fileString);
     $totalLine = count($arrLine);
     $getLine = array_combine(range(1, $totalLine), array_values($arrLine));
     $startIterate = $line - 5;
     $endIterate = $line + 5;
     if ($startIterate < 1) {
         $startIterate = 1;
     }
     if ($endIterate > $totalLine) {
         $endIterate = $totalLine;
     }
     for ($i = $startIterate; $i <= $endIterate; $i++) {
         $html = '<span style="margin-right:10px;background:#CFCFCF;">' . $i . '</span>';
         if ($line == $i) {
             $html .= '<span style="color:#DD0000">' . htmlentities($getLine[$i]) . "</span>\n";
         } else {
             $html .= htmlentities($getLine[$i]) . "\n";
         }
         $code[] = $html;
     }
     constructViewData:
     $data = ['message' => $message, 'file' => $file, 'line' => $line, 'code' => $code, 'trace' => $trace];
     $response = new Response();
     $response->setStatusCode(500);
     $response->setBody(Controller::outputError('errors/500', $data));
     return $response;
 }
開發者ID:finzaiko,項目名稱:Panada,代碼行數:42,代碼來源:RunException.php

示例15: runApp

 public static function runApp()
 {
     if (!Request::isАuthorized()) {
         Response::setCode(401);
         return;
     }
     $matchedResource = Router::getMatchedRouterResource(Request::getMethod(), Request::getCleanRequestUrl());
     if ($matchedResource === null) {
         Response::setCode(404);
         return;
     }
     try {
         $response = self::executeResoruceAction($matchedResource[0], $matchedResource[1], Router::getMachedRouteParameters());
         if ($response === false) {
             Response::setCode(404);
         } else {
             Response::setBody($response);
         }
     } catch (\Exception $e) {
         Response::setCode(500);
     }
 }
開發者ID:pavel-tashev,項目名稱:APIJet,代碼行數:22,代碼來源:APIJet.php


注:本文中的Response::setBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。