PHP Class SimpleSAML_Configuration, simplesamlphp

Author: Andreas Aakre Solberg, UNINETT AS. ([email protected])
显示文件 Open project: simplesamlphp/simplesamlphp Class Usage Examples

Public Methods

Method Description
__construct ( array $config, string $location ) Initializes a configuration from the given array.
copyFromBase ( string $instancename, string $filename ) Load a configuration file which is located in the same directory as this configuration file.
getArray ( string $name, mixed $default = self::REQUIRED_OPTION ) : array | mixed This function retrieves an array configuration option.
getArrayize ( string $name, mixed $default = self::REQUIRED_OPTION ) : array This function retrieves an array configuration option.
getArrayizeString ( string $name, mixed $default = self::REQUIRED_OPTION ) : array This function retrieves a configuration option with a string or an array of strings.
getBaseDir ( ) : string Retrieve the base directory for this SimpleSAMLphp installation.
getBasePath ( ) : string Retrieve the absolute path pointing to the SimpleSAMLphp installation.
getBaseURL ( ) : string Retrieve the absolute path of the SimpleSAMLphp installation, relative to the root of the website.
getBoolean ( string $name, mixed $default = self::REQUIRED_OPTION ) : boolean | mixed This function retrieves a boolean configuration option.
getConfig ( string $filename = 'config.php', string $configSet = 'simplesaml' ) : SimpleSAML_Configuration Load a configuration file from a configuration set.
getConfigItem ( string $name, mixed $default = self::REQUIRED_OPTION ) : mixed Retrieve an array as a SimpleSAML_Configuration object.
getConfigList ( string $name, mixed $default = self::REQUIRED_OPTION ) : mixed Retrieve an array of arrays as an array of SimpleSAML_Configuration objects.
getDefaultEndpoint ( string $endpointType, array $bindings = null, mixed $default = self::REQUIRED_OPTION ) : array | null Find the default endpoint of the given type.
getEndpointPrioritizedByBinding ( string $endpointType, array $bindings, mixed $default = self::REQUIRED_OPTION ) : array | null Find an endpoint of the given type, using a list of supported bindings as a way to prioritize.
getEndpoints ( string $endpointType ) : array Helper function for dealing with metadata endpoints.
getInstance ( string $instancename = 'simplesaml' ) : SimpleSAML_Configuration Get a configuration file by its instance name.
getInteger ( string $name, mixed $default = self::REQUIRED_OPTION ) : integer | mixed This function retrieves an integer configuration option.
getIntegerRange ( string $name, integer $minimum, integer $maximum, mixed $default = self::REQUIRED_OPTION ) : integer | mixed This function retrieves an integer configuration option where the value must be in the specified range.
getLocalizedString ( string $name, mixed $default = self::REQUIRED_OPTION ) : array Retrieve a string which may be localized into many languages.
getOptionalConfig ( string $filename = 'config.php', string $configSet = 'simplesaml' ) : SimpleSAML_Configuration Load a configuration file from a configuration set.
getOptions ( ) : array Retrieve list of options.
getPathValue ( string $name, string | null $default = null ) : string | null Retrieve a path configuration option set in config.php.
getPublicKeys ( string | null $use = null, boolean $required = false, string $prefix = '' ) : array | null Get public key from metadata.
getString ( string $name, mixed $default = self::REQUIRED_OPTION ) : string | mixed This function retrieves a string configuration option.
getValue ( string $name, mixed $default = null ) : mixed Retrieve a configuration option set in config.php.
getValueValidate ( string $name, array $allowedValues, mixed $default = self::REQUIRED_OPTION ) : mixed Retrieve a configuration option with one of the given values.
getVersion ( ) : string Retrieve the current version of SimpleSAMLphp.
hasValue ( string $name ) : boolean Check whether a key in the configuration exists or not.
hasValueOneOf ( array $names ) : boolean Check whether any key of the set given exists in the configuration.
init ( string $path, string $instancename = 'simplesaml', string $configfilename = 'config.php' ) Initialize a instance name with the given configuration file.
loadFromArray ( array $config, string $location = '[ARRAY]', string | null $instance = null ) : SimpleSAML_Configuration Loads a configuration from the given array.
resolvePath ( string | null $path ) : string | null This function resolves a path which may be relative to the SimpleSAMLphp base directory.
setConfigDir ( string $path, string $configSet = 'simplesaml' ) Set the directory for configuration files for the given configuration set.
toArray ( ) : array Convert this configuration object back to an array.

