2017 © Pedro Peláez
 

library zimple

A wrapper for Pimple container that adds several useful features to make it easier to manage your code!

image

jtreminio/zimple

A wrapper for Pimple container that adds several useful features to make it easier to manage your code!

  • Friday, December 6, 2013
  • by jtreminio
  • Repository
  • 2 Watchers
  • 11 Stars
  • 84 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 65 % Grown

The README.md

Zimple

This is a wrapper around the simple Pimple container. It provides a few features that makes handling objects and writing tests much easier., (*1)

If you have a codebase that is untestable and you are unable to offer deep refactoring to make it untestable, having a container such as this one is a good step toward gaining control over your codebase., (*2)

Installation

Add it to your composer.json file:, (*3)

"jtreminio/zimple": "1.0.*@dev"

Then run ./composer.phar update. This will also install the Pimple container, (*4)

Now just put it in your code:, (*5)

Zimple::setPimple(new Pimple);

Usage

Zimple accepts a fully qualified name:, (*6)

$date = Zimple::get('\DateTime');

You can also pass in an optional array of parameters for the object constructor:, (*7)

$date = Zimple::get('\DateTime', array('now', Zimple::get('\DateTimeZone')));

By default Zimple returns a new instance of an object everytime you call Zimple::get(). You can override this behavior by calling Zimple::set() and setting the third parameter to true:, (*8)

$today = Zimple::get('\DateTime');
$tomorrow = Zimple::get('\DateTime', array('tomorrow'));

// $today !== $tomorrow

Zimple::set('\DateTime', $tomorrow, true);

$tomorrowDup = Zimple::get('\DateTime');

// $tomorrowDup == $tomorrow

$twoDaysAgo = Zimple::get('\DateTime', array('2 days ago'));

// $twoDaysAgo == $tomorrow

You can define objects as you normally would for Pimple before or after passing to Zimple:, (*9)

// From Pimple's homepage
$pimple = new Pimple;

// define some objects
$pimple['session_storage'] = function ($c) {
    return new $c['session_storage_class']($c['cookie_name']);
};

$pimple['session'] = function ($c) {
    return new Session($c['session_storage']);
};

Zimple::setPimple($pimple);

Then access them as normal: $session = Zimple::get('session_storage');, (*10)

Zimple is a Weird Name

Zimple wraps around Pimple, which is a gross name. SandyZoop recommended I name it Cyst or Zit, which is equally gross. The goal of this container is to make dependency management simple and easy to use, and make previously untestable code testable., (*11)

Pimple + Simple = Zimple., (*12)

You can always alias it with, (*13)

use jtreminio\Zimple\Zimple as Container;
Container::setPimple(new Pimple);
$date = Container::get('\DateTime');

Testing

Zimple makes the process of inserting mocks from your tests extremely easy. It makes use of ::set() to prevent the code from overwriting the PHPUnit mock. Check out the tests for several easy examples., (*14)

The Versions

06/12 2013

dev-master

9999999-dev https://github.com/jtreminio/Zimple

A wrapper for Pimple container that adds several useful features to make it easier to manage your code!

  Sources   Download

MIT

The Requires

 

The Development Requires

testing dependency injection container unit testing dic ioc inversion of control pimple

07/08 2013

v1.1

1.1.0.0 https://github.com/jtreminio/Zimple

A wrapper for Pimple container that adds several useful features to make it easier to manage your code!

  Sources   Download

MIT

The Requires

 

The Development Requires

testing dependency injection container unit testing dic ioc inversion of control pimple

23/04 2013

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/jtreminio/Zimple

A wrapper for Pimple container that adds several useful features to make it easier to manage your code!

  Sources   Download

MIT

The Requires

 

The Development Requires

testing dependency injection container unit testing dic ioc inversion of control pimple