本文整理汇总了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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例9: send
public function send()
{
return parent::send();
}
示例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();
}
示例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);
//.........这里部分代码省略.........
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}