当前位置: 首页>>代码示例>>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;未经允许,请勿转载。