\Greg\Support\Accessor\AccessorTrait
is a private storage trait for object usage.
You don't care anymore about setting a storage variable and creating base methods for using it.
Example:
class Options
{
use \Greg\Support\Accessor\AccessorTrait;
public function __construct(array $options)
{
$this->setAccessor($options);
}
public function has($key)
{
return $this->inAccessor($key);
}
public function get($key)
{
return $this->getFromAccessor($key);
}
public function set($key, $value)
{
return $this->setToAccessor($key, $value);
}
}
- getAccessor - Get storage;
- setAccessor - Set storage;
- inAccessor - Determine if keys exists in storage;
- getFromAccessor - Get values from storage;
- setToAccessor - Set a value to storage;
- addToAccessor - Add values to storage;
- removeFromAccessor - Remove values from storage;
- resetAccessor - Cleanup storage.
Get storage.
&getAccessor(): array
Set storage.
setAccessor(array $accessor): array
$accessor
- Storage.
Set storage.
inAccessor(string|array $key): boolean
$key
- Could be a key or an array of keys.
Get values from storage.
getFromAccessor(string|array $key, string|array $else = null): mixed
$key
- Could be a key or an array of keys;
$else
- If values not found, will return this. Could be a key or an array of keys.
Set a value to storage.
setToAccessor(string $key, mixed $value): array
$key
- Key;
$value
- Value.
Add values to storage.
addToAccessor(array $values): array
$values
- Values. Key-Value pair.
Remove values from storage.
removeFromAccessor(string|array $key): array
$key
- Could be a key or an array of keys.
Cleanup storage.
resetAccessor(): array