当前位置: 首页>>代码示例>>PHP>>正文


PHP IResponse::setCode方法代码示例

本文整理汇总了PHP中Nette\Http\IResponse::setCode方法的典型用法代码示例。如果您正苦于以下问题:PHP IResponse::setCode方法的具体用法?PHP IResponse::setCode怎么用?PHP IResponse::setCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\Http\IResponse的用法示例。


在下文中一共展示了IResponse::setCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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();
     }
 }
开发者ID:mouse-over,项目名称:storage,代码行数:40,代码来源:StorageFileResponse.php

示例2: 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;
 }
开发者ID:kuba1999,项目名称:nette-webimages,代码行数:35,代码来源:Generator.php

示例3: 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);
 }
开发者ID:ublaboo,项目名称:responses,代码行数:10,代码来源:JsonPrettyResponse.php

示例4: 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;
 }
开发者ID:minetro,项目名称:mobilni-platby,代码行数:12,代码来源:Response.php

示例5: 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();
 }
开发者ID:lookyman,项目名称:nette-oauth2-server,代码行数:13,代码来源:Response.php

示例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);
 }
开发者ID:dzibma,项目名称:rest-api,代码行数:12,代码来源:JsonResponse.php

示例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;
 }
开发者ID:tomaj,项目名称:nette-api,代码行数:11,代码来源:XmlApiResponse.php

示例8: terminateWithCode

 /**
  * Terminates current request and sends HTTP response with
  * code and optionaly payload formatted for requested output content type
  *
  * @throws AbortException
  */
 public function terminateWithCode($code, $payload = NULL)
 {
     $this->httpResponse->setCode($code);
     if (func_num_args() == 1) {
         $this->response = $this->createResponse();
     } else {
         $this->response = $this->createResponse($payload);
     }
     throw new AbortException();
 }
开发者ID:vbuilder,项目名称:framework,代码行数:16,代码来源:Presenter.php

示例9: isModified

	/**
	 * Attempts to cache the sent entity by its last modification date.
	 * @param  string|int|\DateTime  last modified time
	 * @param  string  strong entity tag validator
	 * @return bool
	 */
	public function isModified($lastModified = NULL, $etag = NULL)
	{
		if ($lastModified) {
			$this->response->setHeader('Last-Modified', $this->response->date($lastModified));
		}
		if ($etag) {
			$this->response->setHeader('ETag', '"' . addslashes($etag) . '"');
		}

		$ifNoneMatch = $this->request->getHeader('If-None-Match');
		if ($ifNoneMatch === '*') {
			$match = TRUE; // match, check if-modified-since

		} elseif ($ifNoneMatch !== NULL) {
			$etag = $this->response->getHeader('ETag');

			if ($etag == NULL || strpos(' ' . strtr($ifNoneMatch, ",\t", '  '), ' ' . $etag) === FALSE) {
				return TRUE;

			} else {
				$match = TRUE; // match, check if-modified-since
			}
		}

		$ifModifiedSince = $this->request->getHeader('If-Modified-Since');
		if ($ifModifiedSince !== NULL) {
			$lastModified = $this->response->getHeader('Last-Modified');
			if ($lastModified != NULL && strtotime($lastModified) <= strtotime($ifModifiedSince)) {
				$match = TRUE;

			} else {
				return TRUE;
			}
		}

		if (empty($match)) {
			return TRUE;
		}

		$this->response->setCode(IResponse::S304_NOT_MODIFIED);
		return FALSE;
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:48,代码来源:Context.php

示例10: doProcessException

 public function doProcessException($e)
 {
     if (!$e instanceof BadRequestException && $this->httpResponse instanceof Response) {
         $this->httpResponse->warnOnBuffer = false;
     }
     if (!$this->httpResponse->isSent()) {
         $this->httpResponse->setCode($e instanceof BadRequestException ? $e->getCode() ?: 404 : 500);
     }
     $requests = $this->getRequests();
     $request = end($requests) ?: $this->initialRequest;
     $args = ['exception' => $e, 'request' => $request];
     $errorPresenter = $request ? $this->findErrorPresenter($request->getPresenterName()) : $this->errorPresenter;
     if ($this->getPresenter() instanceof Presenter) {
         try {
             $this->getPresenter()->forward(":{$errorPresenter}:", $args);
         } catch (AbortException $_) {
             $this->processRequest($this->getPresenter()->getLastCreatedRequest());
         }
     } else {
         $this->processRequest(new Request($errorPresenter, Request::FORWARD, $args));
     }
 }
开发者ID:enumag,项目名称:application,代码行数:22,代码来源:AbstractApplication.php

示例11: 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;
 }
