Skip to content

Instantly share code, notes, and snippets.

@ken-master
Last active April 6, 2016 07:24
Show Gist options
  • Save ken-master/045a54fecbf5fd7fbc911c2f411c9d77 to your computer and use it in GitHub Desktop.
Save ken-master/045a54fecbf5fd7fbc911c2f411c9d77 to your computer and use it in GitHub Desktop.
PHP Dependency Injection - Quick and Dirty version
<?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