PHP Класс Psecio\Gatekeeper\Gatekeeper

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
loadDotEnv ( string $envPath ) : array | boolean Load the variables using the .env handling

Описание методов

__callStatic() публичный статический Метод

Handle undefined static function calls
public static __callStatic ( string $name, arrya $args ) : mixed
$name string Function name
$args arrya Arguments set
Результат mixed Boolean false if function not matched, otherwise Model instance

authenticate() публичный статический Метод

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
Результат boolean Pass/fail of authentication

buildDataSource() публичный статический Метод

Build a datasource object
public static buildDataSource ( array $config, array $result ) : DataSource
$config array Configuration settings
$result array Environment data
Результат DataSource instance

buildModel() публичный статический Метод

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
Результат object Model instance

checkRememberMe() публичный статический Метод

Check the "Remember Me" token information (if it exists)
public static checkRememberMe ( ) : boolean | Psecio\Gatekeeper\UserModel
Результат boolean | Psecio\Gatekeeper\UserModel Success/fail of token validation or User model instance

clearRestrictions() публичный статический Метод

Clear out the current restrictions
public static clearRestrictions ( )

createPolicy() публичный статический Метод

Allow for the creation of a policy as a callback too
public static createPolicy ( array $policy ) : boolean
$policy array Policy settings
Результат boolean Success/fail of policy creation

disableThrottle() публичный статический Метод

Disable the throttling
public static disableThrottle ( )

enableThrottle() публичный статический Метод

Enable the throttling feature
public static enableThrottle ( )

evaluatePolicy() публичный статический Метод

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)
Результат boolean Pass/fail status of evaluation

getConfig() публичный статический Метод

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]
Результат mixed Single value if index found, otherwise array of all

getDatasource() публичный статический Метод

Get the current datasource
public static getDatasource ( ) : DataSource
Результат DataSource instance

getLastError() публичный статический Метод

Get the last error message from the current datasource
public static getLastError ( ) : string
Результат string Error message (or empty string)

getLogger() публичный статический Метод

Get the current logger instance
public static getLogger ( ) : Psr\Log\LoggerInterface
Результат Psr\Log\LoggerInterface object

getRestrictions() публичный статический Метод

Get the current list of restrictions
public static getRestrictions ( ) : array
Результат array Set of restrictions

getUserThrottle() публичный статический Метод

Get the user throttle information If not found, makes a new one
public static getUserThrottle ( integer $userId ) : Psecio\Gatekeeper\ThrottleModel
$userId integer User ID
Результат Psecio\Gatekeeper\ThrottleModel instance

hash_equals() публичный статический Метод

Safer way to evaluate if hashes equal
public static hash_equals ( string $hash1, string $hash2 ) : boolean
$hash1 string Hash #1
$hash2 string Hash #1
Результат boolean Pass/fail on hash equality

init() публичный статический Метод

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() публичный статический Метод

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
Результат array Set of configuration values

loadDotEnv() защищенный статический Метод

Load the variables using the .env handling
protected static loadDotEnv ( string $envPath ) : array | boolean
$envPath string Path to the .env file
Результат array | boolean Array of data if found, false if load fails

modelFactory() публичный статический Метод

Create and setup a new model instance
public static modelFactory ( string $type, array $data = [] ) : object
$type string Model class name
$data array
Результат object Model instance

register() публичный статический Метод

Register a new user
public static register ( array $userData ) : boolean
$userData array User data
Результат boolean Success/fail of user create

rememberMe() публичный статический Метод

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
Результат boolean Success/fail of sesssion setup

restrict() публичный статический Метод

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() публичный статический Метод

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

setDatasource() публичный статический Метод

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

setLogger() публичный статический Метод

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() публичный статический Метод

Return the enabled/disabled status of the throttling
public static throttleStatus ( ) : boolean
Результат boolean Throttle status