开发者ID:lohini,项目名称:webloader,代码行数:19,代码来源:WebLoaderResponse.php

示例12: send

 /**
  * Sends response to output.
  *
  * @param Http\IRequest $httpRequest
  * @param Http\IResponse $httpResponse
  */
 public function send(Http\IRequest $httpRequest, Http\IResponse $httpResponse)
 {
     $httpResponse->setExpiration(Http\IResponse::PERMANENT);
     if (($inm = $httpRequest->getHeader('if-none-match')) && $inm == $this->etag) {
         $httpResponse->setCode(Http\IResponse::S304_NOT_MODIFIED);
         return;
     }
     $httpResponse->setContentType(AssetsLoader\Files\MimeMapper::getMimeFromFilename($this->filePath));
     $httpResponse->setHeader('Content-Transfer-Encoding', 'binary');
     $httpResponse->setHeader('Content-Length', filesize($this->filePath));
     $httpResponse->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->filePath) . '"');
     $httpResponse->setHeader('Access-Control-Allow-Origin', '*');
     // Read the file
     readfile($this->filePath);
 }
开发者ID:ales-zrak,项目名称:assets-loader,代码行数:21,代码来源:FileResponse.php

示例13: 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', 'inline; filename="' . $this->name . '"');
     $filesize = $length = filesize($this->file);
     $handle = fopen($this->file, 'r');
     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);
     while (!feof($handle) && $length > 0) {
         echo $s = fread($handle, min(4000000.0, $length));
         $length -= strlen($s);
     }
     fclose($handle);
 }
开发者ID:dobryweb,项目名称:nette-ext,代码行数:40,代码来源:FileViewResponse.php

示例14: processException

 /**
  * @return void
  */
 public function processException(\Exception $e)
 {
     if (!$this->httpResponse->isSent()) {
         $this->httpResponse->setCode($e instanceof BadRequestException ? $e->getCode() ?: 404 : 500);
     }
     $args = array('exception' => $e, 'request' => end($this->requests) ?: NULL);
     if ($this->presenter instanceof UI\Presenter) {
         try {
             $this->presenter->forward(":{$this->errorPresenter}:", $args);
         } catch (AbortException $foo) {
             $this->processRequest($this->presenter->getLastCreatedRequest());
         }
     } else {
         $this->processRequest(new Request($this->errorPresenter, Request::FORWARD, $args));
     }
 }
开发者ID:rostenkowski,项目名称:nette,代码行数:19,代码来源:Application.php

示例15: sendError

 /**
  * Send error to image
  *
  * @param \Nette\Http\IResponse $response
  * @param string|\Exception $error
  */
 private function sendError(HttpResponse $response, $error, $width, $height)
 {
     $response->setCode(HttpResponse::S500_INTERNAL_SERVER_ERROR);
     $response->setContentType('image/gif');
     if (!$error instanceof \Exception) {
         $response->setHeader('X-Imager-Error-Message', $error);
     } else {
         $response->setHeader('X-Imager-Error-Message', get_class($error) . ': ' . $error->getMessage());
         // detailed information only in debug mode
         if ($this->factory->getDebugger()) {
             $response->setHeader('X-Imager-Error-File', $error->getFile() . ' (' . $error->getLine() . ')');
             $trace = $error->getTraceAsString();
             $trace = Strings::replace($trace, '~[\\n|\\n\\r]~', '>>>');
             $response->setHeader('X-Imager-Error-Trace', $trace);
         }
     }
     $this->factory->sendErrorImage($width, $height);
 }
开发者ID:lawondyss,项目名称:imager,代码行数:24,代码来源:ImageResponse.php


注:本文中的Nette\Http\IResponse::setCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。