2017 © Pedro Peláez
 

library container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

image

wpfulcrum/container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

  • Tuesday, December 19, 2017
  • by hellofromtonya
  • Repository
  • 1 Watchers
  • 2 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Container Module

Build Status Latest Stable Version License, (*1)

The Fulcrum DI Container Module provides a lean Dependency Injection Container., (*2)

The primary purpose of a a DI Container is to manage objects. By passing in a closure that wraps up the creation of objects, using the container, you can:, (*3)

  1. Create a new object without having to use new in your code or having to specify it's dependencies.
  2. Get an object out of the container without having to use Singletons, statics, or globals. WooHoo!

The container also stores datasets. Think of it like a big array where you add values into it by a unique key. Powerful., (*4)

Seriously, a DI Container makes you job so much easier. Let it handle:, (*5)

  1. Object creation along with all of the object's dependencies.
  2. Managing objects.
  3. Storing datasets in memory.
  4. Retrieving the object or dataset you need.

Functionality

It extends Pimple by providing the following functionality:, (*6)

  1. has() method to check if a unique key exists in the container.
  2. get() method to fetch something out of the container by it's unique key.
  3. registerConcrete() method - providing the ability to register a closure.

Installation

The best way to use this component is through Composer:, (*7)

composer require wpfulcrum/container

Basic Usage

Creating Objects

Using the registerConcrete() method, you can register a closure that then handles creating the object and its dependencies., (*8)

For example, let's say you have an object that has several dependencies. For example, you are adding a Portfolio custom post type to your project using Fulcrum., (*9)

This might be the configuration for that CPT:, (*10)

$concreteConfig = [
    'autoload' => true,
    'concrete' => function ($container) {
        $configObj = new Config(YOURPLUGIN_PATH . '/config/post-type/portfolio.php');

        return new PostType(
            $configObj,
            $configObj->postTypeName,
            new PostTypeSupports($configObj)
        );
    },
];

Let's stop and notice a few points:, (*11)

  1. There are multiple dependencies including:
    • a Config object
    • a post type name
    • PostTypeSupports` object.
  2. Everything you need to create the CPT object is wrapped up in that closure.
  3. The autoload parameter is set to true. Therefore, the object is created immediately upon registering it into the container.

Using the above configuration, it can be registered into the container like this:, (*12)

$container = new DIContainer();
$portfolioCpt = $container->registerConcrete($concreteConfig, 'portfolio_cpt');

Contributing

All feedback, bug reports, and pull requests are welcome., (*13)

The Versions

19/12 2017

dev-develop

dev-develop https://github.com/wpfulcrum/container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tonya Mork

19/12 2017

3.0.5

3.0.5.0 https://github.com/wpfulcrum/container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tonya Mork

18/12 2017

3.0.4

3.0.4.0 https://github.com/wpfulcrum/container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tonya Mork

17/12 2017

3.0.3

3.0.3.0 https://github.com/wpfulcrum/container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tonya Mork

12/12 2017

dev-master

9999999-dev https://github.com/wpfulcrum/container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tonya Mork

12/12 2017

3.0.2

3.0.2.0 https://github.com/wpfulcrum/container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tonya Mork

05/12 2017

3.0.1

3.0.1.0 https://github.com/wpfulcrum/container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tonya Mork

29/11 2017

3.0.0

3.0.0.0 https://github.com/wpfulcrum/container

Fulcrum DI Container Module - a simple Dependency Injection Container that extends Pimple.

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Tonya Mork