Skip to content

Instantly share code, notes, and snippets.

@icanhazstring
Created March 10, 2016 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icanhazstring/a9bb6f5792934bfbbade to your computer and use it in GitHub Desktop.
Save icanhazstring/a9bb6f5792934bfbbade to your computer and use it in GitHub Desktop.
AOP Method Depedency Binding
/**
* @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