Created
May 5, 2014 17:51
-
-
Save danielgsims/84efe4c10ac97c56b18c to your computer and use it in GitHub Desktop.
Dependency Resolver
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
$app = new \Slim\App(); | |
$app['resolver'] = new \Slim\Resolvers\DependencyResolver($app); | |
$app['dependency'] = function() { | |
return new MyDependency; | |
}; | |
$app['ExampleController'] = function($c) { | |
return new MyController($c['response'],$c['dependency']); | |
}; | |
$app->get('/', 'ExampleController:index'); | |
$app->run(); | |
class MyController | |
{ | |
protected $response; | |
protected $dependency; | |
public function __construct(\Slim\Interfaces\Http\ResponseInterface $response, MyDependency $d) | |
{ | |
$this->response = $response; | |
$this->dependency = $d; | |
} | |
public function index() | |
{ | |
$this->response->write($this->dependency->getResponse()); | |
} | |
} | |
class MyDependency | |
{ | |
public function getResponse() | |
{ | |
return "Hello World From My Dependency!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment