Moodle  2.2.1
http://www.collinsharper.com
HTTP_Encoder Class Reference

Public Member Functions

 __construct ($spec)
 getContent ()
 getHeaders ()
 sendHeaders ()
 sendAll ()
 encode ($compressionLevel=null)

Static Public Member Functions

static getAcceptedEncoding ($allowCompress=true, $allowDeflate=true)
static output ($content, $compressionLevel=null)

Static Public Attributes

static $encodeToIe6 = false
static $compressionLevel = 6

Static Protected Member Functions

static _isBuggyIe ()

Protected Attributes

 $_content = ''
 $_headers = array()
 $_encodeMethod = array('', '')

Detailed Description

Definition at line 46 of file Encoder.php.


Constructor & Destructor Documentation

__construct ( spec)

Get an HTTP Encoder object

Parameters:
array$specoptions

'content': (string required) content to be encoded

'type': (string) if set, the Content-Type header will have this value.

'method: (string) only set this if you are forcing a particular encoding method. If not set, the best method will be chosen by getAcceptedEncoding() The available methods are 'gzip', 'deflate', 'compress', and '' (no encoding)

Returns:
null

Definition at line 91 of file Encoder.php.

Here is the call graph for this function:


Member Function Documentation

static _isBuggyIe ( ) [static, protected]

Is the browser an IE version earlier than 6 SP2?

Definition at line 312 of file Encoder.php.

encode ( compressionLevel = null)

Encode (compress) the content

If the encode method is '' (none) or compression level is 0, or the 'zlib' extension isn't loaded, we return false.

Then the appropriate gz_* function is called to compress the content. If this fails, false is returned.

The header "Vary: Accept-Encoding" is added. If encoding is successful, the Content-Length header is updated, and Content-Encoding is also added.

Parameters:
int$compressionLevelgiven to zlib functions. If not given, the class default will be used.
Returns:
bool success true if the content was actually compressed

Definition at line 254 of file Encoder.php.

static getAcceptedEncoding ( allowCompress = true,
allowDeflate = true 
) [static]

Determine the client's best encoding method from the HTTP Accept-Encoding header.

If no Accept-Encoding header is set, or the browser is IE before v6 SP2, this will return ('', ''), the "identity" encoding.

A syntax-aware scan is done of the Accept-Encoding, so the method must be non 0. The methods are favored in order of gzip, deflate, then compress. Deflate is always smallest and generally faster, but is rarely sent by servers, so client support could be buggier.

Parameters:
bool$allowCompressallow the older compress encoding
bool$allowDeflateallow the more recent deflate encoding
Returns:
array two values, 1st is the actual encoding method, 2nd is the alias of that method to use in the Content-Encoding header (some browsers call gzip "x-gzip" etc.)

Definition at line 193 of file Encoder.php.

Here is the caller graph for this function:

Get content in current form

Call after encode() for encoded content.

return string

Definition at line 114 of file Encoder.php.

Get array of output headers to be sent

E.g. array( 'Content-Length' => '615' ,'Content-Encoding' => 'x-gzip' ,'Vary' => 'Accept-Encoding' )

Returns:
array

Definition at line 133 of file Encoder.php.

static output ( content,
compressionLevel = null 
) [static]

Encode and send appropriate headers and content

This is a convenience method for common use of the class

Parameters:
string$content
int$compressionLevelgiven to zlib functions. If not given, the class default will be used.
Returns:
bool success true if the content was actually compressed

Definition at line 294 of file Encoder.php.

sendAll ( )

Send output headers and content

A shortcut for sendHeaders() and echo getContent()

You must call this before headers are sent and it probably cannot be used in conjunction with zlib output buffering / mod_gzip. Errors are not handled purposefully.

Returns:
null

Definition at line 167 of file Encoder.php.

Here is the call graph for this function:

Send output headers

You must call this before headers are sent and it probably cannot be used in conjunction with zlib output buffering / mod_gzip. Errors are not handled purposefully.

See also:
getHeaders()
Returns:
null

Definition at line 149 of file Encoder.php.

Here is the caller graph for this function:


Field Documentation

$_content = '' [protected]

Definition at line 305 of file Encoder.php.

$_encodeMethod = array('', '') [protected]

Definition at line 307 of file Encoder.php.

$_headers = array() [protected]

Definition at line 306 of file Encoder.php.

$compressionLevel = 6 [static]

Definition at line 72 of file Encoder.php.

$encodeToIe6 = false [static]

Definition at line 62 of file Encoder.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations