Permalink
Browse files

Docs, refactoring

  • Loading branch information...
kakserpom committed Mar 19, 2013
1 parent 32855fe commit 7d905172e180bf6b26bb848f954eaeb1a8abd5ab
Showing with 72 additions and 30 deletions.
  1. +62 −19 lib/HTTPRequest.php
  2. +10 −11 lib/Request.php
View
@@ -85,11 +85,10 @@ class HTTPRequest extends Request {
/**
* Preparing before init
- * @todo protected?
* @param object Source request
* @return void
*/
- public function preinit($req) {
+ protected function preinit($req) {
if ($req === null) {
$req = new \stdClass;
$req->attrs = new \stdClass;
@@ -145,10 +144,9 @@ public function sendfile($path, $cb, $pri = EIO_PRI_DEFAULT) {
/**
* Called to check if ready
- * @todo protected?
* @return void
*/
- public function checkIfReady() {
+ protected function checkIfReady() {
if (!$this->attrs->params_done || !$this->attrs->stdin_done) {
return false;
}
@@ -417,8 +415,7 @@ public function onParsedParams() { }
/**
* Outputs data with headers (split by \r\n\r\n)
- * @todo description missed (what is the difference between this and out()) ?
- * @param string String to out
+ * @param string
* @return boolean Success.
*/
public function combinedOut($s) {
@@ -613,30 +610,48 @@ public function header($s, $replace = true, $code = false) {
}
/**
- * @todo description missing
+ * Converts human-readable representation of size to number of bytes
+ * @return integer
*/
- public function parseSize($value) {
- $l = strtolower(substr($value, -1));
+ public static function parseSize($value) {
+ $l = substr($value, -1);
- if ($l === 'b') {
+ if ($l === 'b' || $l === 'B') {
return ((int) substr($value, 0, -1));
}
if ($l === 'k') {
+ return ((int) substr($value, 0, -1) * 1000);
+ }
+
+ if ($l === 'K') {
return ((int) substr($value, 0, -1) * 1024);
}
if ($l === 'm') {
+ return ((int) substr($value, 0, -1) * 1000 * 1000);
+ }
+
+ if ($l === 'M') {
return ((int) substr($value, 0, -1) * 1024 * 1024);
}
if ($l === 'g') {
+ return ((int) substr($value, 0, -1) * 1000 * 1000 * 1000);
+ }
+
+ if ($l === 'G') {
return ((int) substr($value, 0, -1) * 1024 * 1024 * 1024);
}
+
return (int) $value;
}
- protected function startUploadFile() {
+ /**
+ * Called when file upload started.
+ * @return void
+ */
+ protected function onUploadFileStart() {
$this->upstream->freezeInput();
$this->frozenInput = true;
FS::tempnam(ini_get('upload_tmp_dir'), 'php', function ($fp) {
@@ -652,7 +667,31 @@ protected function startUploadFile() {
$this->stdin('');
});
}
- protected function writeUploadChunk($chunk, $last = false) {
+
+ /**
+ * Alias of onUploadFileStart. To be removed in 1.0.
+ * @return void
+ */
+ protected function startUploadFile() {
+ $this->onUploadFileStart();
+ }
+
+ /**
+ * Alias of onUploadFileChunk. To be removed in 1.0.
+ * @return void
+ */
+ protected function writeUploadChunk() {
+ $this->onUploadFileChunk();
+
+ }
+
+ /**
+ * Called when chunk of incoming file has arrived.
+ * @param string Chunk data
+ * @param boolean Last?
+ * @return void
+ */
+ protected function onUploadFileChunk($chunk, $last = false) {
if ($this->mpartcurrent['error'] !== UPLOAD_ERR_OK) {
// just drop the chunk
return;
@@ -735,7 +774,7 @@ public function parseStdin() {
'size' => 0,
);
$this->mpartcurrent = &$this->attrs->files[$name];
- $this->startUploadFile();
+ $this->onUploadFileStart();
$this->mpartstate = self::MPSTATE_UPLOAD;
} else {
$this->mpartcurrent = &$this->attrs->post[$name];
@@ -791,7 +830,7 @@ public function parseStdin() {
if (!isset($this->mpartcurrent['fp'])) {
return; // fd is not ready yet, interrupt
}
- $this->writeUploadChunk($chunk, true);
+ $this->onUploadFileChunk($chunk, true);
$this->mpartcurrent['size'] += strlen($chunk);
}
@@ -830,7 +869,7 @@ public function parseStdin() {
$this->mpartcurrent['error'] = UPLOAD_ERR_FORM_SIZE;
}
- $this->writeUploadChunk($chunk);
+ $this->onUploadFileChunk($chunk);
}
$this->mpartoffset = $p;
@@ -929,10 +968,10 @@ public static function parse_str($s, &$var, $header = false) {
}
/**
- * @todo description missing
- * @todo protected?
+ * Called after request finish
+ * @return void
*/
- public function postFinishHandler() {
+ protected function postFinishHandler() {
if (!$this->headers_sent) {
$this->out('');
}
@@ -949,7 +988,11 @@ public function postFinishHandler() {
}
}
- public function sessionCommit() {
+ /**
+ * Commits the session
+ * @return void
+ */
+ protected function sessionCommit() {
session_commit();
}
}
View
@@ -138,7 +138,7 @@ public function setPriority($p) {
* @param object Source request
* @return void
*/
- public function preinit($req)
+ protected function preinit($req)
{
if ($req === NULL) {
$req = new stdClass;
@@ -309,8 +309,8 @@ public function wakeup() {
* Called by call() to check if ready
* @return boolean Ready?
*/
- public function checkIfReady() {
- return TRUE;
+ protected function checkIfReady() {
+ return true;
}
/**
@@ -435,14 +435,13 @@ public function finish($status = 0, $zombie = FALSE) {
}
}
-
- public function postFinishHandler() { }
-
- public function onDestruct() {}
-
- public function __destruct() {
- $this->onDestruct();
- }
+
+ /**
+ * Called after request finish
+ * @return void
+ */
+ protected function postFinishHandler() { }
+
}
class RequestSleepException extends Exception {}

0 comments on commit 7d90517

Please sign in to comment.