Stores the credentials for re-use.
Access
public static
Parameters
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
|
Required |
The named credential sets that should be made available to the application. |
Examples
Set the credential sets that should be available to the application, and read back the values.
// Dependencies
require_once dirname(__FILE__) . '/../../sdk.class.php';
require_once dirname(__FILE__) . '/../testutil.inc.php';
/**
* Create a group of credential sets. This would normally go inside the config.inc.php file.
*
* Each credential set is assigned a name. Any name that PHP allows as an array key may be used.
* `@inherit` is a keyword that will tell the class to use the inherited credential set as a base,
* then apply changes on top of it. The "default" credential set can be its own credential set,
* or can reference another credential set by name.
*/
CFCredentials::set(array(
// Credentials for the production environment
'production' => array(
'key' => 'production-key',
'secret' => 'production-secret',
'cache' => 'apc',
'something_else' => 'abc123',
'aardvark' => 'applesauce'
),
// Credentials for the staging environment. Inherits from "production".
'staging' => array(
'@inherit' => 'production',
'key' => 'staging-key',
'secret' => 'staging-secret',
),
// Credentials for the development environment. Inherits from "staging", and in-turn, "production".
'development' => array(
'@inherit' => 'staging',
'key' => 'development-key',
'secret' => 'development-secret',
),
// Any name can be used for a credential set.
'my-own-personal-credential-set' => array(
'@inherit' => 'staging'
),
// Set a default credential set for ambiguous cases.
'@default' => 'development'
));
/**
* Requesting data back from the credential sets.
*/
echo CFCredentials::get('production')->key . PHP_EOL;
echo CFCredentials::get('production')->aardvark . PHP_EOL;
echo PHP_EOL;
echo CFCredentials::get('staging')->key . PHP_EOL;
echo CFCredentials::get('staging')->aardvark . PHP_EOL;
echo PHP_EOL;
echo CFCredentials::get('development')->key . PHP_EOL;
echo CFCredentials::get('development')->aardvark . PHP_EOL;
echo PHP_EOL;
echo CFCredentials::get('my-own-personal-credential-set')->key . PHP_EOL;
echo PHP_EOL;
echo CFCredentials::get()->key . PHP_EOL;
Result:
production-key applesauce staging-key applesauce development-key applesauce staging-key development-key
Source
Method defined in utilities/credentials.class.php | Toggle source view (47 lines) | View on GitHub

