elegenceio / containers
There is no license information available for the latest version (1.0.0) of this package.
Core Container Package for lazarusphp FrameWork
1.0.0
2026-07-30 10:27 UTC
Requires
- psr/container: ^2.0
- psr/log: ^3.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
What it is?
elegence io continer package is a core package designed to register content and load it in a global state.
How to use
installation
composer require elegenceIO/containers // or git clone https://github.com/elegenceIO/Container
instantiation
use ElegenceIO\Containers\Container; use ElegenceIO\Containers\ContainerRegistry; function app(){ $container = new Container(); // make static access ContainerRegistry::set($container); // Returns the container return $container }
Bindings
map()- used for Mapping a container Referene
- Supports strings Integers arrays and callables
- Ideal for Mapping config files.
bind()- used to map a new instance when called.
- must be callable using function() or fn()
simgleton()- used to map a single persistant reference
- must be callable using function() or fn()
options
locked()- can be used to map an interface to a class
alias()provides the ability to map an alias to a class.
Example Usage
Creating and Instance
app()->map(Database::class,new Database());
the following example works for both singleton and bind
app()->bind("db",function() { $db = new Database(//Include config file or array data\/); return $db; }) // Optionally app()->bind("db",fn()=> new Database("config.php"));
Returning a container this will activate the container s
app()->get("db");
Adding Aliases
app()->bind(Database::class,function() { $db = new Database(//Include config file or array data\/); return $db; })->alias("database")->alias // Want to alias an alias this can be done like to app()->alias("db2","database"); // Both db2 and database will work as alias files
Locking Interface Currently this only supports locking one interface, however this can be accomplished like so.
app()->bind("db",function() { $db = new Database(//Include config file or array data\/); return $db; })->locked(Connection::class);
locked() and alias() method can be usentogether format;