示例#1
0
 /**
  * Whether the client accepts compressed content.
  *
  * @return bool  if client accepts compressed content.
  */
 protected function clientAcceptsCompression()
 {
     if ($this->server->exists('HTTP_ACCEPT_ENCODING')) {
         $accept = $this->server->asScalar('HTTP_ACCEPT_ENCODING')->uncage();
         return strpos($accept, 'gzip') !== false;
     }
     return false;
 }
示例#2
0
 /**
  * Whether the client already has a current copy.
  *
  * @return bool whether the client copy is current
  */
 protected function isCurrent()
 {
     // if either header is missing, treat as not current.
     if (!$this->server->exists('HTTP_IF_MODIFIED_SINCE') || !$this->server->exists('HTTP_IF_NONE_MATCH')) {
         return false;
     }
     // extract both headers
     try {
         $modified = $this->server->asScalar('HTTP_IF_MODIFIED_SINCE')->filter(new T_Validate_UnixDate())->uncage();
         $etag = $this->server->asScalar('HTTP_IF_NONE_MATCH')->filter('mb_trim')->filter('mb_strtolower')->uncage();
     } catch (T_Exception_Filter $e) {
         // retrieval failed, deliver full content.
         return false;
     }
     // compare headers with current data
     if ($modified < $this->lm || strcmp($etag, $this->getEtag()) !== 0) {
         return false;
         // old content
     }
     return true;
 }
示例#3
0
 /**
  * Whether the field is submitted in a particular array cage.
  *
  * @param T_Cage_Array $source  source array to check
  * @return bool  whether hidden value is submitted
  */
 function isSubmitted(T_Cage_Array $source)
 {
     return $source->exists($this->getFieldname());
 }
示例#4
0
 function testIsset()
 {
     $cage = new T_Cage_Array(array('b' => 1));
     $this->assertTrue($cage->exists('b'));
     $this->assertFalse($cage->exists('a'));
 }
示例#5
0
 /**
  * Whether the field is submitted in a particular array cage.
  *
  * @param T_Cage_Array $source  source array to check
  * @return bool  whether a non-zero length value has been submitted
  */
 function isSubmitted(T_Cage_Array $source)
 {
     $submitted = $source->exists($this->getFieldname());
     if ($submitted) {
         if ($this->as_scalar) {
             $cage = $source->asScalar($this->getFieldname());
             $submitted = strlen($cage->uncage()) > 0;
         } else {
             $cage = $source->asArray($this->getFieldname());
             $submitted = count($cage->uncage()) > 0;
         }
     }
     return $submitted;
 }
示例#6
0
 /**
  * Detects whether the request is HTTPS
  *
  * @param T_Cage_Array $server  server superglobal data
  * @return bool  whether the request has been made over a secure connection
  */
 protected function isSsl(T_Cage_Array $server)
 {
     // extract HTTPS status and port number from $_SERVER
     $https = null;
     if ($server->exists('HTTPS')) {
         $https = $server->asScalar('HTTPS')->uncage();
     }
     $port = null;
     if ($server->exists('SERVER_PORT')) {
         $port = $server->asScalar('SERVER_PORT')->filter(new T_Validate_Int())->uncage();
     }
     // test data
     return strcasecmp($https, 'on') === 0 || $https == 1 || $port == 443;
 }