本文整理汇总了PHP中Nette\Http\IRequest::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP IRequest::getHeader方法的具体用法?PHP IRequest::getHeader怎么用?PHP IRequest::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Http\IRequest
的用法示例。
在下文中一共展示了IRequest::getHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createInput
/**
* @return Input
*/
public function createInput()
{
$parser = null;
$type = strtok($this->request->getHeader('Content-Type'), ';');
if ($type && isset($this->parsers[$type])) {
$parser = $this->parsers[$type];
}
return new Input($this->request, $parser);
}
示例2: setState
protected function setState()
{
$this->state = new ArrayHash();
if (!$this->myPresenter || !$this->httpRequest) {
return;
}
$this->state = \Nette\Utils\Json::decode(base64_decode($this->httpRequest->getHeader('X-Nette-Pagestate', base64_encode('{}'))));
$this->redrawControl();
}
示例3: 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();
}
}
示例4: terminateIfNoOlderThan
/**
* Terminates request and sends empty HTTP 304 response if
* given date is less or equal to date send with If-Modified-Since header.
*
* Method takes date as a parameter. Callable returning DateTime is also
* acceptable and recommended in cases when gathering of last modification date
* is difficult. This way the callback will be invoked only if If-Modified-Since
* is present.
*
* @param DateTime|callable
* @throws AbortException
*/
public function terminateIfNoOlderThan($lastModificationDate)
{
if (!$lastModificationDate instanceof \DateTime && !is_callable($lastModificationDate)) {
throw new Nette\InvalidArgumentException("Function accepts only DateTime or callable returning DateTime");
}
$ifModifiedSince = $this->httpRequest->getHeader('If-Modified-Since');
if ($ifModifiedSince === NULL) {
return;
}
$ifDate = vBuilder\Utils\Http::parseDateTime($ifModifiedSince);
// RFC tell us to ignore invalid dates silently
if (!$ifDate) {
return;
}
$ifDate->setTimeZone(new \DateTimeZone(date_default_timezone_get()));
if (is_callable($lastModificationDate)) {
$lastModificationDate = $lastModificationDate();
if (!$lastModificationDate instanceof \DateTime) {
throw new Nette\InvalidArgumentException("Callback has to return DateTime");
}
}
if ($ifDate >= $lastModificationDate) {
$this->terminateWithCode(Nette\Http\IResponse::S304_NOT_MODIFIED);
}
}
示例5: parseRequestBody
/**
* Parse request body if any
* @return array|\Traversable
*
* @throws BadRequestException
*/
protected function parseRequestBody()
{
$requestBody = array();
$input = class_exists('Nette\\Framework') && Nette\Framework::VERSION_ID <= 20200 ? file_get_contents('php://input') : $this->httpRequest->getRawBody();
if ($input) {
try {
$this->mapper = $this->mapperContext->getMapper($this->httpRequest->getHeader('Content-Type'));
$requestBody = $this->mapper->parse($input);
} catch (InvalidStateException $e) {
throw BadRequestException::unsupportedMediaType('No mapper defined for Content-Type ' . $this->httpRequest->getHeader('Content-Type'), $e);
} catch (MappingException $e) {
throw new BadRequestException($e->getMessage(), 400, $e);
}
}
return $requestBody;
}
示例6: isMobile
/**
* Detects mobile browser
*
* @author http://detectmobilebrowsers.com
* @param IRequest $httpRequest
* @return bool
*/
public function isMobile(IRequest $httpRequest)
{
$useragent = $httpRequest->getHeader("user-agent");
if (preg_match('/(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i', $useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i', substr($useragent, 0, 4))) {
return TRUE;
}
return FALSE;
}
示例7: detectHttpMethod
/**
* @param Http\IRequest $httpRequest
* @return string
*/
private function detectHttpMethod(Http\IRequest $httpRequest)
{
$method = $httpRequest->getMethod();
if ($this->headerOverride && $method === Http\IRequest::POST) {
$overriden = $httpRequest->getHeader($this->headerOverride);
$method = $overriden ? strtoupper($overriden) : $method;
}
return $method;
}
示例8: 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;
}
示例9: register
public static function register(\Nette\Http\IRequest $httpRequest, $storageDir, $expire = 3600)
{
if (static::$httpRequest) {
throw new \Nette\InvalidStateException("Multiple file uploader allready registered");
} elseif (!file_exists($storageDir) || !is_writable($storageDir)) {
throw new \Nette\InvalidStateException("Storage dir must be writable");
}
static::$httpRequest = $httpRequest;
static::$storageDir = $storageDir;
static::$expire = $expire;
// process uploaded file
if ($httpRequest->getHeader('X-Nella-MFU-Token') && $httpRequest->getHeader('X-Uploader')) {
$files = $httpRequest->files;
if (isset($files['file']) && $files['file']->ok) {
$token = $httpRequest->getHeader('X-Nella-MFU-Token');
$path = static::$storageDir . "/";
$path .= $token . "_" . time() . "_" . Strings::random(16);
$path .= "." . pathinfo($files['file']->name, PATHINFO_EXTENSION);
$path .= ".tmp";
$files['file']->move($path);
}
echo "{success:true}";
\Nette\Diagnostics\Debugger::$bar = NULL;
exit;
}
// clean expired files
$files = Finder::findFiles("*.tmp")->from(static::$storageDir);
$expire = time() + static::$expire;
foreach ($files as $file) {
if ($file->getMTime() > $expire) {
@unlink($file->getRealPath()); // prevents error
}
}
}
示例10: 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;
}
示例11: getPreferredMethod
/**
* Get prederred method
* @param IRequest $request
* @return string
*/
protected function getPreferredMethod(IRequest $request)
{
$method = $request->getMethod();
$isPost = $method === IRequest::POST;
$header = $request->getHeader(self::OVERRIDE_HEADER);
$param = $request->getQuery(self::OVERRIDE_PARAM);
if ($header && $isPost) {
return $header;
}
if ($param && $isPost) {
return $param;
}
return $request->getMethod();
}
示例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);
}
示例13: processRequest
/**
* Handles incoming request and sets translations.
*/
private function processRequest()
{
if ($this->httpRequest->isMethod('post') && $this->httpRequest->isAjax() && $this->httpRequest->getHeader(self::XHR_HEADER)) {
$data = json_decode(file_get_contents('php://input'));
if ($data) {
$this->translator->setCurrentLang($data->{self::LANGUAGE_KEY});
if ($data->{self::NAMESPACE_KEY}) {
$this->translator->setNamespace($data->{self::NAMESPACE_KEY});
}
unset($data->{self::LANGUAGE_KEY}, $data->{self::NAMESPACE_KEY});
foreach ($data as $string => $translated) {
$this->translator->setTranslation($string, $translated);
}
}
exit;
}
}
示例14: 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 . '"');
$output = NULL;
if ($this->precalculateFileSize) {
ob_start();
Nette\Utils\Callback::invokeArgs($this->outputGenerator);
$output = ob_get_clean();
$filesize = $length = strlen($output);
}
if ($this->resuming && $this->precalculateFileSize) {
$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;
} else {
$httpResponse->setHeader('Content-Range', 'bytes 0-' . ($filesize - 1) . '/' . $filesize);
}
}
if ($this->precalculateFileSize) {
$httpResponse->setHeader('Content-Length', $length);
}
if (isset($start)) {
echo substr($output, $start, $length);
} elseif (isset($output)) {
echo $output;
} else {
Nette\Utils\Callback::invoke($this->outputGenerator);
}
}
示例15: create
/**
* Create new api response
* @param IResource $resource
* @param string|null $contentType
* @return IResponse
*
* @throws InvalidStateException
*/
public function create(IResource $resource, $contentType = NULL)
{
if ($contentType === NULL) {
$contentType = $this->jsonp === FALSE || !$this->request->getQuery($this->jsonp) ? $this->getPreferredContentType($this->request->getHeader('Accept')) : IResource::JSONP;
}
if (!isset($this->responses[$contentType])) {
throw new InvalidStateException('Unregistered API response for ' . $contentType);
}
if (!class_exists($this->responses[$contentType])) {
throw new InvalidStateException('API response class does not exist.');
}
if (!$resource->getData()) {
$this->response->setCode(204);
// No content
}
$responseClass = $this->responses[$contentType];
$response = new $responseClass($resource->getData(), $this->mapperContext->getMapper($contentType), $contentType);
if ($response instanceof BaseResponse) {
$response->setPrettyPrint($this->isPrettyPrint());
}
return $response;
}