/** * Class responsible for instantiating a DiStrictAbstractServiceFactory * * @param ServiceLocatorInterface $serviceLocator * @return DiStrictAbstractServiceFactory */ public function createService(ServiceLocatorInterface $serviceLocator) { $diAbstractFactory = new DiStrictAbstractServiceFactory($serviceLocator->get('Di'), DiStrictAbstractServiceFactory::USE_SL_BEFORE_DI); $config = $serviceLocator->get('Config'); if (isset($config['di']['allowed_controllers'])) { $diAbstractFactory->setAllowedServiceNames($config['di']['allowed_controllers']); } return $diAbstractFactory; }
/** * Create the controller loader service * * Creates and returns an instance of Controller\ControllerManager. The * only controllers this manager will allow are those defined in the * application configuration's "controllers" array. If a controller is * matched, the scoped manager will attempt to load the controller. * Finally, it will attempt to inject the controller plugin manager * if the controller implements a setPluginManager() method. * * This plugin manager is _not_ peered against DI, and as such, will * not load unknown classes. * * @param ServiceLocatorInterface $serviceLocator * @return ControllerManager */ public function createService(ServiceLocatorInterface $serviceLocator) { $controllerLoader = new ControllerManager(); $controllerLoader->setServiceLocator($serviceLocator); $controllerLoader->addPeeringServiceManager($serviceLocator); $config = $serviceLocator->get('Config'); if (isset($config['di']) && isset($config['di']['allowed_controllers']) && $serviceLocator->has('Di')) { $diAbstractFactory = new DiStrictAbstractServiceFactory($serviceLocator->get('Di'), DiStrictAbstractServiceFactory::USE_SL_BEFORE_DI); $diAbstractFactory->setAllowedServiceNames($config['di']['allowed_controllers']); $controllerLoader->addAbstractFactory($diAbstractFactory); } return $controllerLoader; }
public function testWillFetchDependenciesFromServiceManagerBeforeDi() { $controllerName = __NAMESPACE__ . '\\TestAsset\\ControllerWithDependencies'; $config = new Config(array('instance' => array($controllerName => array('parameters' => array('injected' => 'stdClass'))))); $locator = new ServiceManager(); $testService = new \stdClass(); $locator->setService('stdClass', $testService); $di = new Di(); $config->configure($di); $instance = new DiStrictAbstractServiceFactory($di, DiStrictAbstractServiceFactory::USE_SL_BEFORE_DI); $instance->setAllowedServiceNames(array($controllerName)); $service = $instance->createServiceWithName($locator, $controllerName, $controllerName); $this->assertSame($testService, $service->injectedValue); }