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


PHP Response::send方法代碼示例

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


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

示例1: send

 /**
  * 發送響應消息
  *
  * @param   string  $message    響應信息
  * @param   int     $status     響應狀態碼
  */
 public static function send($message = '', $status = 200)
 {
     if (self::$response === null) {
         self::init();
     }
     self::$response->setStatusCode(intval($status));
     self::$response->setContent(strval($message));
     self::$response->send();
 }
開發者ID:q-phalcon,項目名稱:kernel,代碼行數:15,代碼來源:QpResponse.php

示例2: respond

 /**
  * Send response to client
  */
 public function respond($data, $status = 200)
 {
     $response = new Response();
     $response->setContentType('application/json');
     $response->setStatusCode($status);
     $data = $data instanceof SimpleResultSet ? $data->toArray() : $data;
     $response->setContent(json_encode($data));
     $response->send();
 }
開發者ID:bilna-dev,項目名稱:monitoring-tools,代碼行數:12,代碼來源:Restable.php

示例3: sendResult

 /**
  * 發送數據
  * @param mixed $result
  */
 private static function sendResult($result)
 {
     $response = new Response();
     $response->setHeader('Content-Type', 'application/json; charset=UTF-8');
     $response->setHeader('Access-Control-Allow-Origin', '*');
     $response->setJsonContent($result);
     $response->send();
     exit;
 }
開發者ID:huxiaohe,項目名稱:api-framework,代碼行數:13,代碼來源:ResponseApi.php

示例4: send

 /**
  * 向Client發送響應的資源
  */
 public function send()
 {
     if (is_array($this->resource) || is_object($this->resource)) {
         $this->response->setHeader('Content-Type', 'text/json');
         $this->response->setContent(json_encode($this->resource, true));
     } else {
         $this->response->setContent($this->resource);
     }
     $this->response->send();
 }
開發者ID:sujinw,項目名稱:passport,代碼行數:13,代碼來源:BaseController.php

示例5: sendResponse

 public function sendResponse()
 {
     if ($this->di->has('view')) {
         $this->di->get('view')->disable();
     }
     $response = new Response();
     $response->setContentType('application/json', 'utf8');
     $response->setJsonContent($this->getResponse());
     $response->send();
 }
開發者ID:mzf,項目名稱:phalcon-datatables,代碼行數:10,代碼來源:DataTable.php

示例6: debugEnvAction

 public function debugEnvAction()
 {
     //var_dump($_SERVER['REDIRECT_URL']);die();
     $actual_route = $_SERVER['REDIRECT_URL'];
     $response = new Response();
     $response->setStatusCode(404, "Not Found");
     $response->setContent("Sorry, the route: <b>" . $actual_route . " </b> doesn't exist");
     $response->send();
     return $response;
 }
開發者ID:leyriel,項目名稱:allocuisto_dev,代碼行數:10,代碼來源:NotFoundController.php

示例7: response

 public function response(Response $response, $type, $quality = 90)
 {
     if (is_string($type) && isset(self::$typesConv[$type])) {
         $type = self::$typesConv[$type];
     }
     if ($type !== self::GIF && $type !== self::PNG && $type !== self::JPEG) {
         throw new \InvalidArgumentException("Unsupported image type.");
     }
     if ($type) {
         $this->getInternalImInstance()->setimageformat(self::$types[$type]);
     }
     if ($quality) {
         $this->getInternalImInstance()->setcompressionquality($quality > 1 ? $quality : round($quality * 100));
     }
     $response->setContentType(image_type_to_mime_type($type));
     $response->setContent((string) $this->getInternalImInstance());
     $response->send();
 }
開發者ID:kathynka,項目名稱:Foundation,代碼行數:18,代碼來源:Image.php

示例8: run

 /**
  * Main run block that executes the micro application
  *
  */
 public function run()
 {
     // Handle any routes not found
     $this->notFound(function () {
         $response = new Response();
         $response->setStatusCode(404, 'Not Found')->sendHeaders();
         $response->setContent('Page doesn\'t exist.');
         $response->send();
     });
     $this->handle();
 }
開發者ID:swordkee,項目名稱:phalcon-demo,代碼行數:15,代碼來源:ApplicationMicro.php

示例9: send

 public function send()
 {
     return parent::send();
 }
開發者ID:mattvb91,項目名稱:cphalcon,代碼行數:4,代碼來源:Response.php

