Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'feature/overrideable-di-factories' of https://github.co…

…m/Ocramius/zf2 into feature/di-factory-overrides

Conflicts:
	library/Zend/Mvc/Service/ServiceListenerFactory.php
  • Loading branch information...
commit e141dc150f15e4889976f95f6c71cfefce39d491 2 parents eb8145e + 2567c32
@weierophinney weierophinney authored
View
17 library/Zend/Mvc/Service/AbstractPluginManagerFactory.php
@@ -12,7 +12,6 @@
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Di\DiAbstractServiceFactory;
-use Zend\ServiceManager\Di\DiServiceInitializer;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
@@ -31,23 +30,21 @@
* the PLUGIN_MANGER_CLASS constant.
*
* @param ServiceLocatorInterface $serviceLocator
- * @return AbstractPluginManager
+ * @return \Zend\ServiceManager\AbstractPluginManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$pluginManagerClass = static::PLUGIN_MANAGER_CLASS;
+ /* @var $plugins \Zend\ServiceManager\AbstractPluginManager */
$plugins = new $pluginManagerClass;
$plugins->setServiceLocator($serviceLocator);
- $configuration = $serviceLocator->get('Config');
+ $configuration = $serviceLocator->get('Config');
+
if (isset($configuration['di']) && $serviceLocator->has('Di')) {
- $di = $serviceLocator->get('Di');
- $plugins->addAbstractFactory(
- new DiAbstractServiceFactory($di, DiAbstractServiceFactory::USE_SL_BEFORE_DI)
- );
- $plugins->addInitializer(
- new DiServiceInitializer($di, $serviceLocator)
- );
+ $plugins->addAbstractFactory($serviceLocator->get('DiAbstractServiceFactory'));
+ $plugins->addInitializer($serviceLocator->get('DiServiceInitializer'));
}
+
return $plugins;
}
}
View
8 library/Zend/Mvc/Service/ControllerLoaderFactory.php
@@ -47,13 +47,7 @@ public function createService(ServiceLocatorInterface $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);
+ $controllerLoader->addAbstractFactory($serviceLocator->get('DiStrictAbstractServiceFactory'));
}
return $controllerLoader;
View
42 library/Zend/Mvc/Service/DiAbstractServiceFactoryFactory.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Mvc
+ */
+
+namespace Zend\Mvc\Service;
+
+use Zend\ServiceManager\Di\DiAbstractServiceFactory;
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+use Zend\ServiceManager\ServiceManager;
+
+/**
+ * @category Zend
+ * @package Zend_Mvc
+ * @subpackage Service
+ */
+class DiAbstractServiceFactoryFactory implements FactoryInterface
+{
+ /**
+ * Class responsible for instantiating a DiStrictAbstractServiceFactory
+ *
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return DiStrictAbstractServiceFactory
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ $factory = new DiAbstractServiceFactory($serviceLocator->get('Di'), DiAbstractServiceFactory::USE_SL_BEFORE_DI);
+
+ if ($serviceLocator instanceof ServiceManager) {
+ /* @var $serviceLocator ServiceManager */
+ $serviceLocator->addAbstractFactory($factory);
+ }
+
+ return $factory;
+ }
+}
View
14 library/Zend/Mvc/Service/DiFactory.php
@@ -10,12 +10,10 @@
namespace Zend\Mvc\Service;
-use Zend\Di\Config as DiConfig;
+use Zend\Di\Config;
use Zend\Di\Di;
-use Zend\ServiceManager\Di\DiAbstractServiceFactory;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
-use Zend\ServiceManager\ServiceManager;
/**
* @category Zend
@@ -43,14 +41,8 @@ public function createService(ServiceLocatorInterface $serviceLocator)
$config = $serviceLocator->get('Config');
if (isset($config['di'])) {
- $di->configure(new DiConfig($config['di']));
- }
-
- if ($serviceLocator instanceof ServiceManager) {
- /* @var $serviceLocator ServiceManager */
- $serviceLocator->addAbstractFactory(
- new DiAbstractServiceFactory($di, DiAbstractServiceFactory::USE_SL_BEFORE_DI)
- );
+ $config = new Config($config['di']);
+ $config->configure($di);
}
return $di;
View
42 library/Zend/Mvc/Service/DiServiceInitializerFactory.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Mvc
+ */
+
+namespace Zend\Mvc\Service;
+
+use Zend\ServiceManager\Di\DiServiceInitializer;
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+use Zend\ServiceManager\ServiceManager;
+
+/**
+ * @category Zend
+ * @package Zend_Mvc
+ * @subpackage Service
+ */
+class DiServiceInitializerFactory implements FactoryInterface
+{
+ /**
+ * Class responsible for instantiating a DiServiceInitializer
+ *
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return DiServiceInitializer
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ $initializer = new DiServiceInitializer($serviceLocator->get('Di'), $serviceLocator);
+
+ if ($serviceLocator instanceof ServiceManager) {
+ /* @var $serviceLocator ServiceManager */
+ $serviceLocator->addInitializer($initializer);
+ }
+
+ return $initializer;
+ }
+}
View
44 library/Zend/Mvc/Service/DiStrictAbstractServiceFactoryFactory.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Mvc
+ */
+
+namespace Zend\Mvc\Service;
+
+use Zend\ServiceManager\Di\DiAbstractServiceFactory;
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+
+/**
+ * @category Zend
+ * @package Zend_Mvc
+ * @subpackage Service
+ */
+class DiStrictAbstractServiceFactoryFactory implements FactoryInterface
+{
+ /**
+ * 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;
+ }
+}
View
47 library/Zend/Mvc/Service/ServiceListenerFactory.php
@@ -45,28 +45,31 @@ class ServiceListenerFactory implements FactoryInterface
'RouteListener' => 'Zend\Mvc\RouteListener',
),
'factories' => array(
- 'Application' => 'Zend\Mvc\Service\ApplicationFactory',
- 'Config' => 'Zend\Mvc\Service\ConfigFactory',
- 'ControllerLoader' => 'Zend\Mvc\Service\ControllerLoaderFactory',
- 'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory',
- 'ConsoleAdapter' => 'Zend\Mvc\Service\ConsoleAdapterFactory',
- 'ConsoleRouter' => 'Zend\Mvc\Service\RouterFactory',
- 'DependencyInjector' => 'Zend\Mvc\Service\DiFactory',
- 'FilterManager' => 'Zend\Mvc\Service\FilterManagerFactory',
- 'HttpRouter' => 'Zend\Mvc\Service\RouterFactory',
- 'Request' => 'Zend\Mvc\Service\RequestFactory',
- 'Response' => 'Zend\Mvc\Service\ResponseFactory',
- 'Router' => 'Zend\Mvc\Service\RouterFactory',
- 'ValidatorManager' => 'Zend\Mvc\Service\ValidatorManagerFactory',
- 'ViewHelperManager' => 'Zend\Mvc\Service\ViewHelperManagerFactory',
- 'ViewFeedRenderer' => 'Zend\Mvc\Service\ViewFeedRendererFactory',
- 'ViewFeedStrategy' => 'Zend\Mvc\Service\ViewFeedStrategyFactory',
- 'ViewJsonRenderer' => 'Zend\Mvc\Service\ViewJsonRendererFactory',
- 'ViewJsonStrategy' => 'Zend\Mvc\Service\ViewJsonStrategyFactory',
- 'ViewManager' => 'Zend\Mvc\Service\ViewManagerFactory',
- 'ViewResolver' => 'Zend\Mvc\Service\ViewResolverFactory',
- 'ViewTemplateMapResolver' => 'Zend\Mvc\Service\ViewTemplateMapResolverFactory',
- 'ViewTemplatePathStack' => 'Zend\Mvc\Service\ViewTemplatePathStackFactory',
+ 'Application' => 'Zend\Mvc\Service\ApplicationFactory',
+ 'Config' => 'Zend\Mvc\Service\ConfigFactory',
+ 'ControllerLoader' => 'Zend\Mvc\Service\ControllerLoaderFactory',
+ 'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory',
+ 'ConsoleAdapter' => 'Zend\Mvc\Service\ConsoleAdapterFactory',
+ 'ConsoleRouter' => 'Zend\Mvc\Service\RouterFactory',
+ 'DependencyInjector' => 'Zend\Mvc\Service\DiFactory',
+ 'DiStrictAbstractServiceFactory' => 'Zend\Mvc\Service\DiStrictAbstractServiceFactoryFactory',
+ 'DiAbstractServiceFactory' => 'Zend\Mvc\Service\DiAbstractServiceFactoryFactory',
+ 'DiServiceInitializer' => 'Zend\Mvc\Service\DiServiceInitializerFactory',
+ 'FilterManager' => 'Zend\Mvc\Service\FilterManagerFactory',
+ 'HttpRouter' => 'Zend\Mvc\Service\RouterFactory',
+ 'Request' => 'Zend\Mvc\Service\RequestFactory',
+ 'Response' => 'Zend\Mvc\Service\ResponseFactory',
+ 'Router' => 'Zend\Mvc\Service\RouterFactory',
+ 'ValidatorManager' => 'Zend\Mvc\Service\ValidatorManagerFactory',
+ 'ViewHelperManager' => 'Zend\Mvc\Service\ViewHelperManagerFactory',
+ 'ViewFeedRenderer' => 'Zend\Mvc\Service\ViewFeedRendererFactory',
+ 'ViewFeedStrategy' => 'Zend\Mvc\Service\ViewFeedStrategyFactory',
+ 'ViewJsonRenderer' => 'Zend\Mvc\Service\ViewJsonRendererFactory',
+ 'ViewJsonStrategy' => 'Zend\Mvc\Service\ViewJsonStrategyFactory',
+ 'ViewManager' => 'Zend\Mvc\Service\ViewManagerFactory',
+ 'ViewResolver' => 'Zend\Mvc\Service\ViewResolverFactory',
+ 'ViewTemplateMapResolver' => 'Zend\Mvc\Service\ViewTemplateMapResolverFactory',
+ 'ViewTemplatePathStack' => 'Zend\Mvc\Service\ViewTemplatePathStackFactory',
),
'aliases' => array(
'Configuration' => 'Config',
View
6 tests/ZendTest/Mvc/Service/ControllerLoaderFactoryTest.php
@@ -15,6 +15,9 @@
use Zend\Mvc\Service\ControllerLoaderFactory;
use Zend\Mvc\Service\ControllerPluginManagerFactory;
use Zend\Mvc\Service\DiFactory;
+use Zend\Mvc\Service\DiStrictAbstractServiceFactoryFactory;
+use Zend\Mvc\Service\DiAbstractServiceFactoryFactory;
+use Zend\Mvc\Service\DiServiceInitializerFactory;
use Zend\Mvc\Service\EventManagerFactory;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\ServiceManager;
@@ -42,6 +45,9 @@ public function setUp()
$this->services->setService('Config', $config);
$this->services->setFactory('ControllerPluginBroker', new ControllerPluginManagerFactory());
$this->services->setFactory('Di', new DiFactory());
+ $this->services->setFactory('DiStrictAbstractServiceFactory', new DiStrictAbstractServiceFactoryFactory());
+ $this->services->setFactory('DiAbstractServiceFactory', new DiAbstractServiceFactoryFactory());
+ $this->services->setFactory('DiServiceInitializer', new DiServiceInitializerFactory());
$this->services->setFactory('EventManager', new EventManagerFactory());
$this->services->setInvokableClass('SharedEventManager', 'Zend\EventManager\SharedEventManager');
}
View
27 tests/ZendTest/Mvc/Service/DiFactoryTest.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_ServiceManager
+ */
+
+namespace ZendTest\Mvc\Service;
+
+use Zend\Mvc\Service\DiFactory;
+use Zend\ServiceManager\ServiceManager;
+
+class DiFactoryTest extends \PHPUnit_Framework_TestCase
+{
+ public function testWillInitializeDiAndDiAbstractFactoryAndDiInitializer()
+ {
+ $serviceManager = new ServiceManager();
+ $serviceManager->setService('Config', array('di' => array('')));
+ $serviceManager->setFactory('Di', new DiFactory());
+
+ $di = $serviceManager->get('Di');
+ $this->assertInstanceOf('Zend\Di\Di', $di);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.