2017 © Pedro Peláez
 

library heroine

image

bjyoungblood/heroine

  • Sunday, July 29, 2018
  • by bjyoungblood
  • Repository
  • 1 Watchers
  • 3 Stars
  • 32 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Heroine

Travis-CI Build Status, (*1)

Heroine has come to rescue you from your DI nightmares by providing a simple, dependency-free service locator and repository., (*2)

For more information on the service locator pattern, you can read the Wikipedia article or on Martin Fowler's website., (*3)

Configuration and Usage

How and where you configure Heroine is up to you. All you need to do is construct a new Heroine\Heroine object with an array or an instance of Heroine\Config., (*4)

A sample array configuration follows:, (*5)

 array(
        'MyClass'       => 'MyClass',
        'another_class' => 'Another\Class',
    ),
    'callables' => array(
        'MyCalledClass' => function(Heroine\Heroine $heroine) {
            $instance = new MyCalledClass;
            $instance->setMyClass($heroine->get('MyClass'));
            return $instance;
        },
        'another_called_class' => function(Heroine\Heroine $heroine) {
            $instance = new Another\Called\Class;
            $instance->setAnotherClass($heroine->get('another_class'));
            return $instance;
        },
    ),
    'factories' => array(
        'MyFactoryProductClass' => 'MyFactoryClass',
    ),
    'initializers' => array(
        function (Heroine\Heroine $heroine, $instance) {
            if ($instance instanceof Heroine\HeroineAwareInterface)
            {
                $instance->setHeroine($heroine);
            }
        },
        function (Heroine\Heroine $heroine, $instance) {
            if ($instance instanceof InitializableInterface)
            {
                $instance->initalize();
            }
        },
    ),
);

?>

The four top-level array keys here represent the four creation patterns that Heroine provides., (*6)

  • Instantiables - these are classes that do not have any other dependencies, but that you want to be handled by Heroine. An example of this might be a model entity prototype.
  • Callables - these are simple factories that can use Heroine (or other resources) to create an instance of a class. This is recommended when your class has a few simple dependencies that are already managed by Heroine.
  • Factories - this is a full-blown factory class, which must implement Heroine\Factory\FactoryInterface. The createService method will be called to fetch an instance. This is recommended for objects with many dependencies or complex configuration.
  • Initializers - initializers are a list of functions that are run on every object created by Heroine to provide some initial state. For example, you might have a HeroineAwareInterface that provides a hook to inject Heroine into an object after it is created.

The Versions

29/07 2018

dev-develop

dev-develop

  Sources   Download

25/07 2016

dev-master

9999999-dev

  Sources   Download