PHP Class PHPDaemon\HTTPRequest\Generic

Author: Vasily Zorin ([email protected])
Inheritance: extends PHPDaemon\Request\Generic, use trait PHPDaemon\Traits\DeferredEventHandlers, use trait PHPDaemon\Traits\Sessions
Mostra file Open project: kakserpom/phpdaemon Class Usage Examples

Public Properties

Property Type Description
$htr State
$hvaltr Replacement pairs for processing some header values in parse_str()
$keepalive Keepalive?
$responseLength Current response length

Protected Properties

Property Type Description
$codes Status codes
$contentLength Content length from header() method
$contype Content type parameters
$cookieNum Number of outgoing cookie-headers
$frozenInput Frozen input?
$headers Outgoing headers
$headers_sent Headers sent?
$headers_sent_file File name where output started in the file and line variables
$headers_sent_line Line number where output started in the file and line variables
$sendfp File pointer to send output (X-Sendfile)

Public Methods

Method Description
checkIfReady ( ) : boolean Called to check if Request is ready
chunked ( ) : void Use chunked encoding
combinedOut ( string $s ) : boolean Outputs data with headers (split by \r\n\r\n)
ensureSentHeaders ( ) : boolean Ensure that headers are sent
firstDeferredEventUsed ( ) : void Called when first deferred event used
getUploadMaxSize ( ) : integer Upload maximum file size
getUploadTempDir ( ) : string Returns path to directory of temporary upload files
header ( string $s, boolean $replace = true, integer $code = false ) : boolean Send the header
headersList ( ) : array Return current list of headers
headersSent ( &$file, &$line ) : boolean Checks if headers have been sent
isUploadedFile ( string $path ) : boolean Tells whether the file was uploaded via HTTP POST
moveUploadedFile ( string $filename, string $dest ) : boolean Moves an uploaded file to a new location
onParsedParams ( ) : void Called when request's headers parsed
onSleep ( ) : void Called when the request starts sleep
onUploadFileChunk ( Input $in, boolean $last = false ) : void Called when chunk of incoming file has arrived
onUploadFileStart ( Input $in ) : void Called when file upload started
onWakeup ( ) : void Called when the request wakes up
out ( string $s, boolean $flush = true ) : boolean Output some data
parseSize ( string $value ) : integer Converts human-readable representation of size to number of bytes
parseStr ( string $s, &$var, boolean $header = false ) : void Replacement for default parse_str(), it supoorts UCS-2 like this: %uXXXX
postPrepare ( ) : void Prepares the request body
readBodyFile ( ) : boolean Read request body from the file given in REQUEST_BODY_FILE parameter
removeHeader ( string $s ) : void Removes a header
sendfile ( string $path, callable $cb, integer $pri = EIO_PRI_DEFAULT ) : boolean Output whole contents of file
setcookie ( string $name, string $value = '', integer $maxage, string $path = '', string $domain = '', boolean $secure = false, boolean $HTTPOnly = false ) : void Set the cookie
status ( integer $code = 200 ) : boolean Send HTTP-status

Protected Methods

Method Description
freezeInput ( ) : void Freeze input
getCookieStr ( string $name ) : string Get cookie by name
parseParams ( ) : void Parses GET-query string and other request's headers
postFinishHandler ( callable $cb = null ) : void Called after request finish
preinit ( object $req ) : void Preparing before init
unfreezeInput ( ) : void Unfreeze input

Method Details

checkIfReady() public method

Called to check if Request is ready
public checkIfReady ( ) : boolean
return boolean Ready?

chunked() public method

Use chunked encoding
public chunked ( ) : void
return void

combinedOut() public method

Outputs data with headers (split by \r\n\r\n)
public combinedOut ( string $s ) : boolean
$s string Data
return boolean Success

ensureSentHeaders() public method

Ensure that headers are sent
public ensureSentHeaders ( ) : boolean
return boolean Were already sent?

firstDeferredEventUsed() public method

Called when first deferred event used
public firstDeferredEventUsed ( ) : void
return void

freezeInput() protected method

Freeze input
protected freezeInput ( ) : void
return void

getCookieStr() protected method

Get cookie by name
protected getCookieStr ( string $name ) : string
$name string Name of cookie
return string Contents

getUploadMaxSize() public method

Upload maximum file size
public getUploadMaxSize ( ) : integer
return integer

getUploadTempDir() public method

Returns path to directory of temporary upload files
public getUploadTempDir ( ) : string
return string

header() public method

Send the header
public header ( string $s, boolean $replace = true, integer $code = false ) : boolean
$s string Header. Example: 'Location: http://php.net/'
$replace boolean Optional. Replace?
$code integer Optional. HTTP response code
return boolean Success

