decodelabs / pandora
Potent PSR-11 depdency injection container
Installs: 17 994
Dependents: 3
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^8.4
- decodelabs/archetype: ^0.4
- decodelabs/exceptional: ^0.6.3
- decodelabs/kingdom: ^0.1
- decodelabs/slingshot: ^0.3
- psr/container: ^2.0.2
Requires (Dev)
Provides
- psr/container-implementation: 1.1|2.0
README
PSR-11 dependency injection container
Pandora offers a simple, powerful and flexible dependency injection and instantiation system to used as the core of your application.
Installation
composer require decodelabs/pandora
Usage
Instantiate a new Container
to keep your important objects organised:
use DecodeLabs\Pandora\Container; $container = new Container();
Bind instances or classes to interfaces and retrieve them when you need them:
use My\Library\CoolInterface; use My\Library\CoolImplementation; // Implements CoolInterface // Instance $container->bind(CoolInterface::class, new CoolImplementation()); $imp = $container->get(CoolInterface::class); // Will only bind if CoolInterface has not been bound before $container->tryBind(CoolInterface::class, new OtherImplementation()); // Will not bind $imp = $container->get(CoolInterface::class); // Bind a factory $container->bind(CoolInterface::class, fn() => new CoolImplementation());
Retrieval
Parameters can be passed to constructors of implementation classes:
$imp = $container->getWith(CoolInterface::class, ['list', 'of', 'params']); // Or inject parameters for later: $container->inject(CoolInterface::class, 'paramName', 'paramValue'); $imp = $container->get(CoolInterface::class);
Access the binding controllers:
$binding = $container->getBinding(CoolInterface::class);
Licensing
Pandora is licensed under the MIT License. See LICENSE for the full license text.