Skip to content

Instantly share code, notes, and snippets.

@ThaDafinser
Last active December 26, 2015 07:49
Show Gist options
  • Save ThaDafinser/7117455 to your computer and use it in GitHub Desktop.
Save ThaDafinser/7117455 to your computer and use it in GitHub Desktop.
Proposal for ZF2
<?php
namespace Zend\ServiceManager;
class AbstractServiceManagerAware implements ServiceLocatorAwareInterface
{
/**
*
* @var ServiceLocatorInterface
*/
protected $serviceLocator;
/**
* Set serviceManager instance
*
* @param ServiceLocatorInterface $serviceLocator
* @return void
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
return $this;
}
/**
* Retrieve serviceManager instance
*
* @return ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
}
<?php
namespace MyModule\Services;
use Zend\ServiceManager\AbstractServiceManagerAware;
class MyService extends AbstractServiceManagerAware
{
public function doSomething(){
$otherSerice = $this->getServiceLocator()->get('myOtherSerice');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment