2017 © Pedro Peláez
 

library dependency-inject

Tried and tested minimal dependency injection for PHP

image

monotek/dependency-inject

Tried and tested minimal dependency injection for PHP

  • Saturday, September 3, 2016
  • by titpetric
  • Repository
  • 1 Watchers
  • 0 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 3 % Grown

The README.md

Dependency injection with PHP

Simply, this package consists of two classes. Class Dependency handles the definition of dependencies and resources. Class Inject handles auto injection of defined dependencies when instantiating objects., (*1)

Defining a dependency is as simple as:, (*2)

Dependency::set("database", function($param = false) {
    return new Database();
});

Using a dependency is as simple as:, (*3)

class UsesDatabase extends Inject
{
    public $inject = array("database");
    public function process()
    {
        $db = $this->getDatabase("param");
    }
}

The defined dependencies will create instances only when they are actually used. If the dependency is not used it will not be instantiated, keeping your overhead when executing PHP code as minimal as possible., (*4)

Passing arguments to the dependencies is enabled. This way you can have a utility dependency instantiator, which would return data depending on the arguments., (*5)

If you want to override a dependency in an instance:, (*6)

$object->setDatabase($object_or_callback);

Every next call to getDatabase will return the result of the call or the value which was passed to setDatabase., (*7)

Please see the unit tests for more advanced examples of using this package., (*8)

2014 (c) Tit Petrič, Monotek d.o.o., (*9)

The Versions

03/09 2016

dev-master

9999999-dev https://github.com/titpetric/monotek-dependency-inject

Tried and tested minimal dependency injection for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php dependency di injection tiny small monotek

03/09 2016

v1.0.1

1.0.1.0 https://github.com/titpetric/monotek-dependency-inject

Tried and tested minimal dependency injection for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php dependency di injection tiny small monotek

24/11 2014

v1.0.0

1.0.0.0 https://github.com/titpetric/monotek-dependency-inject

Tried and tested minimal dependency injection for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php dependency di injection tiny small monotek