Private Methods

Method Description
getDefaultBinding ( string $endpointType ) : string Retrieve the default binding for the given endpoint type.
loadFromFile ( string $filename, boolean $required ) : SimpleSAML_Configuration Load the given configuration file.

Method Details

__construct() public method

Initializes a configuration from the given array.
public __construct ( array $config, string $location )
$config array The configuration array.
$location string The location which will be given when an error occurs.

copyFromBase() public method

TODO: remove.
See also: getConfig()
Deprecation: This function is superseeded by the getConfig() function.
public copyFromBase ( string $instancename, string $filename )
$instancename string
$filename string

getArray() public method

An exception will be thrown if this option isn't an array, or if this option isn't found, and no default value is given.
public getArray ( string $name, mixed $default = self::REQUIRED_OPTION ) : array | mixed
$name string The name of the option.
$default mixed A default value which will be returned if the option isn't found. The option will be required if this parameter isn't given. The default value can be any value, including null.
return array | mixed The option with the given name, or $default if the option isn't found and $default is specified.

getArrayize() public method

If the configuration option isn't an array, it will be converted to an array.
public getArrayize ( string $name, mixed $default = self::REQUIRED_OPTION ) : array
$name string The name of the option.
$default mixed A default value which will be returned if the option isn't found. The option will be required if this parameter isn't given. The default value can be any value, including null.
return array The option with the given name, or $default if the option isn't found and $default is specified.

getArrayizeString() public method

If the configuration option is a string, it will be converted to an array with a single string
public getArrayizeString ( string $name, mixed $default = self::REQUIRED_OPTION ) : array
$name string The name of the option.
$default mixed A default value which will be returned if the option isn't found. The option will be required if this parameter isn't given. The default value can be any value, including null.
return array The option with the given name, or $default if the option isn't found and $default is specified.

getBaseDir() public method

This function first checks the 'basedir' configuration option. If this option is undefined or null, then we fall back to looking at the current filename.
public getBaseDir ( ) : string
return string The absolute path to the base directory for this SimpleSAMLphp installation. This path will always end with a slash.

getBasePath() public method

The path is guaranteed to start and end with a slash ('/'). E.g.: /simplesaml/
public getBasePath ( ) : string
return string The absolute path where SimpleSAMLphp can be reached in the web server.

getBaseURL() public method

For example: simplesaml/ The path will always end with a '/' and never have a leading slash.
Deprecation: This method will be removed in SimpleSAMLphp 2.0. Please use getBasePath() instead.
public getBaseURL ( ) : string
return string The absolute path relative to the root of the website.

getBoolean() public method

An exception will be thrown if this option isn't a boolean, or if this option isn't found, and no default value is given.
public getBoolean ( string $name, mixed $default = self::REQUIRED_OPTION ) : boolean | mixed
$name string The name of the option.
$default mixed A default value which will be returned if the option isn't found. The option will be required if this parameter isn't given. The default value can be any value, including null.
return boolean | mixed The option with the given name, or $default if the option isn't found and $default is specified.

getConfig() public static method

Load a configuration file from a configuration set.
public static getConfig ( string $filename = 'config.php', string $configSet = 'simplesaml' ) : SimpleSAML_Configuration
$filename string The name of the configuration file.
$configSet string The configuration set. Optional, defaults to 'simplesaml'.
return SimpleSAML_Configuration The SimpleSAML_Configuration object.

getConfigItem() public method

This function will load the value of an option into a SimpleSAML_Configuration object. The option must contain an array. An exception will be thrown if this option isn't an array, or if this option isn't found, and no default value is given.
public getConfigItem ( string $name, mixed $default = self::REQUIRED_OPTION ) : mixed
$name string The name of the option.
$default mixed A default value which will be returned if the option isn't found. The option will be required if this parameter isn't given. The default value can be any value, including null.
return mixed The option with the given name, or $default if the option isn't found and $default is specified.

getConfigList() public method

