ACTION_NONE
ACTION_NONE = 0
Disallow all actions
Static and non-static registry functionality.
Supports plain access rights and storing values by references.
use \donbidon\Core\Registry\Common;
$registry = new Common[
'key_1' => "value_1",
'key_2' => "value_2",
'ref_1' => "~~> ref_2",
'ref_2' => "~~> ref_value",
'ref_value' => "final reference value",
], Common::ACTION_ALL & ~Common::ACTION_MODIFY);
var_dump($registry->exists('key_1'));
var_dump($registry->exists('key_3'));
var_dump($registry->get('key_3', "default value"));
var_dump($registry->get('ref_1'));
var_dump($registry->get('ref_2'));
$registry->set('key_3', "value_3");
$registry->set('key_1', "value_11");
outputs
bool(true)
bool(false)
string(13) "default value"
string(21) "final reference value"
string(21) "final reference value"
Fatal error: Uncaught RuntimeException: ACTION_MODIFY: no permissions for key 'key_1'
_get(string $key = null, mixed $default = null, boolean $throw = true) : mixed
Short alias for self::getInstance()->get().
string | $key | |
mixed | $default | |
boolean | $throw | Throw exception if no default value passed and key doesn't exist |
Risen from self::get().
__construct(array $scope = array(), integer $options = self::ALL_INCLUSIVE)
Constructor.
Example:
use donbidon\Core\Registry\Common;
// Create registry allowing to add new keys only
$registry = new Common(
[
'key_1' => "value_1",
],
Common::ACTION_CREATE
);
$registry->set('key_2', "value_2"); // Ok
// RuntimeException having Registry:ACTION_CREATE
// code will be thrown.
$registry->set('key_2', "value_2*");
array | $scope | |
integer | $options | Combination of the following flags:
|
get(string $key = null, mixed $default = null, boolean $throw = true) : mixed
Returns scope value.
string | $key | If not passed, whole scope will be returned |
mixed | $default | |
boolean | $throw | Throw exception if no default value passed and key doesn't exist |
Risen from self::checkPermissions().
If key doesn't exist.