Last active
April 6, 2016 07:24
-
-
Save ken-master/045a54fecbf5fd7fbc911c2f411c9d77 to your computer and use it in GitHub Desktop.
PHP Dependency Injection - Quick and Dirty version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Src\Cache; | |
/** | |
* Dependency Injection Container | |
*/ | |
class Container | |
{ | |
protected $object; | |
public function __construct(InterfaceObject $object) | |
{ | |
$this->object = $object; | |
} | |
public function set() | |
{ | |
return $this->object; | |
} | |
} | |
/* | |
//USAGE | |
$obj = new Container(new SampleObject()); | |
$obj = $obj->set(); | |
$obj->doSomething(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment