PHP Class Psecio\Gatekeeper\Gatekeeper

Afficher le fichier Open project: psecio/gatekeeper Class Usage Examples

Méthodes publiques

Méthode 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

Méthodes protégées

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

Method Details

__callStatic() public static méthode

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

authenticate() public static méthode

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
Résultat boolean Pass/fail of authentication

buildDataSource() public static méthode

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

buildModel() public static méthode

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
Résultat object Model instance

checkRememberMe() public static méthode

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

clearRestrictions() public static méthode

Clear out the current restrictions
public static clearRestrictions ( )

createPolicy() public static méthode

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

disableThrottle() public static méthode

Disable the throttling
public static disableThrottle ( )

enableThrottle() public static méthode

Enable the throttling feature
public static enableThrottle ( )

evaluatePolicy() public static méthode

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)
Résultat boolean Pass/fail status of evaluation

getConfig() public static méthode

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]
Résultat mixed Single value if index found, otherwise array of all

getDatasource() public static méthode

Get the current datasource
public static getDatasource ( ) : DataSource
Résultat DataSource instance

getLastError() public static méthode

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

getLogger() public static méthode

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

getRestrictions() public static méthode

Get the current list of restrictions
public static getRestrictions ( ) : array
Résultat array Set of restrictions

getUserThrottle() public static méthode

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

hash_equals() public static méthode

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

init() public static méthode

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 méthode

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
Résultat array Set of configuration values

loadDotEnv() protected static méthode

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

modelFactory() public static méthode

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

register() public static méthode

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

rememberMe() public static méthode

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
Résultat boolean Success/fail of sesssion setup

restrict() public static méthode

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 méthode

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

setDatasource() public static méthode

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

setLogger() public static méthode

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 méthode

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