class HttpCompressor (View source)

The HttpCompressor class to support gzip encoding.

Constants

ENCODING_GZIP

ENCODING_XGZIP

ENCODING_DEFLATE

Methods

__construct(string $acceptEncoding = null)

Compressor constructor.

static boolean
isSupported()

Method to check zlib supported.

ResponseInterface
compress(ResponseInterface $response)

Checks the accept encoding of the browser and compresses the data before sending it to the client if possible.

string
encode(string $data, int $encoding = FORCE_GZIP, int $level = 4)

Compress raw data.

string
getAcceptEncoding()

Method to get property AcceptEncoding

setAcceptEncoding(string $acceptEncoding)

Method to set property acceptEncoding

boolean
checkHeadersSent()

Method to check to see if headers have already been sent.

boolean
checkConnectionAlive()

Method to check the current client connection status to ensure that it is alive.

string
getEncodedBy()

Method to get property EncodedBy

setEncodedBy(string $encodedBy)

Method to set property encodedBy

Details

at line line 53
__construct(string $acceptEncoding = null)

Compressor constructor.

Parameters

string $acceptEncoding The Accept-Encoding value, most is "gzip, deflate". Keep null to get it from globals.

at line line 63
static boolean isSupported()

Method to check zlib supported.

Return Value

boolean

at line line 90
ResponseInterface compress(ResponseInterface $response)

Checks the accept encoding of the browser and compresses the data before sending it to the client if possible.

Parameters

ResponseInterface $response The Response object contains the data we want to encode.

Return Value

ResponseInterface Return Response object.

Exceptions

CompressException

at line line 152
string encode(string $data, int $encoding = FORCE_GZIP, int $level = 4)

Compress raw data.

Parameters

string $data The data to encode.
int $encoding The encoding mode. Can be FORCEGZIP (the default) or FORCEDEFLATE.
int $level The level of compression. Can be given as 0 for no compression up to 9 for maximum compression. If not given, the default compression level will be the default compression level of the zlib library.

Return Value

string

Exceptions

CompressException

at line line 182
string getAcceptEncoding()

Method to get property AcceptEncoding

Return Value

string

at line line 199
HttpCompressor setAcceptEncoding(string $acceptEncoding)

Method to set property acceptEncoding

Parameters

string $acceptEncoding

Return Value

HttpCompressor Return self to support chaining.

at line line 215
boolean checkHeadersSent()

Method to check to see if headers have already been sent.

We wrap headers_sent() function with this method for testing reason.

Return Value

boolean True if the headers have already been sent.

See also

headers_sent()

at line line 229
boolean checkConnectionAlive()

Method to check the current client connection status to ensure that it is alive.

We wrap connection_status() function with this method for testing reason.

Return Value

boolean True if the connection is valid and normal.

See also

connection_status()

at line line 239
string getEncodedBy()

Method to get property EncodedBy

Return Value

string

at line line 251
HttpCompressor setEncodedBy(string $encodedBy)

Method to set property encodedBy

Parameters

string $encodedBy

Return Value

HttpCompressor Return self to support chaining.