xtompie/lainstance
Lainstance
Laravel container extension for resolving and defining singletons alongside classes
Installation
composer require xtompie/lainstance
Usage
Getting instance
<?php
use Xtompie\Lainstance\Instance;
class Foo
{
use Instance;
}
$foo = Foo::instance();
Automatic Injection
<?php
use Xtompie\Lainstance\Instance;
class Bar
{
}
class Foo
{
use Instance;
public function __construct(
public Bar $bar
) {}
}
$foo = Foo::instance();
echo get_class($foo->bar); // => Bar
Shared aka singleton binding
<?php
use Xtompie\Lainstance\Instance;
use Xtompie\Lainstance\Shared;
class Foo implements Shared
{
use Instance;
}
echo Foo::instance() === Foo::instance(); // => 1
Related Packages
guanguans/di
A flexible dependency injection container based on the modification of `illumina...
1,234
5
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
637,827,751
9,703
Version History
| Version | Released | Laravel | License |
|---|---|---|---|
| 2.0 | ^8.0 | MIT | |
| 1.0.2 | ^8.0 | MIT | |
| 1.0.1 | ^8.0 | MIT | |
| 1.0.0 | ^8.0 | MIT |