[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/minify/lib/HTTP/ -> Encoder.php (summary)

Class HTTP_Encoder

File Size: 335 lines (11 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

HTTP_Encoder:: (9 methods):
  __construct()
  getContent()
  getHeaders()
  sendHeaders()
  sendAll()
  getAcceptedEncoding()
  encode()
  output()
  isBuggyIe()


Class: HTTP_Encoder  - X-Ref

Encode and send gzipped/deflated content

The "Vary: Accept-Encoding" header is sent. If the client allows encoding,
Content-Encoding and Content-Length are added.

<code>
// Send a CSS file, compressed if possible
$he = new HTTP_Encoder(array(
'content' => file_get_contents($cssFile)
,'type' => 'text/css'
));
$he->encode();
$he->sendAll();
</code>

<code>
// Shortcut to encoding output
header('Content-Type: text/css'); // needed if not HTML
HTTP_Encoder::output($css);
</code>

<code>
// Just sniff for the accepted encoding
$encoding = HTTP_Encoder::getAcceptedEncoding();
</code>

For more control over headers, use getHeaders() and getData() and send your
own output.

Note: If you don't need header mgmt, use PHP's native gzencode, gzdeflate,
and gzcompress functions for gzip, deflate, and compress-encoding
respectively.

__construct($spec)   X-Ref
Get an HTTP Encoder object

param: array $spec options

getContent()   X-Ref
Get content in current form

Call after encode() for encoded content.

return: string

getHeaders()   X-Ref
Get array of output headers to be sent

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

return: array

sendHeaders()   X-Ref
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.


sendAll()   X-Ref
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.

getAcceptedEncoding($allowCompress = true, $allowDeflate = true)   X-Ref
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.

param: bool $allowCompress allow the older compress encoding
param: bool $allowDeflate allow the more recent deflate encoding
return: array two values, 1st is the actual encoding method, 2nd is the

encode($compressionLevel = null)   X-Ref
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.

param: int $compressionLevel given to zlib functions. If not given, the
return: bool success true if the content was actually compressed

output($content, $compressionLevel = null)   X-Ref
Encode and send appropriate headers and content

This is a convenience method for common use of the class

param: string $content
param: int $compressionLevel given to zlib functions. If not given, the
return: bool success true if the content was actually compressed

isBuggyIe()   X-Ref
Is the browser an IE version earlier than 6 SP2?

return: bool



Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1