I've been looking at what it would mean to have a bare minimal application
bootstrap, i.e no modules (or ModuleManager) and just one single
application.config.php file for routes, controllers, and service_manager
directives.
This is an interesting exercise not only because it could provide a slim
ZF2 framework, but also because it shows how the Module Manager could be
decoupled and become an optional add on, e.g if a module is specified in
the config then use it.
Some observations:
These configurations could be added to the Mvc\Service\ServiceManageConfig
'RouteListener' => 'Zend\Mvc\RouteListener',
'DispatchListener' => 'Zend\Mvc\DispatchListener',
Moved all of the factory configurations from the
Mvc\Service\ServiceListenerFactory to the ServiceManagerConfig. The
ServiceListenerFactory actually ended up not being used at all.
Added a Default ControllerLoader to the ServiceManagerConfig which would
configure the ControllerManager with the controllers config from
application.config.php.
'ControllerLoader' => 'Zend\Mvc\Service\ControllerLoaderDefaultFactory',
public function createService(ServiceLocatorInterface $serviceLocator)
{
$configuration = $serviceLocator->get('Config');
$cConfig = isset($configuration['controllers']) ?
$configuration['controllers'] : array();
$controllerLoader = new \Zend\Mvc\Controller\ControllerManager(new
\Zend\ServiceManager\Config($cConfig));
$controllerLoader->setServiceLocator($serviceLocator);
$controllerLoader->addPeeringServiceManager($serviceLocator);
return $controllerLoader;
}
At this point, without invoking the ModuleManager or loadingModules, the
Mvc\Application init method reduced to
public static function init($configuration = array())
{
$smConfig = isset($configuration['service_manager']) ?
$configuration['service_manager'] : array();
$serviceManager = new ServiceManager(new
Service\ServiceManagerConfig($smConfig));
$serviceManager->setService('Config', $configuration);
//$serviceManager->setService('ApplicationConfig', $configuration);
//$serviceManager->get('ModuleManager')->loadModules();
return $serviceManager->get('Application')->bootstrap();
}
This still provides view templates and layouts via the ViewManager and
view_manager application.config.php settings.
The question I suppose it so what? Well its bare minimal, alternatively for
me I suppose, its been a way of getting my teeth into what happening.
However it does potentially show that it should be possible to decouple the
ModuleManager and more easily clearly show what overrides are needed in
order to support modules.
Anyhow, just sharing some some of my thoughts towards what could be a slim
ZF2 framework. Took some sweat figuring out the ControllerLoader, so you
might as well hear about it :)
Regards,
--
Greg