Created
May 7, 2012 23:39
-
-
Save dragoonis/2631457 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Inject services into our controller using setters matching against service names | |
* | |
* @return void | |
*/ | |
public function injectServices() { | |
if($this->_serviceLocator === null) { | |
return; | |
} | |
// A bunch of public methods that should be omitted. | |
$blackList = array('setServiceLocator', 'getServiceLocator', 'injectServices'); | |
$r = new \ReflectionClass($this); | |
foreach($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { | |
if(!in_array($method->name, $blackList) | |
&& substr($method->name, 0, 3) === 'set' | |
&& $this->_serviceLocator->has(($service = substr($method->name, 3))) | |
) { | |
$this->{$method->name}($this->_serviceLocator->get($service)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment