Created
March 10, 2016 10:32
-
-
Save icanhazstring/a9bb6f5792934bfbbade to your computer and use it in GitHub Desktop.
AOP Method Depedency Binding
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
/** | |
* @dependency($awesomeService => \Common\Service\AwesomeService) | |
* @dependency($megaService => \Common\Service\MegaService) | |
*/ | |
public function getFubar($id, $dependecies) | |
{ | |
$awesomeService = $dependencies->awesomeService; | |
$megaService = $dependencies->megaService; | |
$awesomeService->getData($id); | |
$megaService->getData($id); | |
} | |
// Dependency handler with servicelocator | |
// pseudo-code | |
public function aroundMethod($params) | |
{ | |
// $params are default params | |
// array with n values | |
$deps = $this->getTarget()->getDependency(); | |
$injects = new \stdClass; | |
foreach ($deps as $name => $dep) { | |
$injects->$name = $serviceLocator->get($dep); | |
} | |
return $this->getTarget()->call($params, $injects); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment