PHP 클래스 HTTP_Encoder, minify

The "Vary: Accept-Encoding" header is sent. If the client allows encoding, Content-Encoding and Content-Length are added. Send a CSS file, compressed if possible $he = new HTTP_Encoder(array( 'content' => file_get_contents($cssFile) ,'type' => 'text/css' )); $he->encode(); $he->sendAll(); Shortcut to encoding output header('Content-Type: text/css'); // needed if not HTML HTTP_Encoder::output($css); Just sniff for the accepted encoding $encoding = HTTP_Encoder::getAcceptedEncoding(); 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.
저자: Stephen Clay ([email protected])
파일 보기 프로젝트 열기: mrclay/minify 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$compressionLevel integer This level is used if encode() is not given a $compressionLevel
$encodeToIe6 boolean If you have many IE6 users and the bandwidth savings is worth troubling some of them, set this to true. By default, encoding is only offered to IE7+. When this is true, getAcceptedEncoding() will return an encoding for IE6 if its user agent string contains "SV1". This has been documented in many places as "safe", but there seem to be remaining, intermittent encoding bugs in patched IE6 on the wild web.

보호된 프로퍼티들

프로퍼티 타입 설명
$_content
$_encodeMethod
$_headers
$_useMbStrlen

공개 메소드들

메소드 설명
__construct ( array $spec ) Get an HTTP Encoder object
encode ( integer $compressionLevel = null ) : boolean Encode (compress) the content
getAcceptedEncoding ( boolean $allowCompress = true, boolean $allowDeflate = true ) : array Determine the client's best encoding method from the HTTP Accept-Encoding header.
getContent ( ) : string Get content in current form
getHeaders ( ) : array Get array of output headers to be sent
isBuggyIe ( ) : boolean Is the browser an IE version earlier than 6 SP2?
output ( string $content, integer $compressionLevel = null ) : boolean Encode and send appropriate headers and content
sendAll ( ) Send output headers and content
sendHeaders ( ) Send output headers

메소드 상세

__construct() 공개 메소드

Get an HTTP Encoder object
public __construct ( array $spec )
$spec array options '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)

encode() 공개 메소드

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.
public encode ( integer $compressionLevel = null ) : boolean
$compressionLevel integer given to zlib functions. If not given, the class default will be used.
리턴 boolean success true if the content was actually compressed

getAcceptedEncoding() 공개 정적인 메소드

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.
public static getAcceptedEncoding ( boolean $allowCompress = true, boolean $allowDeflate = true ) : array
$allowCompress boolean allow the older compress encoding
$allowDeflate boolean allow the more recent deflate encoding
리턴 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.)

getContent() 공개 메소드

Call after encode() for encoded content.
public getContent ( ) : string
리턴 string

getHeaders() 공개 메소드

E.g. array( 'Content-Length' => '615' ,'Content-Encoding' => 'x-gzip' ,'Vary' => 'Accept-Encoding' )
public getHeaders ( ) : array
리턴 array

isBuggyIe() 공개 정적인 메소드

Is the browser an IE version earlier than 6 SP2?
public static isBuggyIe ( ) : boolean
리턴 boolean

output() 공개 정적인 메소드

This is a convenience method for common use of the class
public static output ( string $content, integer $compressionLevel = null ) : boolean
$content string
$compressionLevel integer given to zlib functions. If not given, the class default will be used.
리턴 boolean success true if the content was actually compressed

sendAll() 공개 메소드

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

sendHeaders() 공개 메소드

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.
또한 보기: getHeaders()
public sendHeaders ( )

프로퍼티 상세

$_content 보호되어 있는 프로퍼티

protected $_content

$_encodeMethod 보호되어 있는 프로퍼티

protected $_encodeMethod

$_headers 보호되어 있는 프로퍼티

protected $_headers

$_useMbStrlen 보호되어 있는 프로퍼티

protected $_useMbStrlen

$compressionLevel 공개적으로 정적으로 프로퍼티

This level is used if encode() is not given a $compressionLevel
public static int $compressionLevel
리턴 integer

$encodeToIe6 공개적으로 정적으로 프로퍼티

If you have many IE6 users and the bandwidth savings is worth troubling some of them, set this to true. By default, encoding is only offered to IE7+. When this is true, getAcceptedEncoding() will return an encoding for IE6 if its user agent string contains "SV1". This has been documented in many places as "safe", but there seem to be remaining, intermittent encoding bugs in patched IE6 on the wild web.
public static bool $encodeToIe6
리턴 boolean