class Pouch implements ContainerInterface, Countable

Traits

Properties

static string $cacheStoreKey Key of the singleton holding the cache handler. from CacheTrait
protected bool $isFactory Whether a bind will be a factory. from FactoryTrait
protected array $factoryArgs Holds the data to be passed as args to the factory. from FactoryTrait
protected bool $named Whether this item should be retrievable by only its name and without a typehint.
static protected array $singletons Store all singletons.
protected Item[] $replaceables Store all the data that can be replaced.

Methods

register(string|array $keyOrData, callable|null $data = null)

Alias for bind.

set(string|array $keyOrData, callable|null $data = null)

Alias for bind.

mixed
resolve(string $key)

Fetches from container with getContent.

bool
contains(string $key)

Alias for has.

mixed
__get(string $key)

Allow retrieving container values via magic properties.

bool
__isset(string $key)

Allows the use of isset() to determine if something exists in the container.

void
__unset(string $key)

Allows the use of unset() to remove key a key from the container.

mixed
__call(string $key, array $data)

Bind a new key or fetch an existing one if no argument is provided.

mixed
cache(string $key, Closure $value)

Helper to retrieve data from cache store.

$this|Item
factory(bool|Closure|Item $isFactoryOrCallableOrItem = true)

Set factory for upcoming bind or create a factory callable.

withArgs(mixed ...$args)

Set the args to construct the factory with.

setFactoryArgs(string $key)

Set the arguments during fetch-time.

static void
bootstrap(string $rootDir, CacheInterface|null $cacheStore = null, string|null $startPath = null)

Bootstrap pouch.

static mixed
singleton(string $key, Closure $data = null)

Insert or return a singleton instance from our container.

bind(string|array $keyOrData, callable|Item|null $data = null)

Bind a new element to the replaceables.

alias(string $key, string $referenceKey)

Create an alias key for an existing key.

registerNamespaces(string|string[] $namespaces)

Register one or more namespaces for automatic resolution.

mixed
get(string $key)

Resolve specific key from the replaceables array.

raw(string $key)

Resolve a key without invoking it if it happens to be a factory.

item(string $key)

Returns the item instance for the key.

$this|Item
named(bool|Closure|Item $isNamedOrCallableOrItem = true)

No description

bool
has(string $key)

See if specific key exists in our replaceables.

remove(string $key)

Remove key from the container.

getHookManager()

Returns the hook manager.

string
__toString()

String representation of a pouch instance.

int
count()

Count elements of the container.

void
validateData(mixed $data)

Throws an exception if the callable argument is not a callable.

Details

in AliasTrait at line 17
AliasTrait register(string|array $keyOrData, callable|null $data = null)

Alias for bind.

Parameters

string|array $keyOrData
callable|null $data

Return Value

AliasTrait

in AliasTrait at line 30
AliasTrait set(string|array $keyOrData, callable|null $data = null)

Alias for bind.

Parameters

string|array $keyOrData
callable|null $data

Return Value

AliasTrait

in AliasTrait at line 42
mixed resolve(string $key)

Fetches from container with getContent.

Parameters

string $key

Return Value

mixed

in AliasTrait at line 54
bool contains(string $key)

Alias for has.

Parameters

string $key

Return Value

bool

in AliasTrait at line 66
mixed __get(string $key)

Allow retrieving container values via magic properties.

Parameters

string $key

Return Value

mixed

in AliasTrait at line 78
bool __isset(string $key)

Allows the use of isset() to determine if something exists in the container.

Parameters

string $key

Return Value

bool

in AliasTrait at line 90
void __unset(string $key)

Allows the use of unset() to remove key a key from the container.

Parameters

string $key

Return Value

void

in AliasTrait at line 104
mixed __call(string $key, array $data)

Bind a new key or fetch an existing one if no argument is provided.

. If an argument is provided: Only the first one will be considered and it must be a callable.

Parameters

string $key
array $data

Return Value

mixed

in CacheTrait at line 31
protected mixed cache(string $key, Closure $value)

Helper to retrieve data from cache store.

Parameters

string $key
Closure $value

Return Value

mixed

Exceptions

NotFoundException
InvalidArgumentException

in FactoryTrait at line 33
$this|Item factory(bool|Closure|Item $isFactoryOrCallableOrItem = true)

Set factory for upcoming bind or create a factory callable.

Parameters

bool|Closure|Item $isFactoryOrCallableOrItem

Return Value

$this|Item

in FactoryTrait at line 54
FactoryTrait withArgs(mixed ...$args)

Set the args to construct the factory with.

Parameters

mixed ...$args

Return Value

FactoryTrait

in FactoryTrait at line 68
protected FactoryTrait setFactoryArgs(string $key)

Set the arguments during fetch-time.

Parameters

string $key

Return Value

FactoryTrait

at line 73
static void bootstrap(string $rootDir, CacheInterface|null $cacheStore = null, string|null $startPath = null)

Bootstrap pouch.

Parameters

string $rootDir Path to the app's root (Where composer.json is).
CacheInterface|null $cacheStore PSR-16 compatible cache store instance. Will be used to speed up Pouch's performance by caching some heavy-ish tasks.
string|null $startPath

Return Value

void

Exceptions

NotFoundException

at line 102
static mixed singleton(string $key, Closure $data = null)

Insert or return a singleton instance from our container.

Parameters

string $key
Closure $data

Return Value

mixed

Exceptions

NotFoundException

at line 127
Pouch bind(string|array $keyOrData, callable|Item|null $data = null)

Bind a new element to the replaceables.

Parameters

string|array $keyOrData Can be a string for the key when binding a single thing, but can also be an array with $key => $callable format if providing multiple things to bind.
callable|Item|null $data The data to be bound. Must be provided if $key is a string.

Return Value

Pouch

Exceptions

InvalidArgumentException
NotFoundException

at line 165
Pouch alias(string $key, string $referenceKey)

Create an alias key for an existing key.

Parameters

string $key
string $referenceKey

Return Value

Pouch

Exceptions

NotFoundException

at line 183
Pouch registerNamespaces(string|string[] $namespaces)

Register one or more namespaces for automatic resolution.

Parameters

string|string[] $namespaces List of namespaces to be made resolvable. Will go recursively through the namespace.

Return Value

Pouch

Exceptions

InvalidArgumentException
NotFoundException

at line 209
mixed get(string $key)

Resolve specific key from the replaceables array.

Parameters

string $key

Return Value

mixed

Exceptions

NotFoundException

at line 236
Closure raw(string $key)

Resolve a key without invoking it if it happens to be a factory.

Parameters

string $key

Return Value

Closure

Exceptions

NotFoundException

at line 256
Item item(string $key)

Returns the item instance for the key.

Parameters

string $key

Return Value

Item

Exceptions

NotFoundException

at line 270
$this|Item named(bool|Closure|Item $isNamedOrCallableOrItem = true)

Parameters

bool|Closure|Item $isNamedOrCallableOrItem

Return Value

$this|Item

at line 290
bool has(string $key)

See if specific key exists in our replaceables.

Parameters

string $key

Return Value

bool

at line 302
Pouch remove(string $key)

Remove key from the container.

Parameters

string $key

Return Value

Pouch

at line 316
HookManager getHookManager()

Returns the hook manager.

Return Value

HookManager

at line 326
string __toString()

String representation of a pouch instance.

Return Value

string

at line 341
int count()

Count elements of the container.

Return Value

int The custom count as an integer.

at line 353
protected void validateData(mixed $data)

Throws an exception if the callable argument is not a callable.

Parameters

mixed $data

Return Value

void

Exceptions

InvalidArgumentException