Coder Social home page Coder Social logo

container-discovery's Introduction

Containers discovery for container-interop

This package contains an interface and Puli binding-types to automatically discover containers.

Introduction

container-interop defines a common interface for Container objects (the ContainerInterface). This package proposes a default interface for factories that can generate container objects.

This factory is static and can be automatically detected by Puli using class discovery.

The goal is to allow a composite container to automatically detect and create container instances.

Installation

composer require thecodingmachine/container-discovery@dev

This package adheres to the SemVer specification and will be fully backward compatible between minor versions.

Containers discovery

The goal of this package is to enable a package to automatically publish or discover containers.

To automatically provide a container to your application, we use Puli's discovery mechanism.

This package contains a Puli binding-type named container-interop/ContainerFactories. This binding-type should contain fully qualified class names implementing the ContainerFactoryInterface interface.

Providing containers

To provide a container, write a ContainerFactory that will return an instance of your container implementing ContainerInterface.

For instance (using Picotainer):

namespace My\Package;

use Interop\Container\Factory\ContainerFactoryInterface;
use Assembly\ArrayDefinitionProvider;

class MyContainerFactory implements ContainerFactoryInterface {
    public static function buildContainer(ContainerInterface $rootContainer, Discovery $discovery) {
        return new Picotainer([
            'logger' => function() {
                new MyLogger();
            },
            $rootContainer
        ]);    
    }
}

Once your class is written, use Puli to bind it to the list of available containers:

$ puli bind "My\\Package\\MyContainerFactory" container-interop/ContainerFactories

Note: by convention, you can add a "priority" parameter to the binding. Default priority is 0. Lower priorities are processed first (and therefore, higher priorities are overloading lower priorities).

$ puli bind "My\\Package\\MyContainerFactory" container-interop/ContainerFactories --param priority=42

Consuming containers

In your code, you can find all classes of the container-interop/ContainerFactories binding-type using:

// $discovery is the Puli Discovery object.

$factories = $discovery->findByType('container-interop/ContainerFactories');

// TODO: sample code to sort by priority.

container-discovery's People

Contributors

moufmouf avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  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.