Skip to content

Latest commit

 

History

History
126 lines (85 loc) · 2.2 KB

AccessorTrait.md

File metadata and controls

126 lines (85 loc) · 2.2 KB

AccessorTrait Documentation

\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);
    }
}

Table of contents:

Methods:

getAccessor

Get storage.

&getAccessor(): array

setAccessor

Set storage.

setAccessor(array $accessor): array

$accessor - Storage.

inAccessor

Set storage.

inAccessor(string|array $key): boolean

$key - Could be a key or an array of keys.

getFromAccessor

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.

setToAccessor

Set a value to storage.

setToAccessor(string $key, mixed $value): array

$key - Key;
$value - Value.

addToAccessor

Add values to storage.

addToAccessor(array $values): array

$values - Values. Key-Value pair.

removeFromAccessor

Remove values from storage.

removeFromAccessor(string|array $key): array

$key - Could be a key or an array of keys.

resetAccessor

Cleanup storage.

resetAccessor(): array