3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 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\Exception
;
14 use Zend\ServiceManager\InitializerInterface
;
15 use Zend\ServiceManager\ServiceLocatorInterface
;
17 class DiServiceInitializer
extends Di
implements InitializerInterface
25 * @var DiInstanceManagerProxy
27 protected $diInstanceManagerProxy = null;
30 * @var ServiceLocatorInterface
32 protected $serviceLocator = null;
37 * @param \Zend\Di\Di $di
38 * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
39 * @param null|DiInstanceManagerProxy $diImProxy
41 public function __construct(Di
$di, ServiceLocatorInterface
$serviceLocator, DiInstanceManagerProxy
$diImProxy = null)
44 $this->serviceLocator
= $serviceLocator;
45 $this->diInstanceManagerProxy
= ($diImProxy) ?
: new DiInstanceManagerProxy($di->instanceManager(), $serviceLocator);
52 * @param ServiceLocatorInterface $serviceLocator
55 public function initialize($instance, ServiceLocatorInterface
$serviceLocator)
57 $instanceManager = $this->di
->instanceManager
;
58 $this->di
->instanceManager
= $this->diInstanceManagerProxy
;
60 $this->di
->injectDependencies($instance);
61 $this->di
->instanceManager
= $instanceManager;
62 } catch (\Exception
$e) {
63 $this->di
->instanceManager
= $instanceManager;