本文整理汇总了PHP中Nette\Http\IResponse类的典型用法代码示例。如果您正苦于以下问题:PHP IResponse类的具体用法?PHP IResponse怎么用?PHP IResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Sends response to output.
* @return void
*/
public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
{
$httpResponse->setContentType($this->contentType);
$httpResponse->setHeader('Content-Disposition', ($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->name . '"' . '; filename*=utf-8\'\'' . rawurlencode($this->name));
$length = strlen($this->data);
/*
if ($this->resuming) {
$httpResponse->setHeader('Accept-Ranges', 'bytes');
if (preg_match('#^bytes=(\d*)-(\d*)\z#', $httpRequest->getHeader('Range'), $matches)) {
list(, $start, $end) = $matches;
if ($start === '') {
$start = max(0, $filesize - $end);
$end = $filesize - 1;
} elseif ($end === '' || $end > $filesize - 1) {
$end = $filesize - 1;
}
if ($end < $start) {
$httpResponse->setCode(416); // requested range not satisfiable
return;
}
$httpResponse->setCode(206);
$httpResponse->setHeader('Content-Range', 'bytes ' . $start . '-' . $end . '/' . $filesize);
$length = $end - $start + 1;
fseek($handle, $start);
} else {
$httpResponse->setHeader('Content-Range', 'bytes 0-' . ($filesize - 1) . '/' . $filesize);
}
}*/
$httpResponse->setHeader('Content-Length', $length);
echo $this->data;
}
示例2: send
/**
* {inheritDoc}
*/
public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
{
$httpResponse->setContentType($this->getContentType(), 'utf-8');
$httpResponse->setExpiration(FALSE);
$httpResponse->setCode($this->code);
echo Nette\Utils\Json::encode($this->getPayload(), Nette\Utils\Json::PRETTY);
}
示例3: generateImage
public function generateImage(ImageRequest $request)
{
$width = $request->getWidth();
$height = $request->getHeight();
$format = $request->getFormat();
if (!$this->validator->validate($width, $height)) {
throw new Application\BadRequestException();
}
$image = NULL;
foreach ($this->providers as $provider) {
$image = $provider->getImage($request);
if ($image) {
break;
}
}
if (!$image) {
$this->httpResponse->setHeader('Content-Type', 'image/jpeg');
$this->httpResponse->setCode(Http\IResponse::S404_NOT_FOUND);
exit;
}
$destination = $this->wwwDir . '/' . $this->httpRequest->getUrl()->getRelativeUrl();
$dirname = dirname($destination);
if (!is_dir($dirname)) {
$success = @mkdir($dirname, 0777, TRUE);
if (!$success) {
throw new Application\BadRequestException();
}
}
$success = $image->save($destination, 90, $format);
if (!$success) {
throw new Application\BadRequestException();
}
$image->send();
exit;
}
示例4: send
/**
* @param IRequest $httpRequest
* @param IResponse $httpResponse
* @return void
*/
public function send(IRequest $httpRequest, IResponse $httpResponse)
{
$httpResponse->setCode($this->code);
foreach ($this->headers as $name => $value) {
$httpResponse->setHeader($name, $value);
}
echo (string) $this->getBody();
}
示例5: send
/**
* @param Nette\Http\IRequest $httpRequest
* @param Nette\Http\IResponse $httpResponse
*/
function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
{
$response = $this->getResponse();
$httpResponse->setCode(200);
$httpResponse->setContentType('text/plain');
$httpResponse->setHeader('Content-Length', strlen($response));
echo $response;
}
示例6: send
/**
* @param Http\IRequest $request
* @param Http\IResponse $response
*/
public function send(Http\IRequest $request, Http\IResponse $response)
{
$response->setContentType($this->contentType);
$response->setCode($this->code ?: Http\IResponse::S200_OK);
$response->setExpiration($this->expiration);
$response->setHeader('Pragma', $this->expiration ? 'cache' : 'no-cache');
echo Json::encode($this->data);
}
示例7: send
/**
* {@inheritdoc}
*/
public function send(IRequest $httpRequest, IResponse $httpResponse)
{
$httpResponse->setContentType('text/xml');
$httpResponse->setExpiration(false);
$httpResponse->setCode($this->getCode());
$httpResponse->setHeader('Content-Length', strlen($this->response));
echo $this->response;
}
示例8: send
/**
* Send JSONP response to output
* @param IRequest $httpRequest
* @param IResponse $httpResponse
* @throws \Drahak\Restful\InvalidArgumentException
*/
public function send(IRequest $httpRequest, IResponse $httpResponse)
{
$httpResponse->setContentType($this->contentType ? $this->contentType : 'application/javascript', 'UTF-8');
$data = array();
$data['response'] = $this->data;
$data['status'] = $httpResponse->getCode();
$data['headers'] = $httpResponse->getHeaders();
$callback = $httpRequest->getQuery('jsonp') ? Strings::webalize($httpRequest->getQuery('jsonp'), NULL, FALSE) : '';
echo $callback . '(' . $this->mapper->stringify($data, $this->isPrettyPrint()) . ');';
}
示例9: send
/**
* @param Nette\Http\IRequest $httpRequest
* @param Nette\Http\IResponse $httpResponse
* @throws \Nette\Application\BadRequestException
*/
public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
{
$httpResponse->setContentType($this->contentType);
$httpResponse->setExpiration(FALSE);
$callback = $httpRequest->getQuery(self::$callbackName);
if (is_null($callback)) {
throw new \Nette\Application\BadRequestException("Invalid JSONP request.");
}
echo $callback . "(" . Nette\Utils\Json::encode($this->payload) . ")";
}
示例10: send
/**
* Sends response to output.
* @param IRequest $request
* @param IResponse $response
*/
public function send(IRequest $request, IResponse $response)
{
// Set response headers for the file download
$response->setHeader('Content-Length', $this->stream->getSize());
$response->setHeader('Content-Type', $this->contentType);
$response->setHeader('Content-Disposition', 'attachment; filename="' . $this->name . '";');
while (!$this->stream->eof()) {
echo $this->stream->read(4000000.0);
}
$this->stream->close();
}
示例11: send
/**
* Sends response to output.
* @return void
*/
public function send(IRequest $httpRequest, \Nette\Http\IResponse $httpResponse)
{
if ($this->error) {
$this->payload = ['error' => TRUE, 'message' => $this->errorMessage];
} else {
$this->payload['error'] = FALSE;
}
$httpResponse->setContentType($this->contentType);
$httpResponse->setExpiration(FALSE);
echo Json::encode($this->payload);
}
示例12: send
/**
* Sends response to output.
*
* @param \Nette\Http\IRequest $httpRequest
* @param \Nette\Http\IResponse $httpResponse
*/
public function send(\Nette\Http\IRequest $httpRequest, \Nette\Http\IResponse $httpResponse)
{
if (strlen($this->etag)) {
$httpResponse->setHeader('Etag', $this->etag);
}
$httpResponse->setExpiration(\Nette\Http\IResponse::PERMANENT);
if (($inm = $httpRequest->getHeader('if-none-match')) && $inm == $this->etag) {
$httpResponse->setCode(\Nette\Http\IResponse::S304_NOT_MODIFIED);
return;
}
$httpResponse->setContentType($this->contentType);
echo $this->content;
}
示例13: send
function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
{
if ($this->isAmfRequest($httpRequest)) {
$httpResponse->setContentType('application/x-amf');
$this->manager->sendResponse();
} else {
$responses = $this->manager->getResponses();
if (count($responses) === 1) {
$responses = array_shift($responses);
}
$response = new Nette\Application\Responses\JsonResponse($responses);
$response->send($httpRequest, $httpResponse);
}
}
示例14: sendStorageFile
/**
* Sends chunked response to output.
*
* @param \MouseOver\Storage\IStorageFile $storageFile Storage file
* @param \Nette\Http\IRequest $httpRequest HTTP request
* @param \Nette\Http\IResponse $httpResponse HTTP response
*
* @return void
*/
protected function sendStorageFile($storageFile, Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
{
$httpResponse->setHeader('Accept-Ranges', 'bytes');
$reader = $storageFile->getReader();
if (preg_match('#^bytes=(\\d*)-(\\d*)\\z#', $httpRequest->getHeader('Range'), $matches)) {
list(, $start, $end) = $matches;
if ($start === '') {
$start = null;
}
if ($end === '') {
$end = null;
}
try {
$reader->setRange($start, $end);
} catch (\InvalidArgumentException $invalidArgumentException) {
$httpResponse->setCode(416);
// requested range not satisfiable
return;
}
$httpResponse->setCode(206);
$httpResponse->setHeader('Content-Range', 'bytes ' . $reader->getRangeStart() . '-' . $reader->getRangeEnd() . '/' . $reader->getFileSize());
$reader->setRange($start, $end);
$httpResponse->setHeader('Content-Length', $reader->getLength());
} else {
$httpResponse->setHeader('Content-Range', 'bytes 0-' . ($reader->getFileSize() - 1) . '/' . $reader->getFileSize());
$httpResponse->setHeader('Content-Length', $reader->getLength());
}
while ($reader->hasContent()) {
echo $reader->read();
}
}
示例15: send
/**
* Sends response to output.
* @param Nette\Http\IRequest $httpRequest
* @param Nette\Http\IResponse $httpResponse
*/
function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
{
$httpResponse->setContentType('application/pdf');
$httpResponse->setHeader('Content-Disposition', 'inline; filename="' . basename($this->filePath) . '"');
$httpResponse->setHeader('Content-Description', 'File Transfer');
$httpResponse->setHeader('Connection', 'Keep-Alive');
$httpResponse->setHeader('Expires', '0');
$httpResponse->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
$httpResponse->setHeader('Pragma', 'public');
$httpResponse->setHeader('Content-Length', filesize($this->filePath));
readfile($this->filePath);
}