Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • None
  • PHP

Classes

  • Context
  • FileUpload
  • Request
  • RequestFactory
  • Response
  • Session
  • SessionSection
  • Url
  • UrlScript
  • User

Interfaces

  • IRequest
  • IResponse
  • ISessionStorage
  • IUser
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette\Http;
 13: 
 14: use Nette;
 15: 
 16: 
 17: 
 18: /**
 19:  * HTTP-specific tasks.
 20:  *
 21:  * @author     David Grudl
 22:  */
 23: class Context extends Nette\Object
 24: {
 25:     /** @var IRequest */
 26:     private $request;
 27: 
 28:     /** @var IResponse */
 29:     private $response;
 30: 
 31: 
 32: 
 33:     public function __construct(IRequest $request, IResponse $response)
 34:     {
 35:         $this->request = $request;
 36:         $this->response = $response;
 37:     }
 38: 
 39: 
 40: 
 41:     /**
 42:      * Attempts to cache the sent entity by its last modification date.
 43:      * @param  string|int|DateTime  last modified time
 44:      * @param  string  strong entity tag validator
 45:      * @return bool
 46:      */
 47:     public function isModified($lastModified = NULL, $etag = NULL)
 48:     {
 49:         if ($lastModified) {
 50:             $this->response->setHeader('Last-Modified', $this->response->date($lastModified));
 51:         }
 52:         if ($etag) {
 53:             $this->response->setHeader('ETag', '"' . addslashes($etag) . '"');
 54:         }
 55: 
 56:         $ifNoneMatch = $this->request->getHeader('If-None-Match');
 57:         if ($ifNoneMatch === '*') {
 58:             $match = TRUE; // match, check if-modified-since
 59: 
 60:         } elseif ($ifNoneMatch !== NULL) {
 61:             $etag = $this->response->getHeader('ETag');
 62: 
 63:             if ($etag == NULL || strpos(' ' . strtr($ifNoneMatch, ",\t", '  '), ' ' . $etag) === FALSE) {
 64:                 return TRUE;
 65: 
 66:             } else {
 67:                 $match = TRUE; // match, check if-modified-since
 68:             }
 69:         }
 70: 
 71:         $ifModifiedSince = $this->request->getHeader('If-Modified-Since');
 72:         if ($ifModifiedSince !== NULL) {
 73:             $lastModified = $this->response->getHeader('Last-Modified');
 74:             if ($lastModified != NULL && strtotime($lastModified) <= strtotime($ifModifiedSince)) {
 75:                 $match = TRUE;
 76: 
 77:             } else {
 78:                 return TRUE;
 79:             }
 80:         }
 81: 
 82:         if (empty($match)) {
 83:             return TRUE;
 84:         }
 85: 
 86:         $this->response->setCode(IResponse::S304_NOT_MODIFIED);
 87:         return FALSE;
 88:     }
 89: 
 90: 
 91: 
 92:     /**
 93:      * @return IRequest
 94:      */
 95:     public function getRequest()
 96:     {
 97:         return $this->request;
 98:     }
 99: 
100: 
101: 
102:     /**
103:      * @return IResponse
104:      */
105:     public function getResponse()
106:     {
107:         return $this->response;
108:     }
109: 
110: }
111: 
Nette Framework 2.0beta1 API API documentation generated by ApiGen 2.3.0