/** * Whether the field is submitted in the $_FILES superglobal. * * @param T_Cage_Array $source source array (POST) * @return bool whether a file is submitted */ function isSubmitted(T_Cage_Array $source) { if (!$source instanceof T_Cage_Post) { return false; } $key = $this->getFieldname(); return $source->isFile($key) || $source->isFileError($key); }
/** * 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; }
/** * Encapsulate $_FILES superglobal. * * @param array $files */ function __construct(array $data, array $files) { parent::__construct($data); foreach ($files as $name => $data) { /* check whether an upload attempt was made */ if ($data['error'] == UPLOAD_ERR_NO_FILE) { continue; /* skip */ } $msg = 'An error occurred uploading the file'; /* check uploaded with no error */ if ($data['error'] !== UPLOAD_ERR_OK) { $this->files[$name] = new T_Exception_UploadedFile($msg); continue; } /* check that size > 0 and tmp_name is non-zero */ if ($data['size'] < 1 || strlen($data['tmp_name']) < 1) { $this->files[$name] = new T_Exception_UploadedFile($msg); continue; } /* check is uploaded file */ if (!is_uploaded_file($data['tmp_name'])) { $this->files[$name] = new T_Exception_UploadedFile($msg); continue; } /* valid file */ $this->files[$name] = new T_File_Uploaded($data['tmp_name'], $data['size'], $data['name']); } }
/** * 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; }
/** * 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()); }
function testCanFilterDataOnExtraction() { $f = new T_Test_Filter_ArrayPrefix(); $data = array('One', 'Two'); $cage = new T_Cage_Array($data); $expect = $f->transform($data); $test = $cage->filter($f)->uncage(); $this->assertSame($test, $expect); }
/** * 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; }
/** * 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; }