PHP Class bandwidthThrottle\tokenBucket\util\TokenConverter

Author: Markus Malkusch ([email protected])
Show file Open project: bandwidth-throttle/token-bucket Class Usage Examples

Public Methods

Method Description
__construct ( Rate $rate ) Sets the token rate.
convertMicrotimeToTokens ( double $microtime ) : integer Converts a timestamp into tokens.
convertSecondsToTokens ( double $seconds ) : integer Converts a duration of seconds into an amount of tokens.
convertTokensToMicrotime ( integer $tokens ) : double Converts an amount of tokens into a timestamp.
convertTokensToSeconds ( integer $tokens ) : double Converts an amount of tokens into a duration of seconds.

Method Details

__construct() public method

Sets the token rate.
public __construct ( Rate $rate )
$rate bandwidthThrottle\tokenBucket\Rate The rate.

convertMicrotimeToTokens() public method

Converts a timestamp into tokens.
public convertMicrotimeToTokens ( double $microtime ) : integer
$microtime double The timestamp.
return integer The tokens.

convertSecondsToTokens() public method

Converts a duration of seconds into an amount of tokens.
public convertSecondsToTokens ( double $seconds ) : integer
$seconds double The duration in seconds.
return integer The amount of tokens.

convertTokensToMicrotime() public method

Converts an amount of tokens into a timestamp.
public convertTokensToMicrotime ( integer $tokens ) : double
$tokens integer The amount of tokens.
return double The timestamp.

convertTokensToSeconds() public method

Converts an amount of tokens into a duration of seconds.
public convertTokensToSeconds ( integer $tokens ) : double
$tokens integer The amount of tokens.
return double The seconds.