This function will retrieve an option containing an array of arrays, and create an array of SimpleSAML_Configuration objects from that array. The indexes in the new array will be the same as the original indexes, but the values will be SimpleSAML_Configuration objects. An exception will be thrown if this option isn't an array of arrays, or if this option isn't found, and no default value is given.
public getConfigList ( string $name, mixed $default = self::REQUIRED_OPTION ) : mixed
$name string The name of the option.
$default mixed A default value which will be returned if the option isn't found. The option will be required if this parameter isn't given. The default value can be any value, including null.
return mixed The option with the given name, or $default if the option isn't found and $default is specified.

getDefaultEndpoint() public method

Find the default endpoint of the given type.
public getDefaultEndpoint ( string $endpointType, array $bindings = null, mixed $default = self::REQUIRED_OPTION ) : array | null
$endpointType string The endpoint type.
$bindings array Array with acceptable bindings. Can be null if any binding is allowed.
$default mixed The default value to return if no matching endpoint is found. If no default is provided, an exception will be thrown.
return array | null The default endpoint, or null if no acceptable endpoints are used.

getEndpointPrioritizedByBinding() public method

Find an endpoint of the given type, using a list of supported bindings as a way to prioritize.
public getEndpointPrioritizedByBinding ( string $endpointType, array $bindings, mixed $default = self::REQUIRED_OPTION ) : array | null
$endpointType string The endpoint type.
$bindings array Sorted array of acceptable bindings.
$default mixed The default value to return if no matching endpoint is found. If no default is provided, an exception will be thrown.
return array | null The default endpoint, or null if no acceptable endpoints are used.

getEndpoints() public method

Helper function for dealing with metadata endpoints.
public getEndpoints ( string $endpointType ) : array
$endpointType string The endpoint type.
return array Array of endpoints of the given type.

getInstance() public static method

This function retrieves a configuration file by its instance name. The instance name is initialized by the init function, or by copyFromBase function. If no configuration file with the given instance name is found, an exception will be thrown.
public static getInstance ( string $instancename = 'simplesaml' ) : SimpleSAML_Configuration
$instancename string The instance name of the configuration file. Deprecated.
return SimpleSAML_Configuration The configuration object.

getInteger() public method

An exception will be thrown if this option isn't an integer, or if this option isn't found, and no default value is given.
public getInteger ( string $name, mixed $default = self::REQUIRED_OPTION ) : integer | mixed
$name string The name of the option.
$default mixed A default value which will be returned if the option isn't found. The option will be required if this parameter isn't given. The default value can be any value, including null.
return integer | mixed The option with the given name, or $default if the option isn't found and $default is specified.

getIntegerRange() public method

An exception will be thrown if: - the option isn't an integer - the option isn't found, and no default value is given - the value is outside of the allowed range
public getIntegerRange ( string $name, integer $minimum, integer $maximum, mixed $default = self::REQUIRED_OPTION ) : integer | mixed
$name string The name of the option.
$minimum integer The smallest value which is allowed.
$maximum integer The largest value which is allowed.
$default mixed A default value which will be returned if the option isn't found. The option will be required if this parameter isn't given. The default value can be any value, including null.
return integer | mixed The option with the given name, or $default if the option isn't found and $default is specified.

getLocalizedString() public method

The default language returned is always 'en'.
public getLocalizedString ( string $name, mixed $default = self::REQUIRED_OPTION ) : array
$name string The name of the option.
$default mixed The default value. If no default is given, and the option isn't found, an exception will be thrown.
return array Associative array with language => string pairs.

getOptionalConfig() public static method

This function will return a configuration object even if the file does not exist.
public static getOptionalConfig ( string $filename = 'config.php', string $configSet = 'simplesaml' ) : SimpleSAML_Configuration
$filename string The name of the configuration file.
$configSet string The configuration set. Optional, defaults to 'simplesaml'.
return SimpleSAML_Configuration A configuration object.

getOptions() public method

This function returns the name of all options which are defined in this configuration file, as an array of strings.
public getOptions ( ) : array
return array Name of all options defined in this configuration file.

getPathValue() public method

