3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\ServiceManager\Di
;
13 use Zend\ServiceManager\AbstractFactoryInterface
;
14 use Zend\ServiceManager\ServiceLocatorInterface
;
16 class DiAbstractServiceFactory
extends DiServiceFactory
implements AbstractFactoryInterface
21 * @param \Zend\Di\Di $di
22 * @param null|string|\Zend\Di\InstanceManager $useServiceLocator
24 public function __construct(Di
$di, $useServiceLocator = self
::USE_SL_NONE
)
27 if (in_array($useServiceLocator, array(self
::USE_SL_BEFORE_DI
, self
::USE_SL_AFTER_DI
, self
::USE_SL_NONE
))) {
28 $this->useServiceLocator
= $useServiceLocator;
31 // since we are using this in a proxy-fashion, localize state
32 $this->definitions
= $this->di
->definitions
;
33 $this->instanceManager
= $this->di
->instanceManager
;
39 public function createServiceWithName(ServiceLocatorInterface
$serviceLocator, $name, $requestedName)
41 $this->serviceLocator
= $serviceLocator;
43 return $this->get($requestedName, array());
46 return $this->get($name, array());
52 public function canCreateServiceWithName(ServiceLocatorInterface
$serviceLocator, $name, $requestedName)
54 if ($this->instanceManager
->hasSharedInstance($requestedName)
55 ||
$this->instanceManager
->hasAlias($requestedName)
56 ||
$this->instanceManager
->hasConfig($requestedName)
57 ||
$this->instanceManager
->hasTypePreferences($requestedName)
62 if (! $this->definitions
->hasClass($requestedName) ||
interface_exists($requestedName)) {