2017 © Pedro Peláez
 

library container

A Dependency Injection Container based on Pimple

image

minphp/container

A Dependency Injection Container based on Pimple

  • Saturday, April 2, 2016
  • by clphillips
  • Repository
  • 3 Watchers
  • 1 Stars
  • 303 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 8 % Grown

The README.md

Minphp/Container

Build Status Coverage Status, (*1)

A standards compliant Pimple-based container., (*2)

Installation

Install via composer:, (*3)

composer require minphp/container:~2.0

Basic Usage

<?php
use Minphp\Container\Container;

$container = new Container();

// Add/Update
$container->set('queue', function($c) {
    return new \SplQueue();
});

// Verify
$queue_exists = $container->has('queue');

// Fetch
$queue = $container->get('queue');

// Remove
$container->remove('queue');

You can also use the container as an array, as per Pimple. Though, using the ContainerInterface defined methods is preferable as it eases switching to a different container if you ever need to., (*4)

<?php
use Minphp\Container\Container;

$container = new Container();
$container['queue'] = function($c) {
    return new \SplQueue();
};

$queue = $container['queue'];

ContainerInterface

interface ContainerInterface
{
    // inherited from Interop\Container\ContainerInterface
    public function get($id);

    // inherited from Interop\Container\ContainerInterface
    public function has($id);

    public function set($id, $value);

    public function remove($id);
}

ContainerAwareInterface

Also provided is the ContainerAwareInterface, which allows your classes to declare that they support container injection. Nifty for granting objects access to your container (you weren't thinking of using a static class, were you?)., (*5)

interface ContainerAwareInterface
{
    public function setContainer(Minphp\Container\ContainerInterface $container = null);

    public function getContainer();
}

Usage

<?php
namespace myApp\Controller;

use Minphp\Container\ContainerAwareInterface;
use Minphp\Container\ContainerInterface;

class MyController implements ContainerAwareInterface
{
    private $container = null;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function getContainer()
    {
        return $this->container;
    }
}

The Versions

02/04 2016

dev-master

9999999-dev http://github.com/phillipsdata/minphp-container

A Dependency Injection Container based on Pimple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Cody Phillips

02/04 2016

2.1.0

2.1.0.0 http://github.com/phillipsdata/minphp-container

A Dependency Injection Container based on Pimple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Cody Phillips

11/12 2015
11/12 2015

dev-update-namespace

dev-update-namespace http://github.com/phillipsdata/minphp-container

A Dependency Injection Container based on Pimple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Cody Phillips

05/04 2015

dev-php7

dev-php7 http://github.com/phillipsdata/minphp-container

A Dependency Injection Container based on Pimple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Cody Phillips

12/02 2015

1.0.0

1.0.0.0 http://github.com/phillipsdata/minphp-container

A Dependency Injection Container based on Pimple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Cody Phillips