class RegistryInvokable implements InvokableInterface
Magic handling of properties access
Presentation
This model will store any property dynamically set in the $_data
registry:
$obj->prop = value => $_data[prop] = value
$obj->setProp(value) => $_data[prop] = value
Depending on the flag of the object, to access the property, use:
echo $obj->prop // if flag=PUBLIC_PROPERTIES
echo $obj->getProp() // if flag=PROTECTED_PROPERTIES
Be very careful about the properties names as they will all be transformed in lower case and underscore:
$obj->myPropertyName => $_data[ my_property_name ]
$obj->myProperty_name => $_data[ my_property_name ]
$obj->setMyPropertyName => $_data[ my_property_name ]
$obj->setMyProperty_name => $_data[ my_property_name ]
Flags
Three constants flags are defined in the class to let you choose the visibility of the object properties:
PUBLIC_PROPERTIES
: every type of property invocation is allowed,PROTECTED_PROPERTIES
: only magic getter is allowed:$obj->getProp()
,$obj->prop
will returnnull
,UNAUTHORIZED_PROPERTIES
: only magic getter is allowed and an exception will be thrown using$obj->prop
Default flag of the class is PROTECTED_PROPERTIES
to force the magic getter usage and allow you
to override these methods in your child class if necessary, without worrying about method existence.
Rules
All setter methods returns the object itself for chainability.
Constants
PUBLIC_PROPERTIES |
Defines all registry properties as public
|
PROTECTED_PROPERTIES |
Defines all registry properties as protected
|
UNAUTHORIZED_PROPERTIES |
Defines all registry properties as protected and throw an error if an access is done
|
Methods
__construct(array $data = null, int $flag = self::PROTECTED_PROPERTIES)
Object constructor |
||
RegistryInvokable |
setFlag(int $flag)
Set the object flag for registry properties visibility |
|
int |
getFlag()
Get the object flag for registry properties visibility |
|
mixed |
__call(string $name, array $arguments)
Magic handler when calling a non-existing method on an object |
|
static null |
__callStatic(string $name, array $arguments)
Avoiding magic static handler |
|
mixed |
__get(string $name)
Magic getter |
|
RegistryInvokable |
__set(string $name, mixed $value)
Magic setter |
|
bool |
__isset(string $name)
Magic checker |
|
RegistryInvokable |
__unset(string $name)
Magic unsetter |
|
mixed |
getData(string $name = null, mixed $default = null)
Global getter |
|
mixed |
setData($value, $arg2 = null)
Global setter |
Details
at line 115
public
__construct(array $data = null, int $flag = self::PROTECTED_PROPERTIES)
Object constructor
at line 130
public RegistryInvokable
setFlag(int $flag)
Set the object flag for registry properties visibility
at line 141
public int
getFlag()
Get the object flag for registry properties visibility
at line 162
public mixed
__call(string $name, array $arguments)
Magic handler when calling a non-existing method on an object
Magic method handling getProp(default)
, setProp(value)
, unsetProp()
, issetProp()
or resetProp()
.
Warning: the reset
function here is the same as unset
(not a real resetting to the original value).
at line 201
static public null
__callStatic(string $name, array $arguments)
Avoiding magic static handler
at line 221
public mixed
__get(string $name)
Magic getter
Magic method called when getProp(arg, default)
or $this->prop
are invoked. If the object
flag is set on self::PROTECTED_PROPERTIES
, this will return null ; if the flag is set on
self::UNAUTHORIZED_PROPERTIES
, an exception is thrown.
at line 244
public RegistryInvokable
__set(string $name, mixed $value)
Magic setter
Magic method called when setProp(arg, value)
or $this->arg = value
are invoked.
at line 261
public bool
__isset(string $name)
Magic checker
Magic method called when issetProp()
, isset($this->prop)
or empty($this->prop)
are invoked.
at line 277
public RegistryInvokable
__unset(string $name)
Magic unsetter
Magic method called when unsetProp()
or unset($this->prop)
are invoked.
at line 293
public mixed
getData(string $name = null, mixed $default = null)
Global getter
Get the value of a registry property or the whole registry array.
at line 314
public mixed
setData($value, $arg2 = null)
Global setter
Set the value of a registry property or the whole registry array.