PHP Class Psecio\Gatekeeper\Gatekeeper

ファイルを表示 Open project: psecio/gatekeeper Class Usage Examples

Public Methods

Method Description
__callStatic ( string $name, arrya $args ) : mixed Handle undefined static function calls
authenticate ( array $credentials, boolean $remember = false ) : boolean Authenticate a user given the username/password credentials
buildDataSource ( array $config, array $result ) : DataSource Build a datasource object
buildModel ( string $action = 'find', string $name, array $args ) : object Build the model instance with data given
checkRememberMe ( ) : boolean | Psecio\Gatekeeper\UserModel Check the "Remember Me" token information (if it exists)
clearRestrictions ( ) Clear out the current restrictions
createPolicy ( array $policy ) : boolean Allow for the creation of a policy as a callback too
disableThrottle ( ) Disable the throttling
enableThrottle ( ) Enable the throttling feature
evaluatePolicy ( string $name, mixed $data ) : boolean Evaluate the policy (found by name) against the data provided
getConfig ( string $index = null ) : mixed Get the current configuration information If an index is given, it tries to find it. If found, returns just that value. If not, returns null. Otherwise returns all config values
getDatasource ( ) : DataSource Get the current datasource
getLastError ( ) : string Get the last error message from the current datasource
getLogger ( ) : Psr\Log\LoggerInterface Get the current logger instance
getRestrictions ( ) : array Get the current list of restrictions
getUserThrottle ( integer $userId ) : Psecio\Gatekeeper\ThrottleModel Get the user throttle information If not found, makes a new one
hash_equals ( string $hash1, string $hash2 ) : boolean Safer way to evaluate if hashes equal
init ( string $envPath = null, array $config = [], DataSource $datasource = null, $logger = null ) Initialize the Gatekeeper instance, set up environment file and PDO connection
loadConfig ( array $config, string $envPath = null ) : array Get the configuration either from the config given or .env path
modelFactory ( string $type, array $data = [] ) : object Create and setup a new model instance
register ( array $userData ) : boolean Register a new user
rememberMe ( Psecio\Gatekeeper\UserModel | string $user, array $config = [] ) : boolean Enable and set up the "Remember Me" cookie token handling for the given user
restrict ( string $type, array $config ) Create a restriction and add it to be evaluated
setConfig ( array $config ) Set the current configuration options
setDatasource ( DataSource $ds ) Set the current data source to the one given
setLogger ( Psr\Log\LoggerInterface $logger = null ) Set the current logger interface If the logger value is null, a Monolog instance will be created
throttleStatus ( ) : boolean Return the enabled/disabled status of the throttling

Protected Methods

Method Description
loadDotEnv ( string $envPath ) : array | boolean Load the variables using the .env handling

Method Details

__callStatic() public static method

Handle undefined static function calls
public static __callStatic ( string $name, arrya $args ) : mixed
$name string Function name
$args arrya Arguments set
return mixed Boolean false if function not matched, otherwise Model instance

authenticate() public static method

Authenticate a user given the username/password credentials
public static authenticate ( array $credentials, boolean $remember = false ) : boolean
$credentials array Credential information (must include "username" and "password")
$remember boolean Flag to activate the "remember me" functionality
return boolean Pass/fail of authentication

buildDataSource() public static method

Build a datasource object
public static buildDataSource ( array $config, array $result ) : DataSource
$config array Configuration settings
$result array Environment data
return DataSource instance

buildModel() public static method

Build the model instance with data given
public static buildModel ( string $action = 'find', string $name, array $args ) : object
$action string Action called (ex: "delete" or "create")
$name string Function nname
$args array Arguments set
return object Model instance

checkRememberMe() public static method

Check the "Remember Me" token information (if it exists)
public static checkRememberMe ( ) : boolean | Psecio\Gatekeeper\UserModel
return boolean | Psecio\Gatekeeper\UserModel Success/fail of token validation or User model instance

clearRestrictions() public static method

Clear out the current restrictions
public static clearRestrictions ( )

