Giter Site home page Giter Site logo

glue's Introduction

Nazg\Glue

Dependency Injection Container For Hack

Travis (.org) Packagist Packagist Version Packagist

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;
}
enum
Nazg\Glue\Scope\PROTOTYPE single instance
Nazg\Glue\Scope\SINGLETON prototype instance

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();

glue's People

Contributors

ytake avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.