nazg / glue
Dependency Injection Container For HHVM/Hack
Installs: 10 945
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Language:Hack
Requires
- hhvm: ^4.62
- hhvm/hhvm-autoload: ^3.0
- hhvm/hsl: ^4.0
- hhvm/hsl-experimental: ^4.25
Requires (Dev)
- facebook/fbexpect: ^2.7
- hhvm/hacktest: ^2.0
- hhvm/hhast: ^4.0
README
Dependency Injection Container For Hack
Requirements
HHVM 4.35.0 and above.
Installation
Composer is the recommended installation method.
To add Nazg\Glue to your project, add the following to your composer.json then re-run composer:
"require": { "nazg/glue": "^1.4" }
Run Composer commands using HHVM like so:
$ composer install
In addition, you will need to use hhvm-autoload as your autoloader.
or
$ composer require nazg/glue
Usage
First steps
Create Class
interface AnyInterface { }
final class Any implements AnyInterface { // any }
Bindings
use type Nazg\Glue\Container; use type Nazg\Glue\Scope; $container = new Container(); $container->bind(AnyInterface::class) ->to(Mock::class) ->in(Scope::PROTOTYPE); \HH\Asio\join($container->lockAsync());
dependencies will be automatically resolved
$container->get(AnyInterface::class);
Scopes
use the Nazg\Glue\Scope
enum.
enum Scope : int { PROTOTYPE = 0; SINGLETON = 1; }
Providers
use \Nazg\Glue\ProviderInterface.
use type Nazg\Glue\ProviderInterface; final class AnyProvider implements ProviderInterface<AnyInterface> { public function get(): AnyInterface { return new Any(); } }
$container->bind(AnyInterface::class) ->provider(new AnyProvider();
Binding Serialization Cache
use type Nazg\Glue\ContainerBuilder; $builder = new ContainerBuilder(true, 'apc.cache.key.name'); // return a \Nazg\Glue\CachedContainer Instance $container = $builder->make();