headersList() public method

Return current list of headers
public headersList ( ) : array
return array Headers

headersSent() public method

Checks if headers have been sent
public headersSent ( &$file, &$line ) : boolean
return boolean Success

isUploadedFile() public method

Tells whether the file was uploaded via HTTP POST
public isUploadedFile ( string $path ) : boolean
$path string The filename being checked
return boolean Whether if this is uploaded file

moveUploadedFile() public method

Moves an uploaded file to a new location
public moveUploadedFile ( string $filename, string $dest ) : boolean
$filename string The filename of the uploaded file
$dest string The destination of the moved file
return boolean Success

onParsedParams() public method

Called when request's headers parsed
public onParsedParams ( ) : void
return void

onSleep() public method

Called when the request starts sleep
public onSleep ( ) : void
return void

onUploadFileChunk() public method

Called when chunk of incoming file has arrived
public onUploadFileChunk ( Input $in, boolean $last = false ) : void
$in Input Input buffer
$last boolean Last?
return void

onUploadFileStart() public method

Called when file upload started
public onUploadFileStart ( Input $in ) : void
$in Input Input buffer
return void

onWakeup() public method

Called when the request wakes up
public onWakeup ( ) : void
return void

out() public method

Output some data
public out ( string $s, boolean $flush = true ) : boolean
$s string String to out
$flush boolean ob_flush?
return boolean Success

parseParams() protected method

Parses GET-query string and other request's headers
protected parseParams ( ) : void
return void

parseSize() public static method

Converts human-readable representation of size to number of bytes
public static parseSize ( string $value ) : integer
$value string String of size
return integer

parseStr() public static method

Replacement for default parse_str(), it supoorts UCS-2 like this: %uXXXX
public static parseStr ( string $s, &$var, boolean $header = false ) : void
$s string String to parse
$header boolean Header-style string
return void

postFinishHandler() protected method

Called after request finish
protected postFinishHandler ( callable $cb = null ) : void
$cb callable Callback
return void

postPrepare() public method

Prepares the request body
public postPrepare ( ) : void
return void

preinit() protected method

Preparing before init
protected preinit ( object $req ) : void
$req object Source request
return void

readBodyFile() public method

Read request body from the file given in REQUEST_BODY_FILE parameter
public readBodyFile ( ) : boolean
return boolean Success

removeHeader() public method

Removes a header
public removeHeader ( string $s ) : void
$s string Header name. Example: 'Location'
return void

sendfile() public method

Output whole contents of file
public sendfile ( string $path, callable $cb, integer $pri = EIO_PRI_DEFAULT ) : boolean
$path string Path
$cb callable Callback
$pri integer Priority
return boolean Success

setcookie() public method

Set the cookie
public setcookie ( string $name, string $value = '', integer $maxage, string $path = '', string $domain = '', boolean $secure = false, boolean $HTTPOnly = false ) : void
$name string Name of cookie
$value string Value
$maxage integer Optional. Max-Age. Default is 0
$path string Optional. Path. Default is empty string
$domain string Optional. Domain. Default is empty string
$secure boolean Optional. Secure. Default is false
$HTTPOnly boolean Optional. HTTPOnly. Default is false
return void

status() public method

Send HTTP-status
public status ( integer $code = 200 ) : boolean
$code integer Code
return boolean Success

unfreezeInput() protected method

Unfreeze input
protected unfreezeInput ( ) : void
return void

Property Details

$codes protected_oe static_oe property

Status codes
protected static $codes

$contentLength protected_oe property

Content length from header() method
protected $contentLength

$contype protected_oe property

Content type parameters
protected $contype

$cookieNum protected_oe property

Number of outgoing cookie-headers
protected $cookieNum

$frozenInput protected_oe property

Frozen input?
protected $frozenInput

$headers protected_oe property

Outgoing headers
protected $headers

$headers_sent protected_oe property

Headers sent?
protected $headers_sent

$headers_sent_file protected_oe property

File name where output started in the file and line variables
protected $headers_sent_file

$headers_sent_line protected_oe property

Line number where output started in the file and line variables
protected $headers_sent_line

$htr public_oe static_oe property

State
public static $htr

$hvaltr public_oe static_oe property

Replacement pairs for processing some header values in parse_str()
public static $hvaltr

$keepalive public_oe property

Keepalive?
public $keepalive

$responseLength public_oe property

Current response length
public $responseLength

$sendfp protected_oe property

File pointer to send output (X-Sendfile)
protected $sendfp