2017 © Pedro Peláez
 

library container-discovery

Allowing discovery of container objects

image

thecodingmachine/container-discovery

Allowing discovery of container objects

  • Monday, November 30, 2015
  • by thecodingmachine
  • Repository
  • 4 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Containers discovery for container-interop

This package contains an interface and Puli binding-types to automatically discover containers., (*1)

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., (*2)

This factory is static and can be automatically detected by Puli using class discovery., (*3)

The goal is to allow a composite container to automatically detect and create container instances., (*4)

Installation

composer require thecodingmachine/container-discovery@dev

This package adheres to the SemVer specification and will be fully backward compatible between minor versions., (*5)

Containers discovery

The goal of this package is to enable a package to automatically publish or discover containers., (*6)

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

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

Providing containers

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

For instance (using Picotainer):, (*10)

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:, (*11)

$ 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)., (*12)

$ 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:, (*13)

// $discovery is the Puli Discovery object.

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

// TODO: sample code to sort by priority.

The Versions

30/11 2015

dev-master

9999999-dev

Allowing discovery of container objects

  Sources   Download

MIT

The Requires

 

The Development Requires