PHP Classes

PHP Dependency Injection Container: Autoload dependent objects accessing variables

Recommend this page to a friend!
  Info   View files Example   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (2)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 368 All time: 6,816 This week: 201Up
Version License PHP version Categories
pdi 1.0GNU General Publi...7.0Design Patterns, PHP 7


This class can autoload dependent objects accessing variables.

It provides a dependency injection base class that when it is accessed a given inexistent variable it will automatically load a class with a name based on the variable name and assign it an object of that class.

The class can use a given autoloader to load the dependency class in case it is not yet loaded.

Innovation Award
PHP Programming Innovation award nominee
October 2015
Number 6

Prize: SourceGuarding PHP encoder tool
Dependency injection is a design pattern that allows to configure the behavior of an object using external objects.

This package implements a dependency injection container that autoloads external dependency objects dynamically when certain variables of the dependent object are accessed for the first time.

Manuel Lemos
Picture of Samuel Adeshina
  Performance   Level  
Name: Samuel Adeshina is available for providing paid consulting. Contact Samuel Adeshina .
Classes: 19 packages by
Country: Nigeria Nigeria
Age: 24
All time rank: 5272 in Nigeria Nigeria
Week rank: 59 Up4 in Nigeria Nigeria Down
Innovation award
Innovation award
Nominee: 7x

Winner: 1x



    * Instantiate the Depender Class like a pro ;) [No need to worry about any dependencies]
$dependerClass = new Example\Depender(); //
    * Use a method that makes use of properties/attributes from other classes (Dependee class in this case)
    * without passing those objects (or classes) as parameter!
$dependerClass->callDependee(); //isn't this interesting?


CONFUSED?? Don't know which of Injector.php or Injector_5.php to choose from? Injector.php has complete support for PHP 7, it's possible you've not heard of PHP 7 yet or you haven't upgraded (which BTW, you must have a very good reason for) So the script has been rewritten (Injector_5.php) with support for the already 'legacy' versions of php. I recommend leaving the import.php script as is, if you are in a development environment, but please try as much as possible to change exit() to some proper logic you use for error reporting in your production environment. Enjoy! Samuel Adeshina

  Files folder image Files  
File Role Description
Files folder imageexample (4 files)
Files folder imagesrc (4 files)
Accessible without login Plain text file composer.json Data Required Dependencies
Accessible without login Plain text file Data Read Me

  Files folder image Files  /  example  
File Role Description
  Plain text file Dependee.php Class [Example]Dependee Class
  Plain text file Depender.php Class [Example]Depender Class
  Accessible without login Plain text file index.php Example [Example] Index
  Accessible without login Plain text file test.php Example run this file without an autoloader

  Files folder image Files  /  src  
File Role Description
  Accessible without login Plain text file import.php Aux. Use in development only
  Plain text file Injector.php Class Main Class. PHP 7 compatible
  Plain text file Injector_5.php Class Main Class. PHP 7 Incompatible
  Accessible without login Plain text file readme.txt Doc. Read Me

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:6,816
This week:201Up