Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Create factories for selected view collaborators #4251

Merged
merged 2 commits into from

2 participants

@weierophinney

Currently, I've made independent factories for HTTP and Console ViewManagers:

  • Created HttpViewManagerFactory and ConsoleViewManagerFactory; each will return the requested view manager.
  • ViewManagerFactory now consumes the above two factories (instead of using direct instantiation).

This will allow console endpoints to utilize the HTTP view manager if
desired by doing the following:

'service_manager' => array(
    'factories' => array(
        'ViewManager' => 'Zend\Mvc\Service\HttpViewManager',
    ),
),
@weierophinney

Failure is due to inability of Composer to lookup ocramius/proxy-manager. Marco's looking into that. Regardless, a work in progress...

@weierophinney weierophinney Make independent factories for HTTP and Console ViewManagers
- Created `HttpViewManagerFactory` and `ConsoleViewManagerFactory`; each
  will return the requested view manager.
- `ViewManagerFactory` now consumes the above two factories (instead of
  using direct instantiation).

This will allow console endpoints to utilize the HTTP view manager if
desired by doing the following:

```php
'service_manager' => array(
    'factories' => array(
        'ViewManager' => 'Zend\Mvc\Service\HttpViewManager',
    ),
),
```

I plan further refactoring to move the event listener registration into
individual factories as well.
fb79c13
@mwillbanks
Collaborator

@weierophinney looks like this breaks current tests:

There were 3 errors:

1) ZendTest\View\Helper\UrlIntegrationTest::testUrlHelperWorksUnderNormalHttpParadigms
Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for HttpViewManager

/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:496
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/Mvc/Service/ViewManagerFactory.php:32
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:853
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:983
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:598
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:557
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:481
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/Mvc/Application.php:144
/Users/mwillbanks/Projects/zf2_ZF/tests/ZendTest/View/Helper/UrlIntegrationTest.php:97

2) ZendTest\View\Helper\UrlIntegrationTest::testUrlHelperWorksWithForceCanonicalFlag
Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for HttpViewManager

/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:496
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/Mvc/Service/ViewManagerFactory.php:32
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:853
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:983
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:598
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:557
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:481
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/Mvc/Application.php:144
/Users/mwillbanks/Projects/zf2_ZF/tests/ZendTest/View/Helper/UrlIntegrationTest.php:109

3) ZendTest\View\Helper\UrlIntegrationTest::testUrlHelperUnderConsoleParadigmShouldReturnHttpRoutes
Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for ConsoleViewManager

/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:496
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/Mvc/Service/ViewManagerFactory.php:29
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:853
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:983
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:598
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:557
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/ServiceManager/ServiceManager.php:481
/Users/mwillbanks/Projects/zf2_ZF/library/Zend/Mvc/Application.php:144
/Users/mwillbanks/Projects/zf2_ZF/tests/ZendTest/View/Helper/UrlIntegrationTest.php:124