createPolicy() public static method

Allow for the creation of a policy as a callback too
public static createPolicy ( array $policy ) : boolean
$policy array Policy settings
return boolean Success/fail of policy creation

disableThrottle() public static method

Disable the throttling
public static disableThrottle ( )

enableThrottle() public static method

Enable the throttling feature
public static enableThrottle ( )

evaluatePolicy() public static method

Evaluate the policy (found by name) against the data provided
public static evaluatePolicy ( string $name, mixed $data ) : boolean
$name string Name of the policy
$data mixed Data to use in evaluation (single object or array)
return boolean Pass/fail status of evaluation

getConfig() public static method

Get the current configuration information If an index is given, it tries to find it. If found, returns just that value. If not, returns null. Otherwise returns all config values
public static getConfig ( string $index = null ) : mixed
$index string Index to locate [optional]
return mixed Single value if index found, otherwise array of all

getDatasource() public static method

Get the current datasource
public static getDatasource ( ) : DataSource
return DataSource instance

getLastError() public static method

Get the last error message from the current datasource
public static getLastError ( ) : string
return string Error message (or empty string)

getLogger() public static method

Get the current logger instance
public static getLogger ( ) : Psr\Log\LoggerInterface
return Psr\Log\LoggerInterface object

getRestrictions() public static method

Get the current list of restrictions
public static getRestrictions ( ) : array
return array Set of restrictions

getUserThrottle() public static method

Get the user throttle information If not found, makes a new one
public static getUserThrottle ( integer $userId ) : Psecio\Gatekeeper\ThrottleModel
$userId integer User ID
return Psecio\Gatekeeper\ThrottleModel instance

hash_equals() public static method

Safer way to evaluate if hashes equal
public static hash_equals ( string $hash1, string $hash2 ) : boolean
$hash1 string Hash #1
$hash2 string Hash #1
return boolean Pass/fail on hash equality

init() public static method

Initialize the Gatekeeper instance, set up environment file and PDO connection
public static init ( string $envPath = null, array $config = [], DataSource $datasource = null, $logger = null )
$envPath string Environment file path (defaults to CWD)
$config array Configuration settings [optional]
$datasource DataSource Custom datasource provider

loadConfig() public static method

Get the configuration either from the config given or .env path
public static loadConfig ( array $config, string $envPath = null ) : array
$config array Configuration values
$envPath string Path to .env file
return array Set of configuration values

loadDotEnv() protected static method

Load the variables using the .env handling
protected static loadDotEnv ( string $envPath ) : array | boolean
$envPath string Path to the .env file
return array | boolean Array of data if found, false if load fails

modelFactory() public static method

Create and setup a new model instance
public static modelFactory ( string $type, array $data = [] ) : object
$type string Model class name
$data array
return object Model instance

register() public static method

Register a new user
public static register ( array $userData ) : boolean
$userData array User data
return boolean Success/fail of user create

rememberMe() public static method

Enable and set up the "Remember Me" cookie token handling for the given user
public static rememberMe ( Psecio\Gatekeeper\UserModel | string $user, array $config = [] ) : boolean
$user Psecio\Gatekeeper\UserModel | string User model instance
$config array Set of configuration settings
return boolean Success/fail of sesssion setup

restrict() public static method

Create a restriction and add it to be evaluated
public static restrict ( string $type, array $config )
$type string Restriction type
$config array Restriction configuration

setConfig() public static method

Set the current configuration options
public static setConfig ( array $config )
$config array Set of configuration settings

setDatasource() public static method

Set the current data source to the one given
public static setDatasource ( DataSource $ds )
$ds DataSource Data source instance

setLogger() public static method

Set the current logger interface If the logger value is null, a Monolog instance will be created
public static setLogger ( Psr\Log\LoggerInterface $logger = null )
$logger Psr\Log\LoggerInterface PSR logger or null

throttleStatus() public static method

Return the enabled/disabled status of the throttling
public static throttleStatus ( ) : boolean
return boolean Throttle status