本文整理汇总了PHP中Nette\Environment::getHttpResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::getHttpResponse方法的具体用法?PHP Environment::getHttpResponse怎么用?PHP Environment::getHttpResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Environment
的用法示例。
在下文中一共展示了Environment::getHttpResponse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Sends response to output.
* @return void
*/
public function send()
{
Nette\Environment::getHttpResponse()->setContentType($this->contentType);
Nette\Environment::getHttpResponse()->setExpiration(FALSE);
echo Nette\Json::encode($this->payload);
}
示例2: download
/**
* Download the file!
* @param IDownloader $downloader
*/
function download(IDownloader $downloader = null)
{
$req = Environment::getHttpRequest();
$res = Environment::getHttpResponse();
if (self::$closeSession) {
$ses = Environment::getSession();
if ($ses->isStarted()) {
$ses->close();
}
}
if ($this->getContentDisposition() == "inline" and is_null($this->enableBrowserCache)) {
$this->enableBrowserCache = true;
} else {
$this->enableBrowserCache = false;
}
if ($downloader === null) {
$downloaders = self::getFileDownloaders();
} else {
$downloaders = array($downloader);
}
if (count($downloaders) <= 0) {
throw new InvalidStateException("There is no registred downloader!");
}
krsort($downloaders);
$lastException = null;
foreach ($downloaders as $downloader) {
if ($downloader instanceof IDownloader and $downloader->isCompatible($this)) {
try {
FDTools::clearHeaders($res);
// Delete all headers
$this->transferredBytes = 0;
$this->onBeforeDownloaderStarts($this, $downloader);
$downloader->download($this);
// Start download
$this->onComplete($this, $downloader);
die;
// If all gone ok -> die
} catch (FDSkypeMeException $e) {
if ($res->isSent()) {
throw new InvalidStateException("Headers are already sent! Can't skip downloader.");
} else {
continue;
}
} catch (Exception $e) {
if (!$res->isSent()) {
FDTools::clearHeaders($res);
}
throw $e;
}
}
}
// Pokud se soubor nějakým způsobem odešle - toto už se nespustí
if ($lastException instanceof Exception) {
FDTools::clearHeaders(Environment::getHttpResponse(), TRUE);
throw $lastException;
}
if ($req->getHeader("Range")) {
FDTools::_HTTPError(416);
} else {
$res->setCode(500);
}
throw new InvalidStateException("There is no compatible downloader (all downloader returns downloader->isComplatible()=false or was skipped)!");
}
示例3: getHttpResponse
/**
* @return Nette\Web\IHttpResponse
*/
protected function getHttpResponse()
{
return Nette\Environment::getHttpResponse();
}
示例4: download
/**
* Download file!
* @param BaseFileDownload $file
*/
function download(BaseFileDownload $transfer)
{
$this->currentTransfer = $transfer;
$this->sendStandardFileHeaders($transfer, $this);
@ignore_user_abort(true);
// For onAbort event
$req = Environment::getHttpRequest();
$res = Environment::getHttpResponse();
$filesize = $this->size = $transfer->sourceFileSize;
$this->length = $this->size;
// Content-length
$this->start = 0;
$this->end = $this->size - 1;
/* ### Headers ### */
// Now that we've gotten so far without errors we send the accept range header
/* At the moment we only support single ranges.
* Multiple ranges requires some more work to ensure it works correctly
* and comply with the spesifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
*
* Multirange support annouces itself with:
* header('Accept-Ranges: bytes');
*
* Multirange content must be sent with multipart/byteranges mediatype,
* (mediatype = mimetype)
* as well as a boundry header to indicate the various chunks of data.
*/
//$res->setHeader("Accept-Ranges", "0-".$this->end); // single-part - now not accepted by mozilla
$res->setHeader("Accept-Ranges", "bytes");
// multi-part (through Mozilla)
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
if ($req->getHeader("Range", false)) {
try {
$range_start = $this->start;
$range_end = $this->end;
// Extract the range string
$rangeArray = explode('=', $req->getHeader("Range"), 2);
$range = $rangeArray[1];
// Make sure the client hasn't sent us a multibyte range
if (strpos($range, ',') !== false) {
// (?) Shoud this be issued here, or should the first
// range be used? Or should the header be ignored and
// we output the whole content?
throw new FileDownloaderException("HTTP 416", 416);
}
// If the range starts with an '-' we start from the beginning
// If not, we forward the file pointer
// And make sure to get the end byte if spesified
if ($range[0] == '-') {
// The n-number of the last bytes is requested
$range_start = $this->size - (double) substr($range, 1);
} else {
$range = explode('-', $range);
$range_start = $range[0];
$range_end = isset($range[1]) && is_numeric($range[1]) ? $range[1] : $this->size;
}
/**
* Check the range and make sure it's treated according to the specs.
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
*/
// End bytes can not be larger than $end.
$range_end = $range_end > $this->end ? $this->end : $range_end;
// Validate the requested range and return an error if it's not correct.
if ($range_start > $range_end || $range_start > $this->size - 1 || $range_end >= $this->size) {
throw new FileDownloaderException("HTTP 416", 416);
}
// All is ok - so assign variables back
$this->start = $range_start;
$this->end = $range_end;
$this->length = $this->end - $this->start + 1;
// Calculate new content length
} catch (FileDownloaderException $e) {
if ($e->getCode() === 416) {
$res->setHeader("Content-Range", "bytes {$this->start}-{$this->end}/{$this->size}");
FDTools::_HTTPError(416);
} else {
throw $e;
}
}
$res->setCode(206);
// Partial content
}
// End of if partial download
// Notify the client the byte range we'll be outputting
$res->setHeader("Content-Range", "bytes {$this->start}-{$this->end}/{$this->size}");
$res->setHeader("Content-Length", $this->length);
/* ### Call callbacks ### */
$transfer->onBeforeOutputStarts($transfer, $this);
if ($this->start > 0) {
$transfer->onTransferContinue($transfer, $this);
} else {
$transfer->onNewTransferStart($transfer, $this);
}
/* ### Send file to browser - document body ### */
$buffer = FDTools::$readFileBuffer;
$sleep = false;
if (is_int($transfer->speedLimit) and $transfer->speedLimit > 0) {
//.........这里部分代码省略.........
示例5: getResponse
/**
* @return Nette\Web\IHttpResponse
*/
public function getResponse()
{
return Nette\Environment::getHttpResponse();
}
示例6: send
/**
* Sends response to output.
* @return void
*/
public function send()
{
Nette\Environment::getHttpResponse()->redirect($this->uri, $this->code);
}
示例7: send
/**
* Sends response to output.
* @return void
*/
public function send()
{
Nette\Environment::getHttpResponse()->setContentType($this->contentType);
Nette\Environment::getHttpResponse()->setHeader('Content-Disposition', 'attachment; filename="' . $this->name . '"');
readfile($this->file);
}
示例8: console
<?php
use Nette\Environment;
Environment::getHttpResponse()->setHeader("refresh", "1");
$cache = Environment::getCache("FileDownloader/log");
echo "<html><body>";
echo "<h1>Log console (called events)</h1>";
echo "<p>Clear log = delete temp files</p>";
echo "<style>p{font-size: 11px;font-family: monospace;}</style>";
$reg = $cache["registry"];
$y = 0;
if (count($reg) > 0) {
krsort($reg);
foreach ($reg as $tid => $none) {
$y++;
$tid = (string) $tid;
$log = $cache[$tid];
$i = 0;
if (count($log) > 0) {
krsort($log);
foreach ($log as $key => $val) {
if ($i == 0) {
echo "<h2>Con. #" . $tid;
if (strstr($val, "Abort")) {
echo " <span style=\"color: orange;\">(Aborted)</span>";
} elseif (strstr($val, "Lost")) {
echo " <span style=\"color: red;\">(Connection losted)</span>";
} elseif (strstr($val, "Complete")) {
echo " <span style=\"color: green;\">(Completed)</span>";
} else {
echo " (Running)";
示例9: array
/**
* Sends http error to client
*
* @author Jan Kuchař
* @param int $code HTTP code
* @param string $message HTTP status
*/
static function _HTTPError($code, $message = null)
{
$errors = array(416 => "Requested Range not satisfiable");
if ($message === null and isset($errors[$code])) {
$message = $errors[$code];
}
$res = Environment::getHttpResponse();
$res->setCode($code);
$res->setContentType("plain/text", "UTF-8");
die("<html><body><h1>HTTP Error " . $code . " - " . $message . "</h1><p>" . $message . "</p></body></html>");
}
示例10: setupNonCacheHeaders
protected function setupNonCacheHeaders(BaseFileDownload $file)
{
$res = \Nette\Environment::getHttpResponse();
$res->setHeader('Expires', '0');
$res->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
}