@weierophinney weierophinney [#4251] Fix URL helper integration tests
- Ensure both HttpViewManager and ConsoleViewManager factories are present
9b544f6
@mwillbanks mwillbanks merged commit 9b544f6 into zendframework:develop
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#4251] Fix URL helper integration tests
- Ensure both HttpViewManager and ConsoleViewManager factories are present
779457e
@ghost Unknown referenced this pull request from a commit
@mwillbanks mwillbanks Merge branch 'feature/4251' into develop
Close #4251
9c826c2
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-view
@weierophinney weierophinney [zendframework/zf2#4251] Fix URL helper integration tests
- Ensure both HttpViewManager and ConsoleViewManager factories are present
8fa8f9b
@gianarb gianarb referenced this pull request from a commit in zendframework/zend-view
@mwillbanks mwillbanks Merge branch 'feature/4251' into develop 2aa926c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 29, 2013
  1. @weierophinney

    Make independent factories for HTTP and Console ViewManagers

    weierophinney authored
    - Created `HttpViewManagerFactory` and `ConsoleViewManagerFactory`; each
      will return the requested view manager.
    - `ViewManagerFactory` now consumes the above two factories (instead of
      using direct instantiation).
    
    This will allow console endpoints to utilize the HTTP view manager if
    desired by doing the following:
    
    ```php
    'service_manager' => array(
        'factories' => array(
            'ViewManager' => 'Zend\Mvc\Service\HttpViewManager',
        ),
    ),
    ```
    
    I plan further refactoring to move the event listener registration into
    individual factories as well.
Commits on Apr 30, 2013
  1. @weierophinney

    [#4251] Fix URL helper integration tests

    weierophinney authored
    - Ensure both HttpViewManager and ConsoleViewManager factories are present
This page is out of date. Refresh to see the latest.
View
35 library/Zend/Mvc/Service/ConsoleViewManagerFactory.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+namespace Zend\Mvc\Service;
+
+use Zend\Console\Console;
+use Zend\ServiceManager\Exception\ServiceNotCreatedException;
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+use Zend\Mvc\View\Console\ViewManager as ConsoleViewManager;
+
+class ConsoleViewManagerFactory implements FactoryInterface
+{
+ /**
+ * Create and return the view manager for the console environment
+ *
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return ConsoleViewManager
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ if (!Console::isConsole()) {
+ throw new ServiceNotCreatedException(
+ 'ConsoleViewManager requires a Console environment; console environment not detected'
+ );
+ }
+ return new ConsoleViewManager();
+ }
+}
View
28 library/Zend/Mvc/Service/HttpViewManagerFactory.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+namespace Zend\Mvc\Service;
+
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+use Zend\Mvc\View\Http\ViewManager as HttpViewManager;
+
+class HttpViewManagerFactory implements FactoryInterface
+{
+ /**
+ * Create and return a view manager for the HTTP environment
+ *
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return HttpViewManager
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ return new HttpViewManager();
+ }
+}
View
2  library/Zend/Mvc/Service/ServiceListenerFactory.php
@@ -46,6 +46,7 @@ class ServiceListenerFactory implements FactoryInterface
'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory',
'ConsoleAdapter' => 'Zend\Mvc\Service\ConsoleAdapterFactory',
'ConsoleRouter' => 'Zend\Mvc\Service\RouterFactory',
+ 'ConsoleViewManager' => 'Zend\Mvc\Service\ConsoleViewManagerFactory',
'DependencyInjector' => 'Zend\Mvc\Service\DiFactory',
'DiAbstractServiceFactory' => 'Zend\Mvc\Service\DiAbstractServiceFactoryFactory',
'DiServiceInitializer' => 'Zend\Mvc\Service\DiServiceInitializerFactory',
@@ -53,6 +54,7 @@ class ServiceListenerFactory implements FactoryInterface
'FilterManager' => 'Zend\Mvc\Service\FilterManagerFactory',
'FormElementManager' => 'Zend\Mvc\Service\FormElementManagerFactory',
'HttpRouter' => 'Zend\Mvc\Service\RouterFactory',
+ 'HttpViewManager' => 'Zend\Mvc\Service\HttpViewManagerFactory',
'HydratorManager' => 'Zend\Mvc\Service\HydratorManagerFactory',
'InputFilterManager' => 'Zend\Mvc\Service\InputFilterManagerFactory',
'PaginatorPluginManager' => 'Zend\Mvc\Service\PaginatorPluginManagerFactory',
View
8 library/Zend/Mvc/Service/ViewManagerFactory.php
@@ -18,17 +18,17 @@
class ViewManagerFactory implements FactoryInterface
{
/**
- * Create and return a request instance, according to current environment.
+ * Create and return a view manager based on detected environment
*
* @param ServiceLocatorInterface $serviceLocator
- * @return HttpViewManager
+ * @return ConsoleViewManager|HttpViewManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (Console::isConsole()) {
- return new ConsoleViewManager();
+ return $serviceLocator->get('ConsoleViewManager');
}
- return new HttpViewManager();
+ return $serviceLocator->get('HttpViewManager');
}
}
View
2  tests/ZendTest/View/Helper/UrlIntegrationTest.php
@@ -67,6 +67,7 @@ protected function setUp()
),
'factories' => array(
'Application' => 'Zend\Mvc\Service\ApplicationFactory',
+ 'ConsoleViewManager' => 'Zend\Mvc\Service\ConsoleViewManagerFactory',
'EventManager' => 'Zend\Mvc\Service\EventManagerFactory',
'ViewHelperManager' => 'Zend\Mvc\Service\ViewHelperManagerFactory',
'Request' => 'Zend\Mvc\Service\RequestFactory',
@@ -74,6 +75,7 @@ protected function setUp()
'Router' => 'Zend\Mvc\Service\RouterFactory',
'ConsoleRouter' => 'Zend\Mvc\Service\RouterFactory',
'HttpRouter' => 'Zend\Mvc\Service\RouterFactory',
+ 'HttpViewManager' => 'Zend\Mvc\Service\HttpViewManagerFactory',
'RoutePluginManager' => 'Zend\Mvc\Service\RoutePluginManagerFactory',
'ViewManager' => 'Zend\Mvc\Service\ViewManagerFactory',
'ViewResolver' => 'Zend\Mvc\Service\ViewResolverFactory',
Something went wrong with that request. Please try again.