The function will always return an absolute path unless the option is not set. It will then return the default value. It checks if the value starts with a slash, and prefixes it with the value from getBaseDir if it doesn't.
public getPathValue ( string $name, string | null $default = null ) : string | null
$name string Name of the configuration option.
$default string | null Default value of the configuration option. This parameter will default to null if not specified.
return string | null The path configuration option with name $name, or $default if the option was not found.

getPublicKeys() public method

Get public key from metadata.
public getPublicKeys ( string | null $use = null, boolean $required = false, string $prefix = '' ) : array | null
$use string | null The purpose this key can be used for. (encryption or signing).
$required boolean Whether the public key is required. If this is true, a missing key will cause an exception. Default is false.
$prefix string The prefix which should be used when reading from the metadata array. Defaults to ''.
return array | null Public key data, or null if no public key or was found.

getString() public method

An exception will be thrown if this option isn't a string, or if this option isn't found, and no default value is given.
public getString ( string $name, mixed $default = self::REQUIRED_OPTION ) : string | mixed
$name string The name of the option.
$default mixed A default value which will be returned if the option isn't found. The option will be required if this parameter isn't given. The default value can be any value, including null.
return string | mixed The option with the given name, or $default if the option isn't found and $default is specified.

getValue() public method

Retrieve a configuration option set in config.php.
public getValue ( string $name, mixed $default = null ) : mixed
$name string Name of the configuration option.
$default mixed Default value of the configuration option. This parameter will default to null if not specified. This can be set to SimpleSAML_Configuration::REQUIRED_OPTION, which will cause an exception to be thrown if the option isn't found.
return mixed The configuration option with name $name, or $default if the option was not found.

getValueValidate() public method

This will check that the configuration option matches one of the given values. The match will use strict comparison. An exception will be thrown if it does not match. The option can be mandatory or optional. If no default value is given, it will be considered to be mandatory, and an exception will be thrown if it isn't provided. If a default value is given, it is considered to be optional, and the default value is returned. The default value is automatically included in the list of allowed values.
public getValueValidate ( string $name, array $allowedValues, mixed $default = self::REQUIRED_OPTION ) : mixed
$name string The name of the option.
$allowedValues array The values the option is allowed to take, as an array.
$default mixed The default value which will be returned if the option isn't found. If this parameter isn't given, the option will be considered to be mandatory. The default value can be any value, including null.
return mixed The option with the given name, or $default if the option isn't found and $default is given.

getVersion() public method

Retrieve the current version of SimpleSAMLphp.
public getVersion ( ) : string
return string

hasValue() public method

Check whether a key in the configuration exists or not.
public hasValue ( string $name ) : boolean
$name string The key in the configuration to look for.
return boolean If the value is set in this configuration.

hasValueOneOf() public method

Check whether any key of the set given exists in the configuration.
public hasValueOneOf ( array $names ) : boolean
$names array An array of options to look for.
return boolean If any of the keys in $names exist in the configuration

init() public static method

TODO: remove.
See also: setConfigDir()
Deprecation: This function is superseeded by the setConfigDir function.
public static init ( string $path, string $instancename = 'simplesaml', string $configfilename = 'config.php' )
$path string
$instancename string
$configfilename string

loadFromArray() public static method

Loads a configuration from the given array.
public static loadFromArray ( array $config, string $location = '[ARRAY]', string | null $instance = null ) : SimpleSAML_Configuration
$config array The configuration array.
$location string The location which will be given when an error occurs. Optional.
$instance string | null The name of this instance. If specified, the configuration will be loaded and an instance with that name will be kept for it to be retrieved later with getInstance($instance). If null, the configuration will not be kept for later use. Defaults to null.
return SimpleSAML_Configuration The configuration object.

resolvePath() public method

The path will never end with a '/'.
public resolvePath ( string | null $path ) : string | null
$path string | null The path we should resolve. This option may be null.
return string | null $path if $path is an absolute path, or $path prepended with the base directory of this SimpleSAMLphp installation. We will return NULL if $path is null.

setConfigDir() public static method

Set the directory for configuration files for the given configuration set.
public static setConfigDir ( string $path, string $configSet = 'simplesaml' )
$path string The directory which contains the configuration files.
$configSet string The configuration set. Defaults to 'simplesaml'.

toArray() public method

Convert this configuration object back to an array.
public toArray ( ) : array
return array An associative array with all configuration options and values.