Download the PHP package celestriode/dynamic-registry without Composer
On this page you can find all versions of the php package celestriode/dynamic-registry. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download celestriode/dynamic-registry
More information about celestriode/dynamic-registry
Files in celestriode/dynamic-registry
Package dynamic-registry
Short Description Simple, individual registries that are populated on-demand to save on memory.
License MIT
Informations about the package dynamic-registry
Dynamic Registry
Create registries that are filled on-demand instead of wasting memory when they are never accessed.
Example
Extending
Extend AbstractRegistry
for each type of registry you want to keep a set of values for.
Or if you only want strings in the registry, you can extend AbstractStringRegistry
. When a non-string value is added to such a registry, InvalidValue
is thrown.
Or if you want a simple container and have no use for multiple unique registries, create a new SimpleRegistry
object.
Usage
You can either use new
to create a new object for your registry or obtain a singleton via get()
.
Apart from those initially-present values, you can create and register a dynamic populator. A dynamic populator adds values to the registry the first time that the registry has been queried via has()
or if the registry has been forcibly populated with populate()
.
Of course, rather than dynamically populating with hard-coded values, you would instead populate the registry through some other means, such as from a database or via an external API. After registering the populator, once has()
is called, the registry will be automatically populated and will return true if the value exists.
Be warned that attempting to add multiple of the same value will result in InvalidValue
being thrown. To avoid this consequence and instead cause it to fail silently, override the failSilently
method.
All versions of dynamic-registry with dependencies
ext-ds Version *