PHP Class Vectorface\Whip\Whip

This class checks a call time configurable list of headers in the $_SERVER superglobal to determine the client's IP address.
Author: Daniel Bruce ([email protected])
Author: Cory Darby ([email protected])
Afficher le fichier Open project: vectorface/whip Class Usage Examples

Méthodes publiques

Méthode Description
__construct ( integer $enabled = self::ALL_METHODS, array $whitelists = [], mixed $source = null ) Constructor for the class.
addCustomHeader ( string $header ) : Whip Adds a custom header to the list.
getIpAddress ( mixed $source = null ) : string Returns the IP address of the client using the given methods.
getValidIpAddress ( mixed $source = null ) : string | false Returns the valid IP address or false if no valid IP address was found.
setSource ( $source ) : Whip Sets the source data used to lookup the addresses.

Private Methods

Méthode Description
coalesceSources ( mixed $source = null ) : mixed Given available sources, get the first available source of IP data.
extractAddressFromHeaders ( array $requestHeaders, array $headers ) : string | false Finds the first element in $headers that is present in $_SERVER and returns the IP address mapped to that value.
getRequestAdapter ( mixed $source ) : Vectorface\Whip\Request\RequestAdapter Get a source/request adapter for a given source of IP data.
isMethodUsable ( string $key, string $ipAddress ) : boolean Returns whether or not the given method is enabled and usable.
normalizeHeaderName ( string $header ) : string Normalizes HTTP header name representations.

Method Details

__construct() public méthode

Constructor for the class.
public __construct ( integer $enabled = self::ALL_METHODS, array $whitelists = [], mixed $source = null )
$enabled integer The bitmask of enabled headers.
$whitelists array The array of IP ranges to be whitelisted.
$source mixed A supported source of IP data.

addCustomHeader() public méthode

Adds a custom header to the list.
public addCustomHeader ( string $header ) : Whip
$header string The custom header to add.
Résultat Whip Returns $this.

getIpAddress() public méthode

Returns the IP address of the client using the given methods.
public getIpAddress ( mixed $source = null ) : string
$source mixed (optional) The source data. If omitted, the class will use the value passed to Whip::setSource or fallback to $_SERVER.
Résultat string Returns the IP address as a string or false if no IP address could be found.

getValidIpAddress() public méthode

Returns the valid IP address or false if no valid IP address was found.
public getValidIpAddress ( mixed $source = null ) : string | false
$source mixed (optional) The source data. If omitted, the class will use the value passed to Whip::setSource or fallback to $_SERVER.
Résultat string | false Returns the IP address (as a string) of the client or false if no valid IP address was found.

setSource() public méthode

Sets the source data used to lookup the addresses.
public setSource ( $source ) : Whip
$source The source array.
Résultat Whip Returns $this.