示例10: download

 /**
  * Create an invoice download response.
  *
  * @param array $data
  */
 public function download(array $data)
 {
     $filename = $data['product'] . '_' . $this->date()->month . '_' . $this->date()->year . '.pdf';
     $response = new Response();
     $response->setHeader('Content-Description', 'File Transfer');
     $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
     $response->setStatusCode(200, 'OK');
     $response->setContent($this->pdf($data));
     $response->setContentType('application/pdf');
     return $response->send();
 }
開發者ID:duythien,項目名稱:cashier,代碼行數:16,代碼來源:Invoice.php

示例11: download

 public function download($url, $destination = "", $file_name = "")
 {
     // check URL and get token if necessary
     preg_match("/(.*)periscope\\.tv\\/w\\/(.*)/", trim($url), $output_array);
     if (isset($output_array[2])) {
         $periscope_token = $output_array[2];
     } else {
         preg_match("/(.*)watchonperiscope\\.com\\/broadcast\\/(.*)/", trim($url), $output_array);
         if (isset($output_array[2])) {
             try {
                 $watchonperiscope_response = $this->_guzzle->get("https://watchonperiscope.com/api/accessChannel?broadcast_id=" . $output_array[2])->getBody();
             } catch (\GuzzleHttp\Exception\ServerException $e) {
                 throw new \Exception("URL error: Invalid watchonperiscope.com URL", 2);
             }
             $watchonperiscope_json = json_decode($watchonperiscope_response, true);
             if (!isset($watchonperiscope_json["error"])) {
                 preg_match("/(.*)periscope\\.tv\\/w\\/(.*)/", $watchonperiscope_json["share_url"], $output_array);
                 $periscope_token = $output_array[2];
             } else {
                 throw new \Exception("URL error: Invalid watchonperiscope.com URL", 2);
             }
         } else {
             throw new \Exception("URL error: Unsupported URL", 1);
         }
     }
     // construct filename and destination
     if ($file_name == "") {
         try {
             $periscope_details_response = $this->_guzzle->get("https://api.periscope.tv/api/v2/getBroadcastPublic?broadcast_id=" . $periscope_token)->getBody();
         } catch (\GuzzleHttp\Exception\ClientException $e) {
             throw new \Exception("Periscope error: Invalid token", 3);
         }
         $periscope_details_json = json_decode($periscope_details_response, true);
         $periscope_user = $periscope_details_json["user"]["username"];
         $periscope_start_time = $periscope_details_json["broadcast"]["start"];
         $date = substr($periscope_start_time, 0, 10);
         $hours = substr($periscope_start_time, 11, 2);
         $mins = substr($periscope_start_time, 14, 2);
         $file_name = $periscope_user . "_" . $date . "_" . $hours . "_" . $mins . ".ts";
     } else {
         $file_name = rtrim($file_name, ".ts") . ".ts";
     }
     if ($destination == "") {
         $destination = __DIR__ . "/";
     } else {
         $destination = rtrim($destination, "/") . "/";
     }
     // set up cookies
     try {
         $periscope_cookies_response = $this->_guzzle->get("https://api.periscope.tv/api/v2/getAccessPublic?broadcast_id=" . $periscope_token)->getBody();
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         throw new \Exception("Periscope error: Invalid token", 3);
     }
     $periscope_cookies_json = json_decode($periscope_cookies_response, true);
     $replay_url = $periscope_cookies_json["replay_url"];
     $base_url = str_replace("/playlist.m3u8", "", $replay_url);
     $cookies = array();
     foreach ($periscope_cookies_json["cookies"] as $cookie) {
         $cookies[$cookie["Name"]] = $cookie["Value"];
     }
     $cookie_jar = new \GuzzleHttp\Cookie\CookieJar();
     $periscope_cookies = $cookie_jar::fromArray($cookies, "replay.periscope.tv");
     // download playlist and all chunks
     $periscope_playlist_response = $this->_guzzle->get($replay_url, ["cookies" => $periscope_cookies])->getBody()->getContents();
     preg_match_all("/chunk_(.*)\\.ts/", $periscope_playlist_response, $chunk_array);
     $tmp_folder = $destination . "/" . bin2hex(openssl_random_pseudo_bytes(16)) . "/";
     shell_exec("mkdir " . $tmp_folder);
     $path = $destination . $file_name;
     if (!file_exists($path)) {
         shell_exec("cat " . $tmp_folder . $chunk_array[0][0] . " >> " . $path);
     }
     $response = new Response();
     $filetype = filetype($path);
     $filesize = filesize($path);
     while (ob_get_level()) {
         ob_end_clean();
     }
     $response->setHeader("Content-Description", 'File Transfer');
     $response->setHeader("Cache-Control", 'must-revalidate, post-check=0, pre-check=0');
     $response->setHeader("Content-Disposition", 'attachment; filename=' . $file_name);
     $response->setHeader("Content-Type", $filetype);
     $response->setHeader("Content-Length", $filesize);
     $response->setHeader("Content-Transfer-Encoding", 'binary');
     $response->setHeader("Expires", '0');
     $response->setHeader("Pragma", 'public');
     $response->setFileToSend($path, null, false);
     $response->send();
     foreach ($chunk_array[0] as $chunk) {
         $chunk_response = $this->_guzzle->get($base_url . "/" . $chunk, ["cookies" => $periscope_cookies])->getBody()->getContents();
         //, 'stream' => true
         //               $chunk_size = $chunk_response->getHeader('content-length');
         //               $body = $chunk_response->getBody();
         //
         //                while ( ! $body->eof()) {
         //                    echo $body->read($chunk_size[0]);
         //                }
         file_put_contents($tmp_folder . $chunk, $chunk_response);
         $chunk_size = filesize($tmp_folder . $chunk);
         if (file_exists($path)) {
             shell_exec("cat " . $path . ' ' . $tmp_folder . $chunk . " >> " . $path);
//.........這裏部分代碼省略.........
開發者ID:sinbad13,項目名稱:periscope-downloader,代碼行數:101,代碼來源:PeriscopeDownloader.php

示例12: sendException

 /**
  * @param \Exception $exception
  *
  * @return \Phalcon\Http\ResponseInterface|void
  */
 public function sendException(\Exception $exception)
 {
     $this->setStatusCode($exception->getCode(), $exception->getMessage());
     $this->setJsonContent($this);
     return parent::send();
 }
開發者ID:spuy767,項目名稱:api,代碼行數:11,代碼來源:JSONResponse.php

示例13: saveLayoutAction

 /**
  * Save page layout with content.
  *
  * @param int $id Page identity.
  *
  * @return ResponseInterface
  *
  * @Route("/save-layout/{id:[0-9]+}", methods={"POST"}, name="admin-pages-save-layout")
  */
 public function saveLayoutAction($id)
 {
     $response = new Response();
     $response->setStatusCode(200, "OK");
     $response->setContent(json_encode(["error" => 0]));
     $layout = $this->request->get("layout");
     $items = $this->request->get("items");
     // Save page with widgets and layout.
     $page = Page::findFirstById($id);
     $page->layout = $layout;
     $page->setWidgets($items);
     $page->save();
     // Clear widgets cache.
     /** @var \Phalcon\Cache\BackendInterface $cache */
     $cache = $this->getDI()->get('cacheOutput');
     $prefix = $this->config->application->cache->prefix;
     $widgetKeys = $cache->queryKeys($prefix . WidgetController::CACHE_PREFIX);
     foreach ($widgetKeys as $key) {
         $cache->delete(str_replace($prefix, '', $key));
     }
     $this->flashSession->success('Page saved!');
     return $response->send();
 }
開發者ID:biggtfish,項目名稱:cms,代碼行數:32,代碼來源:AdminPagesController.php

示例14: Application

     */
    require ROOT_DIR . 'core/config/services.php';
    /**
     * Handle the request
     */
    $application = new Application();
    /**
     * Assign the DI
     */
    $application->setDI($di);
    /**
     * Include modules
     */
    $application->registerModules(require ROOT_DIR . 'core/config/modules.php');
    /**
     * Sets the event manager
     */
    $application->setEventsManager($eventsManager);
    echo $application->handle()->getContent();
} catch (Exception $e) {
    echo $e->getMessage();
    echo $e->getTraceAsString();
    /**
     * Show an static error page
     */
    if (!$di->get('config')->application->debug) {
        $response = new Response();
        $response->redirect('errors/503');
        $response->send();
    }
}
開發者ID:kjmtrue,項目名稱:phanbook,代碼行數:31,代碼來源:index.php

示例15: getSignOutAction

 /**
  * 用戶注銷頁
  */
 public function getSignOutAction()
 {
     $this->session->has('auth') and $this->session->remove('auth');
     $response = new Response();
     $response->redirect(isset($_GET['callback']) ? $_GET['callback'] : $this->url->get('signin'), true);
     $response->send();
 }
開發者ID:sujinw,項目名稱:passport,代碼行數:10,代碼來源:MainController.php


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