Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
New ViewManager class
Browse files Browse the repository at this point in the history
- Created ViewManager class for managing creation and composition of various
  events and objects in the view layer
  - Registers a number of them as services when done
- Application pulls ViewManager from service manager and attaches it to events
- ViewManager has an onBootstrap listener that attaches to the bootstrap event
  at high (10000) priority
  • Loading branch information
weierophinney committed May 15, 2012
1 parent de245da commit 7a8e953
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 272 deletions.
46 changes: 8 additions & 38 deletions library/Zend/Mvc/Application.php
Expand Up @@ -63,7 +63,6 @@ class Application implements
*/
protected $moduleManager;


public function __construct($configuration, ServiceManager $instanceManager = null)
{
$this->configuration = $configuration;
Expand All @@ -85,16 +84,16 @@ public function __construct($configuration, ServiceManager $instanceManager = nu
// $appManager->configureInstanceManager($instanceManager);
// }

$this->serviceManager = $instanceManager;
$this->setEventManager($instanceManager->get('EventManager'));

$this->moduleManager = $instanceManager->get('ModuleManager');
$this->request = $instanceManager->get('Request');
$this->response = $instanceManager->get('Response');

$this->events->attach($instanceManager->get('ViewManager'));
$this->events->attach($instanceManager->get('RouteListener'));
$this->events->attach($instanceManager->get('DispatchListener'));
$this->events->attach($instanceManager->get('ViewDefaultRenderingStrategy'));
$this->request = $instanceManager->get('Request');
$this->response = $instanceManager->get('Response');

$this->serviceManager = $instanceManager;
}

public function getConfiguration()
Expand All @@ -105,43 +104,14 @@ public function getConfiguration()
public function bootstrap()
{
$serviceManager = $this->serviceManager;
$events = $this->events();
$sharedEvents = $events->getSharedManager();

// Setup error strategies
$noRouteStrategy = $serviceManager->get('ViewRouteNotFoundStrategy');
$exceptionStrategy = $serviceManager->get('ViewExceptionStrategy');
$events->attach($noRouteStrategy);
$events->attach($exceptionStrategy);

// Setup default view events
$createViewModelListener = new View\CreateViewModelListener();
$injectTemplateListener = new View\InjectTemplateListener();
$injectViewModelListener = new View\InjectViewModelListener();

$sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($createViewModelListener, 'createViewModelFromArray'), -80);
$sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($noRouteStrategy, 'prepareNotFoundViewModel'), -90);
$sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($createViewModelListener, 'createViewModelFromNull'), -80);
$sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($injectTemplateListener, 'injectTemplate'), -90);
$sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($injectViewModelListener, 'injectViewModel'), -100);
$events->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($injectViewModelListener, 'injectViewModel'), -100);

// Setup MVC Event
$this->event = $event = new MvcEvent();
$event->setTarget($this);
$event->setApplication($this)
->setRequest($this->getRequest())
->setResponse($this->getResponse())
->setRouter($serviceManager->get('Router'));

// Setup "layout" view model for event
$renderingStrategy = $serviceManager->get('ViewDefaultRenderingStrategy');
$viewModel = $event->getViewModel();
$viewModel->setTemplate($renderingStrategy->getLayoutTemplate());

$renderer = $this->serviceManager->get('ViewPhpRenderer');
$modelHelper = $renderer->plugin('view_model');
$modelHelper->setRoot($viewModel);
->setRequest($this->getRequest())
->setResponse($this->getResponse())
->setRouter($serviceManager->get('Router'));

// Trigger bootstrap events
$this->events()->trigger('bootstrap', $event);
Expand Down
17 changes: 3 additions & 14 deletions library/Zend/Mvc/Service/ServiceManagerConfiguration.php
Expand Up @@ -13,7 +13,8 @@ class ServiceManagerConfiguration implements ConfigurationInterface
'Request' => 'Zend\Http\PhpEnvironment\Request',
'Response' => 'Zend\Http\PhpEnvironment\Response',
'RouteListener' => 'Zend\Mvc\RouteListener',
'DispatchListener' => 'Zend\Mvc\DispatchListener'
'DispatchListener' => 'Zend\Mvc\DispatchListener',
'ViewManager' => 'Zend\Mvc\View\ViewManager',
);

protected $factories = array(
Expand All @@ -26,18 +27,6 @@ class ServiceManagerConfiguration implements ConfigurationInterface
'Application' => 'Zend\Mvc\Service\ApplicationFactory',
'DependencyInjector' => 'Zend\Mvc\Service\DiFactory',
'ControllerLoader' => 'Zend\Mvc\Service\ControllerLoaderFactory',

// view related stuffs
'View' => 'Zend\Mvc\Service\ViewFactory',
'ViewAggregateResolver' => 'Zend\Mvc\Service\ViewAggregateResolverFactory',
'ViewDefaultRenderingStrategy' => 'Zend\Mvc\Service\ViewDefaultRenderingStrategyFactory',
'ViewExceptionStrategy' => 'Zend\Mvc\Service\ViewExceptionStrategyFactory',
'ViewHelperLoader' => 'Zend\Mvc\Service\ViewHelperLoaderFactory',
'ViewPhpRenderer' => 'Zend\Mvc\Service\ViewPhpRendererFactory',
'ViewPhpRendererStrategy' => 'Zend\Mvc\Service\ViewPhpRendererStrategyFactory',
'ViewRouteNotFoundStrategy' => 'Zend\Mvc\Service\ViewRouteNotFoundStrategyFactory',
'ViewTemplateMapResolver' => 'Zend\Mvc\Service\ViewTemplateMapResolverFactory',
'ViewTemplatePathStack' => 'Zend\Mvc\Service\ViewTemplatePathStackFactory',
);

protected $abstractFactories = array(
Expand Down Expand Up @@ -114,4 +103,4 @@ public function configureServiceManager(ServiceManager $serviceManager)
$serviceManager->setAlias('Zend\ServiceManager\ServiceManager', 'ServiceManager');
}

}
}
20 changes: 0 additions & 20 deletions library/Zend/Mvc/Service/ViewAggregateResolverFactory.php

This file was deleted.

19 changes: 0 additions & 19 deletions library/Zend/Mvc/Service/ViewDefaultRenderingStrategyFactory.php

This file was deleted.

21 changes: 0 additions & 21 deletions library/Zend/Mvc/Service/ViewExceptionStrategyFactory.php

This file was deleted.

18 changes: 0 additions & 18 deletions library/Zend/Mvc/Service/ViewFactory.php

This file was deleted.

21 changes: 0 additions & 21 deletions library/Zend/Mvc/Service/ViewHelperLoaderFactory.php

This file was deleted.

38 changes: 0 additions & 38 deletions library/Zend/Mvc/Service/ViewPhpRendererFactory.php

This file was deleted.

16 changes: 0 additions & 16 deletions library/Zend/Mvc/Service/ViewPhpRendererStrategyFactory.php

This file was deleted.

25 changes: 0 additions & 25 deletions library/Zend/Mvc/Service/ViewRouteNotFoundStrategyFactory.php

This file was deleted.

21 changes: 0 additions & 21 deletions library/Zend/Mvc/Service/ViewTemplateMapResolverFactory.php

This file was deleted.

21 changes: 0 additions & 21 deletions library/Zend/Mvc/Service/ViewTemplatePathStackFactory.php

This file was deleted.

0 comments on commit 7a8e953

Please sign in to comment.