From 97693879821b50a540718a4a261736694135d9c2 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 5 Jan 2018 16:27:32 +1000 Subject: [PATCH 01/51] Move Service namespace to Container namespace --- docs/book/intro.md | 6 +-- docs/book/services.md | 52 +++++++++---------- src/Application.php | 2 +- .../ApplicationFactory.php | 2 +- src/{Service => Container}/ConfigFactory.php | 2 +- .../ControllerManagerFactory.php | 2 +- .../ControllerPluginManagerFactory.php | 3 +- .../DefaultRenderingStrategyFactory.php} | 6 +-- .../DispatchListenerFactory.php | 2 +- .../EventManagerFactory.php | 2 +- .../ExceptionStrategyFactory.php} | 6 +-- .../HttpMethodListenerFactory.php | 2 +- .../HttpViewManagerFactory.php | 2 +- .../InjectTemplateListenerFactory.php | 2 +- .../ModuleManagerFactory.php | 2 +- .../PaginatorPluginManagerFactory.php | 3 +- src/{Service => Container}/RequestFactory.php | 2 +- .../ResponseFactory.php | 2 +- .../RouteNotFoundStrategyFactory.php} | 6 +-- .../SendResponseListenerFactory.php | 2 +- .../ServiceListenerFactory.php | 44 ++++++++-------- .../ServiceManagerConfig.php | 2 +- src/{Service => Container}/ViewFactory.php | 2 +- .../ViewFeedStrategyFactory.php | 2 +- .../ViewHelperManagerFactory.php | 3 +- .../ViewJsonStrategyFactory.php | 2 +- .../ViewManagerConfigTrait.php} | 4 +- .../ViewManagerFactory.php | 2 +- .../ViewPhpRendererFactory.php | 2 +- .../ViewPhpRendererStrategyFactory.php | 2 +- .../ViewPrefixPathStackResolverFactory.php | 2 +- .../ViewResolverFactory.php | 2 +- .../ViewTemplateMapResolverFactory.php | 2 +- .../ViewTemplatePathStackFactory.php | 2 +- test/Application/BadControllerTrait.php | 4 +- .../InvalidControllerTypeTrait.php | 4 +- test/Application/MissingControllerTrait.php | 4 +- test/Application/PathControllerTrait.php | 4 +- .../Application/config/module.config.php | 2 +- test/ApplicationTest.php | 4 +- .../ControllerManagerFactoryTest.php | 9 ++-- .../HttpMethodListenerFactoryTest.php | 6 +-- .../InjectTemplateListenerFactoryTest.php | 8 +-- .../RequestFactoryTest.php | 4 +- .../ResponseFactoryTest.php | 4 +- .../SendResponseListenerFactoryTest.php | 4 +- .../ServiceListenerFactoryTest.php | 6 +-- .../ServiceManagerConfigTest.php | 8 ++- .../ViewFeedStrategyFactoryTest.php | 4 +- .../ViewHelperManagerFactoryTest.php | 4 +- .../ViewJsonStrategyFactoryTest.php | 4 +- .../ViewManagerFactoryTest.php | 4 +- ...ViewPrefixPathStackResolverFactoryTest.php | 4 +- 53 files changed, 136 insertions(+), 136 deletions(-) rename src/{Service => Container}/ApplicationFactory.php (97%) rename src/{Service => Container}/ConfigFactory.php (97%) rename src/{Service => Container}/ControllerManagerFactory.php (97%) rename src/{Service => Container}/ControllerPluginManagerFactory.php (86%) rename src/{Service/HttpDefaultRenderingStrategyFactory.php => Container/DefaultRenderingStrategyFactory.php} (91%) rename src/{Service => Container}/DispatchListenerFactory.php (96%) rename src/{Service => Container}/EventManagerFactory.php (97%) rename src/{Service/HttpExceptionStrategyFactory.php => Container/ExceptionStrategyFactory.php} (93%) rename src/{Service => Container}/HttpMethodListenerFactory.php (97%) rename src/{Service => Container}/HttpViewManagerFactory.php (96%) rename src/{Service => Container}/InjectTemplateListenerFactory.php (97%) rename src/{Service => Container}/ModuleManagerFactory.php (99%) rename src/{Service => Container}/PaginatorPluginManagerFactory.php (86%) rename src/{Service => Container}/RequestFactory.php (96%) rename src/{Service => Container}/ResponseFactory.php (96%) rename src/{Service/HttpRouteNotFoundStrategyFactory.php => Container/RouteNotFoundStrategyFactory.php} (94%) rename src/{Service => Container}/SendResponseListenerFactory.php (95%) rename src/{Service => Container}/ServiceListenerFactory.php (83%) rename src/{Service => Container}/ServiceManagerConfig.php (99%) rename src/{Service => Container}/ViewFactory.php (96%) rename src/{Service => Container}/ViewFeedStrategyFactory.php (97%) rename src/{Service => Container}/ViewHelperManagerFactory.php (98%) rename src/{Service => Container}/ViewJsonStrategyFactory.php (97%) rename src/{Service/HttpViewManagerConfigTrait.php => Container/ViewManagerConfigTrait.php} (93%) rename src/{Service => Container}/ViewManagerFactory.php (96%) rename src/{Service => Container}/ViewPhpRendererFactory.php (96%) rename src/{Service => Container}/ViewPhpRendererStrategyFactory.php (96%) rename src/{Service => Container}/ViewPrefixPathStackResolverFactory.php (97%) rename src/{Service => Container}/ViewResolverFactory.php (98%) rename src/{Service => Container}/ViewTemplateMapResolverFactory.php (97%) rename src/{Service => Container}/ViewTemplatePathStackFactory.php (98%) rename test/{Service => Container}/ControllerManagerFactoryTest.php (94%) rename test/{Service => Container}/HttpMethodListenerFactoryTest.php (92%) rename test/{Service => Container}/InjectTemplateListenerFactoryTest.php (91%) rename test/{Service => Container}/RequestFactoryTest.php (90%) rename test/{Service => Container}/ResponseFactoryTest.php (90%) rename test/{Service => Container}/SendResponseListenerFactoryTest.php (96%) rename test/{Service => Container}/ServiceListenerFactoryTest.php (98%) rename test/{Service => Container}/ServiceManagerConfigTest.php (96%) rename test/{Service => Container}/ViewFeedStrategyFactoryTest.php (92%) rename test/{Service => Container}/ViewHelperManagerFactoryTest.php (98%) rename test/{Service => Container}/ViewJsonStrategyFactoryTest.php (92%) rename test/{Service => Container}/ViewManagerFactoryTest.php (93%) rename test/{Service => Container}/ViewPrefixPathStackResolverFactoryTest.php (92%) diff --git a/docs/book/intro.md b/docs/book/intro.md index 178e64aea..859635af2 100644 --- a/docs/book/intro.md +++ b/docs/book/intro.md @@ -25,7 +25,7 @@ Within the MVC layer, several sub-components are exposed: - `Zend\Mvc\Controller`, a set of abstract "controller" classes with basic responsibilities such as event wiring, action dispatching, etc., as well as controller plugins. -- `Zend\Mvc\Service` provides a set of zend-servicemanager factories and +- `Zend\Mvc\Container` provides a set of zend-servicemanager factories and definitions for the default application workflow. - `Zend\Mvc\View` provides default wiring for renderer selection, view script resolution, helper registration, and more; additionally, it provides a @@ -271,7 +271,7 @@ services available by default yet. You can greatly simplify things by using the ```php use Zend\Loader\AutoloaderFactory; -use Zend\Mvc\Service\ServiceManagerConfig; +use Zend\Mvc\Container\ServiceManagerConfig; use Zend\ServiceManager\ServiceManager; // setup autoloader @@ -300,7 +300,7 @@ You can make this even simpler by using the `init()` method of the ```php use Zend\Loader\AutoloaderFactory; use Zend\Mvc\Application; -use Zend\Mvc\Service\ServiceManagerConfig; +use Zend\Mvc\Container\ServiceManagerConfig; use Zend\ServiceManager\ServiceManager; // setup autoloader diff --git a/docs/book/services.md b/docs/book/services.md index 1e3a82e66..5cd543c7b 100644 --- a/docs/book/services.md +++ b/docs/book/services.md @@ -1,7 +1,7 @@ # Default Services The default and recommended way to write zend-mvc applications uses a set of -services defined in the `Zend\Mvc\Service` namespace. This chapter details what +services defined in the `Zend\Mvc\Container` namespace. This chapter details what each of those services are, the classes they represent, and the configuration options available. @@ -17,17 +17,17 @@ somewhat complex set of services and their factories has been created. We'll try to give a simplified explanation of the process. When a `Zend\Mvc\Application` is created, a `Zend\ServiceManager\ServiceManager` -object is created and configured via `Zend\Mvc\Service\ServiceManagerConfig`. +object is created and configured via `Zend\Mvc\Container\ServiceManagerConfig`. The `ServiceManagerConfig` gets the configuration from `config/application.config.php` (or some other application configuration you passed to the `Application` when creating it). From all the service and -factories provided in the `Zend\Mvc\Service` namespace, `ServiceManagerConfig` +factories provided in the `Zend\Mvc\Container` namespace, `ServiceManagerConfig` is responsible of configuring only three: `SharedEventManager`, `EventManager`, and `ModuleManager`. After this, the `Application` fetches the `ModuleManager`. At this point, the `ModuleManager` further configures the `ServiceManager` with services and -factories provided in `Zend\Mvc\Service\ServiceListenerFactory`. This approach +factories provided in `Zend\Mvc\Container\ServiceListenerFactory`. This approach allows us to keep the main application configuration concise, and to give the developer the power to configure different parts of the MVC system from within the modules, overriding any default configuration in these MVC services. @@ -84,14 +84,14 @@ services configured out of the box. ### Factories -- `Application`, mapping to `Zend\Mvc\Service\ApplicationFactory`. +- `Application`, mapping to `Zend\Mvc\Container\ApplicationFactory`. -- `Config`, mapping to `Zend\Mvc\Service\ConfigFactory`. Internally, this +- `Config`, mapping to `Zend\Mvc\Container\ConfigFactory`. Internally, this pulls the `ModuleManager` service, calls its `loadModules()` method, and retrieves the merged configuration from the module event. As such, this service contains the entire, merged application configuration. -- `ControllerManager`, mapping to `Zend\Mvc\Service\ControllerLoaderFactory`. +- `ControllerManager`, mapping to `Zend\Mvc\Container\ControllerManagerFactory`. This creates an instance of `Zend\Mvc\Controller\ControllerManager`, passing the service manager instance. Additionally, it uses the `DiStrictAbstractServiceFactory` service, effectively allowing you to fall @@ -112,7 +112,7 @@ services configured out of the box. service, as long as the `setPluginManager` method is implemented. - `ControllerPluginManager`, mapping to - `Zend\Mvc\Service\ControllerPluginManagerFactory`. This instantiates the + `Zend\Mvc\Container\ControllerPluginManagerFactory`. This instantiates the `Zend\Mvc\Controller\PluginManager` instance, passing it the service manager instance. It also uses the `DiAbstractServiceFactory` service, effectively allowing you to fall back to DI in order to retrieve your [controller plugins](plugins.md). @@ -158,13 +158,13 @@ services configured out of the box. This creates an instance of `Zend\Mvc\Service\DiStrictAbstractServiceFactoryFactory`, injecting the `Di` service instance. -- `EventManager`, mapping to `Zend\Mvc\Service\EventManagerFactory`. This +- `EventManager`, mapping to `Zend\Mvc\Container\EventManagerFactory`. This factory returns a *discrete* instance of `Zend\EventManager\EventManager` on each request. This service is not shared by default, allowing the ability to have an `EventManager` per service, with a shared `SharedEventManager` injected in each. -- `FilterManager`, mapping to `Zend\Mvc\Service\FilterManagerFactory`. This +- `FilterManager`, mapping to `Zend\Mvc\Container\FilterManagerFactory`. This instantiates the `Zend\Filter\FilterPluginManager` instance, passing it the service manager instance; this is used to manage filters for [filter chains](http://docs.zendframework.com/zend-filter/filter-chains/). It also uses the `DiAbstractServiceFactory` service, effectively allowing @@ -180,7 +180,7 @@ services configured out of the box. the `Config` service, and pulls from the `router` key, configuring a `Zend\Router\Http\TreeRouteStack` instance. -- `HttpViewManager`, mapping to `Zend\Mvc\Service\HttpViewManagerFactory`. +- `HttpViewManager`, mapping to `Zend\Mvc\Container\HttpViewManagerFactory`. This creates and returns an instance of `Zend\Mvc\View\Http\ViewManager`, which in turn registers and initializes a number of HTTP-specific view services. @@ -193,14 +193,14 @@ services configured out of the box. This creates and returns an instance of `Zend\InputFilter\InputFilterPluginManager`, which can be used to manage and persist input filter instances. -- `ModuleManager`, mapping to `Zend\Mvc\Service\ModuleManagerFactory`. This is +- `ModuleManager`, mapping to `Zend\Mvc\Container\ModuleManagerFactory`. This is perhaps the most complex factory in the MVC stack. It expects that an `ApplicationConfig` service has been injected, with keys for `module_listener_options` and `modules`; see the quick start for samples. It creates an instance of `Zend\ModuleManager\Listener\DefaultListenerAggregate`, using the `module_listener_options` retrieved. It then checks if a service with the name `ServiceListener` exists; if not, it sets a factory with that - name mapping to `Zend\Mvc\Service\ServiceListenerFactory`. A bunch of + name mapping to `Zend\Mvc\Container\ServiceListenerFactory`. A bunch of service listeners will be added to the `ServiceListener`, like listeners for the `getServiceConfig`, `getControllerConfig`, `getControllerPluginConfig`, and `getViewHelperConfig` module methods. Next, it retrieves the @@ -216,20 +216,20 @@ services configured out of the box. allowing the instance to be used anywhere a translator may be required in the framework. -- `PaginatorPluginManager`, mapping to `Zend\Mvc\Service\PaginatorPluginManagerFactory`. +- `PaginatorPluginManager`, mapping to `Zend\Mvc\Container\PaginatorPluginManagerFactory`. This instantiates the `Zend\Paginator\AdapterPluginManager` instance, passing it the service manager instance. This is used to manage [paginator adapters](https://docs.zendframework.com/zend-paginator/advanced/#custom-data-source-adapters). It also uses the `DiAbstractServiceFactory` service, effectively allowing you to fall back to DI in order to retrieve paginator adapters. -- `Request`, mapping to `Zend\Mvc\Service\RequestFactory`. The factory is used +- `Request`, mapping to `Zend\Mvc\Container\RequestFactory`. The factory is used to create and return a request instance, according to the current environment. If the current environment is a console environment, it will create a `Zend\Console\Request`; otherwise, for HTTP environments, it creates a `Zend\Http\PhpEnvironment\Request`. -- `Response`, mapping to `Zend\Mvc\Service\ResponseFactory`. The factory is +- `Response`, mapping to `Zend\Mvc\Container\ResponseFactory`. The factory is used to create and return a response instance, according to the current environment. If the current environment is a console environment, it will create a `Zend\Console\Response`; otherwise, for HTTP environments, it @@ -249,7 +249,7 @@ services configured out of the box. which returns an instance of `Zend\Serializer\AdapterPluginManager`. This is a plugin manager for managing serializer adapter instances. -- `ServiceListener`, mapping to `Zend\Mvc\Service\ServiceListenerFactory`. The +- `ServiceListener`, mapping to `Zend\Mvc\Container\ServiceListenerFactory`. The factory is used to instantiate the `ServiceListener`, while allowing easy extending. It checks if a service with the name `ServiceListenerInterface` exists, which must implement `Zend\ModuleManager\Listener\ServiceListenerInterface`, @@ -266,15 +266,15 @@ services configured out of the box. It also uses the `DiAbstractServiceFactory` service, effectively allowing you to fall back to DI in order to retrieve validators. -- `ViewFeedRenderer`, mapping to `Zend\Mvc\Service\ViewFeedRendererFactory`, +- `ViewFeedRenderer`, mapping to `Zend\Mvc\Container\ViewFeedRendererFactory`, which returns an instance of `Zend\View\Renderer\FeedRenderer`, used to render feeds. -- `ViewFeedStrategy`, mapping to `Zend\Mvc\Service\ViewFeedStrategyFactory`, +- `ViewFeedStrategy`, mapping to `Zend\Mvc\Container\ViewFeedStrategyFactory`, which returns an instance of `Zend\View\Strategy\FeedStrategy`, used to select the `ViewFeedRenderer` given the appropriate criteria. -- `ViewHelperManager`, mapping to `Zend\Mvc\Service\ViewHelperManagerFactory`, +- `ViewHelperManager`, mapping to `Zend\Mvc\Container\ViewHelperManagerFactory`, which returns an instance of `Zend\View\HelperManager`. This is a plugin manager for managing view helper instances. @@ -282,24 +282,24 @@ services configured out of the box. which returns an instance of `Zend\View\Renderer\JsonRenderer`, used to render JSON structures. -- `ViewJsonStrategy`, mapping to `Zend\Mvc\Service\ViewJsonStrategyFactory`, +- `ViewJsonStrategy`, mapping to `Zend\Mvc\Container\ViewJsonStrategyFactory`, which returns an instance of `Zend\View\Strategy\JsonStrategy`, used to select the `ViewJsonRenderer` given the appropriate criteria. -- `ViewManager`, mapping to `Zend\Mvc\Service\ViewManagerFactory`. The factory +- `ViewManager`, mapping to `Zend\Mvc\Container\ViewManagerFactory`. The factory is used to create and return a view manager, according to the current environment. If the current environment is a console environment, it will create a `Zend\Mvc\View\Console\ViewManager`; otherwise, for HTTP environments, it returns a `Zend\Mvc\View\Http\ViewManager`. -- `ViewResolver`, mapping to `Zend\Mvc\Service\ViewResolverFactory`, which +- `ViewResolver`, mapping to `Zend\Mvc\Container\ViewResolverFactory`, which creates and returns the aggregate view resolver. It also attaches the `ViewTemplateMapResolver` and `ViewTemplatePathStack` services to it. -- `ViewTemplateMapResolver`, mapping to `Zend\Mvc\Service\ViewTemplateMapResolverFactory`, +- `ViewTemplateMapResolver`, mapping to `Zend\Mvc\Container\ViewTemplateMapResolverFactory`, which creates, configures and returns the `Zend\View\Resolver\TemplateMapResolver`. -- `ViewTemplatePathStack`, mapping to `Zend\Mvc\Service\ViewTemplatePathStackFactory`, +- `ViewTemplatePathStack`, mapping to `Zend\Mvc\Container\ViewTemplatePathStackFactory`, which creates, configures and returns the `Zend\View\Resolver\TemplatePathStack`. ### Abstract factories @@ -519,7 +519,7 @@ created and managed by the `ViewManager`: - `ViewHelperManager`, representing and aliased to `Zend\View\HelperPluginManager`. It is seeded with the `ServiceManager`. Created via the - `Zend\Mvc\Service\ViewHelperManagerFactory`. + `Zend\Mvc\Container\ViewHelperManagerFactory`. - The `Router` service is retrieved, and injected into the `Url` helper. diff --git a/src/Application.php b/src/Application.php index cc66cbb22..085af9f75 100644 --- a/src/Application.php +++ b/src/Application.php @@ -252,7 +252,7 @@ public static function init($configuration = []) { // Prepare the service manager $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : []; - $smConfig = new Service\ServiceManagerConfig($smConfig); + $smConfig = new Container\ServiceManagerConfig($smConfig); $serviceManager = new ServiceManager(); $smConfig->configureServiceManager($serviceManager); diff --git a/src/Service/ApplicationFactory.php b/src/Container/ApplicationFactory.php similarity index 97% rename from src/Service/ApplicationFactory.php rename to src/Container/ApplicationFactory.php index 2871cc334..6af06f338 100644 --- a/src/Service/ApplicationFactory.php +++ b/src/Container/ApplicationFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\Application; diff --git a/src/Service/ConfigFactory.php b/src/Container/ConfigFactory.php similarity index 97% rename from src/Service/ConfigFactory.php rename to src/Container/ConfigFactory.php index 4b9fbcbe6..1b92f2ff2 100644 --- a/src/Service/ConfigFactory.php +++ b/src/Container/ConfigFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Traversable; diff --git a/src/Service/ControllerManagerFactory.php b/src/Container/ControllerManagerFactory.php similarity index 97% rename from src/Service/ControllerManagerFactory.php rename to src/Container/ControllerManagerFactory.php index a1dd50812..29157efd0 100644 --- a/src/Service/ControllerManagerFactory.php +++ b/src/Container/ControllerManagerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\Controller\ControllerManager; diff --git a/src/Service/ControllerPluginManagerFactory.php b/src/Container/ControllerPluginManagerFactory.php similarity index 86% rename from src/Service/ControllerPluginManagerFactory.php rename to src/Container/ControllerPluginManagerFactory.php index 3b5c5a5fe..7b4278d1a 100644 --- a/src/Service/ControllerPluginManagerFactory.php +++ b/src/Container/ControllerPluginManagerFactory.php @@ -5,9 +5,10 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; +use Zend\Mvc\Service\AbstractPluginManagerFactory; class ControllerPluginManagerFactory extends AbstractPluginManagerFactory { diff --git a/src/Service/HttpDefaultRenderingStrategyFactory.php b/src/Container/DefaultRenderingStrategyFactory.php similarity index 91% rename from src/Service/HttpDefaultRenderingStrategyFactory.php rename to src/Container/DefaultRenderingStrategyFactory.php index 21a47daae..bc2302a8b 100644 --- a/src/Service/HttpDefaultRenderingStrategyFactory.php +++ b/src/Container/DefaultRenderingStrategyFactory.php @@ -5,16 +5,16 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\View\Http\DefaultRenderingStrategy; use Zend\ServiceManager\Factory\FactoryInterface; use Zend\View\View; -class HttpDefaultRenderingStrategyFactory implements FactoryInterface +class DefaultRenderingStrategyFactory implements FactoryInterface { - use HttpViewManagerConfigTrait; + use ViewManagerConfigTrait; /** * @param ContainerInterface $container diff --git a/src/Service/DispatchListenerFactory.php b/src/Container/DispatchListenerFactory.php similarity index 96% rename from src/Service/DispatchListenerFactory.php rename to src/Container/DispatchListenerFactory.php index 5d4aa99f5..1ee3e09de 100644 --- a/src/Service/DispatchListenerFactory.php +++ b/src/Container/DispatchListenerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\DispatchListener; diff --git a/src/Service/EventManagerFactory.php b/src/Container/EventManagerFactory.php similarity index 97% rename from src/Service/EventManagerFactory.php rename to src/Container/EventManagerFactory.php index 98bc186a6..f6e94ef07 100644 --- a/src/Service/EventManagerFactory.php +++ b/src/Container/EventManagerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\EventManager\EventManager; diff --git a/src/Service/HttpExceptionStrategyFactory.php b/src/Container/ExceptionStrategyFactory.php similarity index 93% rename from src/Service/HttpExceptionStrategyFactory.php rename to src/Container/ExceptionStrategyFactory.php index 6798f5a0a..3ad30ece1 100644 --- a/src/Service/HttpExceptionStrategyFactory.php +++ b/src/Container/ExceptionStrategyFactory.php @@ -5,15 +5,15 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\View\Http\ExceptionStrategy; use Zend\ServiceManager\Factory\FactoryInterface; -class HttpExceptionStrategyFactory implements FactoryInterface +class ExceptionStrategyFactory implements FactoryInterface { - use HttpViewManagerConfigTrait; + use ViewManagerConfigTrait; /** * @param ContainerInterface $container diff --git a/src/Service/HttpMethodListenerFactory.php b/src/Container/HttpMethodListenerFactory.php similarity index 97% rename from src/Service/HttpMethodListenerFactory.php rename to src/Container/HttpMethodListenerFactory.php index 7562ac9b8..72cf82f57 100644 --- a/src/Service/HttpMethodListenerFactory.php +++ b/src/Container/HttpMethodListenerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\HttpMethodListener; diff --git a/src/Service/HttpViewManagerFactory.php b/src/Container/HttpViewManagerFactory.php similarity index 96% rename from src/Service/HttpViewManagerFactory.php rename to src/Container/HttpViewManagerFactory.php index 07745e372..1336c6080 100644 --- a/src/Service/HttpViewManagerFactory.php +++ b/src/Container/HttpViewManagerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\View\Http\ViewManager as HttpViewManager; diff --git a/src/Service/InjectTemplateListenerFactory.php b/src/Container/InjectTemplateListenerFactory.php similarity index 97% rename from src/Service/InjectTemplateListenerFactory.php rename to src/Container/InjectTemplateListenerFactory.php index effd137a3..9aa66e9c5 100644 --- a/src/Service/InjectTemplateListenerFactory.php +++ b/src/Container/InjectTemplateListenerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\View\Http\InjectTemplateListener; diff --git a/src/Service/ModuleManagerFactory.php b/src/Container/ModuleManagerFactory.php similarity index 99% rename from src/Service/ModuleManagerFactory.php rename to src/Container/ModuleManagerFactory.php index 2d50ea820..de8bee354 100644 --- a/src/Service/ModuleManagerFactory.php +++ b/src/Container/ModuleManagerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ModuleManager\Listener\DefaultListenerAggregate; diff --git a/src/Service/PaginatorPluginManagerFactory.php b/src/Container/PaginatorPluginManagerFactory.php similarity index 86% rename from src/Service/PaginatorPluginManagerFactory.php rename to src/Container/PaginatorPluginManagerFactory.php index eac7de893..44f15c42b 100644 --- a/src/Service/PaginatorPluginManagerFactory.php +++ b/src/Container/PaginatorPluginManagerFactory.php @@ -5,8 +5,9 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; +use Zend\Mvc\Service\AbstractPluginManagerFactory; use Zend\Paginator\AdapterPluginManager as PaginatorPluginManager; class PaginatorPluginManagerFactory extends AbstractPluginManagerFactory diff --git a/src/Service/RequestFactory.php b/src/Container/RequestFactory.php similarity index 96% rename from src/Service/RequestFactory.php rename to src/Container/RequestFactory.php index df3f39aee..c16fc8356 100644 --- a/src/Service/RequestFactory.php +++ b/src/Container/RequestFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Http\PhpEnvironment\Request as HttpRequest; diff --git a/src/Service/ResponseFactory.php b/src/Container/ResponseFactory.php similarity index 96% rename from src/Service/ResponseFactory.php rename to src/Container/ResponseFactory.php index ff917299c..c6751b964 100644 --- a/src/Service/ResponseFactory.php +++ b/src/Container/ResponseFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Http\PhpEnvironment\Response as HttpResponse; diff --git a/src/Service/HttpRouteNotFoundStrategyFactory.php b/src/Container/RouteNotFoundStrategyFactory.php similarity index 94% rename from src/Service/HttpRouteNotFoundStrategyFactory.php rename to src/Container/RouteNotFoundStrategyFactory.php index a426d1aea..964873d08 100644 --- a/src/Service/HttpRouteNotFoundStrategyFactory.php +++ b/src/Container/RouteNotFoundStrategyFactory.php @@ -5,15 +5,15 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\View\Http\RouteNotFoundStrategy; use Zend\ServiceManager\Factory\FactoryInterface; -class HttpRouteNotFoundStrategyFactory implements FactoryInterface +class RouteNotFoundStrategyFactory implements FactoryInterface { - use HttpViewManagerConfigTrait; + use ViewManagerConfigTrait; /** * @param ContainerInterface $container diff --git a/src/Service/SendResponseListenerFactory.php b/src/Container/SendResponseListenerFactory.php similarity index 95% rename from src/Service/SendResponseListenerFactory.php rename to src/Container/SendResponseListenerFactory.php index c94b559af..215dddb36 100644 --- a/src/Service/SendResponseListenerFactory.php +++ b/src/Container/SendResponseListenerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\SendResponseListener; diff --git a/src/Service/ServiceListenerFactory.php b/src/Container/ServiceListenerFactory.php similarity index 83% rename from src/Service/ServiceListenerFactory.php rename to src/Container/ServiceListenerFactory.php index 4416fb6e8..17d471419 100644 --- a/src/Service/ServiceListenerFactory.php +++ b/src/Container/ServiceListenerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ModuleManager\Listener\ServiceListener; @@ -62,27 +62,27 @@ class ServiceListenerFactory implements FactoryInterface 'invokables' => [], 'factories' => [ 'Application' => ApplicationFactory::class, - 'config' => 'Zend\Mvc\Service\ConfigFactory', - 'ControllerManager' => 'Zend\Mvc\Service\ControllerManagerFactory', - 'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory', - 'DispatchListener' => 'Zend\Mvc\Service\DispatchListenerFactory', - 'HttpExceptionStrategy' => HttpExceptionStrategyFactory::class, - 'HttpMethodListener' => 'Zend\Mvc\Service\HttpMethodListenerFactory', - 'HttpRouteNotFoundStrategy' => HttpRouteNotFoundStrategyFactory::class, - 'HttpViewManager' => 'Zend\Mvc\Service\HttpViewManagerFactory', - 'InjectTemplateListener' => 'Zend\Mvc\Service\InjectTemplateListenerFactory', - 'PaginatorPluginManager' => 'Zend\Mvc\Service\PaginatorPluginManagerFactory', - 'Request' => 'Zend\Mvc\Service\RequestFactory', - 'Response' => 'Zend\Mvc\Service\ResponseFactory', - 'ViewHelperManager' => 'Zend\Mvc\Service\ViewHelperManagerFactory', - View\Http\DefaultRenderingStrategy::class => HttpDefaultRenderingStrategyFactory::class, - 'ViewFeedStrategy' => 'Zend\Mvc\Service\ViewFeedStrategyFactory', - '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', - 'ViewPrefixPathStackResolver' => 'Zend\Mvc\Service\ViewPrefixPathStackResolverFactory', + 'config' => 'Zend\Mvc\Container\ConfigFactory', + 'ControllerManager' => 'Zend\Mvc\Container\ControllerManagerFactory', + 'ControllerPluginManager' => 'Zend\Mvc\Container\ControllerPluginManagerFactory', + 'DispatchListener' => 'Zend\Mvc\Container\DispatchListenerFactory', + 'HttpExceptionStrategy' => ExceptionStrategyFactory::class, + 'HttpMethodListener' => 'Zend\Mvc\Container\HttpMethodListenerFactory', + 'HttpRouteNotFoundStrategy' => RouteNotFoundStrategyFactory::class, + 'HttpViewManager' => 'Zend\Mvc\Container\HttpViewManagerFactory', + 'InjectTemplateListener' => 'Zend\Mvc\Container\InjectTemplateListenerFactory', + 'PaginatorPluginManager' => 'Zend\Mvc\Container\PaginatorPluginManagerFactory', + 'Request' => 'Zend\Mvc\Container\RequestFactory', + 'Response' => 'Zend\Mvc\Container\ResponseFactory', + 'ViewHelperManager' => 'Zend\Mvc\Container\ViewHelperManagerFactory', + View\Http\DefaultRenderingStrategy::class => DefaultRenderingStrategyFactory::class, + 'ViewFeedStrategy' => 'Zend\Mvc\Container\ViewFeedStrategyFactory', + 'ViewJsonStrategy' => 'Zend\Mvc\Container\ViewJsonStrategyFactory', + 'ViewManager' => 'Zend\Mvc\Container\ViewManagerFactory', + 'ViewResolver' => 'Zend\Mvc\Container\ViewResolverFactory', + 'ViewTemplateMapResolver' => 'Zend\Mvc\Container\ViewTemplateMapResolverFactory', + 'ViewTemplatePathStack' => 'Zend\Mvc\Container\ViewTemplatePathStackFactory', + 'ViewPrefixPathStackResolver' => 'Zend\Mvc\Container\ViewPrefixPathStackResolverFactory', 'Zend\Mvc\MiddlewareListener' => InvokableFactory::class, 'Zend\Mvc\RouteListener' => InvokableFactory::class, 'Zend\Mvc\SendResponseListener' => SendResponseListenerFactory::class, diff --git a/src/Service/ServiceManagerConfig.php b/src/Container/ServiceManagerConfig.php similarity index 99% rename from src/Service/ServiceManagerConfig.php rename to src/Container/ServiceManagerConfig.php index dc1073a4e..9cdee66ad 100644 --- a/src/Service/ServiceManagerConfig.php +++ b/src/Container/ServiceManagerConfig.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\EventManager\EventManager; diff --git a/src/Service/ViewFactory.php b/src/Container/ViewFactory.php similarity index 96% rename from src/Service/ViewFactory.php rename to src/Container/ViewFactory.php index ed5852752..2fa90ed7c 100644 --- a/src/Service/ViewFactory.php +++ b/src/Container/ViewFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/src/Service/ViewFeedStrategyFactory.php b/src/Container/ViewFeedStrategyFactory.php similarity index 97% rename from src/Service/ViewFeedStrategyFactory.php rename to src/Container/ViewFeedStrategyFactory.php index 61a0d6c1a..7b3eefb8f 100644 --- a/src/Service/ViewFeedStrategyFactory.php +++ b/src/Container/ViewFeedStrategyFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/src/Service/ViewHelperManagerFactory.php b/src/Container/ViewHelperManagerFactory.php similarity index 98% rename from src/Service/ViewHelperManagerFactory.php rename to src/Container/ViewHelperManagerFactory.php index 371885b19..e1781b668 100644 --- a/src/Service/ViewHelperManagerFactory.php +++ b/src/Container/ViewHelperManagerFactory.php @@ -5,9 +5,10 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; +use Zend\Mvc\Service\AbstractPluginManagerFactory; use Zend\Router\RouteMatch; use Zend\ServiceManager\Exception\ServiceNotCreatedException; use Zend\View\Helper as ViewHelper; diff --git a/src/Service/ViewJsonStrategyFactory.php b/src/Container/ViewJsonStrategyFactory.php similarity index 97% rename from src/Service/ViewJsonStrategyFactory.php rename to src/Container/ViewJsonStrategyFactory.php index 1f5615031..acbc4b26c 100644 --- a/src/Service/ViewJsonStrategyFactory.php +++ b/src/Container/ViewJsonStrategyFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/src/Service/HttpViewManagerConfigTrait.php b/src/Container/ViewManagerConfigTrait.php similarity index 93% rename from src/Service/HttpViewManagerConfigTrait.php rename to src/Container/ViewManagerConfigTrait.php index 6c6efa62d..81da41c0d 100644 --- a/src/Service/HttpViewManagerConfigTrait.php +++ b/src/Container/ViewManagerConfigTrait.php @@ -5,12 +5,12 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use ArrayAccess; use Interop\Container\ContainerInterface; -trait HttpViewManagerConfigTrait +trait ViewManagerConfigTrait { /** * Retrieve view_manager configuration, if present. diff --git a/src/Service/ViewManagerFactory.php b/src/Container/ViewManagerFactory.php similarity index 96% rename from src/Service/ViewManagerFactory.php rename to src/Container/ViewManagerFactory.php index 28c1ecb76..81d2bc2bd 100644 --- a/src/Service/ViewManagerFactory.php +++ b/src/Container/ViewManagerFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\Mvc\View\Http\ViewManager as HttpViewManager; diff --git a/src/Service/ViewPhpRendererFactory.php b/src/Container/ViewPhpRendererFactory.php similarity index 96% rename from src/Service/ViewPhpRendererFactory.php rename to src/Container/ViewPhpRendererFactory.php index 3cd3d836b..13ea74d99 100644 --- a/src/Service/ViewPhpRendererFactory.php +++ b/src/Container/ViewPhpRendererFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/src/Service/ViewPhpRendererStrategyFactory.php b/src/Container/ViewPhpRendererStrategyFactory.php similarity index 96% rename from src/Service/ViewPhpRendererStrategyFactory.php rename to src/Container/ViewPhpRendererStrategyFactory.php index 6b83c7254..2dfe9909f 100644 --- a/src/Service/ViewPhpRendererStrategyFactory.php +++ b/src/Container/ViewPhpRendererStrategyFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/src/Service/ViewPrefixPathStackResolverFactory.php b/src/Container/ViewPrefixPathStackResolverFactory.php similarity index 97% rename from src/Service/ViewPrefixPathStackResolverFactory.php rename to src/Container/ViewPrefixPathStackResolverFactory.php index 08e9f49e1..11a29b3e2 100644 --- a/src/Service/ViewPrefixPathStackResolverFactory.php +++ b/src/Container/ViewPrefixPathStackResolverFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/src/Service/ViewResolverFactory.php b/src/Container/ViewResolverFactory.php similarity index 98% rename from src/Service/ViewResolverFactory.php rename to src/Container/ViewResolverFactory.php index ae743b8d2..42740ef0d 100644 --- a/src/Service/ViewResolverFactory.php +++ b/src/Container/ViewResolverFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/src/Service/ViewTemplateMapResolverFactory.php b/src/Container/ViewTemplateMapResolverFactory.php similarity index 97% rename from src/Service/ViewTemplateMapResolverFactory.php rename to src/Container/ViewTemplateMapResolverFactory.php index 18146d50f..a3727724e 100644 --- a/src/Service/ViewTemplateMapResolverFactory.php +++ b/src/Container/ViewTemplateMapResolverFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/src/Service/ViewTemplatePathStackFactory.php b/src/Container/ViewTemplatePathStackFactory.php similarity index 98% rename from src/Service/ViewTemplatePathStackFactory.php rename to src/Container/ViewTemplatePathStackFactory.php index cf7f01af0..e1a6b59b3 100644 --- a/src/Service/ViewTemplatePathStackFactory.php +++ b/src/Container/ViewTemplatePathStackFactory.php @@ -5,7 +5,7 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace Zend\Mvc\Service; +namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/test/Application/BadControllerTrait.php b/test/Application/BadControllerTrait.php index 5d2f57d75..b45c050d4 100644 --- a/test/Application/BadControllerTrait.php +++ b/test/Application/BadControllerTrait.php @@ -12,8 +12,8 @@ use Zend\Http\PhpEnvironment\Response; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; -use Zend\Mvc\Service\ServiceManagerConfig; -use Zend\Mvc\Service\ServiceListenerFactory; +use Zend\Mvc\Container\ServiceManagerConfig; +use Zend\Mvc\Container\ServiceListenerFactory; use Zend\Router; use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\ArrayUtils; diff --git a/test/Application/InvalidControllerTypeTrait.php b/test/Application/InvalidControllerTypeTrait.php index 5478a638a..a50b496f8 100644 --- a/test/Application/InvalidControllerTypeTrait.php +++ b/test/Application/InvalidControllerTypeTrait.php @@ -13,8 +13,8 @@ use Zend\Http\PhpEnvironment\Response; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; -use Zend\Mvc\Service\ServiceManagerConfig; -use Zend\Mvc\Service\ServiceListenerFactory; +use Zend\Mvc\Container\ServiceManagerConfig; +use Zend\Mvc\Container\ServiceListenerFactory; use Zend\Router; use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\ArrayUtils; diff --git a/test/Application/MissingControllerTrait.php b/test/Application/MissingControllerTrait.php index 8921b78ea..141168898 100644 --- a/test/Application/MissingControllerTrait.php +++ b/test/Application/MissingControllerTrait.php @@ -11,8 +11,8 @@ use Zend\Http\PhpEnvironment\Request; use Zend\Http\PhpEnvironment\Response; use Zend\Mvc\Application; -use Zend\Mvc\Service\ServiceManagerConfig; -use Zend\Mvc\Service\ServiceListenerFactory; +use Zend\Mvc\Container\ServiceManagerConfig; +use Zend\Mvc\Container\ServiceListenerFactory; use Zend\Router; use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\ArrayUtils; diff --git a/test/Application/PathControllerTrait.php b/test/Application/PathControllerTrait.php index f511e8684..075ee1997 100644 --- a/test/Application/PathControllerTrait.php +++ b/test/Application/PathControllerTrait.php @@ -12,8 +12,8 @@ use Zend\Http\PhpEnvironment\Response; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; -use Zend\Mvc\Service\ServiceManagerConfig; -use Zend\Mvc\Service\ServiceListenerFactory; +use Zend\Mvc\Container\ServiceManagerConfig; +use Zend\Mvc\Container\ServiceListenerFactory; use Zend\Router; use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\ArrayUtils; diff --git a/test/Application/TestAsset/modules/Application/config/module.config.php b/test/Application/TestAsset/modules/Application/config/module.config.php index db068ccca..669e51af7 100644 --- a/test/Application/TestAsset/modules/Application/config/module.config.php +++ b/test/Application/TestAsset/modules/Application/config/module.config.php @@ -9,7 +9,7 @@ use Zend\Http\PhpEnvironment\Request as HttpRequest; use Zend\Http\PhpEnvironment\Response as HttpResponse; -use Zend\Mvc\Service\HttpViewManagerFactory; +use Zend\Mvc\Container\HttpViewManagerFactory; use Zend\Router\Http\HttpRouterFactory; return [ diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index 35da58855..37682a561 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -21,8 +21,8 @@ use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\MvcEvent; -use Zend\Mvc\Service\ServiceManagerConfig; -use Zend\Mvc\Service\ServiceListenerFactory; +use Zend\Mvc\Container\ServiceManagerConfig; +use Zend\Mvc\Container\ServiceListenerFactory; use Zend\Router; use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\ArrayUtils; diff --git a/test/Service/ControllerManagerFactoryTest.php b/test/Container/ControllerManagerFactoryTest.php similarity index 94% rename from test/Service/ControllerManagerFactoryTest.php rename to test/Container/ControllerManagerFactoryTest.php index 39aa57ddc..01dbc5723 100644 --- a/test/Service/ControllerManagerFactoryTest.php +++ b/test/Container/ControllerManagerFactoryTest.php @@ -5,19 +5,20 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; use Zend\EventManager\SharedEventManager; -use Zend\Mvc\Service\ControllerManagerFactory; -use Zend\Mvc\Service\ControllerPluginManagerFactory; -use Zend\Mvc\Service\EventManagerFactory; +use Zend\Mvc\Container\ControllerManagerFactory; +use Zend\Mvc\Container\ControllerPluginManagerFactory; +use Zend\Mvc\Container\EventManagerFactory; use Zend\ServiceManager\Config; use Zend\ServiceManager\Exception; use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\ServiceManager; use ZendTest\Mvc\Controller\Plugin\TestAsset\SamplePlugin; use ZendTest\Mvc\Controller\TestAsset\SampleController; +use ZendTest\Mvc\Service\TestAsset; use ZendTest\Mvc\Service\TestAsset\InvalidDispatchableClass; class ControllerManagerFactoryTest extends TestCase diff --git a/test/Service/HttpMethodListenerFactoryTest.php b/test/Container/HttpMethodListenerFactoryTest.php similarity index 92% rename from test/Service/HttpMethodListenerFactoryTest.php rename to test/Container/HttpMethodListenerFactoryTest.php index 230ad0ae4..934a7d6d9 100644 --- a/test/Service/HttpMethodListenerFactoryTest.php +++ b/test/Container/HttpMethodListenerFactoryTest.php @@ -5,16 +5,16 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; use PHPUnit_Framework_MockObject_MockObject as MockObject; -use Zend\Mvc\Service\HttpMethodListenerFactory; +use Zend\Mvc\Container\HttpMethodListenerFactory; use Zend\ServiceManager\ServiceLocatorInterface; /** - * @covers Zend\Mvc\Service\HttpMethodListenerFactory + * @covers \Zend\Mvc\Container\HttpMethodListenerFactory */ class HttpMethodListenerFactoryTest extends TestCase { diff --git a/test/Service/InjectTemplateListenerFactoryTest.php b/test/Container/InjectTemplateListenerFactoryTest.php similarity index 91% rename from test/Service/InjectTemplateListenerFactoryTest.php rename to test/Container/InjectTemplateListenerFactoryTest.php index 2fb0b4e0d..99f515743 100644 --- a/test/Service/InjectTemplateListenerFactoryTest.php +++ b/test/Container/InjectTemplateListenerFactoryTest.php @@ -5,19 +5,19 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use ArrayObject; use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; -use Zend\Mvc\Service\InjectTemplateListenerFactory; +use Zend\Mvc\Container\InjectTemplateListenerFactory; use Zend\Mvc\View\Http\InjectTemplateListener; use Zend\ServiceManager\ServiceLocatorInterface; /** - * Tests for {@see \Zend\Mvc\Service\InjectTemplateListenerFactory} + * Tests for {@see \Zend\Mvc\Container\InjectTemplateListenerFactory} * - * @covers \Zend\Mvc\Service\InjectTemplateListenerFactory + * @covers \Zend\Mvc\Container\InjectTemplateListenerFactory */ class InjectTemplateListenerFactoryTest extends TestCase { diff --git a/test/Service/RequestFactoryTest.php b/test/Container/RequestFactoryTest.php similarity index 90% rename from test/Service/RequestFactoryTest.php rename to test/Container/RequestFactoryTest.php index bf3382e6c..b7f14458b 100644 --- a/test/Service/RequestFactoryTest.php +++ b/test/Container/RequestFactoryTest.php @@ -5,12 +5,12 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; use Zend\Http\Request as HttpRequest; -use Zend\Mvc\Service\RequestFactory; +use Zend\Mvc\Container\RequestFactory; class RequestFactoryTest extends TestCase { diff --git a/test/Service/ResponseFactoryTest.php b/test/Container/ResponseFactoryTest.php similarity index 90% rename from test/Service/ResponseFactoryTest.php rename to test/Container/ResponseFactoryTest.php index 47c6a6142..7ac7b9cf3 100644 --- a/test/Service/ResponseFactoryTest.php +++ b/test/Container/ResponseFactoryTest.php @@ -5,12 +5,12 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; use Zend\Http\Response as HttpResponse; -use Zend\Mvc\Service\ResponseFactory; +use Zend\Mvc\Container\ResponseFactory; class ResponseFactoryTest extends TestCase { diff --git a/test/Service/SendResponseListenerFactoryTest.php b/test/Container/SendResponseListenerFactoryTest.php similarity index 96% rename from test/Service/SendResponseListenerFactoryTest.php rename to test/Container/SendResponseListenerFactoryTest.php index e9adc2f22..b5eb7b18f 100644 --- a/test/Service/SendResponseListenerFactoryTest.php +++ b/test/Container/SendResponseListenerFactoryTest.php @@ -5,19 +5,19 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\SharedEventManagerInterface; +use Zend\Mvc\Container\SendResponseListenerFactory; use Zend\Mvc\ResponseSender\HttpResponseSender; use Zend\Mvc\ResponseSender\PhpEnvironmentResponseSender; use Zend\Mvc\ResponseSender\SendResponseEvent; use Zend\Mvc\ResponseSender\SimpleStreamResponseSender; use Zend\Mvc\SendResponseListener; -use Zend\Mvc\Service\SendResponseListenerFactory; class SendResponseListenerFactoryTest extends TestCase { diff --git a/test/Service/ServiceListenerFactoryTest.php b/test/Container/ServiceListenerFactoryTest.php similarity index 98% rename from test/Service/ServiceListenerFactoryTest.php rename to test/Container/ServiceListenerFactoryTest.php index 0d71cb93a..c6527734a 100644 --- a/test/Service/ServiceListenerFactoryTest.php +++ b/test/Container/ServiceListenerFactoryTest.php @@ -5,12 +5,10 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; -use ReflectionClass; -use ReflectionProperty; -use Zend\Mvc\Service\ServiceListenerFactory; +use Zend\Mvc\Container\ServiceListenerFactory; use Zend\ServiceManager\ServiceManager; class ServiceListenerFactoryTest extends TestCase diff --git a/test/Service/ServiceManagerConfigTest.php b/test/Container/ServiceManagerConfigTest.php similarity index 96% rename from test/Service/ServiceManagerConfigTest.php rename to test/Container/ServiceManagerConfigTest.php index c767403e8..d5739267d 100644 --- a/test/Service/ServiceManagerConfigTest.php +++ b/test/Container/ServiceManagerConfigTest.php @@ -5,22 +5,20 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; -use ReflectionClass; use stdClass; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\SharedEventManagerInterface; -use Zend\Mvc\Controller\PluginManager; -use Zend\Mvc\Service\ServiceManagerConfig; +use Zend\Mvc\Container\ServiceManagerConfig; use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\ServiceManager; use ZendTest\Mvc\Service\TestAsset\EventManagerAwareObject; /** - * @covers \Zend\Mvc\Service\ServiceManagerConfig + * @covers \Zend\Mvc\Container\ServiceManagerConfig */ class ServiceManagerConfigTest extends TestCase { diff --git a/test/Service/ViewFeedStrategyFactoryTest.php b/test/Container/ViewFeedStrategyFactoryTest.php similarity index 92% rename from test/Service/ViewFeedStrategyFactoryTest.php rename to test/Container/ViewFeedStrategyFactoryTest.php index d6f24b7e9..e15f4f707 100644 --- a/test/Service/ViewFeedStrategyFactoryTest.php +++ b/test/Container/ViewFeedStrategyFactoryTest.php @@ -5,11 +5,11 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; -use Zend\Mvc\Service\ViewFeedStrategyFactory; +use Zend\Mvc\Container\ViewFeedStrategyFactory; use Zend\View\Renderer\FeedRenderer; use Zend\View\Strategy\FeedStrategy; diff --git a/test/Service/ViewHelperManagerFactoryTest.php b/test/Container/ViewHelperManagerFactoryTest.php similarity index 98% rename from test/Service/ViewHelperManagerFactoryTest.php rename to test/Container/ViewHelperManagerFactoryTest.php index fc9b3a15b..1030ed888 100644 --- a/test/Service/ViewHelperManagerFactoryTest.php +++ b/test/Container/ViewHelperManagerFactoryTest.php @@ -5,13 +5,13 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; use Zend\Http\PhpEnvironment\Request; use Zend\Mvc\Application; +use Zend\Mvc\Container\ViewHelperManagerFactory; use Zend\Mvc\MvcEvent; -use Zend\Mvc\Service\ViewHelperManagerFactory; use Zend\Router\RouteMatch; use Zend\Router\RouteStackInterface; use Zend\ServiceManager\ServiceManager; diff --git a/test/Service/ViewJsonStrategyFactoryTest.php b/test/Container/ViewJsonStrategyFactoryTest.php similarity index 92% rename from test/Service/ViewJsonStrategyFactoryTest.php rename to test/Container/ViewJsonStrategyFactoryTest.php index 0768537c9..202250700 100644 --- a/test/Service/ViewJsonStrategyFactoryTest.php +++ b/test/Container/ViewJsonStrategyFactoryTest.php @@ -5,11 +5,11 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; -use Zend\Mvc\Service\ViewJsonStrategyFactory; +use Zend\Mvc\Container\ViewJsonStrategyFactory; use Zend\View\Renderer\JsonRenderer; use Zend\View\Strategy\JsonStrategy; diff --git a/test/Service/ViewManagerFactoryTest.php b/test/Container/ViewManagerFactoryTest.php similarity index 93% rename from test/Service/ViewManagerFactoryTest.php rename to test/Container/ViewManagerFactoryTest.php index 2d28a13d0..a77d9a49d 100644 --- a/test/Service/ViewManagerFactoryTest.php +++ b/test/Container/ViewManagerFactoryTest.php @@ -5,11 +5,11 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; -use Zend\Mvc\Service\ViewManagerFactory; +use Zend\Mvc\Container\ViewManagerFactory; use Zend\Mvc\View\Http\ViewManager as HttpViewManager; class ViewManagerFactoryTest extends TestCase diff --git a/test/Service/ViewPrefixPathStackResolverFactoryTest.php b/test/Container/ViewPrefixPathStackResolverFactoryTest.php similarity index 92% rename from test/Service/ViewPrefixPathStackResolverFactoryTest.php rename to test/Container/ViewPrefixPathStackResolverFactoryTest.php index e0dedba2c..8ecf83207 100644 --- a/test/Service/ViewPrefixPathStackResolverFactoryTest.php +++ b/test/Container/ViewPrefixPathStackResolverFactoryTest.php @@ -5,11 +5,11 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ -namespace ZendTest\Mvc\Service; +namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; -use Zend\Mvc\Service\ViewPrefixPathStackResolverFactory; +use Zend\Mvc\Container\ViewPrefixPathStackResolverFactory; use Zend\ServiceManager\ServiceLocatorInterface; use Zend\View\Resolver\PrefixPathStackResolver; From a30d415a2b341f0dd5ea32a714f8d71ff5060cbb Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 13 Jan 2018 08:02:39 +1000 Subject: [PATCH 02/51] Bump minimum php to 7.1 --- composer.json | 2 +- composer.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index e34462775..0751ff404 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ "forum": "https://discourse.zendframework.com/c/questions/components" }, "require": { + "php": "^7.1", "container-interop/container-interop": "^1.2", - "php": "^5.6 || ^7.0", "zendframework/zend-eventmanager": "^3.2", "zendframework/zend-http": "^2.7", "zendframework/zend-modulemanager": "^2.8", diff --git a/composer.lock b/composer.lock index 0087b6629..3288ff23b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "4dca15262833c4fd34ad940c5472e161", + "content-hash": "8f489bb459890e234edb8612619b55c1", "packages": [ { "name": "container-interop/container-interop", @@ -2743,7 +2743,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^5.6 || ^7.0" + "php": "^7.1" }, "platform-dev": [] } From 29cd5003706b58cfd976020fcb1f32760158586e Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 13 Jan 2018 08:13:31 +1000 Subject: [PATCH 03/51] Update composer dependencies --- composer.json | 4 +- composer.lock | 287 +++++++++++++++++++++++++------------------------- 2 files changed, 148 insertions(+), 143 deletions(-) diff --git a/composer.json b/composer.json index 0751ff404..e961576f8 100644 --- a/composer.json +++ b/composer.json @@ -28,9 +28,9 @@ }, "require-dev": { "http-interop/http-middleware": "^0.4.1", - "phpunit/phpunit": "^6.4.4 || ^5.7.14", + "phpunit/phpunit": "^7.0", "zendframework/zend-coding-standard": "~1.0.0", - "zendframework/zend-json": "^2.6.1 || ^3.0", + "zendframework/zend-json": "^3.0", "zendframework/zend-psr7bridge": "^1.0", "zendframework/zend-stratigility": "^2.0.1" }, diff --git a/composer.lock b/composer.lock index 3288ff23b..881f41b57 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "8f489bb459890e234edb8612619b55c1", + "content-hash": "fb6ba17cab04ae71783b41718f15f852", "packages": [ { "name": "container-interop/container-interop", @@ -343,23 +343,23 @@ }, { "name": "zendframework/zend-modulemanager", - "version": "2.8.1", + "version": "2.8.2", "source": { "type": "git", "url": "https://github.com/zendframework/zend-modulemanager.git", - "reference": "710c13353b1ff0975777dbeb39bbf1c85e3353a3" + "reference": "394df6e12248ac430a312d4693f793ee7120baa6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-modulemanager/zipball/710c13353b1ff0975777dbeb39bbf1c85e3353a3", - "reference": "710c13353b1ff0975777dbeb39bbf1c85e3353a3", + "url": "https://api.github.com/repos/zendframework/zend-modulemanager/zipball/394df6e12248ac430a312d4693f793ee7120baa6", + "reference": "394df6e12248ac430a312d4693f793ee7120baa6", "shasum": "" }, "require": { "php": "^5.6 || ^7.0", "zendframework/zend-config": "^3.1 || ^2.6", "zendframework/zend-eventmanager": "^3.2 || ^2.6.3", - "zendframework/zend-stdlib": "^3.0 || ^2.7" + "zendframework/zend-stdlib": "^3.1 || ^2.7" }, "require-dev": { "phpunit/phpunit": "^6.0.8 || ^5.7.15", @@ -367,7 +367,7 @@ "zendframework/zend-console": "^2.6", "zendframework/zend-di": "^2.6", "zendframework/zend-loader": "^2.5", - "zendframework/zend-mvc": "^2.7", + "zendframework/zend-mvc": "^3.0 || ^2.7", "zendframework/zend-servicemanager": "^3.0.3 || ^2.7.5" }, "suggest": { @@ -379,8 +379,8 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.8-dev", - "dev-develop": "2.9-dev" + "dev-master": "2.7-dev", + "dev-develop": "2.8-dev" } }, "autoload": { @@ -392,12 +392,14 @@ "license": [ "BSD-3-Clause" ], + "description": "Modular application system for zend-mvc applications", "homepage": "https://github.com/zendframework/zend-modulemanager", "keywords": [ + "ZendFramework", "modulemanager", - "zf2" + "zf" ], - "time": "2017-11-01T18:30:41+00:00" + "time": "2017-12-02T06:11:18+00:00" }, { "name": "zendframework/zend-router", @@ -462,16 +464,16 @@ }, { "name": "zendframework/zend-servicemanager", - "version": "3.3.0", + "version": "3.3.1", "source": { "type": "git", "url": "https://github.com/zendframework/zend-servicemanager.git", - "reference": "c3036efb81f71bfa36cc9962ee5d4474f36581d0" + "reference": "0fa3d3cf588dde0850fff1efa60d44a7aa3c3ab7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-servicemanager/zipball/c3036efb81f71bfa36cc9962ee5d4474f36581d0", - "reference": "c3036efb81f71bfa36cc9962ee5d4474f36581d0", + "url": "https://api.github.com/repos/zendframework/zend-servicemanager/zipball/0fa3d3cf588dde0850fff1efa60d44a7aa3c3ab7", + "reference": "0fa3d3cf588dde0850fff1efa60d44a7aa3c3ab7", "shasum": "" }, "require": { @@ -503,7 +505,7 @@ "extra": { "branch-alias": { "dev-master": "3.3-dev", - "dev-develop": "3.4-dev" + "dev-develop": "4.0-dev" } }, "autoload": { @@ -521,7 +523,7 @@ "servicemanager", "zf" ], - "time": "2017-03-01T22:08:02+00:00" + "time": "2017-11-27T18:11:25+00:00" }, { "name": "zendframework/zend-stdlib", @@ -1085,29 +1087,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.1.1", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2" + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/2d3d238c433cf69caeb4842e97a3223a116f94b2", - "reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", "shasum": "" }, "require": { "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/reflection-common": "^1.0.0", "phpdocumentor/type-resolver": "^0.4.0", "webmozart/assert": "^1.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": [ @@ -1126,7 +1134,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-08-30T18:51:59+00:00" + "time": "2017-11-30T07:14:17+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -1177,16 +1185,16 @@ }, { "name": "phpspec/prophecy", - "version": "v1.7.2", + "version": "1.7.3", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6" + "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", + "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", "shasum": "" }, "require": { @@ -1198,7 +1206,7 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8 || ^5.6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7" }, "type": "library", "extra": { @@ -1236,45 +1244,44 @@ "spy", "stub" ], - "time": "2017-09-04T11:05:03+00:00" + "time": "2017-11-24T13:59:53+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "5.2.3", + "version": "6.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "8e1d2397d8adf59a3f12b2878a3aaa66d1ab189d" + "reference": "f8ca4b604baf23dab89d87773c28cc07405189ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/8e1d2397d8adf59a3f12b2878a3aaa66d1ab189d", - "reference": "8e1d2397d8adf59a3f12b2878a3aaa66d1ab189d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f8ca4b604baf23dab89d87773c28cc07405189ba", + "reference": "f8ca4b604baf23dab89d87773c28cc07405189ba", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^7.0", + "php": "^7.1", "phpunit/php-file-iterator": "^1.4.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^2.0", + "phpunit/php-token-stream": "^3.0", "sebastian/code-unit-reverse-lookup": "^1.0.1", "sebastian/environment": "^3.0", "sebastian/version": "^2.0.1", "theseer/tokenizer": "^1.1" }, "require-dev": { - "ext-xdebug": "^2.5", - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^7.0" }, "suggest": { - "ext-xdebug": "^2.5.5" + "ext-xdebug": "^2.6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "5.2.x-dev" + "dev-master": "6.0-dev" } }, "autoload": { @@ -1289,7 +1296,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1300,20 +1307,20 @@ "testing", "xunit" ], - "time": "2017-11-03T13:47:33+00:00" + "time": "2018-02-02T07:01:41+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.2", + "version": "1.4.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", "shasum": "" }, "require": { @@ -1347,7 +1354,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03T07:40:28+00:00" + "time": "2017-11-27T13:52:08+00:00" }, { "name": "phpunit/php-text-template", @@ -1392,28 +1399,28 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.9", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b8454ea6958c3dee38453d3bd571e023108c91f", + "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1428,7 +1435,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1437,33 +1444,33 @@ "keywords": [ "timer" ], - "time": "2017-02-26T11:10:40+00:00" + "time": "2018-02-01T13:07:23+00:00" }, { "name": "phpunit/php-token-stream", - "version": "2.0.1", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0" + "reference": "21ad88bbba7c3d93530d93994e0a33cd45f02ace" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/9a02332089ac48e704c70f6cefed30c224e3c0b0", - "reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/21ad88bbba7c3d93530d93994e0a33cd45f02ace", + "reference": "21ad88bbba7c3d93530d93994e0a33cd45f02ace", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": "^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.2.4" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1486,20 +1493,20 @@ "keywords": [ "tokenizer" ], - "time": "2017-08-20T05:47:52+00:00" + "time": "2018-02-01T13:16:43+00:00" }, { "name": "phpunit/phpunit", - "version": "6.4.4", + "version": "7.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "562f7dc75d46510a4ed5d16189ae57fbe45a9932" + "reference": "9b3373439fdf2f3e9d1578f5e408a3a0d161c3bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/562f7dc75d46510a4ed5d16189ae57fbe45a9932", - "reference": "562f7dc75d46510a4ed5d16189ae57fbe45a9932", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9b3373439fdf2f3e9d1578f5e408a3a0d161c3bc", + "reference": "9b3373439fdf2f3e9d1578f5e408a3a0d161c3bc", "shasum": "" }, "require": { @@ -1511,15 +1518,15 @@ "myclabs/deep-copy": "^1.6.1", "phar-io/manifest": "^1.0.1", "phar-io/version": "^1.0", - "php": "^7.0", + "php": "^7.1", "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^5.2.2", - "phpunit/php-file-iterator": "^1.4.2", + "phpunit/php-code-coverage": "^6.0", + "phpunit/php-file-iterator": "^1.4.3", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^1.0.9", - "phpunit/phpunit-mock-objects": "^4.0.3", - "sebastian/comparator": "^2.0.2", - "sebastian/diff": "^2.0", + "phpunit/php-timer": "^2.0", + "phpunit/phpunit-mock-objects": "^6.0", + "sebastian/comparator": "^2.1", + "sebastian/diff": "^3.0", "sebastian/environment": "^3.1", "sebastian/exporter": "^3.1", "sebastian/global-state": "^2.0", @@ -1527,16 +1534,12 @@ "sebastian/resource-operations": "^1.0", "sebastian/version": "^2.0.1" }, - "conflict": { - "phpdocumentor/reflection-docblock": "3.0.2", - "phpunit/dbunit": "<3.0" - }, "require-dev": { "ext-pdo": "*" }, "suggest": { "ext-xdebug": "*", - "phpunit/php-invoker": "^1.1" + "phpunit/php-invoker": "^2.0" }, "bin": [ "phpunit" @@ -1544,7 +1547,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "6.4.x-dev" + "dev-master": "7.0-dev" } }, "autoload": { @@ -1570,33 +1573,30 @@ "testing", "xunit" ], - "time": "2017-11-08T11:26:09+00:00" + "time": "2018-02-02T05:04:08+00:00" }, { "name": "phpunit/phpunit-mock-objects", - "version": "4.0.4", + "version": "6.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "2f789b59ab89669015ad984afa350c4ec577ade0" + "reference": "e495e5d3660321b62c294d8c0e954d02d6ce2573" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/2f789b59ab89669015ad984afa350c4ec577ade0", - "reference": "2f789b59ab89669015ad984afa350c4ec577ade0", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/e495e5d3660321b62c294d8c0e954d02d6ce2573", + "reference": "e495e5d3660321b62c294d8c0e954d02d6ce2573", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.5", - "php": "^7.0", + "php": "^7.1", "phpunit/php-text-template": "^1.2.1", - "sebastian/exporter": "^3.0" - }, - "conflict": { - "phpunit/phpunit": "<6.0" + "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^7.0" }, "suggest": { "ext-soap": "*" @@ -1604,7 +1604,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "6.0.x-dev" } }, "autoload": { @@ -1619,7 +1619,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1629,7 +1629,7 @@ "mock", "xunit" ], - "time": "2017-08-03T14:08:16+00:00" + "time": "2018-02-01T13:11:13+00:00" }, { "name": "psr/http-message", @@ -1728,21 +1728,21 @@ }, { "name": "sebastian/comparator", - "version": "2.1.0", + "version": "2.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1174d9018191e93cb9d719edec01257fc05f8158" + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1174d9018191e93cb9d719edec01257fc05f8158", - "reference": "1174d9018191e93cb9d719edec01257fc05f8158", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", "shasum": "" }, "require": { "php": "^7.0", - "sebastian/diff": "^2.0", + "sebastian/diff": "^2.0 || ^3.0", "sebastian/exporter": "^3.1" }, "require-dev": { @@ -1788,32 +1788,33 @@ "compare", "equality" ], - "time": "2017-11-03T07:16:52+00:00" + "time": "2018-02-01T13:46:46+00:00" }, { "name": "sebastian/diff", - "version": "2.0.1", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd" + "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", - "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/e09160918c66281713f1c324c1f4c4c3037ba1e8", + "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.2" + "phpunit/phpunit": "^7.0", + "symfony/process": "^2 || ^3.3 || ^4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1838,9 +1839,12 @@ "description": "Diff implementation", "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ - "diff" + "diff", + "udiff", + "unidiff", + "unified diff" ], - "time": "2017-08-03T08:09:46+00:00" + "time": "2018-02-01T13:45:15+00:00" }, { "name": "sebastian/environment", @@ -2448,20 +2452,21 @@ "psr-15", "webimpress" ], + "abandoned": "psr/http-server-middleware", "time": "2017-10-17T17:31:10+00:00" }, { "name": "webmozart/assert", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + "reference": "0df1908962e7a3071564e857d86874dad1ef204a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a", "shasum": "" }, "require": { @@ -2498,7 +2503,7 @@ "check", "validate" ], - "time": "2016-11-23T20:04:58+00:00" + "time": "2018-01-29T19:49:41+00:00" }, { "name": "zendframework/zend-coding-standard", @@ -2531,16 +2536,16 @@ }, { "name": "zendframework/zend-diactoros", - "version": "1.6.1", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/zendframework/zend-diactoros.git", - "reference": "c8664b92a6d5bc229e48b0923486c097e45a7877" + "reference": "ed6ce7e2105c400ca10277643a8327957c0384b7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/c8664b92a6d5bc229e48b0923486c097e45a7877", - "reference": "c8664b92a6d5bc229e48b0923486c097e45a7877", + "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/ed6ce7e2105c400ca10277643a8327957c0384b7", + "reference": "ed6ce7e2105c400ca10277643a8327957c0384b7", "shasum": "" }, "require": { @@ -2559,8 +2564,8 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev", - "dev-develop": "1.7-dev" + "dev-master": "1.7.x-dev", + "dev-develop": "1.8.x-dev" } }, "autoload": { @@ -2579,29 +2584,29 @@ "psr", "psr-7" ], - "time": "2017-10-12T15:24:51+00:00" + "time": "2018-01-04T18:21:48+00:00" }, { "name": "zendframework/zend-json", - "version": "3.0.0", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/zendframework/zend-json.git", - "reference": "f42a1588e75c2a3e338cd94c37906231e616daab" + "reference": "4dd940e8e6f32f1d36ea6b0677ea57c540c7c19c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-json/zipball/f42a1588e75c2a3e338cd94c37906231e616daab", - "reference": "f42a1588e75c2a3e338cd94c37906231e616daab", + "url": "https://api.github.com/repos/zendframework/zend-json/zipball/4dd940e8e6f32f1d36ea6b0677ea57c540c7c19c", + "reference": "4dd940e8e6f32f1d36ea6b0677ea57c540c7c19c", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "^2.3", - "zendframework/zend-stdlib": "^2.7 || ^3.0" + "phpunit/phpunit": "^5.7.23 || ^6.4.3", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-stdlib": "^2.7.7 || ^3.1" }, "suggest": { "zendframework/zend-json-server": "For implementing JSON-RPC servers", @@ -2610,8 +2615,8 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev", - "dev-develop": "3.1-dev" + "dev-master": "3.1.x-dev", + "dev-develop": "3.2.x-dev" } }, "autoload": { @@ -2624,25 +2629,25 @@ "BSD-3-Clause" ], "description": "provides convenience methods for serializing native PHP to JSON and decoding JSON to native PHP", - "homepage": "https://github.com/zendframework/zend-json", "keywords": [ + "ZendFramework", "json", - "zf2" + "zf" ], - "time": "2016-04-01T02:34:00+00:00" + "time": "2018-01-04T17:51:34+00:00" }, { "name": "zendframework/zend-psr7bridge", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/zendframework/zend-psr7bridge.git", - "reference": "935721336ded76fd5ba90ba7637c7d85b4d0cf68" + "reference": "93494337a475135a457d86f6b150c67aa4f31aea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-psr7bridge/zipball/935721336ded76fd5ba90ba7637c7d85b4d0cf68", - "reference": "935721336ded76fd5ba90ba7637c7d85b4d0cf68", + "url": "https://api.github.com/repos/zendframework/zend-psr7bridge/zipball/93494337a475135a457d86f6b150c67aa4f31aea", + "reference": "93494337a475135a457d86f6b150c67aa4f31aea", "shasum": "" }, "require": { @@ -2680,7 +2685,7 @@ "psr-7", "zend" ], - "time": "2017-08-02T15:52:02+00:00" + "time": "2017-12-18T11:59:51+00:00" }, { "name": "zendframework/zend-stratigility", From d44bb5f231d7757c169c6c9e9b5822f2d2aa8191 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 13 Jan 2018 08:24:07 +1000 Subject: [PATCH 04/51] Update travis and phpunit config --- .travis.yml | 23 +---------------------- LICENSE.md | 2 +- mkdocs.yml | 2 +- phpunit.xml.dist | 24 ++++++------------------ 4 files changed, 9 insertions(+), 42 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3c5f852b5..49bc879bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,26 +13,6 @@ env: matrix: include: - - php: 5.6 - env: - - DEPS=lowest - - php: 5.6 - env: - - DEPS=locked - - LEGACY_DEPS="phpunit/phpunit" - - php: 5.6 - env: - - DEPS=latest - - php: 7 - env: - - DEPS=lowest - - php: 7 - env: - - DEPS=locked - - LEGACY_DEPS="phpunit/phpunit" - - php: 7 - env: - - DEPS=latest - php: 7.1 env: - DEPS=lowest @@ -58,8 +38,7 @@ before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi install: - - travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs - - if [[ $LEGACY_DEPS != '' ]]; then travis_retry composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi + - travis_retry composer install $COMPOSER_ARGS - if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi - if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi diff --git a/LICENSE.md b/LICENSE.md index 63df4102c..d44ab5dc7 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2005-2017, Zend Technologies USA, Inc. +Copyright (c) 2005-2018, Zend Technologies USA, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/mkdocs.yml b/mkdocs.yml index 1d2f5d300..50551655c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -23,4 +23,4 @@ pages: site_name: zend-mvc site_description: 'zend-mvc: MVC application provider' repo_url: 'https://github.com/zendframework/zend-mvc' -copyright: 'Copyright (c) 2005-2017 Zend Technologies USA Inc.' +copyright: 'Copyright (c) 2005-2018 Zend Technologies USA Inc.' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2cffbef67..1668ad5a4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,34 +1,22 @@ - - ./test/ + + ./test - - - disable - - - - + ./src - - - - From 1c8fa9e2164e9a20d82d540b88e089617b556164 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 8 Sep 2017 10:46:08 +1000 Subject: [PATCH 05/51] Enable strict types --- src/Application.php | 2 ++ src/ApplicationInterface.php | 2 ++ src/Container/ApplicationFactory.php | 2 ++ src/Container/ConfigFactory.php | 2 ++ src/Container/ControllerManagerFactory.php | 2 ++ src/Container/ControllerPluginManagerFactory.php | 2 ++ src/Container/DefaultRenderingStrategyFactory.php | 2 ++ src/Container/DispatchListenerFactory.php | 2 ++ src/Container/EventManagerFactory.php | 2 ++ src/Container/ExceptionStrategyFactory.php | 2 ++ src/Container/HttpMethodListenerFactory.php | 2 ++ src/Container/HttpViewManagerFactory.php | 2 ++ src/Container/InjectTemplateListenerFactory.php | 2 ++ src/Container/ModuleManagerFactory.php | 2 ++ src/Container/PaginatorPluginManagerFactory.php | 2 ++ src/Container/RequestFactory.php | 2 ++ src/Container/ResponseFactory.php | 2 ++ src/Container/RouteNotFoundStrategyFactory.php | 2 ++ src/Container/SendResponseListenerFactory.php | 2 ++ src/Container/ServiceListenerFactory.php | 2 ++ src/Container/ServiceManagerConfig.php | 2 ++ src/Container/ViewFactory.php | 2 ++ src/Container/ViewFeedStrategyFactory.php | 2 ++ src/Container/ViewHelperManagerFactory.php | 2 ++ src/Container/ViewJsonStrategyFactory.php | 2 ++ src/Container/ViewManagerConfigTrait.php | 2 ++ src/Container/ViewManagerFactory.php | 2 ++ src/Container/ViewPhpRendererFactory.php | 2 ++ src/Container/ViewPhpRendererStrategyFactory.php | 2 ++ src/Container/ViewPrefixPathStackResolverFactory.php | 2 ++ src/Container/ViewResolverFactory.php | 2 ++ src/Container/ViewTemplateMapResolverFactory.php | 2 ++ src/Container/ViewTemplatePathStackFactory.php | 2 ++ src/Controller/AbstractActionController.php | 2 ++ src/Controller/AbstractController.php | 2 ++ src/Controller/AbstractRestfulController.php | 3 +++ src/Controller/ControllerManager.php | 2 ++ src/Controller/LazyControllerAbstractFactory.php | 2 ++ src/Controller/MiddlewareController.php | 2 ++ src/Controller/Plugin/AbstractPlugin.php | 2 ++ src/Controller/Plugin/AcceptableViewModelSelector.php | 2 ++ src/Controller/Plugin/CreateHttpNotFoundModel.php | 2 ++ src/Controller/Plugin/Forward.php | 2 ++ src/Controller/Plugin/Layout.php | 2 ++ src/Controller/Plugin/Params.php | 2 ++ src/Controller/Plugin/PluginInterface.php | 2 ++ src/Controller/Plugin/Redirect.php | 2 ++ src/Controller/Plugin/Service/ForwardFactory.php | 2 ++ src/Controller/Plugin/Url.php | 2 ++ src/Controller/PluginManager.php | 2 ++ src/DispatchListener.php | 2 ++ src/Exception/BadMethodCallException.php | 2 ++ src/Exception/DomainException.php | 2 ++ src/Exception/ExceptionInterface.php | 2 ++ src/Exception/InvalidArgumentException.php | 2 ++ src/Exception/InvalidControllerException.php | 2 ++ src/Exception/InvalidMiddlewareException.php | 2 ++ src/Exception/InvalidPluginException.php | 2 ++ src/Exception/MissingLocatorException.php | 2 ++ src/Exception/ReachedFinalHandlerException.php | 2 ++ src/Exception/RuntimeException.php | 2 ++ src/HttpMethodListener.php | 2 ++ src/InjectApplicationEventInterface.php | 2 ++ src/MiddlewareListener.php | 2 ++ src/ModuleRouteListener.php | 2 ++ src/MvcEvent.php | 2 ++ src/ResponseSender/AbstractResponseSender.php | 2 ++ src/ResponseSender/HttpResponseSender.php | 2 ++ src/ResponseSender/PhpEnvironmentResponseSender.php | 2 ++ src/ResponseSender/ResponseSenderInterface.php | 2 ++ src/ResponseSender/SendResponseEvent.php | 2 ++ src/ResponseSender/SimpleStreamResponseSender.php | 2 ++ src/RouteListener.php | 2 ++ src/SendResponseListener.php | 2 ++ src/Service/AbstractPluginManagerFactory.php | 2 ++ src/View/Http/CreateViewModelListener.php | 2 ++ src/View/Http/DefaultRenderingStrategy.php | 2 ++ src/View/Http/ExceptionStrategy.php | 2 ++ src/View/Http/InjectRoutematchParamsListener.php | 2 ++ src/View/Http/InjectTemplateListener.php | 2 ++ src/View/Http/InjectViewModelListener.php | 2 ++ src/View/Http/RouteNotFoundStrategy.php | 2 ++ src/View/Http/ViewManager.php | 2 ++ test/Application/AllowsReturningEarlyFromRoutingTest.php | 2 ++ test/Application/BadControllerTrait.php | 2 ++ test/Application/ControllerIsDispatchedTest.php | 2 ++ ...nsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php | 2 ++ ...ilityToRetrieveControllerShouldTriggerDispatchErrorTest.php | 2 ++ ...InabilityToRetrieveControllerShouldTriggerExceptionTest.php | 2 ++ test/Application/InitializationIntegrationTest.php | 2 ++ .../InvalidControllerTypeShouldTriggerDispatchErrorTest.php | 2 ++ test/Application/InvalidControllerTypeTrait.php | 2 ++ test/Application/MissingControllerTrait.php | 2 ++ test/Application/PathControllerTrait.php | 2 ++ test/Application/RoutingSuccessTest.php | 2 ++ test/Application/TestAsset/modules/Application/Module.php | 2 ++ .../TestAsset/modules/Application/config/module.config.php | 2 ++ .../Application/src/Application/Controller/PathController.php | 2 ++ test/ApplicationTest.php | 2 ++ test/Container/ControllerManagerFactoryTest.php | 2 ++ test/Container/HttpMethodListenerFactoryTest.php | 2 ++ test/Container/InjectTemplateListenerFactoryTest.php | 2 ++ test/Container/RequestFactoryTest.php | 2 ++ test/Container/ResponseFactoryTest.php | 2 ++ test/Container/SendResponseListenerFactoryTest.php | 2 ++ test/Container/ServiceListenerFactoryTest.php | 2 ++ test/Container/ServiceManagerConfigTest.php | 2 ++ test/Container/ViewFeedStrategyFactoryTest.php | 2 ++ test/Container/ViewHelperManagerFactoryTest.php | 2 ++ test/Container/ViewJsonStrategyFactoryTest.php | 2 ++ test/Container/ViewManagerFactoryTest.php | 2 ++ test/Container/ViewPrefixPathStackResolverFactoryTest.php | 2 ++ test/Controller/AbstractControllerTest.php | 2 ++ test/Controller/ActionControllerTest.php | 2 ++ test/Controller/ControllerManagerTest.php | 2 ++ test/Controller/IntegrationTest.php | 2 ++ test/Controller/LazyControllerAbstractFactoryTest.php | 2 ++ test/Controller/MiddlewareControllerTest.php | 2 ++ test/Controller/Plugin/AcceptableViewModelSelectorTest.php | 2 ++ test/Controller/Plugin/CreateHttpNotFoundModelTest.php | 2 ++ test/Controller/Plugin/ForwardTest.php | 2 ++ test/Controller/Plugin/LayoutTest.php | 2 ++ test/Controller/Plugin/ParamsTest.php | 2 ++ test/Controller/Plugin/RedirectTest.php | 2 ++ test/Controller/Plugin/TestAsset/ListenerStub.php | 2 ++ test/Controller/Plugin/TestAsset/SamplePlugin.php | 2 ++ test/Controller/Plugin/TestAsset/SamplePluginFactory.php | 2 ++ .../Plugin/TestAsset/SamplePluginWithConstructor.php | 2 ++ .../Plugin/TestAsset/SamplePluginWithConstructorFactory.php | 2 ++ test/Controller/Plugin/UrlTest.php | 2 ++ test/Controller/PluginManagerTest.php | 2 ++ test/Controller/RestfulControllerTest.php | 2 ++ test/Controller/TestAsset/BadController.php | 2 ++ .../TestAsset/ControllerAcceptingConfigToConstructor.php | 2 ++ ...rollerAcceptingWellKnownServicesAsConstructorParameters.php | 2 ++ test/Controller/TestAsset/ControllerLoaderAbstractFactory.php | 2 ++ test/Controller/TestAsset/ControllerWithEmptyConstructor.php | 2 ++ .../TestAsset/ControllerWithMixedConstructorParameters.php | 2 ++ test/Controller/TestAsset/ControllerWithScalarParameters.php | 2 ++ .../TestAsset/ControllerWithTypeHintedConstructorParameter.php | 2 ++ test/Controller/TestAsset/ForwardController.php | 2 ++ test/Controller/TestAsset/Request.php | 2 ++ test/Controller/TestAsset/RestfulContentTypeTestController.php | 2 ++ .../TestAsset/RestfulMethodNotAllowedTestController.php | 2 ++ test/Controller/TestAsset/RestfulTestController.php | 2 ++ test/Controller/TestAsset/SampleController.php | 2 ++ test/Controller/TestAsset/SampleInterface.php | 2 ++ test/Controller/TestAsset/UneventfulController.php | 2 ++ .../TestAsset/UnlocatableControllerLoaderAbstractFactory.php | 2 ++ test/Controller/TestAsset/UnlocatableEventfulController.php | 2 ++ test/DispatchListenerTest.php | 2 ++ test/Exception/InvalidMiddlewareExceptionTest.php | 2 ++ test/Exception/ReachedFinalHandlerExceptionTest.php | 2 ++ test/HttpMethodListenerTest.php | 2 ++ test/MiddlewareListenerTest.php | 2 ++ test/ModuleRouteListenerTest.php | 2 ++ test/ResponseSender/AbstractResponseSenderTest.php | 2 ++ test/ResponseSender/PhpEnvironmentResponseSenderTest.php | 2 ++ test/ResponseSender/SendResponseEventTest.php | 2 ++ test/ResponseSender/SimpleStreamResponseSenderTest.php | 2 ++ test/SendResponseListenerTest.php | 2 ++ test/Service/TestAsset/ControllerWithDependencies.php | 2 ++ test/Service/TestAsset/Dispatchable.php | 2 ++ test/Service/TestAsset/EventManagerAwareObject.php | 2 ++ test/Service/TestAsset/InvalidDispatchableClass.php | 2 ++ test/TestAsset/Locator.php | 2 ++ test/TestAsset/Middleware.php | 2 ++ test/TestAsset/MiddlewareAbstractFactory.php | 2 ++ test/TestAsset/MockSendResponseListener.php | 2 ++ test/TestAsset/MockViewManager.php | 2 ++ test/TestAsset/PathController.php | 2 ++ test/TestAsset/StubBootstrapListener.php | 2 ++ test/View/CreateViewModelListenerTest.php | 2 ++ test/View/DefaultRendereringStrategyTest.php | 2 ++ test/View/ExceptionStrategyTest.php | 2 ++ test/View/InjectTemplateListenerTest.php | 2 ++ test/View/InjectViewModelListenerTest.php | 2 ++ test/View/RouteNotFoundStrategyTest.php | 2 ++ test/View/TestAsset/DumbStrategy.php | 2 ++ test/_autoload.php | 2 ++ 180 files changed, 361 insertions(+) diff --git a/src/Application.php b/src/Application.php index 085af9f75..c6d42e113 100644 --- a/src/Application.php +++ b/src/Application.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use Zend\EventManager\EventManagerAwareInterface; diff --git a/src/ApplicationInterface.php b/src/ApplicationInterface.php index 6f8c4062f..99807c4c6 100644 --- a/src/ApplicationInterface.php +++ b/src/ApplicationInterface.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use Zend\EventManager\EventsCapableInterface; diff --git a/src/Container/ApplicationFactory.php b/src/Container/ApplicationFactory.php index 6af06f338..038068e36 100644 --- a/src/Container/ApplicationFactory.php +++ b/src/Container/ApplicationFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ConfigFactory.php b/src/Container/ConfigFactory.php index 1b92f2ff2..bd9b38cd4 100644 --- a/src/Container/ConfigFactory.php +++ b/src/Container/ConfigFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ControllerManagerFactory.php b/src/Container/ControllerManagerFactory.php index 29157efd0..ce294a6a7 100644 --- a/src/Container/ControllerManagerFactory.php +++ b/src/Container/ControllerManagerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ControllerPluginManagerFactory.php b/src/Container/ControllerPluginManagerFactory.php index 7b4278d1a..a8793b28d 100644 --- a/src/Container/ControllerPluginManagerFactory.php +++ b/src/Container/ControllerPluginManagerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; diff --git a/src/Container/DefaultRenderingStrategyFactory.php b/src/Container/DefaultRenderingStrategyFactory.php index bc2302a8b..58993c4e1 100644 --- a/src/Container/DefaultRenderingStrategyFactory.php +++ b/src/Container/DefaultRenderingStrategyFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/DispatchListenerFactory.php b/src/Container/DispatchListenerFactory.php index 1ee3e09de..05aac4e32 100644 --- a/src/Container/DispatchListenerFactory.php +++ b/src/Container/DispatchListenerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/EventManagerFactory.php b/src/Container/EventManagerFactory.php index f6e94ef07..deca72a86 100644 --- a/src/Container/EventManagerFactory.php +++ b/src/Container/EventManagerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ExceptionStrategyFactory.php b/src/Container/ExceptionStrategyFactory.php index 3ad30ece1..b4d2ef231 100644 --- a/src/Container/ExceptionStrategyFactory.php +++ b/src/Container/ExceptionStrategyFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/HttpMethodListenerFactory.php b/src/Container/HttpMethodListenerFactory.php index 72cf82f57..6a90dced9 100644 --- a/src/Container/HttpMethodListenerFactory.php +++ b/src/Container/HttpMethodListenerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/HttpViewManagerFactory.php b/src/Container/HttpViewManagerFactory.php index 1336c6080..33a1a0e93 100644 --- a/src/Container/HttpViewManagerFactory.php +++ b/src/Container/HttpViewManagerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/InjectTemplateListenerFactory.php b/src/Container/InjectTemplateListenerFactory.php index 9aa66e9c5..6f5a2183e 100644 --- a/src/Container/InjectTemplateListenerFactory.php +++ b/src/Container/InjectTemplateListenerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ModuleManagerFactory.php b/src/Container/ModuleManagerFactory.php index de8bee354..e4282e414 100644 --- a/src/Container/ModuleManagerFactory.php +++ b/src/Container/ModuleManagerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/PaginatorPluginManagerFactory.php b/src/Container/PaginatorPluginManagerFactory.php index 44f15c42b..c77e55bcf 100644 --- a/src/Container/PaginatorPluginManagerFactory.php +++ b/src/Container/PaginatorPluginManagerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Zend\Mvc\Service\AbstractPluginManagerFactory; diff --git a/src/Container/RequestFactory.php b/src/Container/RequestFactory.php index c16fc8356..e2711a026 100644 --- a/src/Container/RequestFactory.php +++ b/src/Container/RequestFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ResponseFactory.php b/src/Container/ResponseFactory.php index c6751b964..9ad9de7b6 100644 --- a/src/Container/ResponseFactory.php +++ b/src/Container/ResponseFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/RouteNotFoundStrategyFactory.php b/src/Container/RouteNotFoundStrategyFactory.php index 964873d08..c60778885 100644 --- a/src/Container/RouteNotFoundStrategyFactory.php +++ b/src/Container/RouteNotFoundStrategyFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/SendResponseListenerFactory.php b/src/Container/SendResponseListenerFactory.php index 215dddb36..0c9bcc3b9 100644 --- a/src/Container/SendResponseListenerFactory.php +++ b/src/Container/SendResponseListenerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ServiceListenerFactory.php b/src/Container/ServiceListenerFactory.php index 17d471419..d2cc38f70 100644 --- a/src/Container/ServiceListenerFactory.php +++ b/src/Container/ServiceListenerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ServiceManagerConfig.php b/src/Container/ServiceManagerConfig.php index 9cdee66ad..aed858ce8 100644 --- a/src/Container/ServiceManagerConfig.php +++ b/src/Container/ServiceManagerConfig.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewFactory.php b/src/Container/ViewFactory.php index 2fa90ed7c..015c076b4 100644 --- a/src/Container/ViewFactory.php +++ b/src/Container/ViewFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewFeedStrategyFactory.php b/src/Container/ViewFeedStrategyFactory.php index 7b3eefb8f..4e102abbd 100644 --- a/src/Container/ViewFeedStrategyFactory.php +++ b/src/Container/ViewFeedStrategyFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewHelperManagerFactory.php b/src/Container/ViewHelperManagerFactory.php index e1781b668..ace30e1a3 100644 --- a/src/Container/ViewHelperManagerFactory.php +++ b/src/Container/ViewHelperManagerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewJsonStrategyFactory.php b/src/Container/ViewJsonStrategyFactory.php index acbc4b26c..b973c36c2 100644 --- a/src/Container/ViewJsonStrategyFactory.php +++ b/src/Container/ViewJsonStrategyFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewManagerConfigTrait.php b/src/Container/ViewManagerConfigTrait.php index 81da41c0d..6be53a6ef 100644 --- a/src/Container/ViewManagerConfigTrait.php +++ b/src/Container/ViewManagerConfigTrait.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use ArrayAccess; diff --git a/src/Container/ViewManagerFactory.php b/src/Container/ViewManagerFactory.php index 81d2bc2bd..bbac26db2 100644 --- a/src/Container/ViewManagerFactory.php +++ b/src/Container/ViewManagerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewPhpRendererFactory.php b/src/Container/ViewPhpRendererFactory.php index 13ea74d99..2016b23b9 100644 --- a/src/Container/ViewPhpRendererFactory.php +++ b/src/Container/ViewPhpRendererFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewPhpRendererStrategyFactory.php b/src/Container/ViewPhpRendererStrategyFactory.php index 2dfe9909f..550c6b993 100644 --- a/src/Container/ViewPhpRendererStrategyFactory.php +++ b/src/Container/ViewPhpRendererStrategyFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewPrefixPathStackResolverFactory.php b/src/Container/ViewPrefixPathStackResolverFactory.php index 11a29b3e2..5ceb59adb 100644 --- a/src/Container/ViewPrefixPathStackResolverFactory.php +++ b/src/Container/ViewPrefixPathStackResolverFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewResolverFactory.php b/src/Container/ViewResolverFactory.php index 42740ef0d..abd326a52 100644 --- a/src/Container/ViewResolverFactory.php +++ b/src/Container/ViewResolverFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewTemplateMapResolverFactory.php b/src/Container/ViewTemplateMapResolverFactory.php index a3727724e..ea8e83eaa 100644 --- a/src/Container/ViewTemplateMapResolverFactory.php +++ b/src/Container/ViewTemplateMapResolverFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Container/ViewTemplatePathStackFactory.php b/src/Container/ViewTemplatePathStackFactory.php index e1a6b59b3..081531c57 100644 --- a/src/Container/ViewTemplatePathStackFactory.php +++ b/src/Container/ViewTemplatePathStackFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/src/Controller/AbstractActionController.php b/src/Controller/AbstractActionController.php index 54277ab31..8f494e331 100644 --- a/src/Controller/AbstractActionController.php +++ b/src/Controller/AbstractActionController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller; use Zend\Mvc\Exception; diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index da634c5c6..8b8e20911 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller; use Zend\EventManager\EventInterface as Event; diff --git a/src/Controller/AbstractRestfulController.php b/src/Controller/AbstractRestfulController.php index cff21f6db..556abc0be 100644 --- a/src/Controller/AbstractRestfulController.php +++ b/src/Controller/AbstractRestfulController.php @@ -4,6 +4,9 @@ * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com) * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ + +declare(strict_types=1); + namespace Zend\Mvc\Controller; use Zend\Http\Request as HttpRequest; diff --git a/src/Controller/ControllerManager.php b/src/Controller/ControllerManager.php index 20e721655..02de0a7df 100644 --- a/src/Controller/ControllerManager.php +++ b/src/Controller/ControllerManager.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller; use Interop\Container\ContainerInterface; diff --git a/src/Controller/LazyControllerAbstractFactory.php b/src/Controller/LazyControllerAbstractFactory.php index 0cd0f23d8..219e23731 100644 --- a/src/Controller/LazyControllerAbstractFactory.php +++ b/src/Controller/LazyControllerAbstractFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller; use Interop\Container\ContainerInterface; diff --git a/src/Controller/MiddlewareController.php b/src/Controller/MiddlewareController.php index aee5e269d..3060f64d9 100644 --- a/src/Controller/MiddlewareController.php +++ b/src/Controller/MiddlewareController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller; use Psr\Http\Message\ResponseInterface; diff --git a/src/Controller/Plugin/AbstractPlugin.php b/src/Controller/Plugin/AbstractPlugin.php index c00a570cf..0c092763b 100644 --- a/src/Controller/Plugin/AbstractPlugin.php +++ b/src/Controller/Plugin/AbstractPlugin.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin; use Zend\Stdlib\DispatchableInterface as Dispatchable; diff --git a/src/Controller/Plugin/AcceptableViewModelSelector.php b/src/Controller/Plugin/AcceptableViewModelSelector.php index 7a7a5efe7..487d5dceb 100644 --- a/src/Controller/Plugin/AcceptableViewModelSelector.php +++ b/src/Controller/Plugin/AcceptableViewModelSelector.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin; use Zend\Http\Header\Accept\FieldValuePart\AbstractFieldValuePart; diff --git a/src/Controller/Plugin/CreateHttpNotFoundModel.php b/src/Controller/Plugin/CreateHttpNotFoundModel.php index dd35143e2..126c3eec9 100644 --- a/src/Controller/Plugin/CreateHttpNotFoundModel.php +++ b/src/Controller/Plugin/CreateHttpNotFoundModel.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin; use Zend\Http\Response; diff --git a/src/Controller/Plugin/Forward.php b/src/Controller/Plugin/Forward.php index 32f2d8273..354aec88a 100644 --- a/src/Controller/Plugin/Forward.php +++ b/src/Controller/Plugin/Forward.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin; use Zend\EventManager\SharedEventManagerInterface as SharedEvents; diff --git a/src/Controller/Plugin/Layout.php b/src/Controller/Plugin/Layout.php index 89e41588e..b5c50ed79 100644 --- a/src/Controller/Plugin/Layout.php +++ b/src/Controller/Plugin/Layout.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin; use Zend\Mvc\Exception; diff --git a/src/Controller/Plugin/Params.php b/src/Controller/Plugin/Params.php index eeed5456b..ecc5d0f9f 100644 --- a/src/Controller/Plugin/Params.php +++ b/src/Controller/Plugin/Params.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin; use Zend\Mvc\Exception\RuntimeException; diff --git a/src/Controller/Plugin/PluginInterface.php b/src/Controller/Plugin/PluginInterface.php index 1a9fdaffa..bea869aa4 100644 --- a/src/Controller/Plugin/PluginInterface.php +++ b/src/Controller/Plugin/PluginInterface.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin; use Zend\Stdlib\DispatchableInterface as Dispatchable; diff --git a/src/Controller/Plugin/Redirect.php b/src/Controller/Plugin/Redirect.php index df9b650d4..faa7fd9a7 100644 --- a/src/Controller/Plugin/Redirect.php +++ b/src/Controller/Plugin/Redirect.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin; use Zend\Http\Response; diff --git a/src/Controller/Plugin/Service/ForwardFactory.php b/src/Controller/Plugin/Service/ForwardFactory.php index 2bf729545..606a70747 100644 --- a/src/Controller/Plugin/Service/ForwardFactory.php +++ b/src/Controller/Plugin/Service/ForwardFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin\Service; use Interop\Container\ContainerInterface; diff --git a/src/Controller/Plugin/Url.php b/src/Controller/Plugin/Url.php index 7a050a175..a781aa8e1 100644 --- a/src/Controller/Plugin/Url.php +++ b/src/Controller/Plugin/Url.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller\Plugin; use Traversable; diff --git a/src/Controller/PluginManager.php b/src/Controller/PluginManager.php index 5a9295903..1322697e1 100644 --- a/src/Controller/PluginManager.php +++ b/src/Controller/PluginManager.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Controller; use Zend\ServiceManager\AbstractPluginManager; diff --git a/src/DispatchListener.php b/src/DispatchListener.php index ed7c7fe68..37a9d1160 100644 --- a/src/DispatchListener.php +++ b/src/DispatchListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use ArrayObject; diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index 50c951c8c..76d9c4825 100644 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface diff --git a/src/Exception/DomainException.php b/src/Exception/DomainException.php index 8988e676d..fcf8b7c5b 100644 --- a/src/Exception/DomainException.php +++ b/src/Exception/DomainException.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; class DomainException extends \DomainException implements ExceptionInterface diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 28c62d879..7000e1d3e 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; interface ExceptionInterface diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index fd7c910cd..c66f779da 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface diff --git a/src/Exception/InvalidControllerException.php b/src/Exception/InvalidControllerException.php index 51afa29e5..225e5dfcb 100644 --- a/src/Exception/InvalidControllerException.php +++ b/src/Exception/InvalidControllerException.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; class InvalidControllerException extends \Exception implements ExceptionInterface diff --git a/src/Exception/InvalidMiddlewareException.php b/src/Exception/InvalidMiddlewareException.php index 5e4982e8c..5cdbc1d33 100644 --- a/src/Exception/InvalidMiddlewareException.php +++ b/src/Exception/InvalidMiddlewareException.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; final class InvalidMiddlewareException extends RuntimeException diff --git a/src/Exception/InvalidPluginException.php b/src/Exception/InvalidPluginException.php index bb3f3cd00..9f69dbe83 100644 --- a/src/Exception/InvalidPluginException.php +++ b/src/Exception/InvalidPluginException.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; class InvalidPluginException extends \Exception implements ExceptionInterface diff --git a/src/Exception/MissingLocatorException.php b/src/Exception/MissingLocatorException.php index 359d14c3e..93cc33f97 100644 --- a/src/Exception/MissingLocatorException.php +++ b/src/Exception/MissingLocatorException.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; class MissingLocatorException extends RuntimeException diff --git a/src/Exception/ReachedFinalHandlerException.php b/src/Exception/ReachedFinalHandlerException.php index 874d48b80..b90239def 100644 --- a/src/Exception/ReachedFinalHandlerException.php +++ b/src/Exception/ReachedFinalHandlerException.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; class ReachedFinalHandlerException extends RuntimeException diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 4469264e8..1a1171450 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Exception; class RuntimeException extends \RuntimeException implements ExceptionInterface diff --git a/src/HttpMethodListener.php b/src/HttpMethodListener.php index 77e8e007d..20a51d4a2 100644 --- a/src/HttpMethodListener.php +++ b/src/HttpMethodListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/InjectApplicationEventInterface.php b/src/InjectApplicationEventInterface.php index 18ae5af1c..c99e67d4a 100644 --- a/src/InjectApplicationEventInterface.php +++ b/src/InjectApplicationEventInterface.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use Zend\EventManager\EventInterface as Event; diff --git a/src/MiddlewareListener.php b/src/MiddlewareListener.php index 618325451..d99a63331 100644 --- a/src/MiddlewareListener.php +++ b/src/MiddlewareListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use Interop\Container\ContainerInterface; diff --git a/src/ModuleRouteListener.php b/src/ModuleRouteListener.php index 02fc72be9..5fd63f265 100644 --- a/src/ModuleRouteListener.php +++ b/src/ModuleRouteListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/MvcEvent.php b/src/MvcEvent.php index f9918377c..ad17a129c 100644 --- a/src/MvcEvent.php +++ b/src/MvcEvent.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use Zend\EventManager\Event; diff --git a/src/ResponseSender/AbstractResponseSender.php b/src/ResponseSender/AbstractResponseSender.php index ed719d5d0..38f58c821 100644 --- a/src/ResponseSender/AbstractResponseSender.php +++ b/src/ResponseSender/AbstractResponseSender.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\ResponseSender; use Zend\Http\Header\MultipleHeaderInterface; diff --git a/src/ResponseSender/HttpResponseSender.php b/src/ResponseSender/HttpResponseSender.php index 1131cab3f..062c9532c 100644 --- a/src/ResponseSender/HttpResponseSender.php +++ b/src/ResponseSender/HttpResponseSender.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\ResponseSender; use Zend\Http\Response; diff --git a/src/ResponseSender/PhpEnvironmentResponseSender.php b/src/ResponseSender/PhpEnvironmentResponseSender.php index 5309e11f0..e293e09f8 100644 --- a/src/ResponseSender/PhpEnvironmentResponseSender.php +++ b/src/ResponseSender/PhpEnvironmentResponseSender.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\ResponseSender; use Zend\Http\PhpEnvironment\Response; diff --git a/src/ResponseSender/ResponseSenderInterface.php b/src/ResponseSender/ResponseSenderInterface.php index 8322ae631..2e9faebd6 100644 --- a/src/ResponseSender/ResponseSenderInterface.php +++ b/src/ResponseSender/ResponseSenderInterface.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\ResponseSender; interface ResponseSenderInterface diff --git a/src/ResponseSender/SendResponseEvent.php b/src/ResponseSender/SendResponseEvent.php index e7f74215b..3fc02c273 100644 --- a/src/ResponseSender/SendResponseEvent.php +++ b/src/ResponseSender/SendResponseEvent.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\ResponseSender; use Zend\EventManager\Event; diff --git a/src/ResponseSender/SimpleStreamResponseSender.php b/src/ResponseSender/SimpleStreamResponseSender.php index 3d1be8f75..4b7d3409b 100644 --- a/src/ResponseSender/SimpleStreamResponseSender.php +++ b/src/ResponseSender/SimpleStreamResponseSender.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\ResponseSender; use Zend\Http\Response\Stream; diff --git a/src/RouteListener.php b/src/RouteListener.php index 4fd1fc37f..2e85ec36c 100644 --- a/src/RouteListener.php +++ b/src/RouteListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/SendResponseListener.php b/src/SendResponseListener.php index 1b939ef6e..95687b491 100644 --- a/src/SendResponseListener.php +++ b/src/SendResponseListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/Service/AbstractPluginManagerFactory.php b/src/Service/AbstractPluginManagerFactory.php index 0224eb99e..8e2a9c4d7 100644 --- a/src/Service/AbstractPluginManagerFactory.php +++ b/src/Service/AbstractPluginManagerFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\Service; use Interop\Container\ContainerInterface; diff --git a/src/View/Http/CreateViewModelListener.php b/src/View/Http/CreateViewModelListener.php index f75186110..744ddd50a 100644 --- a/src/View/Http/CreateViewModelListener.php +++ b/src/View/Http/CreateViewModelListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\View\Http; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/View/Http/DefaultRenderingStrategy.php b/src/View/Http/DefaultRenderingStrategy.php index 5031966c8..6d13c1b07 100644 --- a/src/View/Http/DefaultRenderingStrategy.php +++ b/src/View/Http/DefaultRenderingStrategy.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\View\Http; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/View/Http/ExceptionStrategy.php b/src/View/Http/ExceptionStrategy.php index 440358210..592493ade 100644 --- a/src/View/Http/ExceptionStrategy.php +++ b/src/View/Http/ExceptionStrategy.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\View\Http; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/View/Http/InjectRoutematchParamsListener.php b/src/View/Http/InjectRoutematchParamsListener.php index adcaf29b9..2eb85b7b4 100644 --- a/src/View/Http/InjectRoutematchParamsListener.php +++ b/src/View/Http/InjectRoutematchParamsListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\View\Http; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/View/Http/InjectTemplateListener.php b/src/View/Http/InjectTemplateListener.php index 3b110a787..01b13a9a6 100644 --- a/src/View/Http/InjectTemplateListener.php +++ b/src/View/Http/InjectTemplateListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\View\Http; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/View/Http/InjectViewModelListener.php b/src/View/Http/InjectViewModelListener.php index 6a61a9b32..0eac32ef3 100644 --- a/src/View/Http/InjectViewModelListener.php +++ b/src/View/Http/InjectViewModelListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\View\Http; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/View/Http/RouteNotFoundStrategy.php b/src/View/Http/RouteNotFoundStrategy.php index 12d397f92..2c9790142 100644 --- a/src/View/Http/RouteNotFoundStrategy.php +++ b/src/View/Http/RouteNotFoundStrategy.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\View\Http; use Zend\EventManager\AbstractListenerAggregate; diff --git a/src/View/Http/ViewManager.php b/src/View/Http/ViewManager.php index 67802c5ac..b2091dcf9 100644 --- a/src/View/Http/ViewManager.php +++ b/src/View/Http/ViewManager.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Zend\Mvc\View\Http; use ArrayAccess; diff --git a/test/Application/AllowsReturningEarlyFromRoutingTest.php b/test/Application/AllowsReturningEarlyFromRoutingTest.php index 77b0f560f..daee26c5f 100644 --- a/test/Application/AllowsReturningEarlyFromRoutingTest.php +++ b/test/Application/AllowsReturningEarlyFromRoutingTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; diff --git a/test/Application/BadControllerTrait.php b/test/Application/BadControllerTrait.php index b45c050d4..8c7f6c88b 100644 --- a/test/Application/BadControllerTrait.php +++ b/test/Application/BadControllerTrait.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use ReflectionProperty; diff --git a/test/Application/ControllerIsDispatchedTest.php b/test/Application/ControllerIsDispatchedTest.php index 42aed39bb..06be86ae0 100644 --- a/test/Application/ControllerIsDispatchedTest.php +++ b/test/Application/ControllerIsDispatchedTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; diff --git a/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php b/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php index 105137ff3..d3262ce2e 100644 --- a/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php +++ b/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; diff --git a/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php b/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php index 614124c3d..bbdefcd77 100644 --- a/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php +++ b/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; diff --git a/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php b/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php index d7983a1d9..38552fd0c 100644 --- a/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php +++ b/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; diff --git a/test/Application/InitializationIntegrationTest.php b/test/Application/InitializationIntegrationTest.php index bd60864f4..372d08ba1 100644 --- a/test/Application/InitializationIntegrationTest.php +++ b/test/Application/InitializationIntegrationTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; diff --git a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php index 709f7be06..295ab8619 100644 --- a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php +++ b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; diff --git a/test/Application/InvalidControllerTypeTrait.php b/test/Application/InvalidControllerTypeTrait.php index a50b496f8..a94f541b7 100644 --- a/test/Application/InvalidControllerTypeTrait.php +++ b/test/Application/InvalidControllerTypeTrait.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use ReflectionProperty; diff --git a/test/Application/MissingControllerTrait.php b/test/Application/MissingControllerTrait.php index 141168898..455ce9cee 100644 --- a/test/Application/MissingControllerTrait.php +++ b/test/Application/MissingControllerTrait.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use ReflectionProperty; diff --git a/test/Application/PathControllerTrait.php b/test/Application/PathControllerTrait.php index 075ee1997..6626830f6 100644 --- a/test/Application/PathControllerTrait.php +++ b/test/Application/PathControllerTrait.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use ReflectionProperty; diff --git a/test/Application/RoutingSuccessTest.php b/test/Application/RoutingSuccessTest.php index d2c05d6af..08c96065a 100644 --- a/test/Application/RoutingSuccessTest.php +++ b/test/Application/RoutingSuccessTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; diff --git a/test/Application/TestAsset/modules/Application/Module.php b/test/Application/TestAsset/modules/Application/Module.php index 0cb6a0fe9..59a66d23d 100644 --- a/test/Application/TestAsset/modules/Application/Module.php +++ b/test/Application/TestAsset/modules/Application/Module.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Application; use Zend\Loader\StandardAutoloader; diff --git a/test/Application/TestAsset/modules/Application/config/module.config.php b/test/Application/TestAsset/modules/Application/config/module.config.php index 669e51af7..f38dee849 100644 --- a/test/Application/TestAsset/modules/Application/config/module.config.php +++ b/test/Application/TestAsset/modules/Application/config/module.config.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Application; use Zend\Http\PhpEnvironment\Request as HttpRequest; diff --git a/test/Application/TestAsset/modules/Application/src/Application/Controller/PathController.php b/test/Application/TestAsset/modules/Application/src/Application/Controller/PathController.php index fd9db7fe9..09cc1f581 100644 --- a/test/Application/TestAsset/modules/Application/src/Application/Controller/PathController.php +++ b/test/Application/TestAsset/modules/Application/src/Application/Controller/PathController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Application\Controller; use Zend\Http\Response as HttpResponse; diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index 37682a561..b59c1d6d4 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; diff --git a/test/Container/ControllerManagerFactoryTest.php b/test/Container/ControllerManagerFactoryTest.php index 01dbc5723..da249fff3 100644 --- a/test/Container/ControllerManagerFactoryTest.php +++ b/test/Container/ControllerManagerFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; diff --git a/test/Container/HttpMethodListenerFactoryTest.php b/test/Container/HttpMethodListenerFactoryTest.php index 934a7d6d9..3234fad36 100644 --- a/test/Container/HttpMethodListenerFactoryTest.php +++ b/test/Container/HttpMethodListenerFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/test/Container/InjectTemplateListenerFactoryTest.php b/test/Container/InjectTemplateListenerFactoryTest.php index 99f515743..ddc6004d9 100644 --- a/test/Container/InjectTemplateListenerFactoryTest.php +++ b/test/Container/InjectTemplateListenerFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use ArrayObject; diff --git a/test/Container/RequestFactoryTest.php b/test/Container/RequestFactoryTest.php index b7f14458b..9969b7928 100644 --- a/test/Container/RequestFactoryTest.php +++ b/test/Container/RequestFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/test/Container/ResponseFactoryTest.php b/test/Container/ResponseFactoryTest.php index 7ac7b9cf3..485990997 100644 --- a/test/Container/ResponseFactoryTest.php +++ b/test/Container/ResponseFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/test/Container/SendResponseListenerFactoryTest.php b/test/Container/SendResponseListenerFactoryTest.php index b5eb7b18f..18a7a8ec5 100644 --- a/test/Container/SendResponseListenerFactoryTest.php +++ b/test/Container/SendResponseListenerFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/test/Container/ServiceListenerFactoryTest.php b/test/Container/ServiceListenerFactoryTest.php index c6527734a..0c31bc110 100644 --- a/test/Container/ServiceListenerFactoryTest.php +++ b/test/Container/ServiceListenerFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; diff --git a/test/Container/ServiceManagerConfigTest.php b/test/Container/ServiceManagerConfigTest.php index d5739267d..186d6c75d 100644 --- a/test/Container/ServiceManagerConfigTest.php +++ b/test/Container/ServiceManagerConfigTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; diff --git a/test/Container/ViewFeedStrategyFactoryTest.php b/test/Container/ViewFeedStrategyFactoryTest.php index e15f4f707..e65b351b4 100644 --- a/test/Container/ViewFeedStrategyFactoryTest.php +++ b/test/Container/ViewFeedStrategyFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/test/Container/ViewHelperManagerFactoryTest.php b/test/Container/ViewHelperManagerFactoryTest.php index 1030ed888..15ead72c6 100644 --- a/test/Container/ViewHelperManagerFactoryTest.php +++ b/test/Container/ViewHelperManagerFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; diff --git a/test/Container/ViewJsonStrategyFactoryTest.php b/test/Container/ViewJsonStrategyFactoryTest.php index 202250700..2781059c1 100644 --- a/test/Container/ViewJsonStrategyFactoryTest.php +++ b/test/Container/ViewJsonStrategyFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/test/Container/ViewManagerFactoryTest.php b/test/Container/ViewManagerFactoryTest.php index a77d9a49d..818b878de 100644 --- a/test/Container/ViewManagerFactoryTest.php +++ b/test/Container/ViewManagerFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/test/Container/ViewPrefixPathStackResolverFactoryTest.php b/test/Container/ViewPrefixPathStackResolverFactoryTest.php index 8ecf83207..f041879fb 100644 --- a/test/Container/ViewPrefixPathStackResolverFactoryTest.php +++ b/test/Container/ViewPrefixPathStackResolverFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Container; use Interop\Container\ContainerInterface; diff --git a/test/Controller/AbstractControllerTest.php b/test/Controller/AbstractControllerTest.php index c7a2f2867..a90f101f2 100644 --- a/test/Controller/AbstractControllerTest.php +++ b/test/Controller/AbstractControllerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/ActionControllerTest.php b/test/Controller/ActionControllerTest.php index c1d5f0dc0..916e0f73c 100644 --- a/test/Controller/ActionControllerTest.php +++ b/test/Controller/ActionControllerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/ControllerManagerTest.php b/test/Controller/ControllerManagerTest.php index b4aac9522..97be79208 100644 --- a/test/Controller/ControllerManagerTest.php +++ b/test/Controller/ControllerManagerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/IntegrationTest.php b/test/Controller/IntegrationTest.php index a6569a88a..70221902e 100644 --- a/test/Controller/IntegrationTest.php +++ b/test/Controller/IntegrationTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/LazyControllerAbstractFactoryTest.php b/test/Controller/LazyControllerAbstractFactoryTest.php index 6e3e385cc..037cfbbe8 100644 --- a/test/Controller/LazyControllerAbstractFactoryTest.php +++ b/test/Controller/LazyControllerAbstractFactoryTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller; use Interop\Container\ContainerInterface; diff --git a/test/Controller/MiddlewareControllerTest.php b/test/Controller/MiddlewareControllerTest.php index b76d1769b..7ce27829a 100644 --- a/test/Controller/MiddlewareControllerTest.php +++ b/test/Controller/MiddlewareControllerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/Plugin/AcceptableViewModelSelectorTest.php b/test/Controller/Plugin/AcceptableViewModelSelectorTest.php index 40320a29a..0b1c4e676 100644 --- a/test/Controller/Plugin/AcceptableViewModelSelectorTest.php +++ b/test/Controller/Plugin/AcceptableViewModelSelectorTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/Plugin/CreateHttpNotFoundModelTest.php b/test/Controller/Plugin/CreateHttpNotFoundModelTest.php index 953f9166d..8b2f83e7a 100644 --- a/test/Controller/Plugin/CreateHttpNotFoundModelTest.php +++ b/test/Controller/Plugin/CreateHttpNotFoundModelTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/Plugin/ForwardTest.php b/test/Controller/Plugin/ForwardTest.php index b8a928b96..6b61fda61 100644 --- a/test/Controller/Plugin/ForwardTest.php +++ b/test/Controller/Plugin/ForwardTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/Plugin/LayoutTest.php b/test/Controller/Plugin/LayoutTest.php index 225df0533..150990c1c 100644 --- a/test/Controller/Plugin/LayoutTest.php +++ b/test/Controller/Plugin/LayoutTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/Plugin/ParamsTest.php b/test/Controller/Plugin/ParamsTest.php index 9f578d452..47db170d9 100644 --- a/test/Controller/Plugin/ParamsTest.php +++ b/test/Controller/Plugin/ParamsTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/Plugin/RedirectTest.php b/test/Controller/Plugin/RedirectTest.php index 64f68051d..e6787d7d4 100644 --- a/test/Controller/Plugin/RedirectTest.php +++ b/test/Controller/Plugin/RedirectTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/Plugin/TestAsset/ListenerStub.php b/test/Controller/Plugin/TestAsset/ListenerStub.php index cf0455d38..bd0fe2bac 100644 --- a/test/Controller/Plugin/TestAsset/ListenerStub.php +++ b/test/Controller/Plugin/TestAsset/ListenerStub.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin\TestAsset; class ListenerStub diff --git a/test/Controller/Plugin/TestAsset/SamplePlugin.php b/test/Controller/Plugin/TestAsset/SamplePlugin.php index f5fcfbb35..1fad2dd3f 100644 --- a/test/Controller/Plugin/TestAsset/SamplePlugin.php +++ b/test/Controller/Plugin/TestAsset/SamplePlugin.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin\TestAsset; use Zend\Mvc\Controller\Plugin\AbstractPlugin; diff --git a/test/Controller/Plugin/TestAsset/SamplePluginFactory.php b/test/Controller/Plugin/TestAsset/SamplePluginFactory.php index d6def1829..6eca684d3 100644 --- a/test/Controller/Plugin/TestAsset/SamplePluginFactory.php +++ b/test/Controller/Plugin/TestAsset/SamplePluginFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin\TestAsset; use Interop\Container\ContainerInterface; diff --git a/test/Controller/Plugin/TestAsset/SamplePluginWithConstructor.php b/test/Controller/Plugin/TestAsset/SamplePluginWithConstructor.php index 3404a54fe..9abd205e8 100644 --- a/test/Controller/Plugin/TestAsset/SamplePluginWithConstructor.php +++ b/test/Controller/Plugin/TestAsset/SamplePluginWithConstructor.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin\TestAsset; use Zend\Mvc\Controller\Plugin\AbstractPlugin; diff --git a/test/Controller/Plugin/TestAsset/SamplePluginWithConstructorFactory.php b/test/Controller/Plugin/TestAsset/SamplePluginWithConstructorFactory.php index a4c1f4a89..9374133e4 100644 --- a/test/Controller/Plugin/TestAsset/SamplePluginWithConstructorFactory.php +++ b/test/Controller/Plugin/TestAsset/SamplePluginWithConstructorFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin\TestAsset; use Interop\Container\ContainerInterface; diff --git a/test/Controller/Plugin/UrlTest.php b/test/Controller/Plugin/UrlTest.php index 393d3fa7a..a7a09e519 100644 --- a/test/Controller/Plugin/UrlTest.php +++ b/test/Controller/Plugin/UrlTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/PluginManagerTest.php b/test/Controller/PluginManagerTest.php index 596589602..28b7d6cc1 100644 --- a/test/Controller/PluginManagerTest.php +++ b/test/Controller/PluginManagerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/RestfulControllerTest.php b/test/Controller/RestfulControllerTest.php index a7ca8186b..edc47a8bf 100644 --- a/test/Controller/RestfulControllerTest.php +++ b/test/Controller/RestfulControllerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller; use PHPUnit\Framework\TestCase; diff --git a/test/Controller/TestAsset/BadController.php b/test/Controller/TestAsset/BadController.php index 72d39f857..41bd15674 100644 --- a/test/Controller/TestAsset/BadController.php +++ b/test/Controller/TestAsset/BadController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Controller/TestAsset/ControllerAcceptingConfigToConstructor.php b/test/Controller/TestAsset/ControllerAcceptingConfigToConstructor.php index 4f68b91e1..3f312ff12 100644 --- a/test/Controller/TestAsset/ControllerAcceptingConfigToConstructor.php +++ b/test/Controller/TestAsset/ControllerAcceptingConfigToConstructor.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Controller/TestAsset/ControllerAcceptingWellKnownServicesAsConstructorParameters.php b/test/Controller/TestAsset/ControllerAcceptingWellKnownServicesAsConstructorParameters.php index 5e4a48fd8..65384d936 100644 --- a/test/Controller/TestAsset/ControllerAcceptingWellKnownServicesAsConstructorParameters.php +++ b/test/Controller/TestAsset/ControllerAcceptingWellKnownServicesAsConstructorParameters.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Controller/TestAsset/ControllerLoaderAbstractFactory.php b/test/Controller/TestAsset/ControllerLoaderAbstractFactory.php index d5626ec8e..4d174062e 100644 --- a/test/Controller/TestAsset/ControllerLoaderAbstractFactory.php +++ b/test/Controller/TestAsset/ControllerLoaderAbstractFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Interop\Container\ContainerInterface; diff --git a/test/Controller/TestAsset/ControllerWithEmptyConstructor.php b/test/Controller/TestAsset/ControllerWithEmptyConstructor.php index ec791c2a5..651a69674 100644 --- a/test/Controller/TestAsset/ControllerWithEmptyConstructor.php +++ b/test/Controller/TestAsset/ControllerWithEmptyConstructor.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Controller/TestAsset/ControllerWithMixedConstructorParameters.php b/test/Controller/TestAsset/ControllerWithMixedConstructorParameters.php index ed2f2408b..0ddfb8208 100644 --- a/test/Controller/TestAsset/ControllerWithMixedConstructorParameters.php +++ b/test/Controller/TestAsset/ControllerWithMixedConstructorParameters.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Controller/TestAsset/ControllerWithScalarParameters.php b/test/Controller/TestAsset/ControllerWithScalarParameters.php index 7cde14553..3cea036cf 100644 --- a/test/Controller/TestAsset/ControllerWithScalarParameters.php +++ b/test/Controller/TestAsset/ControllerWithScalarParameters.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Controller/TestAsset/ControllerWithTypeHintedConstructorParameter.php b/test/Controller/TestAsset/ControllerWithTypeHintedConstructorParameter.php index 204fb1c2d..1c3bdfc0b 100644 --- a/test/Controller/TestAsset/ControllerWithTypeHintedConstructorParameter.php +++ b/test/Controller/TestAsset/ControllerWithTypeHintedConstructorParameter.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Controller/TestAsset/ForwardController.php b/test/Controller/TestAsset/ForwardController.php index 89dfd49c9..d2dc91b99 100644 --- a/test/Controller/TestAsset/ForwardController.php +++ b/test/Controller/TestAsset/ForwardController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Controller/TestAsset/Request.php b/test/Controller/TestAsset/Request.php index 837f3a405..16695aa77 100644 --- a/test/Controller/TestAsset/Request.php +++ b/test/Controller/TestAsset/Request.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Http\Request as HttpRequest; diff --git a/test/Controller/TestAsset/RestfulContentTypeTestController.php b/test/Controller/TestAsset/RestfulContentTypeTestController.php index 67c8767a9..fb8179ecc 100644 --- a/test/Controller/TestAsset/RestfulContentTypeTestController.php +++ b/test/Controller/TestAsset/RestfulContentTypeTestController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractRestfulController; diff --git a/test/Controller/TestAsset/RestfulMethodNotAllowedTestController.php b/test/Controller/TestAsset/RestfulMethodNotAllowedTestController.php index c65efd817..6cccfb4d8 100644 --- a/test/Controller/TestAsset/RestfulMethodNotAllowedTestController.php +++ b/test/Controller/TestAsset/RestfulMethodNotAllowedTestController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractRestfulController; diff --git a/test/Controller/TestAsset/RestfulTestController.php b/test/Controller/TestAsset/RestfulTestController.php index 2ea70f296..620478132 100644 --- a/test/Controller/TestAsset/RestfulTestController.php +++ b/test/Controller/TestAsset/RestfulTestController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractRestfulController; diff --git a/test/Controller/TestAsset/SampleController.php b/test/Controller/TestAsset/SampleController.php index 5fb42d06d..16ce21afe 100644 --- a/test/Controller/TestAsset/SampleController.php +++ b/test/Controller/TestAsset/SampleController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Controller/TestAsset/SampleInterface.php b/test/Controller/TestAsset/SampleInterface.php index 995e5119a..cee2dfa6b 100644 --- a/test/Controller/TestAsset/SampleInterface.php +++ b/test/Controller/TestAsset/SampleInterface.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; interface SampleInterface diff --git a/test/Controller/TestAsset/UneventfulController.php b/test/Controller/TestAsset/UneventfulController.php index 1444147e3..cb8a1cde0 100644 --- a/test/Controller/TestAsset/UneventfulController.php +++ b/test/Controller/TestAsset/UneventfulController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Stdlib\DispatchableInterface; diff --git a/test/Controller/TestAsset/UnlocatableControllerLoaderAbstractFactory.php b/test/Controller/TestAsset/UnlocatableControllerLoaderAbstractFactory.php index c9d2648a9..b8e5d4bcf 100644 --- a/test/Controller/TestAsset/UnlocatableControllerLoaderAbstractFactory.php +++ b/test/Controller/TestAsset/UnlocatableControllerLoaderAbstractFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Interop\Container\ContainerInterface; diff --git a/test/Controller/TestAsset/UnlocatableEventfulController.php b/test/Controller/TestAsset/UnlocatableEventfulController.php index 98c3cfb78..5b74ee745 100644 --- a/test/Controller/TestAsset/UnlocatableEventfulController.php +++ b/test/Controller/TestAsset/UnlocatableEventfulController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Controller\TestAsset; use Zend\EventManager\EventInterface as Event; diff --git a/test/DispatchListenerTest.php b/test/DispatchListenerTest.php index 41da5d19f..92989ccbd 100644 --- a/test/DispatchListenerTest.php +++ b/test/DispatchListenerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; diff --git a/test/Exception/InvalidMiddlewareExceptionTest.php b/test/Exception/InvalidMiddlewareExceptionTest.php index 8311d7945..87b35fe25 100644 --- a/test/Exception/InvalidMiddlewareExceptionTest.php +++ b/test/Exception/InvalidMiddlewareExceptionTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; diff --git a/test/Exception/ReachedFinalHandlerExceptionTest.php b/test/Exception/ReachedFinalHandlerExceptionTest.php index 8628ddd5c..b420173a6 100644 --- a/test/Exception/ReachedFinalHandlerExceptionTest.php +++ b/test/Exception/ReachedFinalHandlerExceptionTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; diff --git a/test/HttpMethodListenerTest.php b/test/HttpMethodListenerTest.php index 86d033994..8bd545505 100644 --- a/test/HttpMethodListenerTest.php +++ b/test/HttpMethodListenerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; diff --git a/test/MiddlewareListenerTest.php b/test/MiddlewareListenerTest.php index c11c7165c..d9b4c8713 100644 --- a/test/MiddlewareListenerTest.php +++ b/test/MiddlewareListenerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc; use Interop\Container\ContainerInterface; diff --git a/test/ModuleRouteListenerTest.php b/test/ModuleRouteListenerTest.php index 622f54f05..aa9d5e2cc 100644 --- a/test/ModuleRouteListenerTest.php +++ b/test/ModuleRouteListenerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; diff --git a/test/ResponseSender/AbstractResponseSenderTest.php b/test/ResponseSender/AbstractResponseSenderTest.php index 05f14bb2d..e700aeb41 100644 --- a/test/ResponseSender/AbstractResponseSenderTest.php +++ b/test/ResponseSender/AbstractResponseSenderTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\ResponseSender; use PHPUnit\Framework\TestCase; diff --git a/test/ResponseSender/PhpEnvironmentResponseSenderTest.php b/test/ResponseSender/PhpEnvironmentResponseSenderTest.php index be983e243..ac1c8bc93 100644 --- a/test/ResponseSender/PhpEnvironmentResponseSenderTest.php +++ b/test/ResponseSender/PhpEnvironmentResponseSenderTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\ResponseSender; use PHPUnit\Framework\TestCase; diff --git a/test/ResponseSender/SendResponseEventTest.php b/test/ResponseSender/SendResponseEventTest.php index e8eb9d2bc..cafc62863 100644 --- a/test/ResponseSender/SendResponseEventTest.php +++ b/test/ResponseSender/SendResponseEventTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\ResponseSender; use PHPUnit\Framework\TestCase; diff --git a/test/ResponseSender/SimpleStreamResponseSenderTest.php b/test/ResponseSender/SimpleStreamResponseSenderTest.php index aca16d9ed..87745a707 100644 --- a/test/ResponseSender/SimpleStreamResponseSenderTest.php +++ b/test/ResponseSender/SimpleStreamResponseSenderTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\ResponseSender; use PHPUnit\Framework\TestCase; diff --git a/test/SendResponseListenerTest.php b/test/SendResponseListenerTest.php index d0b75d0a2..998520a74 100644 --- a/test/SendResponseListenerTest.php +++ b/test/SendResponseListenerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; diff --git a/test/Service/TestAsset/ControllerWithDependencies.php b/test/Service/TestAsset/ControllerWithDependencies.php index b7b4c41eb..24da43149 100644 --- a/test/Service/TestAsset/ControllerWithDependencies.php +++ b/test/Service/TestAsset/ControllerWithDependencies.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Service\TestAsset; use Zend\Stdlib\DispatchableInterface; diff --git a/test/Service/TestAsset/Dispatchable.php b/test/Service/TestAsset/Dispatchable.php index 4c5de0272..e9f861470 100644 --- a/test/Service/TestAsset/Dispatchable.php +++ b/test/Service/TestAsset/Dispatchable.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Service\TestAsset; use Zend\Mvc\Controller\AbstractActionController; diff --git a/test/Service/TestAsset/EventManagerAwareObject.php b/test/Service/TestAsset/EventManagerAwareObject.php index 61478abde..ce278fa2c 100644 --- a/test/Service/TestAsset/EventManagerAwareObject.php +++ b/test/Service/TestAsset/EventManagerAwareObject.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Service\TestAsset; use Zend\EventManager\EventManagerAwareInterface; diff --git a/test/Service/TestAsset/InvalidDispatchableClass.php b/test/Service/TestAsset/InvalidDispatchableClass.php index 6e01df4a9..2596c162b 100644 --- a/test/Service/TestAsset/InvalidDispatchableClass.php +++ b/test/Service/TestAsset/InvalidDispatchableClass.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\Service\TestAsset; use DomainException; diff --git a/test/TestAsset/Locator.php b/test/TestAsset/Locator.php index 0300e06d5..499a67b26 100644 --- a/test/TestAsset/Locator.php +++ b/test/TestAsset/Locator.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\TestAsset; use Zend\ServiceManager\ServiceLocatorInterface; diff --git a/test/TestAsset/Middleware.php b/test/TestAsset/Middleware.php index 289bc3b12..da19fe083 100644 --- a/test/TestAsset/Middleware.php +++ b/test/TestAsset/Middleware.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\TestAsset; use Psr\Http\Message\ServerRequestInterface; diff --git a/test/TestAsset/MiddlewareAbstractFactory.php b/test/TestAsset/MiddlewareAbstractFactory.php index ccde7d726..d6456387f 100644 --- a/test/TestAsset/MiddlewareAbstractFactory.php +++ b/test/TestAsset/MiddlewareAbstractFactory.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\TestAsset; use Interop\Container\ContainerInterface; diff --git a/test/TestAsset/MockSendResponseListener.php b/test/TestAsset/MockSendResponseListener.php index 850314031..02d4f5c1d 100644 --- a/test/TestAsset/MockSendResponseListener.php +++ b/test/TestAsset/MockSendResponseListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\TestAsset; use Zend\EventManager\AbstractListenerAggregate; diff --git a/test/TestAsset/MockViewManager.php b/test/TestAsset/MockViewManager.php index d97a52256..6e6a02f6c 100644 --- a/test/TestAsset/MockViewManager.php +++ b/test/TestAsset/MockViewManager.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\TestAsset; use Zend\EventManager\AbstractListenerAggregate; diff --git a/test/TestAsset/PathController.php b/test/TestAsset/PathController.php index 44e7631e3..3a82ea397 100644 --- a/test/TestAsset/PathController.php +++ b/test/TestAsset/PathController.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\TestAsset; use Zend\Stdlib\DispatchableInterface; diff --git a/test/TestAsset/StubBootstrapListener.php b/test/TestAsset/StubBootstrapListener.php index b3a8528fb..f8c15946b 100644 --- a/test/TestAsset/StubBootstrapListener.php +++ b/test/TestAsset/StubBootstrapListener.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\TestAsset; use Zend\EventManager\ListenerAggregateInterface; diff --git a/test/View/CreateViewModelListenerTest.php b/test/View/CreateViewModelListenerTest.php index dc2eb7fa1..894437b95 100644 --- a/test/View/CreateViewModelListenerTest.php +++ b/test/View/CreateViewModelListenerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; diff --git a/test/View/DefaultRendereringStrategyTest.php b/test/View/DefaultRendereringStrategyTest.php index a608877dd..16bee4dd4 100644 --- a/test/View/DefaultRendereringStrategyTest.php +++ b/test/View/DefaultRendereringStrategyTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; diff --git a/test/View/ExceptionStrategyTest.php b/test/View/ExceptionStrategyTest.php index e61b6e450..d22fb5530 100644 --- a/test/View/ExceptionStrategyTest.php +++ b/test/View/ExceptionStrategyTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; diff --git a/test/View/InjectTemplateListenerTest.php b/test/View/InjectTemplateListenerTest.php index 8636bfde8..9e07eece1 100644 --- a/test/View/InjectTemplateListenerTest.php +++ b/test/View/InjectTemplateListenerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; diff --git a/test/View/InjectViewModelListenerTest.php b/test/View/InjectViewModelListenerTest.php index e8401d87a..1e841e46b 100644 --- a/test/View/InjectViewModelListenerTest.php +++ b/test/View/InjectViewModelListenerTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; diff --git a/test/View/RouteNotFoundStrategyTest.php b/test/View/RouteNotFoundStrategyTest.php index 5766ddad3..24c597fdd 100644 --- a/test/View/RouteNotFoundStrategyTest.php +++ b/test/View/RouteNotFoundStrategyTest.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; diff --git a/test/View/TestAsset/DumbStrategy.php b/test/View/TestAsset/DumbStrategy.php index 3369410ca..217c96889 100644 --- a/test/View/TestAsset/DumbStrategy.php +++ b/test/View/TestAsset/DumbStrategy.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace ZendTest\Mvc\View\TestAsset; use ArrayObject; diff --git a/test/_autoload.php b/test/_autoload.php index a496a8f6a..d2f903736 100644 --- a/test/_autoload.php +++ b/test/_autoload.php @@ -5,6 +5,8 @@ * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + if (! class_exists(PHPUnit_Framework_Assert::class) && class_exists(PHPUnit\Framework\Assert::class) ) { From 518c9ac4a71530985de6557dabe74c725a529a70 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 9 Sep 2017 14:01:09 +1000 Subject: [PATCH 06/51] Fix phpstan complaints --- src/Container/ApplicationFactory.php | 6 +++++ src/Container/ServiceListenerFactory.php | 15 ++++++++--- src/Container/ViewHelperManagerFactory.php | 9 ++++--- src/Container/ViewManagerConfigTrait.php | 2 +- src/Controller/AbstractActionController.php | 5 +++- src/Controller/AbstractController.php | 2 +- src/Controller/AbstractRestfulController.php | 4 +-- .../Plugin/AcceptableViewModelSelector.php | 26 ++++++++++++------- src/Controller/Plugin/Forward.php | 4 +-- src/Controller/Plugin/Layout.php | 4 +-- src/Controller/Plugin/Url.php | 5 ++++ src/DispatchListener.php | 19 +++++++------- src/Exception/InvalidMiddlewareException.php | 3 +-- src/HttpMethodListener.php | 12 ++++----- src/MiddlewareListener.php | 15 ++++++++--- src/ModuleRouteListener.php | 2 +- src/MvcEvent.php | 2 +- src/ResponseSender/HttpResponseSender.php | 4 +-- .../PhpEnvironmentResponseSender.php | 4 +-- .../SimpleStreamResponseSender.php | 4 +++ src/RouteListener.php | 2 +- src/SendResponseListener.php | 2 +- src/View/Http/DefaultRenderingStrategy.php | 6 ++--- src/View/Http/ExceptionStrategy.php | 8 +++--- .../Http/InjectRoutematchParamsListener.php | 10 +++++-- src/View/Http/InjectTemplateListener.php | 10 ++++--- src/View/Http/RouteNotFoundStrategy.php | 12 ++++----- test/ApplicationTest.php | 2 +- test/Controller/ActionControllerTest.php | 4 +-- test/DispatchListenerTest.php | 2 +- 30 files changed, 128 insertions(+), 77 deletions(-) diff --git a/src/Container/ApplicationFactory.php b/src/Container/ApplicationFactory.php index 038068e36..4e261f140 100644 --- a/src/Container/ApplicationFactory.php +++ b/src/Container/ApplicationFactory.php @@ -11,7 +11,9 @@ use Interop\Container\ContainerInterface; use Zend\Mvc\Application; +use Zend\Mvc\Exception\RuntimeException; use Zend\ServiceManager\Factory\FactoryInterface; +use Zend\ServiceManager\ServiceManager; class ApplicationFactory implements FactoryInterface { @@ -28,6 +30,10 @@ class ApplicationFactory implements FactoryInterface */ public function __invoke(ContainerInterface $container, $name, array $options = null) { + if (! $container instanceof ServiceManager) { + // @TODO convert Application to use ContainerInterface + throw new RuntimeException('Mvc Application requires ServiceManager as ContainerInterface implementation'); + } return new Application( $container, $container->get('EventManager'), diff --git a/src/Container/ServiceListenerFactory.php b/src/Container/ServiceListenerFactory.php index d2cc38f70..f05aafd05 100644 --- a/src/Container/ServiceListenerFactory.php +++ b/src/Container/ServiceListenerFactory.php @@ -12,11 +12,13 @@ use Interop\Container\ContainerInterface; use Zend\ModuleManager\Listener\ServiceListener; use Zend\ModuleManager\Listener\ServiceListenerInterface; +use Zend\Mvc\Exception\RuntimeException; use Zend\Mvc\View; use Zend\ServiceManager\Exception\ServiceNotCreatedException; use Zend\ServiceManager\Factory\FactoryInterface; use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\ServiceLocatorInterface; +use Zend\ServiceManager\ServiceManager; class ServiceListenerFactory implements FactoryInterface { @@ -123,9 +125,16 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o { $configuration = $container->get('ApplicationConfig'); - $serviceListener = $container->has('ServiceListenerInterface') - ? $container->get('ServiceListenerInterface') - : new ServiceListener($container); + if ($container->has('ServiceListenerInterface')) { + $serviceListener = $container->get('ServiceListenerInterface'); + } elseif ($container instanceof ServiceManager) { + $serviceListener = new ServiceListener($container); + } else { + // @TODO update ServiceListener to accept ContainerInterface + throw new RuntimeException( + 'Container is not a ServiceManager and ServiceListenerInterface was not provided' + ); + } if (! $serviceListener instanceof ServiceListenerInterface) { throw new ServiceNotCreatedException( diff --git a/src/Container/ViewHelperManagerFactory.php b/src/Container/ViewHelperManagerFactory.php index ace30e1a3..5a233a0c3 100644 --- a/src/Container/ViewHelperManagerFactory.php +++ b/src/Container/ViewHelperManagerFactory.php @@ -12,6 +12,7 @@ use Interop\Container\ContainerInterface; use Zend\Mvc\Service\AbstractPluginManagerFactory; use Zend\Router\RouteMatch; +use Zend\ServiceManager\AbstractPluginManager; use Zend\ServiceManager\Exception\ServiceNotCreatedException; use Zend\View\Helper as ViewHelper; use Zend\View\HelperPluginManager; @@ -34,7 +35,7 @@ class ViewHelperManagerFactory extends AbstractPluginManagerFactory * Create and return the view helper manager * * @param ContainerInterface $container - * @return HelperPluginManager + * @return AbstractPluginManager * @throws ServiceNotCreatedException */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) @@ -52,11 +53,11 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o /** * Inject override factories into the plugin manager. * - * @param HelperPluginManager $plugins + * @param AbstractPluginManager $plugins * @param ContainerInterface $services - * @return HelperPluginManager + * @return AbstractPluginManager */ - private function injectOverrideFactories(HelperPluginManager $plugins, ContainerInterface $services) + private function injectOverrideFactories(AbstractPluginManager $plugins, ContainerInterface $services) { // Configure URL view helper $urlFactory = $this->createUrlHelperFactory($services); diff --git a/src/Container/ViewManagerConfigTrait.php b/src/Container/ViewManagerConfigTrait.php index 6be53a6ef..a0650bae9 100644 --- a/src/Container/ViewManagerConfigTrait.php +++ b/src/Container/ViewManagerConfigTrait.php @@ -18,7 +18,7 @@ trait ViewManagerConfigTrait * Retrieve view_manager configuration, if present. * * @param ContainerInterface $container - * @return array + * @return array|ArrayAccess */ private function getConfig(ContainerInterface $container) { diff --git a/src/Controller/AbstractActionController.php b/src/Controller/AbstractActionController.php index 8f494e331..0c6fa4704 100644 --- a/src/Controller/AbstractActionController.php +++ b/src/Controller/AbstractActionController.php @@ -44,7 +44,10 @@ public function notFoundAction() { $event = $this->getEvent(); $routeMatch = $event->getRouteMatch(); - $routeMatch->setParam('action', 'not-found'); + if ($routeMatch) { + // @TODO figure out what is the course of action in case of missing RouteMatch + $routeMatch->setParam('action', 'not-found'); + } $helper = $this->plugin('createHttpNotFoundModel'); return $helper($event->getResponse()); diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index 8b8e20911..383f9e694 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -57,7 +57,7 @@ abstract class AbstractController implements protected $response; /** - * @var Event + * @var MvcEvent */ protected $event; diff --git a/src/Controller/AbstractRestfulController.php b/src/Controller/AbstractRestfulController.php index 556abc0be..d40345b12 100644 --- a/src/Controller/AbstractRestfulController.php +++ b/src/Controller/AbstractRestfulController.php @@ -77,9 +77,9 @@ abstract class AbstractRestfulController extends AbstractController * @param string $name * @return self */ - public function setIdentifierName($name) + public function setIdentifierName(string $name) { - $this->identifierName = (string) $name; + $this->identifierName = $name; return $this; } diff --git a/src/Controller/Plugin/AcceptableViewModelSelector.php b/src/Controller/Plugin/AcceptableViewModelSelector.php index 487d5dceb..c629eaca6 100644 --- a/src/Controller/Plugin/AcceptableViewModelSelector.php +++ b/src/Controller/Plugin/AcceptableViewModelSelector.php @@ -11,6 +11,7 @@ use Zend\Http\Header\Accept\FieldValuePart\AbstractFieldValuePart; use Zend\Http\Request; +use Zend\Mvc\Exception\RuntimeException; use Zend\Mvc\InjectApplicationEventInterface; use Zend\Mvc\MvcEvent; use Zend\Mvc\Exception\DomainException; @@ -44,7 +45,7 @@ class AcceptableViewModelSelector extends AbstractPlugin /** * Default array to match against. * - * @var Array + * @var array|null */ protected $defaultMatchAgainst; @@ -88,7 +89,7 @@ public function getViewModel( $name = $this->getViewModelName($matchAgainst, $returnDefault, $resultReference); if (! $name) { - return; + return null; } if (! class_exists($name)) { @@ -104,7 +105,7 @@ public function getViewModel( * @param array $matchAgainst (optional) The Array to match against * @param bool $returnDefault (optional) If no match is available. Return default instead * @param AbstractFieldValuePart|null $resultReference (optional) The object that was matched. - * @return ModelInterface|null Returns null if $returnDefault = false and no match could be made + * @return string|null Returns null if $returnDefault = false and no match could be made */ public function getViewModelName( array $matchAgainst = null, @@ -134,7 +135,7 @@ public function match(array $matchAgainst = null) $headers = $request->getHeaders(); if ((! $matchAgainst && ! $this->defaultMatchAgainst) || ! $headers->has('accept')) { - return; + return null; } if (! $matchAgainst) { @@ -150,11 +151,12 @@ public function match(array $matchAgainst = null) /** @var $accept \Zend\Http\Header\Accept */ $accept = $headers->get('Accept'); - if (($res = $accept->match($matchAgainstString)) === false) { - return; + $res = $accept->match($matchAgainstString); + if ($res instanceof AbstractFieldValuePart) { + return $res; } - return $res; + return null; } /** @@ -162,9 +164,9 @@ public function match(array $matchAgainst = null) * @param string $defaultViewModelName The default View Model name * @return AcceptableViewModelSelector provides fluent interface */ - public function setDefaultViewModelName($defaultViewModelName) + public function setDefaultViewModelName(string $defaultViewModelName) { - $this->defaultViewModelName = (string) $defaultViewModelName; + $this->defaultViewModelName = $defaultViewModelName; return $this; } @@ -222,7 +224,11 @@ protected function injectViewModelName($modelAcceptString, $modelName) */ protected function extractViewModelName(AbstractFieldValuePart $res) { - $modelName = $res->getMatchedAgainst()->params[self::INJECT_VIEWMODEL_NAME]; + $matched = $res->getMatchedAgainst(); + if (! $matched) { + throw new RuntimeException('Matched field value part is not set'); + } + $modelName = $matched->params[self::INJECT_VIEWMODEL_NAME]; return str_replace('|', '\\', $modelName); } diff --git a/src/Controller/Plugin/Forward.php b/src/Controller/Plugin/Forward.php index 354aec88a..35068bde8 100644 --- a/src/Controller/Plugin/Forward.php +++ b/src/Controller/Plugin/Forward.php @@ -58,9 +58,9 @@ public function __construct(ControllerManager $controllers) * @param int $maxNestedForwards * @return self */ - public function setMaxNestedForwards($maxNestedForwards) + public function setMaxNestedForwards(integer $maxNestedForwards) { - $this->maxNestedForwards = (int) $maxNestedForwards; + $this->maxNestedForwards = $maxNestedForwards; return $this; } diff --git a/src/Controller/Plugin/Layout.php b/src/Controller/Plugin/Layout.php index b5c50ed79..7171ba66c 100644 --- a/src/Controller/Plugin/Layout.php +++ b/src/Controller/Plugin/Layout.php @@ -27,10 +27,10 @@ class Layout extends AbstractPlugin * @param string $template * @return Layout */ - public function setTemplate($template) + public function setTemplate(string $template) { $viewModel = $this->getViewModel(); - $viewModel->setTemplate((string) $template); + $viewModel->setTemplate($template); return $this; } diff --git a/src/Controller/Plugin/Url.php b/src/Controller/Plugin/Url.php index a781aa8e1..ad68005d0 100644 --- a/src/Controller/Plugin/Url.php +++ b/src/Controller/Plugin/Url.php @@ -70,6 +70,8 @@ public function fromRoute($route = null, $params = [], $options = [], $reuseMatc if (3 == func_num_args() && is_bool($options)) { $reuseMatchedParams = $options; $options = []; + } elseif (\is_bool($options)) { + $options = []; } if ($route === null) { @@ -77,6 +79,9 @@ public function fromRoute($route = null, $params = [], $options = [], $reuseMatc throw new Exception\RuntimeException('No RouteMatch instance present'); } + /** + * @var string|null + */ $route = $matches->getMatchedRouteName(); if ($route === null) { diff --git a/src/DispatchListener.php b/src/DispatchListener.php index 37a9d1160..c0d2df72b 100644 --- a/src/DispatchListener.php +++ b/src/DispatchListener.php @@ -89,10 +89,11 @@ public function onDispatch(MvcEvent $e) $controllerManager = $this->controllerManager; + $return = null; // Query abstract controllers, too! if (! $controllerManager->has($controllerName)) { $return = $this->marshalControllerNotFoundEvent( - $application::ERROR_CONTROLLER_NOT_FOUND, + Application::ERROR_CONTROLLER_NOT_FOUND, $controllerName, $e, $application @@ -104,7 +105,7 @@ public function onDispatch(MvcEvent $e) $controller = $controllerManager->get($controllerName); } catch (Exception\InvalidControllerException $exception) { $return = $this->marshalControllerNotFoundEvent( - $application::ERROR_CONTROLLER_INVALID, + Application::ERROR_CONTROLLER_INVALID, $controllerName, $e, $application, @@ -113,7 +114,7 @@ public function onDispatch(MvcEvent $e) return $this->complete($return, $e); } catch (InvalidServiceException $exception) { $return = $this->marshalControllerNotFoundEvent( - $application::ERROR_CONTROLLER_INVALID, + Application::ERROR_CONTROLLER_INVALID, $controllerName, $e, $application, @@ -146,7 +147,7 @@ public function onDispatch(MvcEvent $e) if ($caughtException !== null) { $e->setName(MvcEvent::EVENT_DISPATCH_ERROR); - $e->setError($application::ERROR_EXCEPTION); + $e->setError(Application::ERROR_EXCEPTION); $e->setController($controllerName); $e->setControllerClass(get_class($controller)); $e->setParam('exception', $caughtException); @@ -202,7 +203,7 @@ protected function complete($return, MvcEvent $event) * @param string $type * @param string $controllerName * @param MvcEvent $event - * @param Application $application + * @param ApplicationInterface $application * @param \Throwable|\Exception $exception * @return mixed */ @@ -210,7 +211,7 @@ protected function marshalControllerNotFoundEvent( $type, $controllerName, MvcEvent $event, - Application $application, + ApplicationInterface $application, $exception = null ) { $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); @@ -235,18 +236,18 @@ protected function marshalControllerNotFoundEvent( * * @param string $controllerName * @param MvcEvent $event - * @param Application $application + * @param ApplicationInterface $application * @param \Throwable|\Exception $exception * @return mixed */ protected function marshalBadControllerEvent( $controllerName, MvcEvent $event, - Application $application, + ApplicationInterface $application, $exception ) { $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); - $event->setError($application::ERROR_EXCEPTION); + $event->setError(Application::ERROR_EXCEPTION); $event->setController($controllerName); $event->setParam('exception', $exception); diff --git a/src/Exception/InvalidMiddlewareException.php b/src/Exception/InvalidMiddlewareException.php index 5cdbc1d33..f76f9493c 100644 --- a/src/Exception/InvalidMiddlewareException.php +++ b/src/Exception/InvalidMiddlewareException.php @@ -20,9 +20,8 @@ final class InvalidMiddlewareException extends RuntimeException * @param string $middlewareName * @return self */ - public static function fromMiddlewareName($middlewareName) + public static function fromMiddlewareName(string $middlewareName) { - $middlewareName = (string)$middlewareName; $instance = new self(sprintf('Cannot dispatch middleware %s', $middlewareName)); $instance->middlewareName = $middlewareName; return $instance; diff --git a/src/HttpMethodListener.php b/src/HttpMethodListener.php index 20a51d4a2..917d65d25 100644 --- a/src/HttpMethodListener.php +++ b/src/HttpMethodListener.php @@ -39,7 +39,7 @@ class HttpMethodListener extends AbstractListenerAggregate /** * @param bool $enabled - * @param array $allowedMethods + * @param null|array $allowedMethods */ public function __construct($enabled = true, $allowedMethods = []) { @@ -68,7 +68,7 @@ public function attach(EventManagerInterface $events, $priority = 1) /** * @param MvcEvent $e - * @return void|HttpResponse + * @return null|HttpResponse */ public function onRoute(MvcEvent $e) { @@ -76,13 +76,13 @@ public function onRoute(MvcEvent $e) $response = $e->getResponse(); if (! $request instanceof HttpRequest || ! $response instanceof HttpResponse) { - return; + return null; } $method = $request->getMethod(); if (in_array($method, $this->getAllowedMethods())) { - return; + return null; } $response->setStatusCode(405); @@ -120,8 +120,8 @@ public function isEnabled() /** * @param bool $enabled */ - public function setEnabled($enabled) + public function setEnabled(bool $enabled) { - $this->enabled = (bool) $enabled; + $this->enabled = $enabled; } } diff --git a/src/MiddlewareListener.php b/src/MiddlewareListener.php index d99a63331..146437baa 100644 --- a/src/MiddlewareListener.php +++ b/src/MiddlewareListener.php @@ -50,6 +50,9 @@ public function onDispatch(MvcEvent $event) } $routeMatch = $event->getRouteMatch(); + if (! $routeMatch) { + return; + } $middleware = $routeMatch->getParam('middleware', false); if (false === $middleware) { return; @@ -57,6 +60,9 @@ public function onDispatch(MvcEvent $event) $request = $event->getRequest(); $application = $event->getApplication(); + /* + * @var $response \Zend\Http\Response + */ $response = $application->getResponse(); $serviceManager = $application->getServiceManager(); @@ -70,7 +76,7 @@ public function onDispatch(MvcEvent $event) ); } catch (InvalidMiddlewareException $invalidMiddlewareException) { $return = $this->marshalInvalidMiddleware( - $application::ERROR_MIDDLEWARE_CANNOT_DISPATCH, + Application::ERROR_MIDDLEWARE_CANNOT_DISPATCH, $invalidMiddlewareException->toMiddlewareName(), $event, $application, @@ -81,6 +87,7 @@ public function onDispatch(MvcEvent $event) } $caughtException = null; + $return = null; try { $return = (new MiddlewareController( $pipe, @@ -96,7 +103,7 @@ public function onDispatch(MvcEvent $event) if ($caughtException !== null) { $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); - $event->setError($application::ERROR_EXCEPTION); + $event->setError(Application::ERROR_EXCEPTION); $event->setParam('exception', $caughtException); $events = $application->getEventManager(); @@ -159,7 +166,7 @@ private function createPipeFromSpec( * @param string $type * @param string $middlewareName * @param MvcEvent $event - * @param Application $application + * @param ApplicationInterface $application * @param \Exception $exception * @return mixed */ @@ -167,7 +174,7 @@ protected function marshalInvalidMiddleware( $type, $middlewareName, MvcEvent $event, - Application $application, + ApplicationInterface $application, \Exception $exception = null ) { $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); diff --git a/src/ModuleRouteListener.php b/src/ModuleRouteListener.php index 5fd63f265..c13ea714c 100644 --- a/src/ModuleRouteListener.php +++ b/src/ModuleRouteListener.php @@ -38,7 +38,7 @@ public function attach(EventManagerInterface $events, $priority = 1) * the matched controller parameter. * * @param MvcEvent $e - * @return null + * @return void */ public function onRoute(MvcEvent $e) { diff --git a/src/MvcEvent.php b/src/MvcEvent.php index ad17a129c..b48d8d521 100644 --- a/src/MvcEvent.php +++ b/src/MvcEvent.php @@ -195,7 +195,7 @@ public function setViewModel(Model $viewModel) * * @return Model */ - public function getViewModel() + public function getViewModel() : Model { if (null === $this->viewModel) { $this->setViewModel(new ViewModel()); diff --git a/src/ResponseSender/HttpResponseSender.php b/src/ResponseSender/HttpResponseSender.php index 062c9532c..9a797f852 100644 --- a/src/ResponseSender/HttpResponseSender.php +++ b/src/ResponseSender/HttpResponseSender.php @@ -43,8 +43,8 @@ public function __invoke(SendResponseEvent $event) return $this; } - $this->sendHeaders($event) - ->sendContent($event); + $this->sendHeaders($event); + $this->sendContent($event); $event->stopPropagation(true); return $this; } diff --git a/src/ResponseSender/PhpEnvironmentResponseSender.php b/src/ResponseSender/PhpEnvironmentResponseSender.php index e293e09f8..69f55340b 100644 --- a/src/ResponseSender/PhpEnvironmentResponseSender.php +++ b/src/ResponseSender/PhpEnvironmentResponseSender.php @@ -26,8 +26,8 @@ public function __invoke(SendResponseEvent $event) return $this; } - $this->sendHeaders($event) - ->sendContent($event); + $this->sendHeaders($event); + $this->sendContent($event); $event->stopPropagation(true); return $this; } diff --git a/src/ResponseSender/SimpleStreamResponseSender.php b/src/ResponseSender/SimpleStreamResponseSender.php index 4b7d3409b..76bff6274 100644 --- a/src/ResponseSender/SimpleStreamResponseSender.php +++ b/src/ResponseSender/SimpleStreamResponseSender.php @@ -10,6 +10,7 @@ namespace Zend\Mvc\ResponseSender; use Zend\Http\Response\Stream; +use Zend\Mvc\Exception\DomainException; class SimpleStreamResponseSender extends AbstractResponseSender { @@ -25,6 +26,9 @@ public function sendStream(SendResponseEvent $event) return $this; } $response = $event->getResponse(); + if (! $response instanceof Stream) { + throw new DomainException('Attempting to send stream of non-stream response'); + } $stream = $response->getStream(); fpassthru($stream); $event->setContentSent(); diff --git a/src/RouteListener.php b/src/RouteListener.php index 2e85ec36c..1f0ffbfb8 100644 --- a/src/RouteListener.php +++ b/src/RouteListener.php @@ -36,7 +36,7 @@ public function attach(EventManagerInterface $events, $priority = 1) * Seeds the event with the route match on completion. * * @param MvcEvent $event - * @return null|RouteMatch + * @return null|RouteMatch|mixed */ public function onRoute(MvcEvent $event) { diff --git a/src/SendResponseListener.php b/src/SendResponseListener.php index 95687b491..eaa5faf12 100644 --- a/src/SendResponseListener.php +++ b/src/SendResponseListener.php @@ -111,7 +111,7 @@ public function getEvent() * Set the send response event * * @param SendResponseEvent $e - * @return SendResponseEvent + * @return SendResponseListener */ public function setEvent(SendResponseEvent $e) { diff --git a/src/View/Http/DefaultRenderingStrategy.php b/src/View/Http/DefaultRenderingStrategy.php index 6d13c1b07..0268abe1f 100644 --- a/src/View/Http/DefaultRenderingStrategy.php +++ b/src/View/Http/DefaultRenderingStrategy.php @@ -57,9 +57,9 @@ public function attach(EventManagerInterface $events, $priority = 1) * @param string $layoutTemplate * @return DefaultRenderingStrategy */ - public function setLayoutTemplate($layoutTemplate) + public function setLayoutTemplate(string $layoutTemplate) { - $this->layoutTemplate = (string) $layoutTemplate; + $this->layoutTemplate = $layoutTemplate; return $this; } @@ -92,7 +92,7 @@ public function render(MvcEvent $e) $response = $e->getResponse(); $viewModel = $e->getViewModel(); if (! $viewModel instanceof ViewModel) { - return; + return null; } $view = $this->view; diff --git a/src/View/Http/ExceptionStrategy.php b/src/View/Http/ExceptionStrategy.php index 592493ade..d420670a7 100644 --- a/src/View/Http/ExceptionStrategy.php +++ b/src/View/Http/ExceptionStrategy.php @@ -46,9 +46,9 @@ public function attach(EventManagerInterface $events, $priority = 1) * @param bool $displayExceptions * @return ExceptionStrategy */ - public function setDisplayExceptions($displayExceptions) + public function setDisplayExceptions(bool $displayExceptions) { - $this->displayExceptions = (bool) $displayExceptions; + $this->displayExceptions = $displayExceptions; return $this; } @@ -68,9 +68,9 @@ public function displayExceptions() * @param string $exceptionTemplate * @return ExceptionStrategy */ - public function setExceptionTemplate($exceptionTemplate) + public function setExceptionTemplate(string $exceptionTemplate) { - $this->exceptionTemplate = (string) $exceptionTemplate; + $this->exceptionTemplate = $exceptionTemplate; return $this; } diff --git a/src/View/Http/InjectRoutematchParamsListener.php b/src/View/Http/InjectRoutematchParamsListener.php index 2eb85b7b4..bc641d6f1 100644 --- a/src/View/Http/InjectRoutematchParamsListener.php +++ b/src/View/Http/InjectRoutematchParamsListener.php @@ -14,6 +14,7 @@ use Zend\Http\Request as HttpRequest; use Zend\Mvc\MvcEvent; +// @TODO looks like this is obsolete unused piece of code. Make sure it is so and remove it class InjectRoutematchParamsListener extends AbstractListenerAggregate { /** @@ -39,7 +40,11 @@ public function attach(EventManagerInterface $events, $priority = 1) */ public function injectParams(MvcEvent $e) { - $routeMatchParams = $e->getRouteMatch()->getParams(); + $routeMatch = $e->getRouteMatch(); + $routeMatchParams = $routeMatch ? $routeMatch->getParams() : []; + /** + * @var HttpRequest + */ $request = $e->getRequest(); if (! $request instanceof HttpRequest) { @@ -47,7 +52,8 @@ public function injectParams(MvcEvent $e) return; } - $params = $request->get(); + // @TODO get() does not exist on Http\Request, was it meant to be getQuery()? + $params = $request->getQuery(); if ($this->overwrite) { // Overwrite existing parameters, or create new ones if not present. diff --git a/src/View/Http/InjectTemplateListener.php b/src/View/Http/InjectTemplateListener.php index 01b13a9a6..e6f62ca54 100644 --- a/src/View/Http/InjectTemplateListener.php +++ b/src/View/Http/InjectTemplateListener.php @@ -12,6 +12,7 @@ use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface as Events; use Zend\Mvc\MvcEvent; +use Zend\Router\RouteMatch; use Zend\Stdlib\StringUtils; use Zend\View\Model\ModelInterface as ViewModel; @@ -60,6 +61,9 @@ public function injectTemplate(MvcEvent $e) return; } + /** + * @var RouteMatch + */ $routeMatch = $e->getRouteMatch(); if ($preferRouteMatchController = $routeMatch->getParam('prefer_route_match_controller', false)) { $this->setPreferRouteMatchController($preferRouteMatchController); @@ -101,7 +105,7 @@ public function setControllerMap(array $map) * Maps controller to template if controller namespace is whitelisted or mapped * * @param string $controller controller FQCN - * @return string|false template name or false if controller was not matched + * @return string template name */ public function mapController($controller) { @@ -189,9 +193,9 @@ protected function deriveControllerClass($controller) * * @param boolean $preferRouteMatchController */ - public function setPreferRouteMatchController($preferRouteMatchController) + public function setPreferRouteMatchController(bool $preferRouteMatchController) { - $this->preferRouteMatchController = (bool) $preferRouteMatchController; + $this->preferRouteMatchController = $preferRouteMatchController; } /** diff --git a/src/View/Http/RouteNotFoundStrategy.php b/src/View/Http/RouteNotFoundStrategy.php index 2c9790142..df63c3a90 100644 --- a/src/View/Http/RouteNotFoundStrategy.php +++ b/src/View/Http/RouteNotFoundStrategy.php @@ -63,9 +63,9 @@ public function attach(EventManagerInterface $events, $priority = 1) * @param bool $displayExceptions * @return RouteNotFoundStrategy */ - public function setDisplayExceptions($displayExceptions) + public function setDisplayExceptions(bool $displayExceptions) { - $this->displayExceptions = (bool) $displayExceptions; + $this->displayExceptions = $displayExceptions; return $this; } @@ -85,9 +85,9 @@ public function displayExceptions() * @param bool $displayNotFoundReason * @return RouteNotFoundStrategy */ - public function setDisplayNotFoundReason($displayNotFoundReason) + public function setDisplayNotFoundReason(bool $displayNotFoundReason) { - $this->displayNotFoundReason = (bool) $displayNotFoundReason; + $this->displayNotFoundReason = $displayNotFoundReason; return $this; } @@ -107,9 +107,9 @@ public function displayNotFoundReason() * @param string $notFoundTemplate * @return RouteNotFoundStrategy */ - public function setNotFoundTemplate($notFoundTemplate) + public function setNotFoundTemplate(string $notFoundTemplate) { - $this->notFoundTemplate = (string) $notFoundTemplate; + $this->notFoundTemplate = $notFoundTemplate; return $this; } diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index b59c1d6d4..2d8586683 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -148,7 +148,7 @@ public function testConfigIsPopulated() $this->assertEquals( $smConfig, $appConfig, - sprintf('SM config: %s; App config: %s', var_export($smConfig, 1), var_export($appConfig, 1)) + sprintf('SM config: %s; App config: %s', var_export($smConfig, true), var_export($appConfig, true)) ); } diff --git a/test/Controller/ActionControllerTest.php b/test/Controller/ActionControllerTest.php index 916e0f73c..8faa183b9 100644 --- a/test/Controller/ActionControllerTest.php +++ b/test/Controller/ActionControllerTest.php @@ -67,7 +67,7 @@ public function testDispatchInvokesNotFoundActionWhenNoActionPresentInRouteMatch $this->assertInstanceOf(ModelInterface::class, $result); $this->assertEquals('content', $result->captureTo()); $vars = $result->getVariables(); - $this->assertArrayHasKey('content', $vars, var_export($vars, 1)); + $this->assertArrayHasKey('content', $vars, var_export($vars, true)); $this->assertContains('Page not found', $vars['content']); } @@ -80,7 +80,7 @@ public function testDispatchInvokesNotFoundActionWhenInvalidActionPresentInRoute $this->assertInstanceOf(ModelInterface::class, $result); $this->assertEquals('content', $result->captureTo()); $vars = $result->getVariables(); - $this->assertArrayHasKey('content', $vars, var_export($vars, 1)); + $this->assertArrayHasKey('content', $vars, var_export($vars, true)); $this->assertContains('Page not found', $vars['content']); } diff --git a/test/DispatchListenerTest.php b/test/DispatchListenerTest.php index 92989ccbd..ed576d415 100644 --- a/test/DispatchListenerTest.php +++ b/test/DispatchListenerTest.php @@ -61,7 +61,7 @@ public function testControllerManagerUsingAbstractFactory() $return = $listener->onDispatch($event); - $this->assertEmpty($log, var_export($log, 1)); + $this->assertEmpty($log, var_export($log, true)); $this->assertSame($event->getResponse(), $return); $this->assertSame(200, $return->getStatusCode()); } From 9ae938bd5498c90b0d0fada1de369a7bc5c7741a Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Tue, 10 Oct 2017 16:53:30 +1000 Subject: [PATCH 07/51] Update composer deps --- composer.json | 10 +- composer.lock | 324 +++++++++++++++++++++++++++++--------------------- 2 files changed, 196 insertions(+), 138 deletions(-) diff --git a/composer.json b/composer.json index e961576f8..a07c55296 100644 --- a/composer.json +++ b/composer.json @@ -18,21 +18,25 @@ "require": { "php": "^7.1", "container-interop/container-interop": "^1.2", + "fig/http-message-util": "^1.1", + "psr/container": "^1.0", + "psr/http-message": "^1.0", + "zendframework/zend-diactoros": "^1.7", "zendframework/zend-eventmanager": "^3.2", "zendframework/zend-http": "^2.7", "zendframework/zend-modulemanager": "^2.8", "zendframework/zend-router": "^3.0.2", "zendframework/zend-servicemanager": "^3.3", "zendframework/zend-stdlib": "^3.1", - "zendframework/zend-view": "^2.9" + "zendframework/zend-view": "^2.10" }, "require-dev": { - "http-interop/http-middleware": "^0.4.1", "phpunit/phpunit": "^7.0", "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-json": "^3.0", "zendframework/zend-psr7bridge": "^1.0", - "zendframework/zend-stratigility": "^2.0.1" + "zendframework/zend-stratigility": "^2.0.1", + "zendframework/zend-validator": "^2.10" }, "suggest": { "zendframework/zend-json": "(^2.6.1 || ^3.0) To auto-deserialize JSON body content in AbstractRestfulController extensions, when json_decode is unavailable", diff --git a/composer.lock b/composer.lock index 881f41b57..c92385f98 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "fb6ba17cab04ae71783b41718f15f852", + "content-hash": "fdae8765e3fb8d69455f4ff7ad75673d", "packages": [ { "name": "container-interop/container-interop", @@ -37,6 +37,56 @@ "homepage": "https://github.com/container-interop/container-interop", "time": "2017-02-14T19:40:03+00:00" }, + { + "name": "fig/http-message-util", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message-util.git", + "reference": "20b2c280cb6914b7b83089720df44e490f4b42f0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message-util/zipball/20b2c280cb6914b7b83089720df44e490f4b42f0", + "reference": "20b2c280cb6914b7b83089720df44e490f4b42f0", + "shasum": "" + }, + "require": { + "php": "^5.3 || ^7.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Fig\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Utility classes and constants for use with PSR-7 (psr/http-message)", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2017-02-09T16:10:21+00:00" + }, { "name": "psr/container", "version": "1.0.0", @@ -86,6 +136,56 @@ ], "time": "2017-02-14T16:28:37+00:00" }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, { "name": "zendframework/zend-config", "version": "3.1.0", @@ -146,6 +246,58 @@ ], "time": "2017-02-22T14:31:10+00:00" }, + { + "name": "zendframework/zend-diactoros", + "version": "1.7.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-diactoros.git", + "reference": "ed6ce7e2105c400ca10277643a8327957c0384b7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/ed6ce7e2105c400ca10277643a8327957c0384b7", + "reference": "ed6ce7e2105c400ca10277643a8327957c0384b7", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0", + "psr/http-message": "^1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "ext-dom": "*", + "ext-libxml": "*", + "phpunit/phpunit": "^5.7.16 || ^6.0.8", + "zendframework/zend-coding-standard": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev", + "dev-develop": "1.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Diactoros\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "description": "PSR HTTP Message implementations", + "homepage": "https://github.com/zendframework/zend-diactoros", + "keywords": [ + "http", + "psr", + "psr-7" + ], + "time": "2018-01-04T18:21:48+00:00" + }, { "name": "zendframework/zend-escaper", "version": "2.5.2", @@ -464,16 +616,16 @@ }, { "name": "zendframework/zend-servicemanager", - "version": "3.3.1", + "version": "3.3.2", "source": { "type": "git", "url": "https://github.com/zendframework/zend-servicemanager.git", - "reference": "0fa3d3cf588dde0850fff1efa60d44a7aa3c3ab7" + "reference": "9f35a104b8d4d3b32da5f4a3b6efc0dd62e5af42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-servicemanager/zipball/0fa3d3cf588dde0850fff1efa60d44a7aa3c3ab7", - "reference": "0fa3d3cf588dde0850fff1efa60d44a7aa3c3ab7", + "url": "https://api.github.com/repos/zendframework/zend-servicemanager/zipball/9f35a104b8d4d3b32da5f4a3b6efc0dd62e5af42", + "reference": "9f35a104b8d4d3b32da5f4a3b6efc0dd62e5af42", "shasum": "" }, "require": { @@ -487,10 +639,10 @@ "psr/container-implementation": "^1.0" }, "require-dev": { - "mikey179/vfsstream": "^1.6", + "mikey179/vfsstream": "^1.6.5", "ocramius/proxy-manager": "^1.0 || ^2.0", - "phpbench/phpbench": "^0.10.0", - "phpunit/phpunit": "^5.7 || ^6.0.6", + "phpbench/phpbench": "^0.13.0", + "phpunit/phpunit": "^5.7.25 || ^6.4.4", "zendframework/zend-coding-standard": "~1.0.0" }, "suggest": { @@ -517,13 +669,18 @@ "license": [ "BSD-3-Clause" ], - "homepage": "https://github.com/zendframework/zend-servicemanager", + "description": "Factory-Driven Dependency Injection Container", "keywords": [ + "PSR-11", + "ZendFramework", + "dependency-injection", + "di", + "dic", "service-manager", "servicemanager", "zf" ], - "time": "2017-11-27T18:11:25+00:00" + "time": "2018-01-29T16:48:37+00:00" }, { "name": "zendframework/zend-stdlib", @@ -619,16 +776,16 @@ }, { "name": "zendframework/zend-validator", - "version": "2.10.1", + "version": "2.10.2", "source": { "type": "git", "url": "https://github.com/zendframework/zend-validator.git", - "reference": "010084ddbd33299bf51ea6f0e07f8f4e8bd832a8" + "reference": "38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-validator/zipball/010084ddbd33299bf51ea6f0e07f8f4e8bd832a8", - "reference": "010084ddbd33299bf51ea6f0e07f8f4e8bd832a8", + "url": "https://api.github.com/repos/zendframework/zend-validator/zipball/38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9", + "reference": "38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9", "shasum": "" }, "require": { @@ -663,8 +820,8 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.10-dev", - "dev-develop": "2.11-dev" + "dev-master": "2.10.x-dev", + "dev-develop": "2.11.x-dev" }, "zf": { "component": "Zend\\Validator", @@ -686,20 +843,20 @@ "validator", "zf2" ], - "time": "2017-08-22T14:19:23+00:00" + "time": "2018-02-01T17:05:33+00:00" }, { "name": "zendframework/zend-view", - "version": "2.9.0", + "version": "2.10.0", "source": { "type": "git", "url": "https://github.com/zendframework/zend-view.git", - "reference": "3b6342c381c4437a03fc81d0064c0bb8924914d3" + "reference": "4478cc5dd960e2339d88b363ef99fa278700e80e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-view/zipball/3b6342c381c4437a03fc81d0064c0bb8924914d3", - "reference": "3b6342c381c4437a03fc81d0064c0bb8924914d3", + "url": "https://api.github.com/repos/zendframework/zend-view/zipball/4478cc5dd960e2339d88b363ef99fa278700e80e", + "reference": "4478cc5dd960e2339d88b363ef99fa278700e80e", "shasum": "" }, "require": { @@ -730,7 +887,7 @@ "zendframework/zend-router": "^3.0.1", "zendframework/zend-serializer": "^2.6.1", "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", - "zendframework/zend-session": "^2.6.2", + "zendframework/zend-session": "^2.8.1", "zendframework/zend-uri": "^2.5" }, "suggest": { @@ -754,8 +911,8 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.9-dev", - "dev-develop": "3.0-dev" + "dev-master": "2.10.x-dev", + "dev-develop": "2.11.x-dev" } }, "autoload": { @@ -773,7 +930,7 @@ "view", "zf2" ], - "time": "2017-03-21T15:05:56+00:00" + "time": "2018-01-17T22:21:50+00:00" } ], "packages-dev": [ @@ -833,16 +990,16 @@ }, { "name": "http-interop/http-middleware", - "version": "0.4.1", + "version": "0.5.0", "source": { "type": "git", "url": "https://github.com/http-interop/http-middleware.git", - "reference": "9a801fe60e70d5d608b61d56b2dcde29516c81b9" + "reference": "b49e1f9f6c584e704317b563302e566b8ce11858" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/http-interop/http-middleware/zipball/9a801fe60e70d5d608b61d56b2dcde29516c81b9", - "reference": "9a801fe60e70d5d608b61d56b2dcde29516c81b9", + "url": "https://api.github.com/repos/http-interop/http-middleware/zipball/b49e1f9f6c584e704317b563302e566b8ce11858", + "reference": "b49e1f9f6c584e704317b563302e566b8ce11858", "shasum": "" }, "require": { @@ -857,7 +1014,7 @@ }, "autoload": { "psr-4": { - "Interop\\Http\\ServerMiddleware\\": "src/" + "Interop\\Http\\Server\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -872,17 +1029,16 @@ ], "description": "Common interface for HTTP server-side middleware", "keywords": [ - "factory", "http", "middleware", "psr", - "psr-17", + "psr-15", "psr-7", "request", "response" ], "abandoned": "http-interop/http-server-middleware", - "time": "2017-01-14T15:23:42+00:00" + "time": "2017-09-18T15:27:03+00:00" }, { "name": "myclabs/deep-copy", @@ -1631,56 +1787,6 @@ ], "time": "2018-02-01T13:11:13+00:00" }, - { - "name": "psr/http-message", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "time": "2016-08-06T14:39:51+00:00" - }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.1", @@ -2534,58 +2640,6 @@ ], "time": "2016-11-09T21:30:43+00:00" }, - { - "name": "zendframework/zend-diactoros", - "version": "1.7.0", - "source": { - "type": "git", - "url": "https://github.com/zendframework/zend-diactoros.git", - "reference": "ed6ce7e2105c400ca10277643a8327957c0384b7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/ed6ce7e2105c400ca10277643a8327957c0384b7", - "reference": "ed6ce7e2105c400ca10277643a8327957c0384b7", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0", - "psr/http-message": "^1.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "ext-dom": "*", - "ext-libxml": "*", - "phpunit/phpunit": "^5.7.16 || ^6.0.8", - "zendframework/zend-coding-standard": "~1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.7.x-dev", - "dev-develop": "1.8.x-dev" - } - }, - "autoload": { - "psr-4": { - "Zend\\Diactoros\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "description": "PSR HTTP Message implementations", - "homepage": "https://github.com/zendframework/zend-diactoros", - "keywords": [ - "http", - "psr", - "psr-7" - ], - "time": "2018-01-04T18:21:48+00:00" - }, { "name": "zendframework/zend-json", "version": "3.1.0", From a5159fd429af9833aa7f7c0a50fd4c0fe391f156 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 15 Oct 2017 22:24:12 +1000 Subject: [PATCH 08/51] Remove on rebase. Point zend-router to modified fork --- composer.json | 8 +++++- composer.lock | 80 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index a07c55296..5be044471 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,12 @@ "slack": "https://zendframework-slack.herokuapp.com", "forum": "https://discourse.zendframework.com/c/questions/components" }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/Xerkus/zend-router.git" + } + ], "require": { "php": "^7.1", "container-interop/container-interop": "^1.2", @@ -25,7 +31,7 @@ "zendframework/zend-eventmanager": "^3.2", "zendframework/zend-http": "^2.7", "zendframework/zend-modulemanager": "^2.8", - "zendframework/zend-router": "^3.0.2", + "zendframework/zend-router": "dev-make-mvc-great-again", "zendframework/zend-servicemanager": "^3.3", "zendframework/zend-stdlib": "^3.1", "zendframework/zend-view": "^2.10" diff --git a/composer.lock b/composer.lock index c92385f98..ea9467b25 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "fdae8765e3fb8d69455f4ff7ad75673d", + "content-hash": "2c0a9cecf2cb5155030304cd2cea832d", "packages": [ { "name": "container-interop/container-interop", @@ -555,36 +555,33 @@ }, { "name": "zendframework/zend-router", - "version": "3.0.2", + "version": "dev-make-mvc-great-again", "source": { "type": "git", - "url": "https://github.com/zendframework/zend-router.git", - "reference": "03763610632a9022aff22a0e8f340852e68392a1" + "url": "https://github.com/Xerkus/zend-router.git", + "reference": "b0dea47dc05ebae7217246b6b81f006bdd1aa009" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-router/zipball/03763610632a9022aff22a0e8f340852e68392a1", - "reference": "03763610632a9022aff22a0e8f340852e68392a1", + "url": "https://api.github.com/repos/Xerkus/zend-router/zipball/b0dea47dc05ebae7217246b6b81f006bdd1aa009", + "reference": "b0dea47dc05ebae7217246b6b81f006bdd1aa009", "shasum": "" }, "require": { - "container-interop/container-interop": "^1.1", - "php": "^5.5 || ^7.0", - "zendframework/zend-http": "^2.5", - "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", - "zendframework/zend-stdlib": "^2.7.5 || ^3.0" - }, - "conflict": { - "zendframework/zend-mvc": "<3.0.0" + "container-interop/container-interop": "^1.2", + "php": "^7.1", + "psr/http-message": "^1.0", + "zendframework/zend-diactoros": "^1.7", + "zendframework/zend-servicemanager": "^3.3", + "zendframework/zend-stdlib": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^4.5", - "sebastian/version": "^1.0.4", - "squizlabs/php_codesniffer": "^2.3", - "zendframework/zend-i18n": "^2.6" + "phpunit/phpunit": "^7.0", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-i18n": "^2.7.4" }, "suggest": { - "zendframework/zend-i18n": "^2.6, if defining translatable HTTP path segments" + "zendframework/zend-i18n": "^2.7.4, if defining translatable HTTP path segments" }, "type": "library", "extra": { @@ -602,17 +599,48 @@ "Zend\\Router\\": "src/" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "ZendTest\\Router\\": "test/" + } + }, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": [ + "phpcs" + ], + "cs-fix": [ + "phpcbf" + ], + "test": [ + "phpunit --colors=always" + ], + "test-coverage": [ + "phpunit --colors=always --coverage-clover clover.xml" + ] + }, "license": [ "BSD-3-Clause" ], - "homepage": "https://github.com/zendframework/zend-router", + "description": "Flexible routing system for HTTP and console applications", "keywords": [ - "mvc", "routing", - "zf2" + "zend", + "zendframework", + "zf" ], - "time": "2016-05-31T20:47:48+00:00" + "support": { + "docs": "https://docs.zendframework.com/zend-router/", + "issues": "https://github.com/zendframework/zend-router/issues", + "source": "https://github.com/zendframework/zend-router", + "rss": "https://github.com/zendframework/zend-router/releases.atom", + "slack": "https://zendframework-slack.herokuapp.com", + "forum": "https://discourse.zendframework.com/c/questions/components" + }, + "time": "2018-02-03T06:17:22+00:00" }, { "name": "zendframework/zend-servicemanager", @@ -2798,7 +2826,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "zendframework/zend-router": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { From 7d7c395cde7cbb9a62b9d9dd18d570635a97d8a3 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 15 Oct 2017 22:02:53 +1000 Subject: [PATCH 09/51] Drop module route listener --- src/ModuleRouteListener.php | 76 ----------------- test/ModuleRouteListenerTest.php | 139 ------------------------------- 2 files changed, 215 deletions(-) delete mode 100644 src/ModuleRouteListener.php delete mode 100644 test/ModuleRouteListenerTest.php diff --git a/src/ModuleRouteListener.php b/src/ModuleRouteListener.php deleted file mode 100644 index c13ea714c..000000000 --- a/src/ModuleRouteListener.php +++ /dev/null @@ -1,76 +0,0 @@ -listeners[] = $events->attach(MvcEvent::EVENT_ROUTE, [$this, 'onRoute'], $priority); - } - - /** - * Listen to the "route" event and determine if the module namespace should - * be prepended to the controller name. - * - * If the route match contains a parameter key matching the MODULE_NAMESPACE - * constant, that value will be prepended, with a namespace separator, to - * the matched controller parameter. - * - * @param MvcEvent $e - * @return void - */ - public function onRoute(MvcEvent $e) - { - $matches = $e->getRouteMatch(); - if (! $matches instanceof RouteMatch) { - // Can't do anything without a route match - return; - } - - $module = $matches->getParam(self::MODULE_NAMESPACE, false); - if (! $module) { - // No module namespace found; nothing to do - return; - } - - $controller = $matches->getParam('controller', false); - if (! $controller) { - // no controller matched, nothing to do - return; - } - - // Ensure the module namespace has not already been applied - if (0 === strpos($controller, $module)) { - return; - } - - // Keep the originally matched controller name around - $matches->setParam(self::ORIGINAL_CONTROLLER, $controller); - - // Prepend the controllername with the module, and replace it in the - // matches - $controller = $module . '\\' . str_replace(' ', '', ucwords(str_replace('-', ' ', $controller))); - $matches->setParam('controller', $controller); - } -} diff --git a/test/ModuleRouteListenerTest.php b/test/ModuleRouteListenerTest.php deleted file mode 100644 index aa9d5e2cc..000000000 --- a/test/ModuleRouteListenerTest.php +++ /dev/null @@ -1,139 +0,0 @@ -request = new Request(); - $this->events = new EventManager(); - $this->router = new Router\Http\TreeRouteStack(); - $this->routeListener = new RouteListener(); - $this->moduleRouteListener = new ModuleRouteListener(); - - $this->routeListener->attach($this->events); - $this->moduleRouteListener->attach($this->events, -1); - } - - public function testRouteReturningModuleNamespaceInRouteMatchTriggersControllerRename() - { - $this->router->addRoute('foo', [ - 'type' => 'Literal', - 'options' => [ - 'route' => '/foo', - 'defaults' => [ - ModuleRouteListener::MODULE_NAMESPACE => 'Foo', - 'controller' => 'Index', - ], - ], - ]); - $this->request->setUri('/foo'); - $event = new MvcEvent(); - $event->setName('route'); - $event->setRouter($this->router); - $event->setRequest($this->request); - $this->events->triggerEvent($event); - - $matches = $event->getRouteMatch(); - $this->assertInstanceOf(RouteMatch::class, $matches); - $this->assertEquals('Foo\Index', $matches->getParam('controller')); - $this->assertEquals('Index', $matches->getParam(ModuleRouteListener::ORIGINAL_CONTROLLER)); - } - - public function testRouteNotReturningModuleNamespaceInRouteMatchLeavesControllerUntouched() - { - $this->router->addRoute('foo', [ - 'type' => 'Literal', - 'options' => [ - 'route' => '/foo', - 'defaults' => [ - 'controller' => 'Index', - ], - ], - ]); - $this->request->setUri('/foo'); - $event = new MvcEvent(); - $event->setName('route'); - $event->setRouter($this->router); - $event->setRequest($this->request); - $this->events->triggerEvent($event); - - $matches = $event->getRouteMatch(); - $this->assertInstanceOf(RouteMatch::class, $matches); - $this->assertEquals('Index', $matches->getParam('controller')); - } - - public function testMultipleRegistrationShouldNotResultInMultiplePrefixingOfControllerName() - { - $moduleListener = new ModuleRouteListener(); - $moduleListener->attach($this->events); - - $this->router->addRoute('foo', [ - 'type' => 'Literal', - 'options' => [ - 'route' => '/foo', - 'defaults' => [ - ModuleRouteListener::MODULE_NAMESPACE => 'Foo', - 'controller' => 'Index', - ], - ], - ]); - $this->request->setUri('/foo'); - $event = new MvcEvent(); - $event->setName('route'); - $event->setRouter($this->router); - $event->setRequest($this->request); - $this->events->triggerEvent($event); - - $matches = $event->getRouteMatch(); - $this->assertInstanceOf(RouteMatch::class, $matches); - $this->assertEquals('Foo\Index', $matches->getParam('controller')); - $this->assertEquals('Index', $matches->getParam(ModuleRouteListener::ORIGINAL_CONTROLLER)); - } - - public function testRouteMatchIsTransformedToProperControllerClassName() - { - $moduleListener = new ModuleRouteListener(); - $moduleListener->attach($this->events); - - $this->router->addRoute('foo', [ - 'type' => 'Literal', - 'options' => [ - 'route' => '/foo', - 'defaults' => [ - ModuleRouteListener::MODULE_NAMESPACE => 'Foo', - 'controller' => 'some-index', - ], - ], - ]); - - $this->request->setUri('/foo'); - $event = new MvcEvent(); - $event->setName('route'); - $event->setRouter($this->router); - $event->setRequest($this->request); - $this->events->triggerEvent($event); - - $matches = $event->getRouteMatch(); - $this->assertInstanceOf(RouteMatch::class, $matches); - $this->assertEquals('Foo\SomeIndex', $matches->getParam('controller')); - $this->assertEquals('some-index', $matches->getParam(ModuleRouteListener::ORIGINAL_CONTROLLER)); - } -} From 0217272e8cf9d2ea4637d50f93d599d9c0e331ad Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Mon, 11 Sep 2017 13:47:04 +1000 Subject: [PATCH 10/51] Drop response sender in favor of diactoros emitter --- src/Application.php | 1 - src/Container/SendResponseListenerFactory.php | 27 ---- src/Emitter/EmitterStack.php | 107 +++++++++++++ src/ResponseSender/AbstractResponseSender.php | 44 ------ src/ResponseSender/HttpResponseSender.php | 51 ------- .../PhpEnvironmentResponseSender.php | 34 ----- .../ResponseSenderInterface.php | 21 --- src/ResponseSender/SendResponseEvent.php | 115 -------------- .../SimpleStreamResponseSender.php | 55 ------- src/SendResponseListener.php | 141 ------------------ .../SendResponseListenerFactoryTest.php | 57 ------- .../AbstractResponseSenderTest.php | 104 ------------- .../PhpEnvironmentResponseSenderTest.php | 69 --------- test/ResponseSender/SendResponseEventTest.php | 34 ----- .../SimpleStreamResponseSenderTest.php | 58 ------- .../TestAsset/sample-stream-file.txt | 10 -- test/SendResponseListenerTest.php | 48 ------ 17 files changed, 107 insertions(+), 869 deletions(-) delete mode 100644 src/Container/SendResponseListenerFactory.php create mode 100644 src/Emitter/EmitterStack.php delete mode 100644 src/ResponseSender/AbstractResponseSender.php delete mode 100644 src/ResponseSender/HttpResponseSender.php delete mode 100644 src/ResponseSender/PhpEnvironmentResponseSender.php delete mode 100644 src/ResponseSender/ResponseSenderInterface.php delete mode 100644 src/ResponseSender/SendResponseEvent.php delete mode 100644 src/ResponseSender/SimpleStreamResponseSender.php delete mode 100644 src/SendResponseListener.php delete mode 100644 test/Container/SendResponseListenerFactoryTest.php delete mode 100644 test/ResponseSender/AbstractResponseSenderTest.php delete mode 100644 test/ResponseSender/PhpEnvironmentResponseSenderTest.php delete mode 100644 test/ResponseSender/SendResponseEventTest.php delete mode 100644 test/ResponseSender/SimpleStreamResponseSenderTest.php delete mode 100644 test/ResponseSender/TestAsset/sample-stream-file.txt delete mode 100644 test/SendResponseListenerTest.php diff --git a/src/Application.php b/src/Application.php index c6d42e113..561bd585b 100644 --- a/src/Application.php +++ b/src/Application.php @@ -67,7 +67,6 @@ class Application implements 'DispatchListener', 'HttpMethodListener', 'ViewManager', - 'SendResponseListener', ]; /** diff --git a/src/Container/SendResponseListenerFactory.php b/src/Container/SendResponseListenerFactory.php deleted file mode 100644 index 0c9bcc3b9..000000000 --- a/src/Container/SendResponseListenerFactory.php +++ /dev/null @@ -1,27 +0,0 @@ -setEventManager($container->get('EventManager')); - return $listener; - } -} diff --git a/src/Emitter/EmitterStack.php b/src/Emitter/EmitterStack.php new file mode 100644 index 000000000..47e9c2e48 --- /dev/null +++ b/src/Emitter/EmitterStack.php @@ -0,0 +1,107 @@ +emit($response)) { + return null; + } + } + + return false; + } + + /** + * Set an emitter on the stack by index. + * + * @param mixed $index + * @param EmitterInterface $emitter + * @return void + * @throws InvalidArgumentException if not an EmitterInterface instance + */ + public function offsetSet($index, $emitter) + { + $this->validateEmitter($emitter); + parent::offsetSet($index, $emitter); + } + + /** + * Push an emitter to the stack. + * + * @param EmitterInterface $emitter + * @return void + * @throws InvalidArgumentException if not an EmitterInterface instance + */ + public function push($emitter) + { + $this->validateEmitter($emitter); + parent::push($emitter); + } + + /** + * Unshift an emitter to the stack. + * + * @param EmitterInterface $emitter + * @return void + * @throws InvalidArgumentException if not an EmitterInterface instance + */ + public function unshift($emitter) + { + $this->validateEmitter($emitter); + parent::unshift($emitter); + } + + /** + * Validate that an emitter implements EmitterInterface. + * + * @param mixed $emitter + * @return void + * @throws InvalidArgumentException for non-emitter instances + */ + private function validateEmitter($emitter) + { + if (! $emitter instanceof EmitterInterface) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects an EmitterInterface implementation', + __CLASS__ + )); + } + } +} diff --git a/src/ResponseSender/AbstractResponseSender.php b/src/ResponseSender/AbstractResponseSender.php deleted file mode 100644 index 38f58c821..000000000 --- a/src/ResponseSender/AbstractResponseSender.php +++ /dev/null @@ -1,44 +0,0 @@ -headersSent()) { - return $this; - } - - $response = $event->getResponse(); - - foreach ($response->getHeaders() as $header) { - if ($header instanceof MultipleHeaderInterface) { - header($header->toString(), false); - continue; - } - header($header->toString()); - } - - $status = $response->renderStatusLine(); - header($status); - - $event->setHeadersSent(); - return $this; - } -} diff --git a/src/ResponseSender/HttpResponseSender.php b/src/ResponseSender/HttpResponseSender.php deleted file mode 100644 index 9a797f852..000000000 --- a/src/ResponseSender/HttpResponseSender.php +++ /dev/null @@ -1,51 +0,0 @@ -contentSent()) { - return $this; - } - $response = $event->getResponse(); - echo $response->getContent(); - $event->setContentSent(); - return $this; - } - - /** - * Send HTTP response - * - * @param SendResponseEvent $event - * @return HttpResponseSender - */ - public function __invoke(SendResponseEvent $event) - { - $response = $event->getResponse(); - if (! $response instanceof Response) { - return $this; - } - - $this->sendHeaders($event); - $this->sendContent($event); - $event->stopPropagation(true); - return $this; - } -} diff --git a/src/ResponseSender/PhpEnvironmentResponseSender.php b/src/ResponseSender/PhpEnvironmentResponseSender.php deleted file mode 100644 index 69f55340b..000000000 --- a/src/ResponseSender/PhpEnvironmentResponseSender.php +++ /dev/null @@ -1,34 +0,0 @@ -getResponse(); - if (! $response instanceof Response) { - return $this; - } - - $this->sendHeaders($event); - $this->sendContent($event); - $event->stopPropagation(true); - return $this; - } -} diff --git a/src/ResponseSender/ResponseSenderInterface.php b/src/ResponseSender/ResponseSenderInterface.php deleted file mode 100644 index 2e9faebd6..000000000 --- a/src/ResponseSender/ResponseSenderInterface.php +++ /dev/null @@ -1,21 +0,0 @@ -setParam('response', $response); - $this->response = $response; - return $this; - } - - /** - * @return \Zend\Stdlib\ResponseInterface - */ - public function getResponse() - { - return $this->response; - } - - /** - * Set content sent for current response - * - * @return SendResponseEvent - */ - public function setContentSent() - { - $response = $this->getResponse(); - $contentSent = $this->getParam('contentSent', []); - $contentSent[spl_object_hash($response)] = true; - $this->setParam('contentSent', $contentSent); - $this->contentSent[spl_object_hash($response)] = true; - return $this; - } - - /** - * @return bool - */ - public function contentSent() - { - $response = $this->getResponse(); - if (isset($this->contentSent[spl_object_hash($response)])) { - return true; - } - return false; - } - - /** - * Set headers sent for current response object - * - * @return SendResponseEvent - */ - public function setHeadersSent() - { - $response = $this->getResponse(); - $headersSent = $this->getParam('headersSent', []); - $headersSent[spl_object_hash($response)] = true; - $this->setParam('headersSent', $headersSent); - $this->headersSent[spl_object_hash($response)] = true; - return $this; - } - - /** - * @return bool - */ - public function headersSent() - { - $response = $this->getResponse(); - if (isset($this->headersSent[spl_object_hash($response)])) { - return true; - } - return false; - } -} diff --git a/src/ResponseSender/SimpleStreamResponseSender.php b/src/ResponseSender/SimpleStreamResponseSender.php deleted file mode 100644 index 76bff6274..000000000 --- a/src/ResponseSender/SimpleStreamResponseSender.php +++ /dev/null @@ -1,55 +0,0 @@ -contentSent()) { - return $this; - } - $response = $event->getResponse(); - if (! $response instanceof Stream) { - throw new DomainException('Attempting to send stream of non-stream response'); - } - $stream = $response->getStream(); - fpassthru($stream); - $event->setContentSent(); - } - - /** - * Send stream response - * - * @param SendResponseEvent $event - * @return SimpleStreamResponseSender - */ - public function __invoke(SendResponseEvent $event) - { - $response = $event->getResponse(); - if (! $response instanceof Stream) { - return $this; - } - - $this->sendHeaders($event); - $this->sendStream($event); - $event->stopPropagation(true); - return $this; - } -} diff --git a/src/SendResponseListener.php b/src/SendResponseListener.php deleted file mode 100644 index eaa5faf12..000000000 --- a/src/SendResponseListener.php +++ /dev/null @@ -1,141 +0,0 @@ -setIdentifiers([ - __CLASS__, - get_class($this), - ]); - $this->eventManager = $eventManager; - $this->attachDefaultListeners(); - return $this; - } - - /** - * Retrieve the event manager - * - * Lazy-loads an EventManager instance if none registered. - * - * @return EventManagerInterface - */ - public function getEventManager() - { - if (! $this->eventManager instanceof EventManagerInterface) { - $this->setEventManager(new EventManager()); - } - return $this->eventManager; - } - - /** - * Attach the aggregate to the specified event manager - * - * @param EventManagerInterface $events - * @param int $priority - * @return void - */ - public function attach(EventManagerInterface $events, $priority = 1) - { - $this->listeners[] = $events->attach(MvcEvent::EVENT_FINISH, [$this, 'sendResponse'], -10000); - } - - /** - * Send the response - * - * @param MvcEvent $e - * @return void - */ - public function sendResponse(MvcEvent $e) - { - $response = $e->getResponse(); - if (! $response instanceof Response) { - return; // there is no response to send - } - $event = $this->getEvent(); - $event->setResponse($response); - $event->setTarget($this); - $this->getEventManager()->triggerEvent($event); - } - - /** - * Get the send response event - * - * @return SendResponseEvent - */ - public function getEvent() - { - if (! $this->event instanceof SendResponseEvent) { - $this->setEvent(new SendResponseEvent()); - } - return $this->event; - } - - /** - * Set the send response event - * - * @param SendResponseEvent $e - * @return SendResponseListener - */ - public function setEvent(SendResponseEvent $e) - { - $this->event = $e; - return $this; - } - - /** - * Register the default event listeners - * - * The order in which the response sender are listed here, is by their usage: - * PhpEnvironmentResponseSender has highest priority, because it's used most often. - * SimpleStreamResponseSender is not used that often, so has a lower priority. - * You can attach your response sender before or after every default response sender implementation. - * All default response sender implementation have negative priority. - * You are able to attach listeners without giving a priority and your response sender would be first to try. - * - * @return SendResponseListener - */ - protected function attachDefaultListeners() - { - $events = $this->getEventManager(); - $events->attach(SendResponseEvent::EVENT_SEND_RESPONSE, new PhpEnvironmentResponseSender(), -1000); - $events->attach(SendResponseEvent::EVENT_SEND_RESPONSE, new SimpleStreamResponseSender(), -3000); - $events->attach(SendResponseEvent::EVENT_SEND_RESPONSE, new HttpResponseSender(), -4000); - } -} diff --git a/test/Container/SendResponseListenerFactoryTest.php b/test/Container/SendResponseListenerFactoryTest.php deleted file mode 100644 index 18a7a8ec5..000000000 --- a/test/Container/SendResponseListenerFactoryTest.php +++ /dev/null @@ -1,57 +0,0 @@ -prophesize(SharedEventManagerInterface::class); - $events = $this->prophesize(EventManagerInterface::class); - $events->getSharedManager()->will([$sharedEvents, 'reveal']); - - $events->setIdentifiers([SendResponseListener::class, SendResponseListener::class])->shouldBeCalled(); - $events->attach( - SendResponseEvent::EVENT_SEND_RESPONSE, - Argument::type(PhpEnvironmentResponseSender::class), - -1000 - )->shouldBeCalled(); - $events->attach( - SendResponseEvent::EVENT_SEND_RESPONSE, - Argument::type(SimpleStreamResponseSender::class), - -3000 - )->shouldBeCalled(); - $events->attach( - SendResponseEvent::EVENT_SEND_RESPONSE, - Argument::type(HttpResponseSender::class), - -4000 - )->shouldBeCalled(); - - $container = $this->prophesize(ContainerInterface::class); - $container->get('EventManager')->will([$events, 'reveal']); - - $factory = new SendResponseListenerFactory(); - $listener = $factory($container->reveal()); - $this->assertInstanceOf(SendResponseListener::class, $listener); - $this->assertSame($events->reveal(), $listener->getEventManager()); - } -} diff --git a/test/ResponseSender/AbstractResponseSenderTest.php b/test/ResponseSender/AbstractResponseSenderTest.php deleted file mode 100644 index e700aeb41..000000000 --- a/test/ResponseSender/AbstractResponseSenderTest.php +++ /dev/null @@ -1,104 +0,0 @@ -markTestSkipped('Xdebug extension needed, skipped test'); - } - $headers = [ - 'Content-Length: 2000', - 'Transfer-Encoding: chunked' - ]; - $response = new Response(); - $response->getHeaders()->addHeaders($headers); - - $mockSendResponseEvent = $this->getMockBuilder(SendResponseEvent::class) - ->setMethods(['getResponse']) - ->getMock(); - - $mockSendResponseEvent->expects( - $this->any() - ) - ->method('getResponse') - ->will($this->returnValue($response)); - - $responseSender = $this->getMockForAbstractClass(AbstractResponseSender::class); - $responseSender->sendHeaders($mockSendResponseEvent); - - $sentHeaders = xdebug_get_headers(); - $diff = array_diff($sentHeaders, $headers); - - if (count($diff)) { - $header = array_shift($diff); - $this->assertContains('XDEBUG_SESSION', $header); - $this->assertEquals(0, count($diff)); - } - - $expected = []; - if (version_compare(phpversion('xdebug'), '2.2.0', '>=')) { - $expected = xdebug_get_headers(); - } - - $responseSender->sendHeaders($mockSendResponseEvent); - $this->assertEquals($expected, xdebug_get_headers()); - } - - /** - * @runInSeparateProcess - */ - public function testSendHeadersSendsStatusLast() - { - if (! function_exists('xdebug_get_headers')) { - $this->markTestSkipped('Xdebug extension needed, skipped test'); - } - - $mockResponse = $this->createMock(Response::class); - $mockResponse - ->expects($this->once()) - ->method('getHeaders') - ->will($this->returnValue(Headers::fromString('Location: example.com'))); - $mockResponse - ->expects($this->once()) - ->method('renderStatusLine') - ->will($this->returnValue('X-Test: HTTP/1.1 202 Accepted')); - - $mockSendResponseEvent = $this->getMockBuilder(SendResponseEvent::class) - ->setMethods(['getResponse']) - ->getMock(); - $mockSendResponseEvent->expects($this->any())->method('getResponse')->will($this->returnValue($mockResponse)); - - $responseSender = $this->getMockForAbstractClass(AbstractResponseSender::class); - $responseSender->sendHeaders($mockSendResponseEvent); - - $sentHeaders = xdebug_get_headers(); - - $this->assertCount(2, $sentHeaders); - $this->assertEquals('Location: example.com', $sentHeaders[0]); - $this->assertEquals( - 'X-Test: HTTP/1.1 202 Accepted', - $sentHeaders[1], - 'Status header is sent last to prevent header() from overwriting the ZF status code when a Location ' - . 'header is used' - ); - } -} diff --git a/test/ResponseSender/PhpEnvironmentResponseSenderTest.php b/test/ResponseSender/PhpEnvironmentResponseSenderTest.php deleted file mode 100644 index ac1c8bc93..000000000 --- a/test/ResponseSender/PhpEnvironmentResponseSenderTest.php +++ /dev/null @@ -1,69 +0,0 @@ -getMockForAbstractClass(ResponseInterface::class); - $mockSendResponseEvent = $this->getSendResponseEventMock(); - $mockSendResponseEvent->expects($this->any())->method('getResponse')->will($this->returnValue($mockResponse)); - $responseSender = new PhpEnvironmentResponseSender(); - ob_start(); - $responseSender($mockSendResponseEvent); - $body = ob_get_clean(); - $this->assertEquals('', $body); - } - - public function testSendResponseTwoTimesPrintsResponseOnlyOnce() - { - $mockResponse = $this->createMock(Response::class); - $mockResponse->expects($this->any())->method('getContent')->will($this->returnValue('body')); - $mockSendResponseEvent = $this->getSendResponseEventMock(); - $mockSendResponseEvent->expects($this->any())->method('getResponse')->will($this->returnValue($mockResponse)); - $mockSendResponseEvent->expects($this->once())->method('setContentSent'); - $responseSender = new PhpEnvironmentResponseSender(); - ob_start(); - $responseSender($mockSendResponseEvent); - $body = ob_get_clean(); - $this->assertEquals('body', $body); - - ob_start(); - $responseSender($mockSendResponseEvent); - $body = ob_get_clean(); - $this->assertEquals('', $body); - } - - protected function getSendResponseEventMock() - { - $returnValue = false; - $mockSendResponseEvent = $this->getMockBuilder(SendResponseEvent::class) - ->setMethods(['getResponse', 'contentSent', 'setContentSent']) - ->getMock(); - - $mockSendResponseEvent->expects($this->any()) - ->method('contentSent') - ->will($this->returnCallback(function () use (&$returnValue) { - if (false === $returnValue) { - $returnValue = true; - return false; - } - return true; - })); - return $mockSendResponseEvent; - } -} diff --git a/test/ResponseSender/SendResponseEventTest.php b/test/ResponseSender/SendResponseEventTest.php deleted file mode 100644 index cafc62863..000000000 --- a/test/ResponseSender/SendResponseEventTest.php +++ /dev/null @@ -1,34 +0,0 @@ -getMockForAbstractClass(ResponseInterface::class); - $mockResponse2 = $this->getMockForAbstractClass(ResponseInterface::class); - $event = new SendResponseEvent(); - $event->setResponse($mockResponse); - $this->assertFalse($event->headersSent()); - $this->assertFalse($event->contentSent()); - $event->setHeadersSent(); - $event->setContentSent(); - $this->assertTrue($event->headersSent()); - $this->assertTrue($event->contentSent()); - $event->setResponse($mockResponse2); - $this->assertFalse($event->headersSent()); - $this->assertFalse($event->contentSent()); - } -} diff --git a/test/ResponseSender/SimpleStreamResponseSenderTest.php b/test/ResponseSender/SimpleStreamResponseSenderTest.php deleted file mode 100644 index 87745a707..000000000 --- a/test/ResponseSender/SimpleStreamResponseSenderTest.php +++ /dev/null @@ -1,58 +0,0 @@ -getMockForAbstractClass(Stdlib\ResponseInterface::class); - $mockSendResponseEvent = $this->getSendResponseEventMock($mockResponse); - $responseSender = new SimpleStreamResponseSender(); - ob_start(); - $responseSender($mockSendResponseEvent); - $body = ob_get_clean(); - $this->assertEquals('', $body); - } - - public function testSendResponseTwoTimesPrintsResponseOnlyOnce() - { - $file = fopen(__DIR__ . '/TestAsset/sample-stream-file.txt', 'rb'); - $mockResponse = $this->createMock(Response\Stream::class); - $mockResponse->expects($this->once())->method('getStream')->will($this->returnValue($file)); - $mockSendResponseEvent = $this->getSendResponseEventMock($mockResponse); - $responseSender = new SimpleStreamResponseSender(); - ob_start(); - $responseSender($mockSendResponseEvent); - $body = ob_get_clean(); - $expected = file_get_contents(__DIR__ . '/TestAsset/sample-stream-file.txt'); - $this->assertEquals($expected, $body); - - ob_start(); - $responseSender($mockSendResponseEvent); - $body = ob_get_clean(); - $this->assertEquals('', $body); - } - - protected function getSendResponseEventMock($response) - { - $mockSendResponseEvent = $this->getMockBuilder(ResponseSender\SendResponseEvent::class) - ->setMethods(['getResponse']) - ->getMock(); - $mockSendResponseEvent->expects($this->any())->method('getResponse')->will($this->returnValue($response)); - return $mockSendResponseEvent; - } -} diff --git a/test/ResponseSender/TestAsset/sample-stream-file.txt b/test/ResponseSender/TestAsset/sample-stream-file.txt deleted file mode 100644 index a63f5a148..000000000 --- a/test/ResponseSender/TestAsset/sample-stream-file.txt +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Zend Framework (http://framework.zend.com/) - * - * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Mvc - */ - -This is a sample file that will be streamed during the unit tests. \ No newline at end of file diff --git a/test/SendResponseListenerTest.php b/test/SendResponseListenerTest.php deleted file mode 100644 index 998520a74..000000000 --- a/test/SendResponseListenerTest.php +++ /dev/null @@ -1,48 +0,0 @@ -getEventManager()->getIdentifiers(); - $expected = [SendResponseListener::class]; - $this->assertEquals($expected, array_values($identifiers)); - } - - public function testSendResponseTriggersSendResponseEvent() - { - $listener = new SendResponseListener(); - $result = []; - $listener->getEventManager()->attach(SendResponseEvent::EVENT_SEND_RESPONSE, function ($e) use (&$result) { - $result['target'] = $e->getTarget(); - $result['response'] = $e->getResponse(); - }, 10000); - $mockResponse = $this->getMockForAbstractClass(ResponseInterface::class); - $mockMvcEvent = $this->getMockBuilder(MvcEvent::class) - ->setMethods(['getResponse']) - ->getMock(); - $mockMvcEvent->expects($this->any())->method('getResponse')->will($this->returnValue($mockResponse)); - $listener->sendResponse($mockMvcEvent); - $expected = [ - 'target' => $listener, - 'response' => $mockResponse - ]; - $this->assertEquals($expected, $result); - } -} From 8cdad4386a2722ec27877fdf4e9346031c99cc21 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 26 Nov 2017 03:52:14 +1000 Subject: [PATCH 11/51] Refactor MvcEvent, drop RouteMatch --- src/MvcEvent.php | 82 ++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 59 deletions(-) diff --git a/src/MvcEvent.php b/src/MvcEvent.php index b48d8d521..265723219 100644 --- a/src/MvcEvent.php +++ b/src/MvcEvent.php @@ -9,11 +9,10 @@ namespace Zend\Mvc; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface as Request; use Zend\EventManager\Event; -use Zend\Router\RouteMatch; use Zend\Router\RouteStackInterface; -use Zend\Stdlib\RequestInterface as Request; -use Zend\Stdlib\ResponseInterface as Response; use Zend\View\Model\ModelInterface as Model; use Zend\View\Model\ViewModel; @@ -39,7 +38,7 @@ class MvcEvent extends Event protected $request; /** - * @var Response + * @var ResponseInterface */ protected $response; @@ -53,11 +52,6 @@ class MvcEvent extends Event */ protected $router; - /** - * @var null|RouteMatch - */ - protected $routeMatch; - /** * @var Model */ @@ -67,13 +61,12 @@ class MvcEvent extends Event * Set application instance * * @param ApplicationInterface $application - * @return MvcEvent + * @return void */ - public function setApplication(ApplicationInterface $application) + public function setApplication(ApplicationInterface $application) : void { $this->setParam('application', $application); $this->application = $application; - return $this; } /** @@ -81,7 +74,7 @@ public function setApplication(ApplicationInterface $application) * * @return ApplicationInterface */ - public function getApplication() + public function getApplication() : ApplicationInterface { return $this->application; } @@ -100,44 +93,20 @@ public function getRouter() * Set router * * @param RouteStackInterface $router - * @return MvcEvent + * @return void */ - public function setRouter(RouteStackInterface $router) + public function setRouter(RouteStackInterface $router) : void { $this->setParam('router', $router); $this->router = $router; - return $this; - } - - /** - * Get route match - * - * @return null|RouteMatch - */ - public function getRouteMatch() - { - return $this->routeMatch; - } - - /** - * Set route match - * - * @param RouteMatch $matches - * @return MvcEvent - */ - public function setRouteMatch(RouteMatch $matches) - { - $this->setParam('route-match', $matches); - $this->routeMatch = $matches; - return $this; } /** - * Get request + * Get request. Not available during bootstrap * * @return Request */ - public function getRequest() + public function getRequest() : ?Request { return $this->request; } @@ -146,21 +115,20 @@ public function getRequest() * Set request * * @param Request $request - * @return MvcEvent + * @return void */ - public function setRequest(Request $request) + public function setRequest(Request $request) : void { $this->setParam('request', $request); $this->request = $request; - return $this; } /** * Get response * - * @return Response + * @return ResponseInterface */ - public function getResponse() + public function getResponse() : ?ResponseInterface { return $this->response; } @@ -168,26 +136,24 @@ public function getResponse() /** * Set response * - * @param Response $response - * @return MvcEvent + * @param ResponseInterface $response + * @return void */ - public function setResponse(Response $response) + public function setResponse(ResponseInterface $response) : void { $this->setParam('response', $response); $this->response = $response; - return $this; } /** * Set the view model * * @param Model $viewModel - * @return MvcEvent + * @return void */ - public function setViewModel(Model $viewModel) + public function setViewModel(Model $viewModel) : void { $this->viewModel = $viewModel; - return $this; } /** @@ -219,11 +185,10 @@ public function getResult() * @param mixed $result * @return MvcEvent */ - public function setResult($result) + public function setResult($result) : void { $this->setParam('__RESULT__', $result); $this->result = $result; - return $this; } /** @@ -231,7 +196,7 @@ public function setResult($result) * * @return bool */ - public function isError() + public function isError() : bool { return (bool) $this->getParam('error', false); } @@ -240,12 +205,11 @@ public function isError() * Set the error message (indicating error in handling request) * * @param string $message - * @return MvcEvent + * @return void */ - public function setError($message) + public function setError($message) : void { $this->setParam('error', $message); - return $this; } /** From 23dccdbcdb2b31ec5db3dcd9bc96ffd23f22ff8b Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 26 Nov 2017 03:56:54 +1000 Subject: [PATCH 12/51] Drop zend-http and psr-7 bridge --- composer.json | 2 - composer.lock | 363 +++++++++++++++----------------------------------- 2 files changed, 106 insertions(+), 259 deletions(-) diff --git a/composer.json b/composer.json index 5be044471..de41acd2a 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "psr/http-message": "^1.0", "zendframework/zend-diactoros": "^1.7", "zendframework/zend-eventmanager": "^3.2", - "zendframework/zend-http": "^2.7", "zendframework/zend-modulemanager": "^2.8", "zendframework/zend-router": "dev-make-mvc-great-again", "zendframework/zend-servicemanager": "^3.3", @@ -40,7 +39,6 @@ "phpunit/phpunit": "^7.0", "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-json": "^3.0", - "zendframework/zend-psr7bridge": "^1.0", "zendframework/zend-stratigility": "^2.0.1", "zendframework/zend-validator": "^2.10" }, diff --git a/composer.lock b/composer.lock index ea9467b25..576808c8e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "2c0a9cecf2cb5155030304cd2cea832d", + "content-hash": "8158e75ff14b1f3c77dc719aa9e5f4fc", "packages": [ { "name": "container-interop/container-interop", @@ -298,50 +298,6 @@ ], "time": "2018-01-04T18:21:48+00:00" }, - { - "name": "zendframework/zend-escaper", - "version": "2.5.2", - "source": { - "type": "git", - "url": "https://github.com/zendframework/zend-escaper.git", - "reference": "2dcd14b61a72d8b8e27d579c6344e12c26141d4e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-escaper/zipball/2dcd14b61a72d8b8e27d579c6344e12c26141d4e", - "reference": "2dcd14b61a72d8b8e27d579c6344e12c26141d4e", - "shasum": "" - }, - "require": { - "php": ">=5.5" - }, - "require-dev": { - "fabpot/php-cs-fixer": "1.7.*", - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.5-dev", - "dev-develop": "2.6-dev" - } - }, - "autoload": { - "psr-4": { - "Zend\\Escaper\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "homepage": "https://github.com/zendframework/zend-escaper", - "keywords": [ - "escaper", - "zf2" - ], - "time": "2016-06-30T19:48:38+00:00" - }, { "name": "zendframework/zend-eventmanager", "version": "3.2.0", @@ -396,59 +352,6 @@ ], "time": "2017-07-11T19:17:22+00:00" }, - { - "name": "zendframework/zend-http", - "version": "2.7.0", - "source": { - "type": "git", - "url": "https://github.com/zendframework/zend-http.git", - "reference": "78aa510c0ea64bfb2aa234f50c4f232c9531acfa" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-http/zipball/78aa510c0ea64bfb2aa234f50c4f232c9531acfa", - "reference": "78aa510c0ea64bfb2aa234f50c4f232c9531acfa", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0", - "zendframework/zend-loader": "^2.5.1", - "zendframework/zend-stdlib": "^3.1 || ^2.7.7", - "zendframework/zend-uri": "^2.5.2", - "zendframework/zend-validator": "^2.10.1" - }, - "require-dev": { - "phpunit/phpunit": "^6.4.1 || ^5.7.15", - "zendframework/zend-coding-standard": "~1.0.0", - "zendframework/zend-config": "^3.1 || ^2.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev", - "dev-develop": "2.8-dev" - } - }, - "autoload": { - "psr-4": { - "Zend\\Http\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests", - "homepage": "https://github.com/zendframework/zend-http", - "keywords": [ - "ZendFramework", - "http", - "http client", - "zend", - "zf" - ], - "time": "2017-10-13T12:06:24+00:00" - }, { "name": "zendframework/zend-loader", "version": "2.5.1", @@ -755,124 +658,6 @@ ], "time": "2016-09-13T14:38:50+00:00" }, - { - "name": "zendframework/zend-uri", - "version": "2.5.2", - "source": { - "type": "git", - "url": "https://github.com/zendframework/zend-uri.git", - "reference": "0bf717a239432b1a1675ae314f7c4acd742749ed" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-uri/zipball/0bf717a239432b1a1675ae314f7c4acd742749ed", - "reference": "0bf717a239432b1a1675ae314f7c4acd742749ed", - "shasum": "" - }, - "require": { - "php": "^5.5 || ^7.0", - "zendframework/zend-escaper": "^2.5", - "zendframework/zend-validator": "^2.5" - }, - "require-dev": { - "fabpot/php-cs-fixer": "1.7.*", - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.5-dev", - "dev-develop": "2.6-dev" - } - }, - "autoload": { - "psr-4": { - "Zend\\Uri\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "a component that aids in manipulating and validating » Uniform Resource Identifiers (URIs)", - "homepage": "https://github.com/zendframework/zend-uri", - "keywords": [ - "uri", - "zf2" - ], - "time": "2016-02-17T22:38:51+00:00" - }, - { - "name": "zendframework/zend-validator", - "version": "2.10.2", - "source": { - "type": "git", - "url": "https://github.com/zendframework/zend-validator.git", - "reference": "38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-validator/zipball/38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9", - "reference": "38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9", - "shasum": "" - }, - "require": { - "container-interop/container-interop": "^1.1", - "php": "^5.6 || ^7.0", - "zendframework/zend-stdlib": "^2.7.6 || ^3.1" - }, - "require-dev": { - "phpunit/phpunit": "^6.0.8 || ^5.7.15", - "zendframework/zend-cache": "^2.6.1", - "zendframework/zend-coding-standard": "~1.0.0", - "zendframework/zend-config": "^2.6", - "zendframework/zend-db": "^2.7", - "zendframework/zend-filter": "^2.6", - "zendframework/zend-http": "^2.5.4", - "zendframework/zend-i18n": "^2.6", - "zendframework/zend-math": "^2.6", - "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", - "zendframework/zend-session": "^2.8", - "zendframework/zend-uri": "^2.5" - }, - "suggest": { - "zendframework/zend-db": "Zend\\Db component, required by the (No)RecordExists validator", - "zendframework/zend-filter": "Zend\\Filter component, required by the Digits validator", - "zendframework/zend-i18n": "Zend\\I18n component to allow translation of validation error messages", - "zendframework/zend-i18n-resources": "Translations of validator messages", - "zendframework/zend-math": "Zend\\Math component, required by the Csrf validator", - "zendframework/zend-servicemanager": "Zend\\ServiceManager component to allow using the ValidatorPluginManager and validator chains", - "zendframework/zend-session": "Zend\\Session component, ^2.8; required by the Csrf validator", - "zendframework/zend-uri": "Zend\\Uri component, required by the Uri and Sitemap\\Loc validators" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.10.x-dev", - "dev-develop": "2.11.x-dev" - }, - "zf": { - "component": "Zend\\Validator", - "config-provider": "Zend\\Validator\\ConfigProvider" - } - }, - "autoload": { - "psr-4": { - "Zend\\Validator\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "provides a set of commonly needed validators", - "homepage": "https://github.com/zendframework/zend-validator", - "keywords": [ - "validator", - "zf2" - ], - "time": "2018-02-01T17:05:33+00:00" - }, { "name": "zendframework/zend-view", "version": "2.10.0", @@ -2668,6 +2453,50 @@ ], "time": "2016-11-09T21:30:43+00:00" }, + { + "name": "zendframework/zend-escaper", + "version": "2.5.2", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-escaper.git", + "reference": "2dcd14b61a72d8b8e27d579c6344e12c26141d4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-escaper/zipball/2dcd14b61a72d8b8e27d579c6344e12c26141d4e", + "reference": "2dcd14b61a72d8b8e27d579c6344e12c26141d4e", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "fabpot/php-cs-fixer": "1.7.*", + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev", + "dev-develop": "2.6-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Escaper\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "homepage": "https://github.com/zendframework/zend-escaper", + "keywords": [ + "escaper", + "zf2" + ], + "time": "2016-06-30T19:48:38+00:00" + }, { "name": "zendframework/zend-json", "version": "3.1.0", @@ -2719,109 +2548,129 @@ "time": "2018-01-04T17:51:34+00:00" }, { - "name": "zendframework/zend-psr7bridge", - "version": "1.0.1", + "name": "zendframework/zend-stratigility", + "version": "2.1.2", "source": { "type": "git", - "url": "https://github.com/zendframework/zend-psr7bridge.git", - "reference": "93494337a475135a457d86f6b150c67aa4f31aea" + "url": "https://github.com/zendframework/zend-stratigility.git", + "reference": "7dfec8dee92dad0d01e68365015f2848c250fe9f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-psr7bridge/zipball/93494337a475135a457d86f6b150c67aa4f31aea", - "reference": "93494337a475135a457d86f6b150c67aa4f31aea", + "url": "https://api.github.com/repos/zendframework/zend-stratigility/zipball/7dfec8dee92dad0d01e68365015f2848c250fe9f", + "reference": "7dfec8dee92dad0d01e68365015f2848c250fe9f", "shasum": "" }, "require": { "php": "^5.6 || ^7.0", "psr/http-message": "^1.0", - "zendframework/zend-diactoros": "^1.1", - "zendframework/zend-http": "^2.6" + "webimpress/http-middleware-compatibility": "^0.1.3", + "zendframework/zend-escaper": "^2.3" }, "require-dev": { - "phpunit/phpunit": "^5.7.15 || ^6.0.8", - "zendframework/zend-coding-standard": "~1.0.0" + "malukenho/docheader": "^0.1.5", + "phpunit/phpunit": "^6.0.8 || ^5.7.15", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-diactoros": "^1.0" + }, + "suggest": { + "psr/http-message-implementation": "Please install a psr/http-message-implementation to consume Stratigility; e.g., zendframework/zend-diactoros" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev", - "dev-develop": "1.1-dev" + "dev-master": "2.1.0-dev", + "dev-develop": "2.2.0-dev" } }, "autoload": { "psr-4": { - "Zend\\Psr7Bridge\\": "src/" + "Zend\\Stratigility\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], - "description": "PSR-7 <-> Zend\\Http bridge", - "homepage": "https://github.com/zendframework/zend-psr7bridge", + "description": "Middleware for PHP", + "homepage": "https://github.com/zendframework/zend-stratigility", "keywords": [ - "ZendFramework", "http", - "psr", - "psr-7", - "zend" + "middleware", + "psr-7" ], - "time": "2017-12-18T11:59:51+00:00" + "time": "2017-10-12T13:14:14+00:00" }, { - "name": "zendframework/zend-stratigility", - "version": "2.1.2", + "name": "zendframework/zend-validator", + "version": "2.10.2", "source": { "type": "git", - "url": "https://github.com/zendframework/zend-stratigility.git", - "reference": "7dfec8dee92dad0d01e68365015f2848c250fe9f" + "url": "https://github.com/zendframework/zend-validator.git", + "reference": "38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-stratigility/zipball/7dfec8dee92dad0d01e68365015f2848c250fe9f", - "reference": "7dfec8dee92dad0d01e68365015f2848c250fe9f", + "url": "https://api.github.com/repos/zendframework/zend-validator/zipball/38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9", + "reference": "38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9", "shasum": "" }, "require": { + "container-interop/container-interop": "^1.1", "php": "^5.6 || ^7.0", - "psr/http-message": "^1.0", - "webimpress/http-middleware-compatibility": "^0.1.3", - "zendframework/zend-escaper": "^2.3" + "zendframework/zend-stdlib": "^2.7.6 || ^3.1" }, "require-dev": { - "malukenho/docheader": "^0.1.5", "phpunit/phpunit": "^6.0.8 || ^5.7.15", + "zendframework/zend-cache": "^2.6.1", "zendframework/zend-coding-standard": "~1.0.0", - "zendframework/zend-diactoros": "^1.0" + "zendframework/zend-config": "^2.6", + "zendframework/zend-db": "^2.7", + "zendframework/zend-filter": "^2.6", + "zendframework/zend-http": "^2.5.4", + "zendframework/zend-i18n": "^2.6", + "zendframework/zend-math": "^2.6", + "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", + "zendframework/zend-session": "^2.8", + "zendframework/zend-uri": "^2.5" }, "suggest": { - "psr/http-message-implementation": "Please install a psr/http-message-implementation to consume Stratigility; e.g., zendframework/zend-diactoros" + "zendframework/zend-db": "Zend\\Db component, required by the (No)RecordExists validator", + "zendframework/zend-filter": "Zend\\Filter component, required by the Digits validator", + "zendframework/zend-i18n": "Zend\\I18n component to allow translation of validation error messages", + "zendframework/zend-i18n-resources": "Translations of validator messages", + "zendframework/zend-math": "Zend\\Math component, required by the Csrf validator", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component to allow using the ValidatorPluginManager and validator chains", + "zendframework/zend-session": "Zend\\Session component, ^2.8; required by the Csrf validator", + "zendframework/zend-uri": "Zend\\Uri component, required by the Uri and Sitemap\\Loc validators" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1.0-dev", - "dev-develop": "2.2.0-dev" + "dev-master": "2.10.x-dev", + "dev-develop": "2.11.x-dev" + }, + "zf": { + "component": "Zend\\Validator", + "config-provider": "Zend\\Validator\\ConfigProvider" } }, "autoload": { "psr-4": { - "Zend\\Stratigility\\": "src/" + "Zend\\Validator\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], - "description": "Middleware for PHP", - "homepage": "https://github.com/zendframework/zend-stratigility", + "description": "provides a set of commonly needed validators", + "homepage": "https://github.com/zendframework/zend-validator", "keywords": [ - "http", - "middleware", - "psr-7" + "validator", + "zf2" ], - "time": "2017-10-12T13:14:14+00:00" + "time": "2018-02-01T17:05:33+00:00" } ], "aliases": [], From d3af86e9fd6824d475bb8c50a300a85d9fcdb459 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 26 Nov 2017 05:51:28 +1000 Subject: [PATCH 13/51] Initial PSR-7 refactoring for view stuff --- src/View/Http/CreateViewModelListener.php | 6 +- src/View/Http/DefaultRenderingStrategy.php | 28 +-- src/View/Http/ExceptionStrategy.php | 18 +- .../Http/InjectRoutematchParamsListener.php | 91 -------- src/View/Http/InjectTemplateListener.php | 49 +++-- src/View/Http/InjectViewModelListener.php | 4 +- src/View/Http/RouteNotFoundStrategy.php | 60 +++--- src/View/Http/ViewManager.php | 12 +- test/View/DefaultRendereringStrategyTest.php | 13 +- test/View/ExceptionStrategyTest.php | 16 +- test/View/InjectTemplateListenerTest.php | 196 ++++++------------ test/View/InjectViewModelListenerTest.php | 3 - test/View/RouteNotFoundStrategyTest.php | 34 ++- 13 files changed, 186 insertions(+), 344 deletions(-) delete mode 100644 src/View/Http/InjectRoutematchParamsListener.php diff --git a/src/View/Http/CreateViewModelListener.php b/src/View/Http/CreateViewModelListener.php index 744ddd50a..b410fbc96 100644 --- a/src/View/Http/CreateViewModelListener.php +++ b/src/View/Http/CreateViewModelListener.php @@ -20,7 +20,7 @@ class CreateViewModelListener extends AbstractListenerAggregate /** * {@inheritDoc} */ - public function attach(Events $events, $priority = 1) + public function attach(Events $events, $priority = 1) : void { $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, [$this, 'createViewModelFromArray'], -80); $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, [$this, 'createViewModelFromNull'], -80); @@ -32,7 +32,7 @@ public function attach(Events $events, $priority = 1) * @param MvcEvent $e * @return void */ - public function createViewModelFromArray(MvcEvent $e) + public function createViewModelFromArray(MvcEvent $e) : void { $result = $e->getResult(); if (! ArrayUtils::hasStringKeys($result, true)) { @@ -49,7 +49,7 @@ public function createViewModelFromArray(MvcEvent $e) * @param MvcEvent $e * @return void */ - public function createViewModelFromNull(MvcEvent $e) + public function createViewModelFromNull(MvcEvent $e) : void { $result = $e->getResult(); if (null !== $result) { diff --git a/src/View/Http/DefaultRenderingStrategy.php b/src/View/Http/DefaultRenderingStrategy.php index 0268abe1f..cf19047d7 100644 --- a/src/View/Http/DefaultRenderingStrategy.php +++ b/src/View/Http/DefaultRenderingStrategy.php @@ -9,11 +9,11 @@ namespace Zend\Mvc\View\Http; +use Psr\Http\Message\ResponseInterface; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; -use Zend\Stdlib\ResponseInterface as Response; use Zend\View\Model\ModelInterface as ViewModel; use Zend\View\View; @@ -45,7 +45,7 @@ public function __construct(View $view) /** * {@inheritDoc} */ - public function attach(EventManagerInterface $events, $priority = 1) + public function attach(EventManagerInterface $events, $priority = 1) : void { $this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER, [$this, 'render'], -10000); $this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER_ERROR, [$this, 'render'], -10000); @@ -55,12 +55,11 @@ public function attach(EventManagerInterface $events, $priority = 1) * Set layout template value * * @param string $layoutTemplate - * @return DefaultRenderingStrategy + * @return void */ - public function setLayoutTemplate(string $layoutTemplate) + public function setLayoutTemplate(string $layoutTemplate) : void { $this->layoutTemplate = $layoutTemplate; - return $this; } /** @@ -68,7 +67,7 @@ public function setLayoutTemplate(string $layoutTemplate) * * @return string */ - public function getLayoutTemplate() + public function getLayoutTemplate() : string { return $this->layoutTemplate; } @@ -77,13 +76,13 @@ public function getLayoutTemplate() * Render the view * * @param MvcEvent $e - * @return Response|null - * @throws \Exception + * @return null|ResponseInterface + * @throws \Throwable */ - public function render(MvcEvent $e) + public function render(MvcEvent $e) : ?ResponseInterface { $result = $e->getResult(); - if ($result instanceof Response) { + if ($result instanceof ResponseInterface) { return $result; } @@ -96,6 +95,7 @@ public function render(MvcEvent $e) } $view = $this->view; + // @TODO fix after view is updated $view->setRequest($request); $view->setResponse($response); @@ -104,14 +104,8 @@ public function render(MvcEvent $e) try { $view->render($viewModel); } catch (\Throwable $ex) { - $caughtException = $ex; - } catch (\Exception $ex) { // @TODO clean up once PHP 7 requirement is enforced - $caughtException = $ex; - } - - if ($caughtException !== null) { if ($e->getName() === MvcEvent::EVENT_RENDER_ERROR) { - throw $caughtException; + throw $ex; } $application = $e->getApplication(); diff --git a/src/View/Http/ExceptionStrategy.php b/src/View/Http/ExceptionStrategy.php index d420670a7..2d8168dcc 100644 --- a/src/View/Http/ExceptionStrategy.php +++ b/src/View/Http/ExceptionStrategy.php @@ -9,12 +9,12 @@ namespace Zend\Mvc\View\Http; +use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; -use Zend\Http\Response as HttpResponse; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; -use Zend\Stdlib\ResponseInterface as Response; use Zend\View\Model\ViewModel; class ExceptionStrategy extends AbstractListenerAggregate @@ -105,7 +105,7 @@ public function prepareExceptionViewModel(MvcEvent $e) // Do nothing if the result is a response object $result = $e->getResult(); - if ($result instanceof Response) { + if ($result instanceof ResponseInterface) { return; } @@ -128,14 +128,12 @@ public function prepareExceptionViewModel(MvcEvent $e) $response = $e->getResponse(); if (! $response) { - $response = new HttpResponse(); - $response->setStatusCode(500); + $response = new Response(); + $response = $response->withStatus(500); + $e->setResponse($response); + } elseif ($response->getStatusCode() === 200) { + $response = $response->withStatus(500); $e->setResponse($response); - } else { - $statusCode = $response->getStatusCode(); - if ($statusCode === 200) { - $response->setStatusCode(500); - } } break; diff --git a/src/View/Http/InjectRoutematchParamsListener.php b/src/View/Http/InjectRoutematchParamsListener.php deleted file mode 100644 index bc641d6f1..000000000 --- a/src/View/Http/InjectRoutematchParamsListener.php +++ /dev/null @@ -1,91 +0,0 @@ -listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, [$this, 'injectParams'], 90); - } - - /** - * Take parameters from RouteMatch and inject them into the request. - * - * @param MvcEvent $e - * @return void - */ - public function injectParams(MvcEvent $e) - { - $routeMatch = $e->getRouteMatch(); - $routeMatchParams = $routeMatch ? $routeMatch->getParams() : []; - /** - * @var HttpRequest - */ - $request = $e->getRequest(); - - if (! $request instanceof HttpRequest) { - // unsupported request type - return; - } - - // @TODO get() does not exist on Http\Request, was it meant to be getQuery()? - $params = $request->getQuery(); - - if ($this->overwrite) { - // Overwrite existing parameters, or create new ones if not present. - foreach ($routeMatchParams as $key => $val) { - $params->$key = $val; - } - return; - } - - // Only create new parameters. - foreach ($routeMatchParams as $key => $val) { - if (! $params->offsetExists($key)) { - $params->$key = $val; - } - } - } - - /** - * Should RouteMatch parameters replace existing Request params? - * - * @param bool $overwrite - */ - public function setOverwrite($overwrite) - { - $this->overwrite = $overwrite; - } - - /** - * @return bool - */ - public function getOverwrite() - { - return $this->overwrite; - } -} diff --git a/src/View/Http/InjectTemplateListener.php b/src/View/Http/InjectTemplateListener.php index e6f62ca54..e8aada1c5 100644 --- a/src/View/Http/InjectTemplateListener.php +++ b/src/View/Http/InjectTemplateListener.php @@ -12,7 +12,7 @@ use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface as Events; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; use Zend\Stdlib\StringUtils; use Zend\View\Model\ModelInterface as ViewModel; @@ -26,16 +26,16 @@ class InjectTemplateListener extends AbstractListenerAggregate protected $controllerMap = []; /** - * Flag to force the use of the route match controller param + * Flag to force the use of the route result controller param * * @var boolean */ - protected $preferRouteMatchController = false; + protected $preferRouteResultController = false; /** * {@inheritDoc} */ - public function attach(Events $events, $priority = 1) + public function attach(Events $events, $priority = 1) : void { $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, [$this, 'injectTemplate'], -90); } @@ -49,7 +49,7 @@ public function attach(Events $events, $priority = 1) * @param MvcEvent $e * @return void */ - public function injectTemplate(MvcEvent $e) + public function injectTemplate(MvcEvent $e) : void { $model = $e->getResult(); if (! $model instanceof ViewModel) { @@ -62,11 +62,16 @@ public function injectTemplate(MvcEvent $e) } /** - * @var RouteMatch + * @var RouteResult $routeResult */ - $routeMatch = $e->getRouteMatch(); - if ($preferRouteMatchController = $routeMatch->getParam('prefer_route_match_controller', false)) { - $this->setPreferRouteMatchController($preferRouteMatchController); + $routeResult = $e->getRequest()->getAttribute(RouteResult::class); + $matchedParams = []; + if ($routeResult) { + $matchedParams = $routeResult->getMatchedParams(); + } + if ($preferRouteResultController = ($matchedParams['prefer_route_result_controller'] ?? false)) { + // @TODO this has potential for reuse side effects. Fix it. + $this->setPreferRouteResultController($preferRouteResultController); } $controller = $e->getTarget(); @@ -74,14 +79,14 @@ public function injectTemplate(MvcEvent $e) $controller = get_class($controller); } - $routeMatchController = $routeMatch->getParam('controller', ''); - if (! $controller || ($this->preferRouteMatchController && $routeMatchController)) { + $routeMatchController = $matchedParams['controller'] ?? null; + if (! $controller || ($this->preferRouteResultController && $routeMatchController)) { $controller = $routeMatchController; } $template = $this->mapController($controller); - $action = $routeMatch->getParam('action'); + $action = $matchedParams['action'] ?? null; if (null !== $action) { $template .= '/' . $this->inflectName($action); } @@ -92,13 +97,12 @@ public function injectTemplate(MvcEvent $e) * Set map of controller namespace -> template pairs * * @param array $map - * @return self + * @return void */ - public function setControllerMap(array $map) + public function setControllerMap(array $map) : void { krsort($map); $this->controllerMap = $map; - return $this; } /** @@ -107,7 +111,7 @@ public function setControllerMap(array $map) * @param string $controller controller FQCN * @return string template name */ - public function mapController($controller) + public function mapController($controller) : string { $mapped = ''; foreach ($this->controllerMap as $namespace => $replacement) { @@ -150,7 +154,7 @@ public function mapController($controller) * @param string $name * @return string */ - protected function inflectName($name) + protected function inflectName($name) : string { if (StringUtils::hasPcreUnicodeSupport()) { $pattern = ['#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#', '#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#']; @@ -172,7 +176,7 @@ protected function inflectName($name) * @param string $controller * @return string */ - protected function deriveControllerClass($controller) + protected function deriveControllerClass($controller) : string { if (false !== strpos($controller, '\\')) { $controller = substr($controller, strrpos($controller, '\\') + 1); @@ -191,18 +195,17 @@ protected function deriveControllerClass($controller) * Sets the flag to instruct the listener to prefer the route match controller param * over the class name * - * @param boolean $preferRouteMatchController */ - public function setPreferRouteMatchController(bool $preferRouteMatchController) + public function setPreferRouteResultController(bool $preferRouteResultController) : void { - $this->preferRouteMatchController = $preferRouteMatchController; + $this->preferRouteResultController = $preferRouteResultController; } /** * @return boolean */ - public function isPreferRouteMatchController() + public function isPreferRouteResultController() : bool { - return $this->preferRouteMatchController; + return $this->preferRouteResultController; } } diff --git a/src/View/Http/InjectViewModelListener.php b/src/View/Http/InjectViewModelListener.php index 0eac32ef3..ef5637630 100644 --- a/src/View/Http/InjectViewModelListener.php +++ b/src/View/Http/InjectViewModelListener.php @@ -20,7 +20,7 @@ class InjectViewModelListener extends AbstractListenerAggregate /** * {@inheritDoc} */ - public function attach(Events $events, $priority = 1) + public function attach(Events $events, $priority = 1) : void { $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, [$this, 'injectViewModel'], -100); $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, [$this, 'injectViewModel'], -100); @@ -37,7 +37,7 @@ public function attach(Events $events, $priority = 1) * @param MvcEvent $e * @return void */ - public function injectViewModel(MvcEvent $e) + public function injectViewModel(MvcEvent $e) : void { $result = $e->getResult(); if (! $result instanceof ViewModel) { diff --git a/src/View/Http/RouteNotFoundStrategy.php b/src/View/Http/RouteNotFoundStrategy.php index df63c3a90..187dfb23b 100644 --- a/src/View/Http/RouteNotFoundStrategy.php +++ b/src/View/Http/RouteNotFoundStrategy.php @@ -9,12 +9,13 @@ namespace Zend\Mvc\View\Http; +use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; -use Zend\Http\Response as HttpResponse; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; -use Zend\Stdlib\ResponseInterface as Response; +use Zend\Router\RouteResult; use Zend\View\Model\ViewModel; class RouteNotFoundStrategy extends AbstractListenerAggregate @@ -50,7 +51,7 @@ class RouteNotFoundStrategy extends AbstractListenerAggregate /** * {@inheritDoc} */ - public function attach(EventManagerInterface $events, $priority = 1) + public function attach(EventManagerInterface $events, $priority = 1) : void { $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, [$this, 'prepareNotFoundViewModel'], -90); $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, [$this, 'detectNotFoundError']); @@ -61,12 +62,11 @@ public function attach(EventManagerInterface $events, $priority = 1) * Set value indicating whether or not to display exceptions related to a not-found condition * * @param bool $displayExceptions - * @return RouteNotFoundStrategy + * @return void */ - public function setDisplayExceptions(bool $displayExceptions) + public function setDisplayExceptions(bool $displayExceptions) : void { $this->displayExceptions = $displayExceptions; - return $this; } /** @@ -74,7 +74,7 @@ public function setDisplayExceptions(bool $displayExceptions) * * @return bool */ - public function displayExceptions() + public function displayExceptions() : bool { return $this->displayExceptions; } @@ -83,12 +83,11 @@ public function displayExceptions() * Set value indicating whether or not to display the reason for a not-found condition * * @param bool $displayNotFoundReason - * @return RouteNotFoundStrategy + * @return void */ - public function setDisplayNotFoundReason(bool $displayNotFoundReason) + public function setDisplayNotFoundReason(bool $displayNotFoundReason) : void { $this->displayNotFoundReason = $displayNotFoundReason; - return $this; } /** @@ -96,7 +95,7 @@ public function setDisplayNotFoundReason(bool $displayNotFoundReason) * * @return bool */ - public function displayNotFoundReason() + public function displayNotFoundReason() : bool { return $this->displayNotFoundReason; } @@ -105,12 +104,11 @@ public function displayNotFoundReason() * Get template for not found conditions * * @param string $notFoundTemplate - * @return RouteNotFoundStrategy + * @return void */ - public function setNotFoundTemplate(string $notFoundTemplate) + public function setNotFoundTemplate(string $notFoundTemplate) : void { $this->notFoundTemplate = $notFoundTemplate; - return $this; } /** @@ -118,7 +116,7 @@ public function setNotFoundTemplate(string $notFoundTemplate) * * @return string */ - public function getNotFoundTemplate() + public function getNotFoundTemplate() : string { return $this->notFoundTemplate; } @@ -132,7 +130,7 @@ public function getNotFoundTemplate() * @param MvcEvent $e * @return void */ - public function detectNotFoundError(MvcEvent $e) + public function detectNotFoundError(MvcEvent $e) : void { $error = $e->getError(); if (empty($error)) { @@ -146,10 +144,11 @@ public function detectNotFoundError(MvcEvent $e) $this->reason = $error; $response = $e->getResponse(); if (! $response) { - $response = new HttpResponse(); - $e->setResponse($response); + // @TODO inject and use response factory + $response = new Response(); } - $response->setStatusCode(404); + $response = $response->withStatus(404); + $e->setResponse($response); break; default: return; @@ -162,10 +161,10 @@ public function detectNotFoundError(MvcEvent $e) * @param MvcEvent $e * @return void */ - public function prepareNotFoundViewModel(MvcEvent $e) + public function prepareNotFoundViewModel(MvcEvent $e) : void { $vars = $e->getResult(); - if ($vars instanceof Response) { + if ($vars instanceof ResponseInterface) { // Already have a response as the result return; } @@ -214,7 +213,7 @@ public function prepareNotFoundViewModel(MvcEvent $e) * @param ViewModel $model * @return void */ - protected function injectNotFoundReason(ViewModel $model) + protected function injectNotFoundReason(ViewModel $model) : void { if (! $this->displayNotFoundReason()) { return; @@ -241,7 +240,7 @@ protected function injectNotFoundReason(ViewModel $model) * @param MvcEvent $e * @return void */ - protected function injectException($model, $e) + protected function injectException($model, $e) : void { if (! $this->displayExceptions()) { return; @@ -251,8 +250,7 @@ protected function injectException($model, $e) $exception = $e->getParam('exception', false); - // @TODO clean up once PHP 7 requirement is enforced - if (! $exception instanceof \Exception && ! $exception instanceof \Throwable) { + if (! $exception instanceof \Throwable) { return; } @@ -272,7 +270,7 @@ protected function injectException($model, $e) * @param MvcEvent $e * @return void */ - protected function injectController($model, $e) + protected function injectController($model, MvcEvent $e) : void { if (! $this->displayExceptions() && ! $this->displayNotFoundReason()) { return; @@ -280,12 +278,16 @@ protected function injectController($model, $e) $controller = $e->getController(); if (empty($controller)) { - $routeMatch = $e->getRouteMatch(); - if (empty($routeMatch)) { + if (! $e->getRequest()) { + return; + } + /** @var RouteResult $result */ + $result = $e->getRequest()->getAttribute(RouteResult::class); + if (empty($result)) { return; } - $controller = $routeMatch->getParam('controller', false); + $controller = $result->getMatchedParams()['controller'] ?? null; if (! $controller) { return; } diff --git a/src/View/Http/ViewManager.php b/src/View/Http/ViewManager.php index b2091dcf9..920a72aad 100644 --- a/src/View/Http/ViewManager.php +++ b/src/View/Http/ViewManager.php @@ -73,7 +73,7 @@ class ViewManager extends AbstractListenerAggregate /** * {@inheritDoc} */ - public function attach(EventManagerInterface $events, $priority = 1) + public function attach(EventManagerInterface $events, $priority = 1) : void { $this->listeners[] = $events->attach(MvcEvent::EVENT_BOOTSTRAP, [$this, 'onBootstrap'], 10000); } @@ -84,10 +84,10 @@ public function attach(EventManagerInterface $events, $priority = 1) * @param $event * @return void */ - public function onBootstrap($event) + public function onBootstrap(MvcEvent $event) : void { $application = $event->getApplication(); - $services = $application->getServiceManager(); + $services = $application->getContainer(); $config = $services->get('config'); $events = $application->getEventManager(); $sharedEvents = $events->getSharedManager(); @@ -196,7 +196,7 @@ public function getViewModel() * @param EventManagerInterface $events * @return void */ - protected function registerMvcRenderingStrategies(EventManagerInterface $events) + protected function registerMvcRenderingStrategies(EventManagerInterface $events) : void { if (! isset($this->config['mvc_strategies'])) { return; @@ -232,7 +232,7 @@ protected function registerMvcRenderingStrategies(EventManagerInterface $events) * * @return void */ - protected function registerViewStrategies() + protected function registerViewStrategies() : void { if (! isset($this->config['strategies'])) { return; @@ -263,7 +263,7 @@ protected function registerViewStrategies() /** * Injects the ViewModel view helper with the root view model. */ - private function injectViewModelIntoPlugin() + private function injectViewModelIntoPlugin() : void { $model = $this->getViewModel(); $plugins = $this->services->get('ViewHelperManager'); diff --git a/test/View/DefaultRendereringStrategyTest.php b/test/View/DefaultRendereringStrategyTest.php index 16bee4dd4..375a5b05b 100644 --- a/test/View/DefaultRendereringStrategyTest.php +++ b/test/View/DefaultRendereringStrategyTest.php @@ -10,12 +10,11 @@ namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; -use Zend\EventManager\Event; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\SharedEventManager; use Zend\EventManager\Test\EventListenerIntrospectionTrait; -use Zend\Http\Request; -use Zend\Http\Response; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; use Zend\Mvc\View\Http\DefaultRenderingStrategy; @@ -41,13 +40,13 @@ class DefaultRendereringStrategyTest extends TestCase public function setUp() { $this->view = new View(); - $this->request = new Request(); + $this->request = new ServerRequest([], [], null, 'GET', 'php://memory'); $this->response = new Response(); $this->event = new MvcEvent(); $this->renderer = new PhpRenderer(); - $this->event->setRequest($this->request) - ->setResponse($this->response); + $this->event->setRequest($this->request); + $this->event->setResponse($this->response); $this->strategy = new DefaultRenderingStrategy($this->view); } @@ -157,7 +156,7 @@ public function testTriggersRenderErrorEventInCaseOfRenderingException() ], ]))->configureServiceManager($services); - $application = new Application($services, $services->get('EventManager'), $this->request, $this->response); + $application = new Application($services, $services->get('EventManager')); $this->event->setApplication($application); $test = (object) ['flag' => false]; diff --git a/test/View/ExceptionStrategyTest.php b/test/View/ExceptionStrategyTest.php index d22fb5530..9626bdecf 100644 --- a/test/View/ExceptionStrategyTest.php +++ b/test/View/ExceptionStrategyTest.php @@ -10,9 +10,9 @@ namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\Response; use Zend\EventManager\EventManager; use Zend\EventManager\Test\EventListenerIntrospectionTrait; -use Zend\Http\Response; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; use Zend\Mvc\View\Http\ExceptionStrategy; @@ -22,6 +22,11 @@ class ExceptionStrategyTest extends TestCase { use EventListenerIntrospectionTrait; + /** + * @var ExceptionStrategy + */ + private $strategy; + public function setUp() { $this->strategy = new ExceptionStrategy(); @@ -81,7 +86,7 @@ public function testCatchesApplicationExceptions() $this->strategy->prepareExceptionViewModel($event); $response = $event->getResponse(); - $this->assertTrue($response->isServerError()); + $this->assertEquals(500, $response->getStatusCode()); $model = $event->getResult(); $this->assertInstanceOf(ViewModel::class, $model); @@ -105,7 +110,7 @@ public function testCatchesUnknownErrorTypes() $this->strategy->prepareExceptionViewModel($event); $response = $event->getResponse(); - $this->assertTrue($response->isServerError()); + $this->assertEquals(500, $response->getStatusCode()); } public function testEmptyErrorInEventResultsInNoOperations() @@ -136,7 +141,8 @@ public function testDoesNothingIfEventResultIsAResponse() $event->setResult($response); $event->setError('foobar'); - $this->assertNull($this->strategy->prepareExceptionViewModel($event)); + $this->strategy->prepareExceptionViewModel($event); + $this->assertSame($response, $event->getResponse()); } public function testAttachesListenerAtExpectedPriority() @@ -167,7 +173,7 @@ public function testReuseResponseStatusCodeIfItExists() { $event = new MvcEvent(); $response = new Response(); - $response->setStatusCode(401); + $response = $response->withStatus(401); $event->setResponse($response); $this->strategy->prepareExceptionViewModel($event); $response = $event->getResponse(); diff --git a/test/View/InjectTemplateListenerTest.php b/test/View/InjectTemplateListenerTest.php index 9e07eece1..abcc34deb 100644 --- a/test/View/InjectTemplateListenerTest.php +++ b/test/View/InjectTemplateListenerTest.php @@ -10,12 +10,12 @@ namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\Test\EventListenerIntrospectionTrait; -use Zend\Mvc\ModuleRouteListener; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; use Zend\Mvc\View\Http\InjectTemplateListener; +use Zend\Router\RouteResult; use Zend\View\Model\ViewModel; use ZendTest\Mvc\Controller\TestAsset\SampleController; @@ -23,23 +23,28 @@ class InjectTemplateListenerTest extends TestCase { use EventListenerIntrospectionTrait; + /** + * @var MvcEvent + */ + private $event; + public function setUp() { - $controllerMap = [ - 'MappedNs' => true, - 'ZendTest\MappedNs' => true, - ]; $this->listener = new InjectTemplateListener(); - $this->listener->setControllerMap($controllerMap); $this->event = new MvcEvent(); - $this->routeMatch = new RouteMatch([]); - $this->event->setRouteMatch($this->routeMatch); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $this->event->setRequest($request); } public function testSetsTemplateBasedOnRouteMatchIfNoTemplateIsSetOnViewModel() { - $this->routeMatch->setParam('controller', 'Foo\Controller\SomewhatController'); - $this->routeMatch->setParam('action', 'useful'); + $result = RouteResult::fromRouteMatch([ + 'controller' => 'Foo\Controller\SomewhatController', + 'action' => 'useful', + ]); + $this->event->setRequest( + $this->event->getRequest()->withAttribute(RouteResult::class, $result) + ); $model = new ViewModel(); $this->event->setResult($model); @@ -51,7 +56,12 @@ public function testSetsTemplateBasedOnRouteMatchIfNoTemplateIsSetOnViewModel() public function testUsesModuleAndControllerOnlyIfNoActionInRouteMatch() { - $this->routeMatch->setParam('controller', 'Foo\Controller\SomewhatController'); + $result = RouteResult::fromRouteMatch([ + 'controller' => 'Foo\Controller\SomewhatController', + ]); + $this->event->setRequest( + $this->event->getRequest()->withAttribute(RouteResult::class, $result) + ); $model = new ViewModel(); $this->event->setResult($model); @@ -63,7 +73,12 @@ public function testUsesModuleAndControllerOnlyIfNoActionInRouteMatch() public function testNormalizesLiteralControllerNameIfNoNamespaceSeparatorPresent() { - $this->routeMatch->setParam('controller', 'SomewhatController'); + $result = RouteResult::fromRouteMatch([ + 'controller' => 'SomewhatController', + ]); + $this->event->setRequest( + $this->event->getRequest()->withAttribute(RouteResult::class, $result) + ); $model = new ViewModel(); $this->event->setResult($model); @@ -75,8 +90,13 @@ public function testNormalizesLiteralControllerNameIfNoNamespaceSeparatorPresent public function testNormalizesNamesToLowercase() { - $this->routeMatch->setParam('controller', 'Somewhat.DerivedController'); - $this->routeMatch->setParam('action', 'some-UberCool'); + $result = RouteResult::fromRouteMatch([ + 'controller' => 'Somewhat.DerivedController', + 'action' => 'some-UberCool', + ]); + $this->event->setRequest( + $this->event->getRequest()->withAttribute(RouteResult::class, $result) + ); $model = new ViewModel(); $this->event->setResult($model); @@ -94,8 +114,13 @@ public function testLackOfViewModelInResultBypassesTemplateInjection() public function testBypassesTemplateInjectionIfResultViewModelAlreadyHasATemplate() { - $this->routeMatch->setParam('controller', 'Foo\Controller\SomewhatController'); - $this->routeMatch->setParam('action', 'useful'); + $result = RouteResult::fromRouteMatch([ + 'controller' => 'Foo\Controller\SomewhatController', + 'action' => 'useful', + ]); + $this->event->setRequest( + $this->event->getRequest()->withAttribute(RouteResult::class, $result) + ); $model = new ViewModel(); $model->setTemplate('custom'); @@ -118,84 +143,14 @@ public function testMapsSubNamespaceToSubDirectory() $this->assertEquals('zend-test/mvc/test-asset/sample', $myViewModel->getTemplate()); } - public function testMapsSubNamespaceToSubDirectoryWithControllerFromRouteMatch() - { - $this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, 'Aj\Controller\SweetAppleAcres\Reports'); - $this->routeMatch->setParam('controller', 'CiderSales'); - $this->routeMatch->setParam('action', 'PinkiePieRevenue'); - - $moduleRouteListener = new ModuleRouteListener; - $moduleRouteListener->onRoute($this->event); - - $model = new ViewModel(); - $this->event->setResult($model); - $this->listener->injectTemplate($this->event); - - $this->assertEquals('aj/sweet-apple-acres/reports/cider-sales/pinkie-pie-revenue', $model->getTemplate()); - } - - public function testMapsSubNamespaceToSubDirectoryWithControllerFromRouteMatchHavingSubNamespace() - { - $this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, 'Aj\Controller\SweetAppleAcres\Reports'); - $this->routeMatch->setParam('controller', 'Sub\CiderSales'); - $this->routeMatch->setParam('action', 'PinkiePieRevenue'); - - $moduleRouteListener = new ModuleRouteListener; - $moduleRouteListener->onRoute($this->event); - - $model = new ViewModel(); - $this->event->setResult($model); - $this->listener->injectTemplate($this->event); - - $this->assertEquals('aj/sweet-apple-acres/reports/sub/cider-sales/pinkie-pie-revenue', $model->getTemplate()); - } - - public function testMapsSubNamespaceToSubDirectoryWithControllerFromEventTarget() - { - $this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, 'ZendTest\Mvc\Controller\TestAsset'); - $this->routeMatch->setParam('action', 'test'); - - $moduleRouteListener = new ModuleRouteListener; - $moduleRouteListener->onRoute($this->event); - - $myViewModel = new ViewModel(); - $myController = new SampleController(); - - $this->event->setTarget($myController); - $this->event->setResult($myViewModel); - $this->listener->injectTemplate($this->event); - - $this->assertEquals('zend-test/mvc/test-asset/sample/test', $myViewModel->getTemplate()); - } - - public function testMapsSubNamespaceToSubDirectoryWithControllerFromEventTargetShouldMatchControllerFromRouteParam() - { - $this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, 'ZendTest\Mvc\Controller'); - $this->routeMatch->setParam('controller', 'TestAsset\SampleController'); - $this->routeMatch->setParam('action', 'test'); - - $moduleRouteListener = new ModuleRouteListener; - $moduleRouteListener->onRoute($this->event); - - $myViewModel = new ViewModel(); - $this->event->setResult($myViewModel); - $this->listener->injectTemplate($this->event); - - $template1 = $myViewModel->getTemplate(); - - $myViewModel = new ViewModel(); - $myController = new SampleController(); - - $this->event->setTarget($myController); - $this->event->setResult($myViewModel); - $this->listener->injectTemplate($this->event); - - $this->assertEquals($template1, $myViewModel->getTemplate()); - } - public function testControllerMatchedByMapIsInflected() { - $this->routeMatch->setParam('controller', 'MappedNs\SubNs\Controller\Sample'); + $result = RouteResult::fromRouteMatch([ + 'controller' => 'MappedNs\SubNs\Controller\Sample', + ]); + $this->event->setRequest( + $this->event->getRequest()->withAttribute(RouteResult::class, $result) + ); $myViewModel = new ViewModel(); $this->event->setResult($myViewModel); @@ -203,7 +158,6 @@ public function testControllerMatchedByMapIsInflected() $this->assertEquals('mapped-ns/sub-ns/sample', $myViewModel->getTemplate()); - $this->listener->setControllerMap(['ZendTest' => true]); $myViewModel = new ViewModel(); $myController = new SampleController(); $this->event->setTarget($myController); @@ -242,30 +196,6 @@ public function testControllerMapMatchedPrefixReplacedByStringValue() $this->assertEquals('string-value/index', $template); } - public function testUsingNamespaceRouteParameterGivesSameResultAsFullControllerParameter() - { - $this->routeMatch->setParam('controller', 'MappedNs\Foo\Controller\Bar\Baz\Sample'); - $myViewModel = new ViewModel(); - - $this->event->setResult($myViewModel); - $this->listener->injectTemplate($this->event); - - $template1 = $myViewModel->getTemplate(); - - $this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, 'MappedNs\Foo\Controller\Bar'); - $this->routeMatch->setParam('controller', 'Baz\Sample'); - - $moduleRouteListener = new ModuleRouteListener; - $moduleRouteListener->onRoute($this->event); - - $myViewModel = new ViewModel(); - - $this->event->setResult($myViewModel); - $this->listener->injectTemplate($this->event); - - $this->assertEquals($template1, $myViewModel->getTemplate()); - } - public function testControllerMapOnlyFullNamespaceMatches() { $this->listener->setControllerMap([ @@ -327,11 +257,17 @@ public function testDetachesListeners() $this->assertEquals(0, count($listeners)); } - public function testPrefersRouteMatchController() + public function testPrefersRouteResultController() { - $this->assertFalse($this->listener->isPreferRouteMatchController()); - $this->listener->setPreferRouteMatchController(true); - $this->routeMatch->setParam('controller', 'Some\Other\Service\Namespace\Controller\Sample'); + $this->assertFalse($this->listener->isPreferRouteResultController()); + $this->listener->setPreferRouteResultController(true); + + $result = RouteResult::fromRouteMatch([ + 'controller' => 'Some\Other\Service\Namespace\Controller\Sample', + ]); + $this->event->setRequest( + $this->event->getRequest()->withAttribute(RouteResult::class, $result) + ); $myViewModel = new ViewModel(); $myController = new SampleController(); @@ -344,19 +280,19 @@ public function testPrefersRouteMatchController() public function testPrefersRouteMatchControllerWithRouteMatchAndControllerMap() { - $this->assertFalse($this->listener->isPreferRouteMatchController()); + $this->assertFalse($this->listener->isPreferRouteResultController()); $controllerMap = [ 'Some\Other\Service\Namespace\Controller\Sample' => 'another/sample' ]; - $this->routeMatch->setParam('prefer_route_match_controller', true); - $this->routeMatch->setParam('controller', 'Some\Other\Service\Namespace\Controller\Sample'); - - $preferRouteMatchControllerRouteMatchConfig = $this->routeMatch->getParam( - 'prefer_route_match_controller', - false + $result = RouteResult::fromRouteMatch([ + 'prefer_route_result_controller' => true, + 'controller' => 'Some\Other\Service\Namespace\Controller\Sample', + ]); + $this->event->setRequest( + $this->event->getRequest()->withAttribute(RouteResult::class, $result) ); - $this->listener->setPreferRouteMatchController($preferRouteMatchControllerRouteMatchConfig); + $this->listener->setControllerMap($controllerMap); $myViewModel = new ViewModel(); diff --git a/test/View/InjectViewModelListenerTest.php b/test/View/InjectViewModelListenerTest.php index 1e841e46b..731e4c69e 100644 --- a/test/View/InjectViewModelListenerTest.php +++ b/test/View/InjectViewModelListenerTest.php @@ -14,7 +14,6 @@ use Zend\EventManager\Test\EventListenerIntrospectionTrait; use Zend\Mvc\MvcEvent; use Zend\Mvc\View\Http\InjectViewModelListener; -use Zend\Router\RouteMatch; use Zend\View\Model\ViewModel; class InjectViewModelListenerTest extends TestCase @@ -25,8 +24,6 @@ public function setUp() { $this->listener = new InjectViewModelListener(); $this->event = new MvcEvent(); - $this->routeMatch = new RouteMatch([]); - $this->event->setRouteMatch($this->routeMatch); } public function testReplacesEventModelWithChildModelIfChildIsMarkedTerminal() diff --git a/test/View/RouteNotFoundStrategyTest.php b/test/View/RouteNotFoundStrategyTest.php index 24c597fdd..9e4cc03b4 100644 --- a/test/View/RouteNotFoundStrategyTest.php +++ b/test/View/RouteNotFoundStrategyTest.php @@ -10,9 +10,10 @@ namespace ZendTest\Mvc\View; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; use Zend\EventManager\EventManager; use Zend\EventManager\Test\EventListenerIntrospectionTrait; -use Zend\Http\Response; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; use Zend\Mvc\View\Http\RouteNotFoundStrategy; @@ -50,7 +51,7 @@ public function testLeavesReturnedMessageIntact($result, $assertion) { $response = new Response(); $event = new MvcEvent(); - $response->setStatusCode(404); + $response = $response->withStatus(404); $event->setResponse($response); $event->setResult($result); @@ -82,12 +83,11 @@ public function test404ErrorsInject404ResponseStatusCode() 'error-controller-invalid' => Application::ERROR_CONTROLLER_INVALID, 'error-router-no-match' => Application::ERROR_ROUTER_NO_MATCH, ]; - $event->setResponse($response); foreach ($errors as $key => $error) { - $response->setStatusCode(200); + $event->setResponse($response); $event->setError($error); $this->strategy->detectNotFoundError($event); - $this->assertTrue($response->isNotFound(), 'Failed asserting against ' . $key); + $this->assertEquals(404, $event->getResponse()->getStatusCode(), 'Failed asserting against ' . $key); } } @@ -100,11 +100,10 @@ public function testRouterAndDispatchErrorsInjectReasonInViewModelWhenAllowed() 'error-controller-invalid' => Application::ERROR_CONTROLLER_INVALID, 'error-router-no-match' => Application::ERROR_ROUTER_NO_MATCH, ]; - $event->setResponse($response); foreach ([true, false] as $allow) { $this->strategy->setDisplayNotFoundReason($allow); foreach ($errors as $key => $error) { - $response->setStatusCode(200); + $event->setResponse($response); $event->setResult(null); $event->setError($error); $this->strategy->detectNotFoundError($event); @@ -132,10 +131,10 @@ public function testNon404ErrorsInjectNoStatusCode() null, ]; foreach ($errors as $error) { - $response->setStatusCode(200); + $event->setResponse($response); $event->setError($error); $this->strategy->detectNotFoundError($event); - $this->assertFalse($response->isNotFound()); + $this->assertNotEquals(404, $event->getResponse()->getStatusCode()); } } @@ -143,8 +142,8 @@ public function testResponseAsResultDoesNotPrepare404ViewModel() { $response = new Response(); $event = new MvcEvent(); - $event->setResponse($response) - ->setResult($response); + $event->setResponse($response); + $event->setResult($response); $this->strategy->prepareNotFoundViewModel($event); $model = $event->getResult(); @@ -161,7 +160,6 @@ public function testNon404ResponseDoesNotPrepare404ViewModel() { $response = new Response(); $event = new MvcEvent(); - $response->setStatusCode(200); $event->setResponse($response); $this->strategy->prepareNotFoundViewModel($event); @@ -179,7 +177,7 @@ public function test404ResponsePrepares404ViewModelWithTemplateFromStrategy() { $response = new Response(); $event = new MvcEvent(); - $response->setStatusCode(404); + $response = $response->withStatus(404); $event->setResponse($response); $this->strategy->prepareNotFoundViewModel($event); @@ -193,11 +191,11 @@ public function test404ResponsePrepares404ViewModelWithTemplateFromStrategy() public function test404ResponsePrepares404ViewModelWithReasonWhenAllowed() { $response = new Response(); + $response = $response->withStatus(404); $event = new MvcEvent(); foreach ([true, false] as $allow) { $this->strategy->setDisplayNotFoundReason($allow); - $response->setStatusCode(404); $event->setResult(null); $event->setResponse($response); $this->strategy->prepareNotFoundViewModel($event); @@ -216,13 +214,13 @@ public function test404ResponsePrepares404ViewModelWithReasonWhenAllowed() public function test404ResponsePrepares404ViewModelWithExceptionWhenAllowed() { $response = new Response(); + $response = $response->withStatus(404); $event = new MvcEvent(); $exception = new \Exception(); $event->setParam('exception', $exception); foreach ([true, false] as $allow) { $this->strategy->setDisplayExceptions($allow); - $response->setStatusCode(404); $event->setResult(null); $event->setResponse($response); $this->strategy->prepareNotFoundViewModel($event); @@ -242,6 +240,7 @@ public function test404ResponsePrepares404ViewModelWithExceptionWhenAllowed() public function test404ResponsePrepares404ViewModelWithControllerWhenAllowed() { $response = new Response(); + $response = $response->withStatus(404); $event = new MvcEvent(); $controller = 'some-or-other'; $controllerClass = 'Some\Controller\OrOtherController'; @@ -251,7 +250,6 @@ public function test404ResponsePrepares404ViewModelWithControllerWhenAllowed() foreach (['setDisplayNotFoundReason', 'setDisplayExceptions'] as $method) { foreach ([true, false] as $allow) { $this->strategy->$method($allow); - $response->setStatusCode(404); $event->setResult(null); $event->setResponse($response); $this->strategy->prepareNotFoundViewModel($event); @@ -282,8 +280,8 @@ public function testInjectsHttpResponseIntoEventIfNoneAlreadyPresent() $event->setError($error); $this->strategy->detectNotFoundError($event); $response = $event->getResponse(); - $this->assertInstanceOf(Response::class, $response); - $this->assertTrue($response->isNotFound(), 'Failed asserting against ' . $key); + $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertEquals(404, $response->getStatusCode(), 'Failed asserting against ' . $key); } } From 4cb46764fb4266061e7ef1dcc77db8b6493562a0 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 26 Nov 2017 10:25:40 +1000 Subject: [PATCH 14/51] Initial PSR-7 refactoring for controllers and plugins --- src/Controller/AbstractActionController.php | 29 +- src/Controller/AbstractController.php | 72 +--- src/Controller/AbstractRestfulController.php | 173 +++++----- src/Controller/ControllerManager.php | 7 +- src/Controller/Dispatchable.php | 16 + .../LazyControllerAbstractFactory.php | 13 +- src/Controller/MiddlewareController.php | 54 +-- src/Controller/Plugin/AbstractPlugin.php | 4 +- .../Plugin/CreateHttpNotFoundModel.php | 4 +- src/Controller/Plugin/Forward.php | 25 +- src/Controller/Plugin/Params.php | 47 +-- src/Controller/Plugin/PluginInterface.php | 4 +- src/Controller/Plugin/Redirect.php | 45 ++- src/Controller/Plugin/Url.php | 26 +- src/Controller/PluginManager.php | 16 +- src/View/Http/ViewManager.php | 11 +- test/Controller/AbstractControllerTest.php | 4 +- test/Controller/ActionControllerTest.php | 72 ++-- test/Controller/MiddlewareControllerTest.php | 48 +-- .../AcceptableViewModelSelectorTest.php | 5 +- .../Plugin/CreateHttpNotFoundModelTest.php | 7 +- test/Controller/Plugin/ForwardTest.php | 36 +- test/Controller/Plugin/ParamsTest.php | 119 +++---- test/Controller/Plugin/RedirectTest.php | 111 +++---- test/Controller/Plugin/UrlTest.php | 93 ++---- test/Controller/RestfulControllerTest.php | 314 ++++++++++-------- .../TestAsset/ForwardController.php | 3 +- .../TestAsset/RestfulTestController.php | 25 +- .../TestAsset/UneventfulController.php | 10 +- 29 files changed, 657 insertions(+), 736 deletions(-) create mode 100644 src/Controller/Dispatchable.php diff --git a/src/Controller/AbstractActionController.php b/src/Controller/AbstractActionController.php index 0c6fa4704..e512a4e79 100644 --- a/src/Controller/AbstractActionController.php +++ b/src/Controller/AbstractActionController.php @@ -9,8 +9,10 @@ namespace Zend\Mvc\Controller; +use Zend\Diactoros\Response; use Zend\Mvc\Exception; use Zend\Mvc\MvcEvent; +use Zend\Router\RouteResult; use Zend\View\Model\ViewModel; /** @@ -43,12 +45,22 @@ public function indexAction() public function notFoundAction() { $event = $this->getEvent(); - $routeMatch = $event->getRouteMatch(); - if ($routeMatch) { - // @TODO figure out what is the course of action in case of missing RouteMatch - $routeMatch->setParam('action', 'not-found'); + $request = $event->getRequest(); + /** @var RouteResult $routeResult */ + // + $routeResult = $request->getAttribute(RouteResult::class); + if (! $routeResult) { + // this should never be reached normally + throw new Exception\DomainException('Missing route result'); } + $params = $routeResult->getMatchedParams(); + $params['action'] = 'not-found'; + $routeResult = $routeResult->withMatchedParams($params); + $request = $request->withAttribute(RouteResult::class, $routeResult); + $event->setRequest($request); + $response = $this->getResponse() ?? new Response(); + $event->setResponse($response->withStatus(404)); $helper = $this->plugin('createHttpNotFoundModel'); return $helper($event->getResponse()); } @@ -62,16 +74,17 @@ public function notFoundAction() */ public function onDispatch(MvcEvent $e) { - $routeMatch = $e->getRouteMatch(); - if (! $routeMatch) { + /** @var RouteResult $routeResult */ + $routeResult = $e->getRequest()->getAttribute(RouteResult::class); + if (! $routeResult) { /** * @todo Determine requirements for when route match is missing. * Potentially allow pulling directly from request metadata? */ - throw new Exception\DomainException('Missing route matches; unsure how to retrieve action'); + throw new Exception\DomainException('Missing route result; unsure how to retrieve action'); } - $action = $routeMatch->getParam('action', 'not-found'); + $action = $routeResult->getMatchedParams()['action'] ?? 'not-found'; $method = static::getMethodFromAction($action); if (! method_exists($this, $method)) { diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index 383f9e694..9fb72a1af 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -9,18 +9,16 @@ namespace Zend\Mvc\Controller; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface as Request; +use Zend\Diactoros\Response; use Zend\EventManager\EventInterface as Event; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerInterface; -use Zend\Http\PhpEnvironment\Response as HttpResponse; -use Zend\Http\Request as HttpRequest; use Zend\Mvc\InjectApplicationEventInterface; use Zend\Mvc\MvcEvent; use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\DispatchableInterface as Dispatchable; -use Zend\Stdlib\RequestInterface as Request; -use Zend\Stdlib\ResponseInterface as Response; /** * Abstract controller @@ -46,16 +44,6 @@ abstract class AbstractController implements */ protected $plugins; - /** - * @var Request - */ - protected $request; - - /** - * @var Response - */ - protected $response; - /** * @var MvcEvent */ @@ -83,26 +71,18 @@ abstract public function onDispatch(MvcEvent $e); * Dispatch a request * * @events dispatch.pre, dispatch.post - * @param Request $request - * @param null|Response $response - * @return Response|mixed + * @param Request $request + * @return mixed|Response */ - public function dispatch(Request $request, Response $response = null) + public function dispatch(Request $request) { - $this->request = $request; - if (! $response) { - $response = new HttpResponse(); - } - $this->response = $response; - $e = $this->getEvent(); $e->setName(MvcEvent::EVENT_DISPATCH); $e->setRequest($request); - $e->setResponse($response); $e->setTarget($this); $result = $this->getEventManager()->triggerEventUntil(function ($test) { - return ($test instanceof Response); + return ($test instanceof ResponseInterface); }, $e); if ($result->stopped()) { @@ -115,38 +95,29 @@ public function dispatch(Request $request, Response $response = null) /** * Get request object * - * @return Request + * @return null|Request */ - public function getRequest() + public function getRequest() : ?Request { - if (! $this->request) { - $this->request = new HttpRequest(); - } - - return $this->request; + return $this->getEvent()->getRequest(); } /** * Get response object * - * @return Response + * @return ResponseInterface */ - public function getResponse() + public function getResponse() : ?ResponseInterface { - if (! $this->response) { - $this->response = new HttpResponse(); - } - - return $this->response; + return $this->getEvent()->getResponse(); } /** * Set the event manager instance used by this context * - * @param EventManagerInterface $events - * @return AbstractController + * @param EventManagerInterface $events */ - public function setEventManager(EventManagerInterface $events) + public function setEventManager(EventManagerInterface $events) : void { $className = get_class($this); @@ -163,8 +134,6 @@ public function setEventManager(EventManagerInterface $events) $this->events = $events; $this->attachDefaultListeners(); - - return $this; } /** @@ -220,10 +189,8 @@ public function getEvent() /** * Get plugin manager - * - * @return PluginManager */ - public function getPluginManager() + public function getPluginManager() : PluginManager { if (! $this->plugins) { $this->setPluginManager(new PluginManager(new ServiceManager())); @@ -236,15 +203,12 @@ public function getPluginManager() /** * Set plugin manager * - * @param PluginManager $plugins - * @return AbstractController + * @param PluginManager $plugins */ - public function setPluginManager(PluginManager $plugins) + public function setPluginManager(PluginManager $plugins) : void { $this->plugins = $plugins; $this->plugins->setController($this); - - return $this; } /** diff --git a/src/Controller/AbstractRestfulController.php b/src/Controller/AbstractRestfulController.php index d40345b12..a6b78a7c9 100644 --- a/src/Controller/AbstractRestfulController.php +++ b/src/Controller/AbstractRestfulController.php @@ -9,12 +9,14 @@ namespace Zend\Mvc\Controller; -use Zend\Http\Request as HttpRequest; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Zend\Diactoros\Response; +use Zend\Diactoros\Stream; use Zend\Json\Json; use Zend\Mvc\Exception; use Zend\Mvc\MvcEvent; -use Zend\Stdlib\RequestInterface as Request; -use Zend\Stdlib\ResponseInterface as Response; +use Zend\Router\RouteResult; /** * Abstract RESTful controller @@ -101,7 +103,9 @@ public function getIdentifierName() */ public function create($data) { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -116,7 +120,9 @@ public function create($data) */ public function delete($id) { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -133,7 +139,9 @@ public function delete($id) */ public function deleteList($data) { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -148,7 +156,9 @@ public function deleteList($data) */ public function get($id) { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -162,7 +172,9 @@ public function get($id) */ public function getList() { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -180,7 +192,9 @@ public function getList() */ public function head($id = null) { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -200,7 +214,9 @@ public function head($id = null) */ public function options() { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -219,7 +235,9 @@ public function options() */ public function patch($id, $data) { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -237,7 +255,9 @@ public function patch($id, $data) */ public function replaceList($data) { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -255,7 +275,9 @@ public function replaceList($data) */ public function patchList($data) { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -271,7 +293,9 @@ public function patchList($data) */ public function update($id, $data) { - $this->response->setStatusCode(405); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(405) + ); return [ 'content' => 'Method Not Allowed' @@ -285,35 +309,15 @@ public function update($id, $data) */ public function notFoundAction() { - $this->response->setStatusCode(404); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withStatus(404) + ); return [ 'content' => 'Page not found' ]; } - /** - * Dispatch a request - * - * If the route match includes an "action" key, then this acts basically like - * a standard action controller. Otherwise, it introspects the HTTP method - * to determine how to handle the request, and which method to delegate to. - * - * @events dispatch.pre, dispatch.post - * @param Request $request - * @param null|Response $response - * @return mixed|Response - * @throws Exception\InvalidArgumentException - */ - public function dispatch(Request $request, Response $response = null) - { - if (! $request instanceof HttpRequest) { - throw new Exception\InvalidArgumentException('Expected an HTTP request'); - } - - return parent::dispatch($request, $response); - } - /** * Handle the request * @@ -324,19 +328,20 @@ public function dispatch(Request $request, Response $response = null) */ public function onDispatch(MvcEvent $e) { - $routeMatch = $e->getRouteMatch(); - if (! $routeMatch) { + /** @var RouteResult $routeResult */ + $routeResult = $e->getRequest()->getAttribute(RouteResult::class); + if (! $routeResult) { /** * @todo Determine requirements for when route match is missing. * Potentially allow pulling directly from request metadata? */ - throw new Exception\DomainException('Missing route matches; unsure how to retrieve action'); + throw new Exception\DomainException('Missing route result; unsure how to retrieve action'); } $request = $e->getRequest(); // Was an "action" requested? - $action = $routeMatch->getParam('action', false); + $action = $routeResult->getMatchedParams()['action'] ?? null; if ($action) { // Handle arbitrary methods, ending in Action $method = static::getMethodFromAction($action); @@ -359,7 +364,7 @@ public function onDispatch(MvcEvent $e) break; // DELETE case 'delete': - $id = $this->getIdentifier($routeMatch, $request); + $id = $this->getIdentifier($request); if ($id !== false) { $action = 'delete'; @@ -374,7 +379,7 @@ public function onDispatch(MvcEvent $e) break; // GET case 'get': - $id = $this->getIdentifier($routeMatch, $request); + $id = $this->getIdentifier($request); if ($id !== false) { $action = 'get'; $return = $this->get($id); @@ -385,25 +390,26 @@ public function onDispatch(MvcEvent $e) break; // HEAD case 'head': - $id = $this->getIdentifier($routeMatch, $request); + $id = $this->getIdentifier($request); if ($id === false) { $id = null; } $action = 'head'; $headResult = $this->head($id); - $response = ($headResult instanceof Response) ? clone $headResult : $e->getResponse(); - $response->setContent(''); - $return = $response; + $response = ($headResult instanceof ResponseInterface) + ? $headResult + : $e->getResponse() ?? new Response(); + $return = $response->withBody(new Stream('php://memory', 'wb+')); break; // OPTIONS case 'options': $action = 'options'; - $this->options(); - $return = $e->getResponse(); + $response = $this->options(); + $return = $response ?? $e->getResponse() ?? new Response(); break; // PATCH case 'patch': - $id = $this->getIdentifier($routeMatch, $request); + $id = $this->getIdentifier($request); $data = $this->processBodyContent($request); if ($id !== false) { @@ -412,17 +418,8 @@ public function onDispatch(MvcEvent $e) break; } - // TODO: This try-catch should be removed in the future, but it - // will create a BC break for pre-2.2.0 apps that expect a 405 - // instead of going to patchList - try { - $action = 'patchList'; - $return = $this->patchList($data); - } catch (Exception\RuntimeException $ex) { - $response = $e->getResponse(); - $response->setStatusCode(405); - return $response; - } + $action = 'patchList'; + $return = $this->patchList($data); break; // POST case 'post': @@ -431,7 +428,7 @@ public function onDispatch(MvcEvent $e) break; // PUT case 'put': - $id = $this->getIdentifier($routeMatch, $request); + $id = $this->getIdentifier($request); $data = $this->processBodyContent($request); if ($id !== false) { @@ -445,12 +442,15 @@ public function onDispatch(MvcEvent $e) break; // All others... default: - $response = $e->getResponse(); - $response->setStatusCode(405); + $response = ($e->getResponse() ?? new Response())->withStatus(405); return $response; } - $routeMatch->setParam('action', $action); + $params = $routeResult->getMatchedParams(); + $params['action'] = $action; + $routeResult = $routeResult->withMatchedParams($params); + $request = $request->withAttribute(RouteResult::class, $routeResult); + $e->setRequest($request); $e->setResult($return); return $return; } @@ -458,36 +458,39 @@ public function onDispatch(MvcEvent $e) /** * Process post data and call create * - * @param Request $request + * @param ServerRequestInterface $request * @return mixed * @throws Exception\DomainException If a JSON request was made, but no * method for parsing JSON is available. */ - public function processPostData(Request $request) + public function processPostData(ServerRequestInterface $request) { if ($this->requestHasContentType($request, self::CONTENT_TYPE_JSON)) { - return $this->create($this->jsonDecode($request->getContent())); + return $this->create($this->jsonDecode($request->getBody()->__toString())); } - return $this->create($request->getPost()->toArray()); + $payload = $request->getParsedBody() ?: []; + return $this->create($payload); } /** * Check if request has certain content type * - * @param Request $request + * @param ServerRequestInterface $request * @param string|null $contentType * @return bool + * @throws \Exception */ - public function requestHasContentType(Request $request, $contentType = '') + public function requestHasContentType(ServerRequestInterface $request, $contentType = '') : bool { - /** @var $headerContentType \Zend\Http\Header\ContentType */ - $headerContentType = $request->getHeaders()->get('content-type'); - if (! $headerContentType) { + $headersContentType = $request->getHeader('content-type'); + if (empty($headersContentType)) { return false; } - $requestedContentType = $headerContentType->getFieldValue(); + // @TODO implement proper content negotiation + + $requestedContentType = array_pop($headersContentType); if (false !== strpos($requestedContentType, ';')) { $headerData = explode(';', $requestedContentType); $requestedContentType = array_shift($headerData); @@ -549,24 +552,18 @@ public function addHttpMethodHandler($method, /* Callable */ $handler) * Attempts to see if an identifier was passed in either the URI or the * query string, returning it if found. Otherwise, returns a boolean false. * - * @param \Zend\Router\RouteMatch $routeMatch - * @param Request $request + * @param ServerRequestInterface $request * @return false|mixed */ - protected function getIdentifier($routeMatch, $request) + protected function getIdentifier(ServerRequestInterface $request) { $identifier = $this->getIdentifierName(); - $id = $routeMatch->getParam($identifier, false); - if ($id !== false) { - return $id; - } - - $id = $request->getQuery()->get($identifier, false); + $id = $request->getAttribute($identifier, false); if ($id !== false) { return $id; } - return false; + return $request->getQueryParams()[$identifier] ?? false; } /** @@ -583,13 +580,13 @@ protected function getIdentifier($routeMatch, $request) * @throws Exception\DomainException If a JSON request was made, but no * method for parsing JSON is available. */ - protected function processBodyContent($request) + protected function processBodyContent(ServerRequestInterface $request) { - $content = $request->getContent(); + $content = $request->getBody()->__toString(); // JSON content? decode and return it. if ($this->requestHasContentType($request, self::CONTENT_TYPE_JSON)) { - return $this->jsonDecode($request->getContent()); + return $this->jsonDecode($content); } parse_str($content, $parsedParams); diff --git a/src/Controller/ControllerManager.php b/src/Controller/ControllerManager.php index 02de0a7df..e40db7a4d 100644 --- a/src/Controller/ControllerManager.php +++ b/src/Controller/ControllerManager.php @@ -15,7 +15,6 @@ use Zend\ServiceManager\AbstractPluginManager; use Zend\ServiceManager\ConfigInterface; use Zend\ServiceManager\Exception\InvalidServiceException; -use Zend\Stdlib\DispatchableInterface; /** * Manager for loading controllers @@ -36,7 +35,7 @@ class ControllerManager extends AbstractPluginManager * * @var string */ - protected $instanceOf = DispatchableInterface::class; + protected $instanceOf = Dispatchable::class; /** * Constructor @@ -81,7 +80,7 @@ public function validate($plugin) * pass. * * @param ContainerInterface $container - * @param DispatchableInterface $controller + * @param Dispatchable $controller */ public function injectEventManager(ContainerInterface $container, $controller) { @@ -99,7 +98,7 @@ public function injectEventManager(ContainerInterface $container, $controller) * Initializer: inject plugin manager * * @param ContainerInterface $container - * @param DispatchableInterface $controller + * @param Dispatchable $controller */ public function injectPluginManager(ContainerInterface $container, $controller) { diff --git a/src/Controller/Dispatchable.php b/src/Controller/Dispatchable.php new file mode 100644 index 000000000..7eafdf729 --- /dev/null +++ b/src/Controller/Dispatchable.php @@ -0,0 +1,16 @@ + 'ConsoleAdapter', FilterPluginManager::class => 'FilterManager', HydratorPluginManager::class => 'HydratorManager', InputFilterPluginManager::class => 'InputFilterManager', @@ -100,7 +97,7 @@ class LazyControllerAbstractFactory implements AbstractFactoryInterface /** * {@inheritDoc} * - * @return DispatchableInterface + * @return Dispatchable */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { @@ -133,7 +130,7 @@ public function canCreate(ContainerInterface $container, $requestedName) return false; } - return in_array(DispatchableInterface::class, class_implements($requestedName), true); + return in_array(Dispatchable::class, class_implements($requestedName), true); } /** @@ -148,10 +145,8 @@ public function canCreate(ContainerInterface $container, $requestedName) private function resolveParameter(ContainerInterface $container, $requestedName) { /** - * @param ReflectionClass $parameter + * @param ReflectionParameter $parameter * @return mixed - * @throws ServiceNotFoundException If type-hinted parameter cannot be - * resolved to a service in the container. */ return function (ReflectionParameter $parameter) use ($container, $requestedName) { if ($parameter->isArray() @@ -166,7 +161,7 @@ private function resolveParameter(ContainerInterface $container, $requestedName) } if (! $parameter->getClass()) { - return; + return null; } $type = $parameter->getClass()->getName(); diff --git a/src/Controller/MiddlewareController.php b/src/Controller/MiddlewareController.php index 3060f64d9..bac347231 100644 --- a/src/Controller/MiddlewareController.php +++ b/src/Controller/MiddlewareController.php @@ -10,21 +10,18 @@ namespace Zend\Mvc\Controller; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Message\ServerRequestInterface as Request; use Zend\EventManager\EventManagerInterface; -use Zend\Http\Request; use Zend\Mvc\Exception\ReachedFinalHandlerException; use Zend\Mvc\Exception\RuntimeException; use Zend\Mvc\MvcEvent; -use Zend\Psr7Bridge\Psr7ServerRequest; -use Zend\Router\RouteMatch; use Zend\Stratigility\Delegate\CallableDelegateDecorator; use Zend\Stratigility\MiddlewarePipe; /** * @internal don't use this in your codebase, or else @ocramius will hunt you * down. This is just an internal hack to make middleware trigger - * 'dispatch' events attached to the DispatchableInterface identifier. + * 'dispatch' events attached to the Dispatchable identifier. * * Specifically, it will receive a @see MiddlewarePipe and a * @see ResponseInterface prototype, and then dispatch the pipe whilst still @@ -66,13 +63,9 @@ public function __construct( */ public function onDispatch(MvcEvent $e) { - $routeMatch = $e->getRouteMatch(); - $psr7Request = $this->populateRequestParametersFromRoute( - $this->loadRequest()->withAttribute(RouteMatch::class, $routeMatch), - $routeMatch - ); + $request = $e->getRequest(); - $result = $this->pipe->process($psr7Request, new CallableDelegateDecorator( + $result = $this->pipe->process($request, new CallableDelegateDecorator( function () { throw ReachedFinalHandlerException::create(); }, @@ -83,43 +76,4 @@ function () { return $result; } - - /** - * @return \Zend\Diactoros\ServerRequest - * - * @throws RuntimeException - */ - private function loadRequest() - { - $request = $this->request; - - if (! $request instanceof Request) { - throw new RuntimeException(sprintf( - 'Expected request to be a %s, %s given', - Request::class, - get_class($request) - )); - } - - return Psr7ServerRequest::fromZend($request); - } - - /** - * @param ServerRequestInterface $request - * @param RouteMatch|null $routeMatch - * - * @return ServerRequestInterface - */ - private function populateRequestParametersFromRoute(ServerRequestInterface $request, RouteMatch $routeMatch = null) - { - if (! $routeMatch) { - return $request; - } - - foreach ($routeMatch->getParams() as $key => $value) { - $request = $request->withAttribute($key, $value); - } - - return $request; - } } diff --git a/src/Controller/Plugin/AbstractPlugin.php b/src/Controller/Plugin/AbstractPlugin.php index 0c092763b..b0dc62677 100644 --- a/src/Controller/Plugin/AbstractPlugin.php +++ b/src/Controller/Plugin/AbstractPlugin.php @@ -9,7 +9,7 @@ namespace Zend\Mvc\Controller\Plugin; -use Zend\Stdlib\DispatchableInterface as Dispatchable; +use Zend\Mvc\Controller\Dispatchable; abstract class AbstractPlugin implements PluginInterface { @@ -34,7 +34,7 @@ public function setController(Dispatchable $controller) * * @return null|Dispatchable */ - public function getController() + public function getController() : ?Dispatchable { return $this->controller; } diff --git a/src/Controller/Plugin/CreateHttpNotFoundModel.php b/src/Controller/Plugin/CreateHttpNotFoundModel.php index 126c3eec9..dcdae007d 100644 --- a/src/Controller/Plugin/CreateHttpNotFoundModel.php +++ b/src/Controller/Plugin/CreateHttpNotFoundModel.php @@ -21,10 +21,8 @@ class CreateHttpNotFoundModel extends AbstractPlugin * * @return ViewModel */ - public function __invoke(Response $response) + public function __invoke() { - $response->setStatusCode(404); - return new ViewModel(['content' => 'Page not found']); } } diff --git a/src/Controller/Plugin/Forward.php b/src/Controller/Plugin/Forward.php index 35068bde8..595274ca6 100644 --- a/src/Controller/Plugin/Forward.php +++ b/src/Controller/Plugin/Forward.php @@ -11,11 +11,11 @@ use Zend\EventManager\SharedEventManagerInterface as SharedEvents; use Zend\Mvc\Controller\ControllerManager; +use Zend\Mvc\Controller\Dispatchable; use Zend\Mvc\Exception; use Zend\Mvc\InjectApplicationEventInterface; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; -use Zend\Stdlib\CallbackHandler; +use Zend\Router\RouteResult; class Forward extends AbstractPlugin { @@ -84,7 +84,7 @@ public function getListenersToDetach() // from getting attached to the ViewModel twice when a calling action // returns the output generated by a forwarded action. $this->listenersToDetach = [[ - 'id' => 'Zend\Stdlib\DispatchableInterface', + 'id' => Dispatchable::class, 'event' => MvcEvent::EVENT_DISPATCH, 'class' => 'Zend\Mvc\View\Http\InjectViewModelListener', ]]; @@ -126,9 +126,18 @@ public function dispatch($name, array $params = null) // Allow passing parameters to seed the RouteMatch with & copy matched route name if ($params !== null) { - $routeMatch = new RouteMatch($params); - $routeMatch->setMatchedRouteName($event->getRouteMatch()->getMatchedRouteName()); - $event->setRouteMatch($routeMatch); + $request = $event->getRequest(); + $routeResult = $request->getAttribute(RouteResult::class); + if ($routeResult) { + $routeResult = $routeResult->withMatchedParams($params); + } else { + $routeResult = RouteResult::fromRouteMatch($params); + } + foreach ($params as $name => $param) { + $request = $request->withAttribute($name, $param); + } + $request = $request->withAttribute(RouteResult::class, $routeResult); + $event->setRequest($request); } if ($this->numNestedForwards > $this->maxNestedForwards) { @@ -142,7 +151,7 @@ public function dispatch($name, array $params = null) $sharedEvents = $event->getApplication()->getEventManager()->getSharedManager(); $listeners = $this->detachProblemListeners($sharedEvents); - $return = $controller->dispatch($event->getRequest(), $event->getResponse()); + $return = $controller->dispatch($event->getRequest()); // If we detached any listeners, reattach them now: $this->reattachProblemListeners($sharedEvents, $listeners); @@ -284,7 +293,7 @@ private function getSharedListenersById($id, $event, SharedEvents $sharedEvents) * Varies detachment based on zend-eventmanager version. * * @param string|int $id - * @param callable|CallbackHandler $listener + * @param callable $listener * @param SharedEvents $sharedEvents * @return void */ diff --git a/src/Controller/Plugin/Params.php b/src/Controller/Plugin/Params.php index ecc5d0f9f..f09660961 100644 --- a/src/Controller/Plugin/Params.php +++ b/src/Controller/Plugin/Params.php @@ -9,6 +9,9 @@ namespace Zend\Mvc\Controller\Plugin; +use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Message\UploadedFileInterface; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\Exception\RuntimeException; use Zend\Mvc\InjectApplicationEventInterface; @@ -34,15 +37,17 @@ public function __invoke($param = null, $default = null) * * @param string $name File name to retrieve, or null to get all. * @param mixed $default Default value to use when the file is missing. - * @return array|\ArrayAccess|null + * @return array|UploadedFileInterface[]|UploadedFileInterface|null */ public function fromFiles($name = null, $default = null) { + $files = $this->getController()->getRequest()->getUploadedFiles(); + if ($name === null) { - return $this->getController()->getRequest()->getFiles($name, $default)->toArray(); + return $files; } - return $this->getController()->getRequest()->getFiles($name, $default); + return $files[$name] ?? $default; } /** @@ -50,15 +55,23 @@ public function fromFiles($name = null, $default = null) * * @param string $header Header name to retrieve, or null to get all. * @param mixed $default Default value to use when the requested header is missing. - * @return null|\Zend\Http\Header\HeaderInterface + * @return string[][]|string[] */ - public function fromHeader($header = null, $default = null) + public function fromHeader($header = null, array $default = []) { + /** + * @var ServerRequestInterface $request + */ + $request = $this->getController()->getRequest(); if ($header === null) { - return $this->getController()->getRequest()->getHeaders($header, $default)->toArray(); + return $request->getHeaders(); + } + + if (! $request->hasHeader($header)) { + return $default; } - return $this->getController()->getRequest()->getHeaders($header, $default); + return $request->getHeader($header); } /** @@ -70,11 +83,12 @@ public function fromHeader($header = null, $default = null) */ public function fromPost($param = null, $default = null) { + $parsedBody = $this->getController()->getRequest()->getParsedBody(); if ($param === null) { - return $this->getController()->getRequest()->getPost($param, $default)->toArray(); + return $parsedBody; } - return $this->getController()->getRequest()->getPost($param, $default); + return $parsedBody[$param] ?? $default; } /** @@ -86,11 +100,12 @@ public function fromPost($param = null, $default = null) */ public function fromQuery($param = null, $default = null) { + $query = $this->getController()->getRequest()->getQueryParams(); if ($param === null) { - return $this->getController()->getRequest()->getQuery($param, $default)->toArray(); + return $query; } - return $this->getController()->getRequest()->getQuery($param, $default); + return $query[$param] ?? $default; } /** @@ -105,16 +120,10 @@ public function fromRoute($param = null, $default = null) { $controller = $this->getController(); - if (! $controller instanceof InjectApplicationEventInterface) { - throw new RuntimeException( - 'Controllers must implement Zend\Mvc\InjectApplicationEventInterface to use this plugin.' - ); - } - if ($param === null) { - return $controller->getEvent()->getRouteMatch()->getParams(); + return $controller->getRequest()->getAttributes(); } - return $controller->getEvent()->getRouteMatch()->getParam($param, $default); + return $controller->getRequest()->getAttribute($param, $default); } } diff --git a/src/Controller/Plugin/PluginInterface.php b/src/Controller/Plugin/PluginInterface.php index bea869aa4..c73a1cb76 100644 --- a/src/Controller/Plugin/PluginInterface.php +++ b/src/Controller/Plugin/PluginInterface.php @@ -9,7 +9,7 @@ namespace Zend\Mvc\Controller\Plugin; -use Zend\Stdlib\DispatchableInterface as Dispatchable; +use Zend\Mvc\Controller\Dispatchable; interface PluginInterface { @@ -26,5 +26,5 @@ public function setController(Dispatchable $controller); * * @return null|Dispatchable */ - public function getController(); + public function getController() : ?Dispatchable; } diff --git a/src/Controller/Plugin/Redirect.php b/src/Controller/Plugin/Redirect.php index faa7fd9a7..b343d81e7 100644 --- a/src/Controller/Plugin/Redirect.php +++ b/src/Controller/Plugin/Redirect.php @@ -9,7 +9,8 @@ namespace Zend\Mvc\Controller\Plugin; -use Zend\Http\Response; +use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; use Zend\Mvc\Exception; use Zend\Mvc\InjectApplicationEventInterface; use Zend\Mvc\MvcEvent; @@ -20,7 +21,6 @@ class Redirect extends AbstractPlugin { protected $event; - protected $response; /** * Generate redirect response based on given route @@ -29,12 +29,16 @@ class Redirect extends AbstractPlugin * @param array $params Parameters to use in url generation, if any * @param array $options RouteInterface-specific options to use in url generation, if any * @param bool $reuseMatchedParams Whether to reuse matched parameters - * @return Response + * @return ResponseInterface * @throws Exception\DomainException if composed controller does not implement InjectApplicationEventInterface, or * router cannot be found in controller event */ - public function toRoute($route = null, $params = [], $options = [], $reuseMatchedParams = false) - { + public function toRoute( + $route = null, + $params = [], + $options = [], + $reuseMatchedParams = false + ) : ResponseInterface { $controller = $this->getController(); if (! $controller || ! method_exists($controller, 'plugin')) { throw new Exception\DomainException( @@ -57,22 +61,23 @@ public function toRoute($route = null, $params = [], $options = [], $reuseMatche * Generate redirect response based on given URL * * @param string $url - * @return Response + * @return ResponseInterface */ - public function toUrl($url) + public function toUrl($url) : ResponseInterface { $response = $this->getResponse(); - $response->getHeaders()->addHeaderLine('Location', $url); - $response->setStatusCode(302); + $response = $response->withStatus(302) + ->withoutHeader('Location') + ->withAddedHeader('Location', $url); return $response; } /** * Refresh to current route * - * @return Response + * @return ResponseInterface */ - public function refresh() + public function refresh() : ResponseInterface { return $this->toRoute(null, [], [], true); } @@ -80,22 +85,14 @@ public function refresh() /** * Get the response * - * @return Response + * @return ResponseInterface * @throws Exception\DomainException if unable to find response */ - protected function getResponse() + protected function getResponse() : ResponseInterface { - if ($this->response) { - return $this->response; - } - $event = $this->getEvent(); - $response = $event->getResponse(); - if (! $response instanceof Response) { - throw new Exception\DomainException('Redirect plugin requires event compose a response'); - } - $this->response = $response; - return $this->response; + $response = $event->getResponse() ?? new Response(); + return $response; } /** @@ -104,7 +101,7 @@ protected function getResponse() * @return MvcEvent * @throws Exception\DomainException if unable to find event */ - protected function getEvent() + protected function getEvent() : MvcEvent { if ($this->event) { return $this->event; diff --git a/src/Controller/Plugin/Url.php b/src/Controller/Plugin/Url.php index ad68005d0..6cd9ba2f8 100644 --- a/src/Controller/Plugin/Url.php +++ b/src/Controller/Plugin/Url.php @@ -13,8 +13,8 @@ use Zend\EventManager\EventInterface; use Zend\Mvc\Exception; use Zend\Mvc\InjectApplicationEventInterface; -use Zend\Mvc\ModuleRouteListener; use Zend\Mvc\MvcEvent; +use Zend\Router\RouteResult; use Zend\Router\RouteStackInterface; class Url extends AbstractPlugin @@ -53,14 +53,15 @@ public function fromRoute($route = null, $params = [], $options = [], $reuseMatc $event = $controller->getEvent(); $router = null; - $matches = null; + $request = null; if ($event instanceof MvcEvent) { $router = $event->getRouter(); - $matches = $event->getRouteMatch(); + $request = $event->getRequest(); } elseif ($event instanceof EventInterface) { $router = $event->getParam('router', false); - $matches = $event->getParam('route-match', false); + $request = $event->getParam('request', false); } + $matches = $request ? $request->getAttribute(RouteResult::class) : null; if (! $router instanceof RouteStackInterface) { throw new Exception\DomainException( 'Url plugin requires that controller event compose a router; none found' @@ -76,7 +77,7 @@ public function fromRoute($route = null, $params = [], $options = [], $reuseMatc if ($route === null) { if (! $matches) { - throw new Exception\RuntimeException('No RouteMatch instance present'); + throw new Exception\RuntimeException('No RouteResult instance present'); } /** @@ -85,26 +86,17 @@ public function fromRoute($route = null, $params = [], $options = [], $reuseMatc $route = $matches->getMatchedRouteName(); if ($route === null) { - throw new Exception\RuntimeException('RouteMatch does not contain a matched route name'); + throw new Exception\RuntimeException('RouteResult does not contain a matched route name'); } } if ($reuseMatchedParams && $matches) { - $routeMatchParams = $matches->getParams(); - - if (isset($routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) { - $routeMatchParams['controller'] = $routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER]; - unset($routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER]); - } - - if (isset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE])) { - unset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE]); - } + $routeMatchParams = $matches->getMatchedParams(); $params = array_merge($routeMatchParams, $params); } $options['name'] = $route; - return $router->assemble($params, $options); + return $router->assemble($params, $options)->__toString(); } } diff --git a/src/Controller/PluginManager.php b/src/Controller/PluginManager.php index 1322697e1..8efeec433 100644 --- a/src/Controller/PluginManager.php +++ b/src/Controller/PluginManager.php @@ -9,10 +9,10 @@ namespace Zend\Mvc\Controller; +use Zend\Mvc\Controller\Plugin\PluginInterface; use Zend\ServiceManager\AbstractPluginManager; use Zend\ServiceManager\Exception\InvalidServiceException; use Zend\ServiceManager\Factory\InvokableFactory; -use Zend\Stdlib\DispatchableInterface; /** * Plugin manager implementation for controllers @@ -75,7 +75,7 @@ class PluginManager extends AbstractPluginManager ]; /** - * @var DispatchableInterface + * @var Dispatchable */ protected $controller; @@ -90,7 +90,7 @@ class PluginManager extends AbstractPluginManager * plugin is lost. * * @param string $name - * @return DispatchableInterface + * @return PluginInterface */ public function get($name, array $options = null) { @@ -103,10 +103,10 @@ public function get($name, array $options = null) /** * Set controller * - * @param DispatchableInterface $controller + * @param Dispatchable $controller * @return PluginManager */ - public function setController(DispatchableInterface $controller) + public function setController(Dispatchable $controller) { $this->controller = $controller; @@ -116,9 +116,9 @@ public function setController(DispatchableInterface $controller) /** * Retrieve controller instance * - * @return null|DispatchableInterface + * @return null|Dispatchable */ - public function getController() + public function getController() : ?Dispatchable { return $this->controller; } @@ -139,7 +139,7 @@ public function injectController($plugin) } $controller = $this->getController(); - if (! $controller instanceof DispatchableInterface) { + if (! $controller) { return; } diff --git a/src/View/Http/ViewManager.php b/src/View/Http/ViewManager.php index 920a72aad..6e368ab85 100644 --- a/src/View/Http/ViewManager.php +++ b/src/View/Http/ViewManager.php @@ -14,6 +14,7 @@ use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\ListenerAggregateInterface; +use Zend\Mvc\Controller\Dispatchable; use Zend\Mvc\MvcEvent; use Zend\ServiceManager\ServiceManager; use Zend\View\View; @@ -120,31 +121,31 @@ public function onBootstrap(MvcEvent $event) : void $mvcRenderingStrategy->attach($events); $sharedEvents->attach( - 'Zend\Stdlib\DispatchableInterface', + Dispatchable::class, MvcEvent::EVENT_DISPATCH, [$createViewModelListener, 'createViewModelFromArray'], -80 ); $sharedEvents->attach( - 'Zend\Stdlib\DispatchableInterface', + Dispatchable::class, MvcEvent::EVENT_DISPATCH, [$routeNotFoundStrategy, 'prepareNotFoundViewModel'], -90 ); $sharedEvents->attach( - 'Zend\Stdlib\DispatchableInterface', + Dispatchable::class, MvcEvent::EVENT_DISPATCH, [$createViewModelListener, 'createViewModelFromNull'], -80 ); $sharedEvents->attach( - 'Zend\Stdlib\DispatchableInterface', + Dispatchable::class, MvcEvent::EVENT_DISPATCH, [$injectTemplateListener, 'injectTemplate'], -90 ); $sharedEvents->attach( - 'Zend\Stdlib\DispatchableInterface', + Dispatchable::class, MvcEvent::EVENT_DISPATCH, [$injectViewModelListener, 'injectViewModel'], -100 diff --git a/test/Controller/AbstractControllerTest.php b/test/Controller/AbstractControllerTest.php index a90f101f2..ee3adac04 100644 --- a/test/Controller/AbstractControllerTest.php +++ b/test/Controller/AbstractControllerTest.php @@ -14,8 +14,8 @@ use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Controller\AbstractController; +use Zend\Mvc\Controller\Dispatchable; use Zend\Mvc\InjectApplicationEventInterface; -use Zend\Stdlib\DispatchableInterface; /** * @covers \Zend\Mvc\Controller\AbstractController @@ -103,7 +103,7 @@ public function testSetEventManagerWithDefaultIdentifiersIncludesImplementedInte ->method('setIdentifiers') ->with($this->logicalAnd( $this->contains(EventManagerAwareInterface::class), - $this->contains(DispatchableInterface::class), + $this->contains(Dispatchable::class), $this->contains(InjectApplicationEventInterface::class) )); diff --git a/test/Controller/ActionControllerTest.php b/test/Controller/ActionControllerTest.php index 8faa183b9..503bb74d8 100644 --- a/test/Controller/ActionControllerTest.php +++ b/test/Controller/ActionControllerTest.php @@ -11,19 +11,19 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\SharedEventManager; use Zend\EventManager\SharedEventManagerInterface; -use Zend\Http\Request; -use Zend\Http\Response; use Zend\Mvc\Controller\AbstractActionController; +use Zend\Mvc\Controller\Dispatchable; use Zend\Mvc\Controller\Plugin\Url; use Zend\Mvc\Controller\PluginManager; use Zend\Mvc\InjectApplicationEventInterface; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\DispatchableInterface; use Zend\View\Model\ModelInterface; use ZendTest\Mvc\Controller\TestAsset\SampleController; use ZendTest\Mvc\Controller\TestAsset\SampleInterface; @@ -33,16 +33,17 @@ class ActionControllerTest extends TestCase public $controller; public $event; public $request; - public $response; + public $sharedEvents; + public $routeResult; + public $events; public function setUp() { $this->controller = new SampleController(); - $this->request = new Request(); - $this->response = null; - $this->routeMatch = new RouteMatch(['controller' => 'controller-sample']); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $routeResult = RouteResult::fromRouteMatch(['controller' => 'controller-sample']); + $this->request = $request->withAttribute(RouteResult::class, $routeResult); $this->event = new MvcEvent(); - $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); $this->sharedEvents = new SharedEventManager(); @@ -50,6 +51,17 @@ public function setUp() $this->controller->setEventManager($this->events); } + public function requestWithMatchedParams(ServerRequest $request, array $params) + { + /** @var RouteResult $routeResult */ + $routeResult = $request->getAttribute(RouteResult::class); + $routeResult = $routeResult->withMatchedParams(\array_merge($routeResult->getMatchedParams(), $params)); + foreach ($params as $name => $param) { + $request = $request->withAttribute($name, $param); + } + return $request->withAttribute(RouteResult::class, $routeResult); + } + /** * @param SharedEventManager * @return EventManager @@ -61,7 +73,7 @@ protected function createEventManager(SharedEventManagerInterface $sharedManager public function testDispatchInvokesNotFoundActionWhenNoActionPresentInRouteMatch() { - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $response = $this->controller->getResponse(); $this->assertEquals(404, $response->getStatusCode()); $this->assertInstanceOf(ModelInterface::class, $result); @@ -73,8 +85,8 @@ public function testDispatchInvokesNotFoundActionWhenNoActionPresentInRouteMatch public function testDispatchInvokesNotFoundActionWhenInvalidActionPresentInRouteMatch() { - $this->routeMatch->setParam('action', 'totally-made-up-action'); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->requestWithMatchedParams($this->request, ['action' => 'totally-made-up-action']); + $result = $this->controller->dispatch($request); $response = $this->controller->getResponse(); $this->assertEquals(404, $response->getStatusCode()); $this->assertInstanceOf(ModelInterface::class, $result); @@ -86,16 +98,16 @@ public function testDispatchInvokesNotFoundActionWhenInvalidActionPresentInRoute public function testDispatchInvokesProvidedActionWhenMethodExists() { - $this->routeMatch->setParam('action', 'test'); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->requestWithMatchedParams($this->request, ['action' => 'test']); + $result = $this->controller->dispatch($request); $this->assertTrue(isset($result['content'])); $this->assertContains('test', $result['content']); } public function testDispatchCallsActionMethodBasedOnNormalizingAction() { - $this->routeMatch->setParam('action', 'test.some-strangely_separated.words'); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->requestWithMatchedParams($this->request, ['action' => 'test.some-strangely_separated.words']); + $result = $this->controller->dispatch($request); $this->assertTrue(isset($result['content'])); $this->assertContains('Test Some Strangely Separated Words', $result['content']); } @@ -103,76 +115,76 @@ public function testDispatchCallsActionMethodBasedOnNormalizingAction() public function testShortCircuitsBeforeActionIfPreDispatchReturnsAResponse() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $this->controller->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { return $response; }, 100); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testPostDispatchEventAllowsReplacingResponse() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $this->controller->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { return $response; }, -10); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testEventManagerListensOnDispatchableInterfaceByDefault() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $sharedEvents = $this->controller->getEventManager()->getSharedManager(); - $sharedEvents->attach(DispatchableInterface::class, MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { + $sharedEvents->attach(Dispatchable::class, MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { return $response; }, 10); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testEventManagerListensOnActionControllerClassByDefault() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $sharedEvents = $this->controller->getEventManager()->getSharedManager(); $sharedEvents->attach(AbstractActionController::class, MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { return $response; }, 10); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testEventManagerListensOnClassNameByDefault() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $sharedEvents = $this->controller->getEventManager()->getSharedManager(); $sharedEvents->attach(get_class($this->controller), MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { return $response; }, 10); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testEventManagerListensOnInterfaceName() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $sharedEvents = $this->controller->getEventManager()->getSharedManager(); $sharedEvents->attach(SampleInterface::class, MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { return $response; }, 10); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testDispatchInjectsEventIntoController() { - $this->controller->dispatch($this->request, $this->response); + $this->controller->dispatch($this->request); $event = $this->controller->getEvent(); $this->assertNotNull($event); $this->assertSame($this->event, $event); diff --git a/test/Controller/MiddlewareControllerTest.php b/test/Controller/MiddlewareControllerTest.php index 7ce27829a..b005e9a65 100644 --- a/test/Controller/MiddlewareControllerTest.php +++ b/test/Controller/MiddlewareControllerTest.php @@ -11,16 +11,16 @@ use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerInterface; -use Zend\Http\Request; -use Zend\Http\Response; use Zend\Mvc\Controller\AbstractController; +use Zend\Mvc\Controller\Dispatchable; use Zend\Mvc\Controller\MiddlewareController; use Zend\Mvc\Exception\RuntimeException; use Zend\Mvc\MvcEvent; -use Zend\Stdlib\DispatchableInterface; -use Zend\Stdlib\RequestInterface; use Zend\Stratigility\MiddlewarePipe; /** @@ -78,13 +78,12 @@ public function testWillAssignCorrectEventManagerIdentifiers() self::assertContains(MiddlewareController::class, $identifiers); self::assertContains(AbstractController::class, $identifiers); - self::assertContains(DispatchableInterface::class, $identifiers); + self::assertContains(Dispatchable::class, $identifiers); } public function testWillDispatchARequestAndResponseWithAGivenPipe() { - $request = new Request(); - $response = new Response(); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); $result = $this->createMock(ResponseInterface::class); /* @var $dispatchListener callable|\PHPUnit_Framework_MockObject_MockObject */ $dispatchListener = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); @@ -97,51 +96,20 @@ public function testWillDispatchARequestAndResponseWithAGivenPipe() $dispatchListener ->expects(self::once()) ->method('__invoke') - ->with(self::callback(function (MvcEvent $event) use ($request, $response) { + ->with(self::callback(function (MvcEvent $event) use ($request) { self::assertSame($this->event, $event); self::assertSame(MvcEvent::EVENT_DISPATCH, $event->getName()); self::assertSame($this->controller, $event->getTarget()); self::assertSame($request, $event->getRequest()); - self::assertSame($response, $event->getResponse()); return true; })); $this->pipe->expects(self::once())->method('process')->willReturn($result); - $controllerResult = $this->controller->dispatch($request, $response); + $controllerResult = $this->controller->dispatch($request); self::assertSame($result, $controllerResult); self::assertSame($result, $this->event->getResult()); } - - public function testWillRefuseDispatchingInvalidRequestTypes() - { - /* @var $request RequestInterface */ - $request = $this->createMock(RequestInterface::class); - $response = new Response(); - /* @var $dispatchListener callable|\PHPUnit_Framework_MockObject_MockObject */ - $dispatchListener = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); - - $this->eventManager->attach(MvcEvent::EVENT_DISPATCH, $dispatchListener, 100); - - $dispatchListener - ->expects(self::once()) - ->method('__invoke') - ->with(self::callback(function (MvcEvent $event) use ($request, $response) { - self::assertSame($this->event, $event); - self::assertSame(MvcEvent::EVENT_DISPATCH, $event->getName()); - self::assertSame($this->controller, $event->getTarget()); - self::assertSame($request, $event->getRequest()); - self::assertSame($response, $event->getResponse()); - - return true; - })); - - $this->pipe->expects(self::never())->method('process'); - - $this->expectException(RuntimeException::class); - - $this->controller->dispatch($request, $response); - } } diff --git a/test/Controller/Plugin/AcceptableViewModelSelectorTest.php b/test/Controller/Plugin/AcceptableViewModelSelectorTest.php index 0b1c4e676..6457a0dd1 100644 --- a/test/Controller/Plugin/AcceptableViewModelSelectorTest.php +++ b/test/Controller/Plugin/AcceptableViewModelSelectorTest.php @@ -10,9 +10,9 @@ namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\ServerRequest; use Zend\Http\Header\Accept\FieldValuePart\AcceptFieldValuePart; use Zend\Mvc\Controller\Plugin\AcceptableViewModelSelector; -use Zend\Http\Request; use Zend\Mvc\Exception\InvalidArgumentException; use Zend\Mvc\MvcEvent; use Zend\Http\Header\Accept; @@ -23,7 +23,8 @@ class AcceptableViewModelSelectorTest extends TestCase { public function setUp() { - $this->request = new Request(); + return self::markTestIncomplete('Content negotiation part needs rewrite'); + $this->request = new ServerRequest([], [], null, 'GET', 'php://memory'); $event = new MvcEvent(); $event->setRequest($this->request); diff --git a/test/Controller/Plugin/CreateHttpNotFoundModelTest.php b/test/Controller/Plugin/CreateHttpNotFoundModelTest.php index 8b2f83e7a..265323b7d 100644 --- a/test/Controller/Plugin/CreateHttpNotFoundModelTest.php +++ b/test/Controller/Plugin/CreateHttpNotFoundModelTest.php @@ -10,7 +10,6 @@ namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; -use Zend\Http\Response; use Zend\Mvc\Controller\Plugin\CreateHttpNotFoundModel; use Zend\View\Model\ViewModel; @@ -21,15 +20,13 @@ */ class CreateHttpNotFoundModelTest extends TestCase { - public function testBuildsModelWithErrorMessageAndSetsResponseStatusCode() + public function testBuildsModelWithErrorMessage() { - $response = new Response(); $plugin = new CreateHttpNotFoundModel(); - $model = $plugin->__invoke($response); + $model = $plugin->__invoke(); $this->assertInstanceOf(ViewModel::class, $model); $this->assertSame('Page not found', $model->getVariable('content')); - $this->assertSame(404, $response->getStatusCode()); } } diff --git a/test/Controller/Plugin/ForwardTest.php b/test/Controller/Plugin/ForwardTest.php index 6b61fda61..7f4f5ab73 100644 --- a/test/Controller/Plugin/ForwardTest.php +++ b/test/Controller/Plugin/ForwardTest.php @@ -12,11 +12,11 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; use stdClass; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\SharedEventManager; use Zend\EventManager\SharedEventManagerInterface; -use Zend\Http\Request; -use Zend\Http\Response; use Zend\Mvc\ApplicationInterface; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\Controller\Plugin\Forward; @@ -25,7 +25,7 @@ use Zend\Mvc\Exception\DomainException; use Zend\Mvc\Exception\InvalidControllerException; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; use Zend\ServiceManager\Config; use Zend\ServiceManager\Exception\InvalidServiceException; use Zend\ServiceManager\Exception\ServiceNotCreatedException; @@ -65,12 +65,10 @@ public function setUp() $event = new MvcEvent(); $event->setApplication($mockApplication); - $event->setRequest(new Request()); - $event->setResponse(new Response()); - - $routeMatch = new RouteMatch(['action' => 'test']); - $routeMatch->setMatchedRouteName('some-route'); - $event->setRouteMatch($routeMatch); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $routeResult = RouteResult::fromRouteMatch(['action' => 'test'], 'some-route'); + $request = $request->withAttribute(RouteResult::class, $routeResult); + $event->setRequest($request); $config = new Config([ 'aliases' => [ @@ -150,7 +148,7 @@ public function testDispatchRaisesDomainExceptionIfDiscoveredControllerIsNotDisp $plugin->setController($this->controller); $this->expectException(InvalidServiceException::class); - $this->expectExceptionMessage('DispatchableInterface'); + $this->expectExceptionMessage('Dispatchable'); $plugin->dispatch('bogus'); } @@ -311,20 +309,13 @@ public function testDispatchWillSeedRouteMatchWithPassedParameters() public function testRouteMatchObjectRemainsSameFollowingForwardDispatch() { - $routeMatch = $this->controller->getEvent()->getRouteMatch(); - $matchParams = $routeMatch->getParams(); - $matchMatchedRouteName = $routeMatch->getMatchedRouteName(); - $result = $this->plugin->dispatch('forward', [ + $routeResult = $this->controller->getRequest()->getAttribute(RouteResult::class); + $this->plugin->dispatch('forward', [ 'action' => 'test-matches', 'param1' => 'foobar', - ]); - $testMatch = $this->controller->getEvent()->getRouteMatch(); - $testParams = $testMatch->getParams(); - $testMatchedRouteName = $testMatch->getMatchedRouteName(); - - $this->assertSame($routeMatch, $testMatch); - $this->assertEquals($matchParams, $testParams); - $this->assertEquals($matchMatchedRouteName, $testMatchedRouteName); + ]); + $testResult = $this->controller->getRequest()->getAttribute(RouteResult::class); + $this->assertSame($routeResult, $testResult); } public function testAllowsPassingEmptyArrayOfRouteParams() @@ -334,6 +325,7 @@ public function testAllowsPassingEmptyArrayOfRouteParams() $this->assertTrue(isset($result['status'])); $this->assertEquals('not-found', $result['status']); $this->assertTrue(isset($result['params'])); + unset($result['params'][RouteResult::class]); $this->assertEquals([], $result['params']); } diff --git a/test/Controller/Plugin/ParamsTest.php b/test/Controller/Plugin/ParamsTest.php index 47db170d9..5ad513e70 100644 --- a/test/Controller/Plugin/ParamsTest.php +++ b/test/Controller/Plugin/ParamsTest.php @@ -10,26 +10,32 @@ namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; -use Zend\Http\Header\GenericHeader; -use Zend\Http\Request; -use Zend\Http\Response; +use Psr\Http\Message\ServerRequestInterface; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; +use Zend\Diactoros\UploadedFile; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; use ZendTest\Mvc\Controller\TestAsset\SampleController; class ParamsTest extends TestCase { + /** + * @var ServerRequestInterface + */ + public $request; + public function setUp() { - $this->request = new Request; + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $request = $request->withAttribute('value', 'rm:1234'); + $request = $request->withAttribute('other', '1234:rm'); + $request = $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch([])); + $this->request = $request; $event = new MvcEvent; $event->setRequest($this->request); $event->setResponse(new Response()); - $event->setRouteMatch(new RouteMatch([ - 'value' => 'rm:1234', - 'other' => '1234:rm', - ])); $this->controller = new SampleController(); $this->controller->setEvent($event); @@ -64,7 +70,7 @@ public function testFromRouteNotReturnsExpectedValueWithDefault() public function testFromRouteReturnsAllIfEmpty() { $value = $this->plugin->fromRoute(); - $this->assertEquals($value, ['value' => 'rm:1234', 'other' => '1234:rm']); + $this->assertEquals($this->request->getAttributes(), $value); } public function testFromQueryReturnsDefaultIfSet() @@ -133,15 +139,15 @@ public function testFromPostReturnsAllIfEmpty() public function testFromFilesReturnsExpectedValue() { - $file = [ - 'name' => 'test.txt', - 'type' => 'text/plain', - 'size' => 0, - 'tmp_name' => '/tmp/' . uniqid(), - 'error' => UPLOAD_ERR_OK, - ]; - $this->request->getFiles()->set('test', $file); - $this->controller->dispatch($this->request); + $file = new UploadedFile( + '/tmp/' . uniqid(), + 0, + \UPLOAD_ERR_OK, + 'test.txt', + 'text/plain' + ); + $request = $this->request->withUploadedFiles(['test' => $file]); + $this->controller->dispatch($request); $value = $this->plugin->fromFiles('test'); $this->assertEquals($value, $file); @@ -149,24 +155,25 @@ public function testFromFilesReturnsExpectedValue() public function testFromFilesReturnsAllIfEmpty() { - $file = [ - 'name' => 'test.txt', - 'type' => 'text/plain', - 'size' => 0, - 'tmp_name' => '/tmp/' . uniqid(), - 'error' => UPLOAD_ERR_OK, - ]; - - $file2 = [ - 'name' => 'file2.txt', - 'type' => 'text/plain', - 'size' => 1, - 'tmp_name' => '/tmp/' . uniqid(), - 'error' => UPLOAD_ERR_OK, - ]; - $this->request->getFiles()->set('file', $file); - $this->request->getFiles()->set('file2', $file2); - $this->controller->dispatch($this->request); + $file = new UploadedFile( + '/tmp/' . uniqid(), + 0, + \UPLOAD_ERR_OK, + 'test.txt', + 'text/plain' + ); + + $file2 = new UploadedFile( + '/tmp/' . uniqid(), + 1, + \UPLOAD_ERR_OK, + 'file2.txt', + 'text/plain' + ); + + $request = $this->request->withUploadedFiles(['file' => $file, 'file2' => $file2]); + + $this->controller->dispatch($request); $value = $this->plugin->fromFiles(); $this->assertEquals($value, ['file' => $file, 'file2' => $file2]); @@ -174,26 +181,22 @@ public function testFromFilesReturnsAllIfEmpty() public function testFromHeaderReturnsExpectedValue() { - $header = new GenericHeader('X-TEST', 'test'); - $this->request->getHeaders()->addHeader($header); - $this->controller->dispatch($this->request); + $request = $this->request->withAddedHeader('X-TEST', 'test'); + $this->controller->dispatch($request); $value = $this->plugin->fromHeader('X-TEST'); - $this->assertSame($value, $header); + $this->assertSame($value, ['test']); } public function testFromHeaderReturnsAllIfEmpty() { - $header = new GenericHeader('X-TEST', 'test'); - $header2 = new GenericHeader('OTHER-TEST', 'value:12345'); - - $this->request->getHeaders()->addHeader($header); - $this->request->getHeaders()->addHeader($header2); + $request = $this->request->withAddedHeader('X-TEST', 'test') + ->withAddedHeader('OTHER-TEST', 'value:12345'); - $this->controller->dispatch($this->request); + $this->controller->dispatch($request); $value = $this->plugin->fromHeader(); - $this->assertSame($value, ['X-TEST' => 'test', 'OTHER-TEST' => 'value:12345']); + $this->assertSame($value, ['X-TEST' => ['test'], 'OTHER-TEST' => ['value:12345']]); } public function testInvokeWithNoArgumentsReturnsInstance() @@ -203,19 +206,23 @@ public function testInvokeWithNoArgumentsReturnsInstance() protected function setQuery() { - $this->request->setMethod(Request::METHOD_GET); - $this->request->getQuery()->set('value', 'query:1234'); - $this->request->getQuery()->set('other', '1234:other'); + $request = $this->request->withMethod('GET') + ->withQueryParams([ + 'value' => 'query:1234', + 'other' => '1234:other', + ]); - $this->controller->dispatch($this->request); + $this->controller->dispatch($request); } protected function setPost() { - $this->request->setMethod(Request::METHOD_POST); - $this->request->getPost()->set('value', 'post:1234'); - $this->request->getPost()->set('other', '2345:other'); + $request = $this->request->withMethod('POST') + ->withParsedBody([ + 'value' => 'post:1234', + 'other' => '2345:other', + ]); - $this->controller->dispatch($this->request); + $this->controller->dispatch($request); } } diff --git a/test/Controller/Plugin/RedirectTest.php b/test/Controller/Plugin/RedirectTest.php index e6787d7d4..a3813b00a 100644 --- a/test/Controller/Plugin/RedirectTest.php +++ b/test/Controller/Plugin/RedirectTest.php @@ -10,23 +10,28 @@ namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; -use Zend\Http\Response; +use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\Controller\Plugin\Redirect as RedirectPlugin; use Zend\Mvc\Exception\DomainException; use Zend\Mvc\Exception\RuntimeException; use Zend\Mvc\MvcEvent; -use Zend\Router\Http\Literal as LiteralRoute; -use Zend\Router\Http\Segment as SegmentRoute; -use Zend\Router\RouteMatch; +use Zend\Router\Route\Literal as LiteralRoute; +use Zend\Router\Route\Segment as SegmentRoute; +use Zend\Router\RouteResult; use Zend\Router\SimpleRouteStack; use ZendTest\Mvc\Controller\TestAsset\SampleController; class RedirectTest extends TestCase { + /** + * @var RedirectPlugin + */ + public $plugin; + public function setUp() { - $this->response = new Response(); - $router = new SimpleRouteStack; $router->addRoute('home', LiteralRoute::factory([ 'route' => '/', @@ -36,13 +41,14 @@ public function setUp() ])); $this->router = $router; - $routeMatch = new RouteMatch([]); - $routeMatch->setMatchedRouteName('home'); - $this->routeMatch = $routeMatch; - $event = new MvcEvent(); + + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $request = $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch([], 'home')); + $this->request = $request; + $event->setRequest($request); + $event->setRouter($router); - $event->setResponse($this->response); $this->event = $event; $this->controller = new SampleController(); @@ -54,19 +60,17 @@ public function setUp() public function testPluginCanRedirectToRouteWhenProperlyConfigured() { $response = $this->plugin->toRoute('home'); - $this->assertTrue($response->isRedirect()); - $headers = $response->getHeaders(); - $location = $headers->get('Location'); - $this->assertEquals('/', $location->getFieldValue()); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertCount(1, $response->getHeader('Location')); + $this->assertEquals('/', $response->getHeader('Location')[0]); } public function testPluginCanRedirectToUrlWhenProperlyConfigured() { $response = $this->plugin->toUrl('/foo'); - $this->assertTrue($response->isRedirect()); - $headers = $response->getHeaders(); - $location = $headers->get('Location'); - $this->assertEquals('/foo', $location->getFieldValue()); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertCount(1, $response->getHeader('Location')); + $this->assertEquals('/foo', $response->getHeader('Location')[0]); } public function testPluginWithoutControllerRaisesDomainException() @@ -86,22 +90,15 @@ public function testPluginWithoutControllerEventRaisesDomainException() $plugin->toRoute('home'); } - public function testPluginWithoutResponseInEventRaisesDomainException() + public function testPluginWithoutResponseInEventReturnsNewResponse() { - $controller = new SampleController(); - $event = new MvcEvent(); - $controller->setEvent($event); - $plugin = $controller->plugin('redirect'); - $this->expectException(DomainException::class); - $this->expectExceptionMessage('event compose'); - $plugin->toRoute('home'); + $this->assertInstanceOf(ResponseInterface::class, $this->plugin->toRoute('home')); } public function testRedirectToRouteWithoutRouterInEventRaisesDomainException() { $controller = new SampleController(); $event = new MvcEvent(); - $event->setResponse($this->response); $controller->setEvent($event); $plugin = $controller->plugin('redirect'); $this->expectException(DomainException::class); @@ -111,20 +108,18 @@ public function testRedirectToRouteWithoutRouterInEventRaisesDomainException() public function testPluginWithoutRouteMatchesInEventRaisesExceptionWhenNoRouteProvided() { + $request = $this->request->withoutAttribute(RouteResult::class); + $this->controller->getEvent()->setRequest($request); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('RouteMatch'); + $this->expectExceptionMessage('RouteResult'); $url = $this->plugin->toRoute(); } public function testPassingNoArgumentsWithValidRouteMatchGeneratesUrl() { - $routeMatch = new RouteMatch([]); - $routeMatch->setMatchedRouteName('home'); - $this->controller->getEvent()->setRouteMatch($routeMatch); $response = $this->plugin->toRoute(); - $headers = $response->getHeaders(); - $location = $headers->get('Location'); - $this->assertEquals('/', $location->getFieldValue()); + $this->assertCount(1, $response->getHeader('Location')); + $this->assertEquals('/', $response->getHeader('Location')[0]); } public function testCanReuseMatchedParameters() @@ -135,15 +130,14 @@ public function testCanReuseMatchedParameters() 'controller' => SampleController::class, ], ])); - $routeMatch = new RouteMatch([ - 'controller' => 'foo', - ]); - $routeMatch->setMatchedRouteName('replace'); - $this->controller->getEvent()->setRouteMatch($routeMatch); + $request = $this->request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch( + ['controller' => 'foo'], + 'replace' + )); + $this->controller->getEvent()->setRequest($request); $response = $this->plugin->toRoute('replace', ['action' => 'bar'], [], true); - $headers = $response->getHeaders(); - $location = $headers->get('Location'); - $this->assertEquals('/foo/bar', $location->getFieldValue()); + $this->assertCount(1, $response->getHeader('Location')); + $this->assertEquals('/foo/bar', $response->getHeader('Location')[0]); } public function testCanPassBooleanValueForThirdArgumentToAllowReusingRouteMatches() @@ -154,34 +148,29 @@ public function testCanPassBooleanValueForThirdArgumentToAllowReusingRouteMatche 'controller' => SampleController::class, ], ])); - $routeMatch = new RouteMatch([ - 'controller' => 'foo', - ]); - $routeMatch->setMatchedRouteName('replace'); - $this->controller->getEvent()->setRouteMatch($routeMatch); + $request = $this->request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch( + ['controller' => 'foo'], + 'replace' + )); + $this->controller->getEvent()->setRequest($request); $response = $this->plugin->toRoute('replace', ['action' => 'bar'], true); - $headers = $response->getHeaders(); - $location = $headers->get('Location'); - $this->assertEquals('/foo/bar', $location->getFieldValue()); + $this->assertCount(1, $response->getHeader('Location')); + $this->assertEquals('/foo/bar', $response->getHeader('Location')[0]); } public function testPluginCanRefreshToRouteWhenProperlyConfigured() { - $this->event->setRouteMatch($this->routeMatch); $response = $this->plugin->refresh(); - $this->assertTrue($response->isRedirect()); - $headers = $response->getHeaders(); - $location = $headers->get('Location'); - $this->assertEquals('/', $location->getFieldValue()); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertCount(1, $response->getHeader('Location')); + $this->assertEquals('/', $response->getHeader('Location')[0]); } public function testPluginCanRedirectToRouteWithNullWhenProperlyConfigured() { - $this->event->setRouteMatch($this->routeMatch); $response = $this->plugin->toRoute(); - $this->assertTrue($response->isRedirect()); - $headers = $response->getHeaders(); - $location = $headers->get('Location'); - $this->assertEquals('/', $location->getFieldValue()); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertCount(1, $response->getHeader('Location')); + $this->assertEquals('/', $response->getHeader('Location')[0]); } } diff --git a/test/Controller/Plugin/UrlTest.php b/test/Controller/Plugin/UrlTest.php index a7a09e519..c00dbc8bf 100644 --- a/test/Controller/Plugin/UrlTest.php +++ b/test/Controller/Plugin/UrlTest.php @@ -10,17 +10,15 @@ namespace ZendTest\Mvc\Controller\Plugin; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\Controller\Plugin\Url as UrlPlugin; use Zend\Mvc\Exception\DomainException; use Zend\Mvc\Exception\RuntimeException; use Zend\Mvc\MvcEvent; -use Zend\Mvc\ModuleRouteListener; -use Zend\Router\Http\Literal as LiteralRoute; -use Zend\Router\Http\Segment as SegmentRoute; -use Zend\Router\Http\Segment; -use Zend\Router\Http\TreeRouteStack; -use Zend\Router\Http\Wildcard; -use Zend\Router\RouteMatch; +use Zend\Router\Route\Literal as LiteralRoute; +use Zend\Router\Route\Segment as SegmentRoute; +use Zend\Router\Route\Segment; +use Zend\Router\RouteResult; use Zend\Router\SimpleRouteStack; use ZendTest\Mvc\Controller\TestAsset\SampleController; @@ -97,14 +95,16 @@ public function testPluginWithoutRouterInEventRaisesDomainException() public function testPluginWithoutRouteMatchesInEventRaisesExceptionWhenNoRouteProvided() { $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('RouteMatch'); + $this->expectExceptionMessage('RouteResult'); $url = $this->plugin->fromRoute(); } public function testPluginWithRouteMatchesReturningNoMatchedRouteNameRaisesExceptionWhenNoRouteProvided() { $event = $this->controller->getEvent(); - $event->setRouteMatch(new RouteMatch([])); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $request = $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch([])); + $event->setRequest($request); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('matched'); $url = $this->plugin->fromRoute(); @@ -112,9 +112,9 @@ public function testPluginWithRouteMatchesReturningNoMatchedRouteNameRaisesExcep public function testPassingNoArgumentsWithValidRouteMatchGeneratesUrl() { - $routeMatch = new RouteMatch([]); - $routeMatch->setMatchedRouteName('home'); - $this->controller->getEvent()->setRouteMatch($routeMatch); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $request = $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch([], 'home')); + $this->controller->getEvent()->setRequest($request); $url = $this->plugin->fromRoute(); $this->assertEquals('/', $url); } @@ -127,11 +127,12 @@ public function testCanReuseMatchedParameters() 'controller' => SampleController::class, ], ])); - $routeMatch = new RouteMatch([ - 'controller' => 'foo', - ]); - $routeMatch->setMatchedRouteName('replace'); - $this->controller->getEvent()->setRouteMatch($routeMatch); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $request = $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch( + ['controller' => 'foo'], + 'replace' + )); + $this->controller->getEvent()->setRequest($request); $url = $this->plugin->fromRoute('replace', ['action' => 'bar'], [], true); $this->assertEquals('/foo/bar', $url); } @@ -144,59 +145,13 @@ public function testCanPassBooleanValueForThirdArgumentToAllowReusingRouteMatche 'controller' => SampleController::class, ], ])); - $routeMatch = new RouteMatch([ - 'controller' => 'foo', - ]); - $routeMatch->setMatchedRouteName('replace'); - $this->controller->getEvent()->setRouteMatch($routeMatch); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $request = $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch( + ['controller' => 'foo'], + 'replace' + )); + $this->controller->getEvent()->setRequest($request); $url = $this->plugin->fromRoute('replace', ['action' => 'bar'], true); $this->assertEquals('/foo/bar', $url); } - - /** - * - */ - public function testRemovesModuleRouteListenerParamsWhenReusingMatchedParameters() - { - $router = new TreeRouteStack; - $router->addRoute('default', [ - 'type' => Segment::class, - 'options' => [ - 'route' => '/:controller/:action', - 'defaults' => [ - ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\Mvc\Controller\TestAsset', - 'controller' => 'SampleController', - 'action' => 'Dash' - ] - ], - 'child_routes' => [ - 'wildcard' => [ - 'type' => Wildcard::class, - 'options' => [ - 'param_delimiter' => '=', - 'key_value_delimiter' => '%' - ] - ] - ] - ]); - - $routeMatch = new RouteMatch([ - ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\Mvc\Controller\TestAsset', - 'controller' => 'Rainbow' - ]); - $routeMatch->setMatchedRouteName('default/wildcard'); - - $event = new MvcEvent(); - $event->setRouter($router) - ->setRouteMatch($routeMatch); - - $moduleRouteListener = new ModuleRouteListener(); - $moduleRouteListener->onRoute($event); - - $controller = new SampleController(); - $controller->setEvent($event); - $url = $controller->plugin('url')->fromRoute('default/wildcard', ['Twenty' => 'Cooler'], true); - - $this->assertEquals('/Rainbow/Dash=Twenty%Cooler', $url); - } } diff --git a/test/Controller/RestfulControllerTest.php b/test/Controller/RestfulControllerTest.php index edc47a8bf..42db6402c 100644 --- a/test/Controller/RestfulControllerTest.php +++ b/test/Controller/RestfulControllerTest.php @@ -10,20 +10,22 @@ namespace ZendTest\Mvc\Controller; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; use ReflectionClass; use ReflectionObject; use stdClass; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\SharedEventManager; use Zend\EventManager\SharedEventManagerInterface; -use Zend\Http\Response; use Zend\Mvc\Controller\AbstractRestfulController; +use Zend\Mvc\Controller\Dispatchable; use Zend\Mvc\Controller\Plugin\Url; use Zend\Mvc\InjectApplicationEventInterface; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; -use Zend\Stdlib\DispatchableInterface; -use ZendTest\Mvc\Controller\TestAsset\Request; +use Zend\Router\RouteResult; use ZendTest\Mvc\Controller\TestAsset\RestfulContentTypeTestController; use ZendTest\Mvc\Controller\TestAsset\RestfulMethodNotAllowedTestController; use ZendTest\Mvc\Controller\TestAsset\RestfulTestController; @@ -32,20 +34,22 @@ class RestfulControllerTest extends TestCase { public $controller; public $emptyController; + /** + * @var ServerRequest + */ public $request; - public $response; - public $routeMatch; public $event; + public $sharedEvents; + public $events; public function setUp() { $this->controller = new RestfulTestController(); $this->emptyController = new RestfulMethodNotAllowedTestController(); - $this->request = new Request(); - $this->response = new Response(); - $this->routeMatch = new RouteMatch(['controller' => 'controller-restful']); - $this->event = new MvcEvent; - $this->event->setRouteMatch($this->routeMatch); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + $routeResult = RouteResult::fromRouteMatch(['controller' => 'controller-restful']); + $this->request = $request->withAttribute(RouteResult::class, $routeResult); + $this->event = new MvcEvent(); $this->controller->setEvent($this->event); $this->emptyController->setEvent($this->event); @@ -54,6 +58,17 @@ public function setUp() $this->controller->setEventManager($this->events); } + public function requestWithMatchedParams(ServerRequest $request, array $params) + { + /** @var RouteResult $routeResult */ + $routeResult = $request->getAttribute(RouteResult::class); + $routeResult = $routeResult->withMatchedParams(\array_merge($routeResult->getMatchedParams(), $params)); + foreach ($params as $name => $param) { + $request = $request->withAttribute($name, $param); + } + return $request->withAttribute(RouteResult::class, $routeResult); + } + /** * @param SharedEventManager * @return EventManager @@ -71,66 +86,80 @@ public function testDispatchInvokesListWhenNoActionPresentAndNoIdentifierOnGet() new stdClass, ]; $this->controller->entities = $entities; - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertArrayHasKey('entities', $result); $this->assertEquals($entities, $result['entities']); - $this->assertEquals('getList', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'getList', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testDispatchInvokesGetMethodWhenNoActionPresentAndIdentifierPresentOnGet() { $entity = new stdClass; $this->controller->entity = $entity; - $this->routeMatch->setParam('id', 1); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->requestWithMatchedParams($this->request, ['id' => 1]); + $result = $this->controller->dispatch($request); $this->assertArrayHasKey('entity', $result); $this->assertEquals($entity, $result['entity']); - $this->assertEquals('get', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'get', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testDispatchInvokesCreateMethodWhenNoActionPresentAndPostInvoked() { $entity = ['id' => 1, 'name' => __FUNCTION__]; - $this->request->setMethod('POST'); - $post = $this->request->getPost(); - $post->fromArray($entity); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->request->withMethod('POST'); + $request = $request->withParsedBody($entity); + $result = $this->controller->dispatch($request); $this->assertArrayHasKey('entity', $result); $this->assertEquals($entity, $result['entity']); - $this->assertEquals('create', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'create', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testCanReceiveStringAsRequestContent() { $string = "any content"; - $this->request->setMethod('PUT'); - $this->request->setContent($string); - $this->routeMatch->setParam('id', $id = 1); + $request = $this->request->withMethod('PUT'); + $request->getBody()->write($string); + $request = $this->requestWithMatchedParams($request, ['id' => 1]); $controller = new RestfulContentTypeTestController(); $controller->setEvent($this->event); - $result = $controller->dispatch($this->request, $this->response); + $result = $controller->dispatch($request); - $this->assertEquals($id, $result['id']); + $this->assertEquals(1, $result['id']); $this->assertEquals($string, $result['data']); - $this->assertEquals('update', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'update', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testDispatchInvokesUpdateMethodWhenNoActionPresentAndPutInvokedWithIdentifier() { $entity = ['name' => __FUNCTION__]; $string = http_build_query($entity); - $this->request->setMethod('PUT') - ->setContent($string); - $this->routeMatch->setParam('id', 1); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->request->withMethod('PUT'); + $request->getBody()->write($string); + $request = $this->requestWithMatchedParams($request, ['id' => 1]); + $result = $this->controller->dispatch($request); $this->assertArrayHasKey('entity', $result); $test = $result['entity']; $this->assertArrayHasKey('id', $test); $this->assertEquals(1, $test['id']); $this->assertArrayHasKey('name', $test); $this->assertEquals(__FUNCTION__, $test['name']); - $this->assertEquals('update', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'update', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testDispatchInvokesReplaceListMethodWhenNoActionPresentAndPutInvokedWithoutIdentifier() @@ -141,11 +170,14 @@ public function testDispatchInvokesReplaceListMethodWhenNoActionPresentAndPutInv ['id' => uniqid(), 'name' => __FUNCTION__], ]; $string = http_build_query($entities); - $this->request->setMethod('PUT') - ->setContent($string); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->request->withMethod('PUT'); + $request->getBody()->write($string); + $result = $this->controller->dispatch($request); $this->assertEquals($entities, $result); - $this->assertEquals('replaceList', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'replaceList', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testDispatchInvokesPatchListMethodWhenNoActionPresentAndPatchInvokedWithoutIdentifier() @@ -156,23 +188,29 @@ public function testDispatchInvokesPatchListMethodWhenNoActionPresentAndPatchInv ['id' => uniqid(), 'name' => __FUNCTION__], ]; $string = http_build_query($entities); - $this->request->setMethod('PATCH') - ->setContent($string); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->request->withMethod('PATCH'); + $request->getBody()->write($string); + $result = $this->controller->dispatch($request); $this->assertEquals($entities, $result); - $this->assertEquals('patchList', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'patchList', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testDispatchInvokesDeleteMethodWhenNoActionPresentAndDeleteInvokedWithIdentifier() { $entity = ['id' => 1, 'name' => __FUNCTION__]; $this->controller->entity = $entity; - $this->request->setMethod('DELETE'); - $this->routeMatch->setParam('id', 1); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->request->withMethod('DELETE'); + $request = $this->requestWithMatchedParams($request, ['id' => 1]); + $result = $this->controller->dispatch($request); $this->assertEquals([], $result); $this->assertEquals([], $this->controller->entity); - $this->assertEquals('delete', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'delete', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testDispatchInvokesDeleteListMethodWhenNoActionPresentAndDeleteInvokedWithoutIdentifier() @@ -186,27 +224,31 @@ public function testDispatchInvokesDeleteListMethodWhenNoActionPresentAndDeleteI $this->controller->entity = $entities; $string = http_build_query($entities); - $this->request->setMethod('DELETE') - ->setContent($string); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->request->withMethod('DELETE'); + $request->getBody()->write($string); + $result = $this->controller->dispatch($request); $this->assertEmpty($this->controller->entity); $this->assertEquals(204, $result->getStatusCode()); - $this->assertTrue($result->getHeaders()->has('X-Deleted')); - $this->assertEquals('deleteList', $this->routeMatch->getParam('action')); + $this->assertTrue($result->hasHeader('X-Deleted')); + $this->assertEquals( + 'deleteList', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testDispatchInvokesOptionsMethodWhenNoActionPresentAndOptionsInvoked() { - $this->request->setMethod('OPTIONS'); - $result = $this->controller->dispatch($this->request, $this->response); - $this->assertSame($this->response, $result); - $this->assertEquals('options', $this->routeMatch->getParam('action')); - $headers = $result->getHeaders(); - $this->assertTrue($headers->has('Allow')); - $allow = $headers->get('Allow'); + $request = $this->request->withMethod('OPTIONS'); + $result = $this->controller->dispatch($request); + $this->assertEquals( + 'options', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); + $this->assertTrue($result->hasHeader('Allow')); + $allow = $result->getHeader('Allow')[0]; $expected = explode(', ', 'GET, POST, PUT, DELETE, PATCH, HEAD, TRACE'); sort($expected); - $test = explode(', ', $allow->getFieldValue()); + $test = explode(', ', $allow); sort($test); $this->assertEquals($expected, $test); } @@ -219,10 +261,10 @@ public function testDispatchInvokesPatchMethodWhenNoActionPresentAndPatchInvoked $this->controller->entity = $entity; $entity = ['name' => __FUNCTION__]; $string = http_build_query($entity); - $this->request->setMethod('PATCH') - ->setContent($string); - $this->routeMatch->setParam('id', 1); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->request->withMethod('PATCH'); + $request->getBody()->write($string); + $request = $this->requestWithMatchedParams($request, ['id' => 1]); + $result = $this->controller->dispatch($request); $this->assertArrayHasKey('entity', $result); $test = $result['entity']; $this->assertArrayHasKey('id', $test); @@ -231,7 +273,10 @@ public function testDispatchInvokesPatchMethodWhenNoActionPresentAndPatchInvoked $this->assertEquals(__FUNCTION__, $test['name']); $this->assertArrayHasKey('type', $test); $this->assertEquals('standard', $test['type']); - $this->assertEquals('patch', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'patch', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } /** @@ -239,17 +284,23 @@ public function testDispatchInvokesPatchMethodWhenNoActionPresentAndPatchInvoked */ public function testOnDispatchHonorsStatusCodeWithHeadMethod() { - $this->controller->headResponse = new Response(); - $this->controller->headResponse->setStatusCode(418); - $this->controller->headResponse->getHeaders()->addHeaderLine('Custom-Header', 'Header Value'); - $this->routeMatch->setParam('id', 1); - $this->request->setMethod('HEAD'); - $result = $this->controller->dispatch($this->request, $this->response); + $response = new Response(); + $response = $response + ->withStatus(418) + ->withAddedHeader('Custom-Header', 'Header Value'); + + $this->controller->headResponse = $response; + $request = $this->request->withMethod('HEAD'); + $request = $this->requestWithMatchedParams($request, ['id' => 1]); + $result = $this->controller->dispatch($request); $this->assertEquals(418, $result->getStatusCode()); - $this->assertEquals('', $result->getContent()); - $this->assertEquals('head', $this->routeMatch->getParam('action')); - $this->assertEquals('Header Value', $result->getHeaders()->get('Custom-Header')->getFieldValue()); + $this->assertEquals('', $result->getBody()->__toString()); + $this->assertEquals( + 'head', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); + $this->assertEquals('Header Value', $result->getHeader('Custom-Header')[0] ?? 'No header set'); } public function testDispatchInvokesHeadMethodWhenNoActionPresentAndHeadInvokedWithoutIdentifier() @@ -260,53 +311,55 @@ public function testDispatchInvokesHeadMethodWhenNoActionPresentAndHeadInvokedWi new stdClass, ]; $this->controller->entities = $entities; - $this->request->setMethod('HEAD'); - $result = $this->controller->dispatch($this->request, $this->response); - $this->assertSame($this->response, $result); - $content = $result->getContent(); + $request = $this->request->withMethod('HEAD'); + $result = $this->controller->dispatch($request); + $content = $result->getBody()->__toString(); $this->assertEquals('', $content); - $this->assertEquals('head', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'head', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testDispatchInvokesHeadMethodWhenNoActionPresentAndHeadInvokedWithIdentifier() { $entity = new stdClass; $this->controller->entity = $entity; - $this->routeMatch->setParam('id', 1); - $this->request->setMethod('HEAD'); - $result = $this->controller->dispatch($this->request, $this->response); - $this->assertSame($this->response, $result); - $content = $result->getContent(); + $request = $this->request->withMethod('HEAD'); + $request = $this->requestWithMatchedParams($request, ['id' => 1]); + $result = $this->controller->dispatch($request); + $content = $result->getBody()->__toString(); $this->assertEquals('', $content); - $this->assertEquals('head', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'head', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); - $headers = $this->controller->getResponse()->getHeaders(); - $this->assertTrue($headers->has('X-ZF2-Id')); - $header = $headers->get('X-ZF2-Id'); - $this->assertEquals(1, $header->getFieldValue()); + $this->assertTrue($result->hasHeader('X-ZF2-Id')); + $this->assertEquals(1, $result->getHeader('X-ZF2-Id')[0]); } public function testAllowsRegisteringCustomHttpMethodsWithHandlers() { $this->controller->addHttpMethodHandler('DESCRIBE', [$this->controller, 'describe']); - $this->request->setMethod('DESCRIBE'); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->request->withMethod('DESCRIBE'); + $result = $this->controller->dispatch($request); $this->assertArrayHasKey('description', $result); $this->assertContains('::describe', $result['description']); } public function testDispatchCallsActionMethodBasedOnNormalizingAction() { - $this->routeMatch->setParam('action', 'test.some-strangely_separated.words'); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->requestWithMatchedParams($this->request, ['action' => 'test.some-strangely_separated.words']); + $result = $this->controller->dispatch($request); $this->assertArrayHasKey('content', $result); $this->assertContains('Test Some Strangely Separated Words', $result['content']); } public function testDispatchCallsNotFoundActionWhenActionPassedThatCannotBeMatched() { - $this->routeMatch->setParam('action', 'test-some-made-up-action'); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->requestWithMatchedParams($this->request, ['action' => 'test-some-made-up-action']); + $result = $this->controller->dispatch($request); $response = $this->controller->getResponse(); $this->assertEquals(404, $response->getStatusCode()); $this->assertArrayHasKey('content', $result); @@ -316,45 +369,45 @@ public function testDispatchCallsNotFoundActionWhenActionPassedThatCannotBeMatch public function testShortCircuitsBeforeActionIfPreDispatchReturnsAResponse() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $this->controller->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { return $response; }, 10); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testPostDispatchEventAllowsReplacingResponse() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $this->controller->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { return $response; }, -10); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testEventManagerListensOnDispatchableInterfaceByDefault() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $this->sharedEvents->attach( - DispatchableInterface::class, + Dispatchable::class, MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { return $response; }, 10 ); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testEventManagerListensOnRestfulControllerClassByDefault() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $this->sharedEvents->attach( AbstractRestfulController::class, MvcEvent::EVENT_DISPATCH, @@ -363,14 +416,14 @@ function ($e) use ($response) { }, 10 ); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testEventManagerListensOnClassNameByDefault() { $response = new Response(); - $response->setContent('short circuited!'); + $response->getBody()->write('short circuited!'); $this->sharedEvents->attach( get_class($this->controller), MvcEvent::EVENT_DISPATCH, @@ -379,13 +432,13 @@ function ($e) use ($response) { }, 10 ); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($this->request); $this->assertSame($response, $result); } public function testDispatchInjectsEventIntoController() { - $this->controller->dispatch($this->request, $this->response); + $this->controller->dispatch($this->request); $event = $this->controller->getEvent(); $this->assertNotNull($event); $this->assertSame($this->event, $event); @@ -416,11 +469,11 @@ public function testMethodOverloadingShouldInvokePluginAsFunctorIfPossible() public function testParsingDataAsJsonWillReturnAsArray() { - $this->request->setMethod('POST'); - $this->request->getHeaders()->addHeaderLine('Content-type', 'application/json'); - $this->request->setContent('{"foo":"bar"}'); + $request = $this->request->withMethod('POST') + ->withAddedHeader('Content-type', 'application/json'); + $request->getBody()->write('{"foo":"bar"}'); - $result = $this->controller->dispatch($this->request, $this->response); + $result = $this->controller->dispatch($request); $this->assertInternalType('array', $result); $this->assertEquals(['entity' => ['foo' => 'bar']], $result); } @@ -440,9 +493,9 @@ public function matchingContentTypes() */ public function testRequestingContentTypeReturnsTrueForValidMatches($contentType) { - $this->request->getHeaders()->addHeaderLine('Content-Type', $contentType); + $request = $this->request->withAddedHeader('Content-Type', $contentType); $this->assertTrue($this->controller->requestHasContentType( - $this->request, + $request, RestfulTestController::CONTENT_TYPE_JSON )); } @@ -460,18 +513,18 @@ public function nonMatchingContentTypes() */ public function testRequestingContentTypeReturnsFalseForInvalidMatches($contentType) { - $this->request->getHeaders()->addHeaderLine('Content-Type', $contentType); + $request = $this->request->withAddedHeader('Content-Type', $contentType); $this->assertFalse($this->controller->requestHasContentType( - $this->request, + $request, RestfulTestController::CONTENT_TYPE_JSON )); } public function testDispatchWithUnrecognizedMethodReturns405Response() { - $this->request->setMethod('PROPFIND'); - $result = $this->controller->dispatch($this->request, $this->response); - $this->assertInstanceOf(Response::class, $result); + $request = $this->request->withMethod('PROPFIND'); + $result = $this->controller->dispatch($request); + $this->assertInstanceOf(ResponseInterface::class, $result); $this->assertEquals(405, $result->getStatusCode()); } @@ -479,11 +532,14 @@ public function testDispatchInvokesGetMethodWhenNoActionPresentAndZeroIdentifier { $entity = new stdClass; $this->controller->entity = $entity; - $this->routeMatch->setParam('id', 0); - $result = $this->controller->dispatch($this->request, $this->response); + $request = $this->requestWithMatchedParams($this->request, ['id' => 0]); + $result = $this->controller->dispatch($request); $this->assertArrayHasKey('entity', $result); $this->assertEquals($entity, $result['entity']); - $this->assertEquals('get', $this->routeMatch->getParam('action')); + $this->assertEquals( + 'get', + $this->controller->getRequest()->getAttribute(RouteResult::class)->getMatchedParams()['action'] ?? null + ); } public function testIdentifierNameDefaultsToId() @@ -505,13 +561,13 @@ public function testUsesConfiguredIdentifierNameToGetIdentifier() $this->controller->setIdentifierName('name'); - $this->routeMatch->setParam('name', 'foo'); - $result = $getIdentifier->invoke($this->controller, $this->routeMatch, $this->request); + $request = $this->request->withAttribute('name', 'foo'); + $result = $getIdentifier->invoke($this->controller, $request); $this->assertEquals('foo', $result); - $this->routeMatch->setParam('name', false); - $this->request->getQuery()->set('name', 'bar'); - $result = $getIdentifier->invoke($this->controller, $this->routeMatch, $this->request); + $request = $this->request->withAttribute('name', false); + $request = $this->request->withQueryParams(['name' => 'bar']); + $result = $getIdentifier->invoke($this->controller, $request); $this->assertEquals('bar', $result); } @@ -520,21 +576,19 @@ public function testUsesConfiguredIdentifierNameToGetIdentifier() */ public function testNotImplementedMethodSets504HttpCode($method, $content, array $routeParams) { - $this->request->setMethod($method); + $request = $this->request->withMethod($method); if ($content) { - $this->request->setContent($content); + $request->getBody()->write($content); } - foreach ($routeParams as $name => $value) { - $this->routeMatch->setParam($name, $value); - } + $request = $this->requestWithMatchedParams($request, $routeParams); - $result = $this->emptyController->dispatch($this->request, $this->response); + $result = $this->emptyController->dispatch($request); $response = $this->emptyController->getResponse(); $this->assertEquals(405, $response->getStatusCode()); - $this->assertEquals('Method Not Allowed', $this->response->getReasonPhrase()); + $this->assertEquals('Method Not Allowed', $response->getReasonPhrase()); } public function providerNotImplementedMethodSets504HttpCodeProvider() diff --git a/test/Controller/TestAsset/ForwardController.php b/test/Controller/TestAsset/ForwardController.php index d2dc91b99..e22f73f41 100644 --- a/test/Controller/TestAsset/ForwardController.php +++ b/test/Controller/TestAsset/ForwardController.php @@ -10,6 +10,7 @@ namespace ZendTest\Mvc\Controller\TestAsset; use Zend\Mvc\Controller\AbstractActionController; +use Zend\Router\RouteResult; class ForwardController extends AbstractActionController { @@ -21,7 +22,7 @@ public function testAction() public function testMatchesAction() { $e = $this->getEvent(); - return $e->getRouteMatch()->getParams(); + return $e->getRequest()->getAttribute(RouteResult::class)->getMatchedParams(); } public function notFoundAction() diff --git a/test/Controller/TestAsset/RestfulTestController.php b/test/Controller/TestAsset/RestfulTestController.php index 620478132..2bd7b374b 100644 --- a/test/Controller/TestAsset/RestfulTestController.php +++ b/test/Controller/TestAsset/RestfulTestController.php @@ -9,6 +9,8 @@ namespace ZendTest\Mvc\Controller\TestAsset; +use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; use Zend\Mvc\Controller\AbstractRestfulController; class RestfulTestController extends AbstractRestfulController @@ -17,7 +19,7 @@ class RestfulTestController extends AbstractRestfulController public $entity = []; /** - * @var \Zend\Stdlib\ResponseInterface|null + * @var ResponseInterface|null */ public $headResponse; @@ -47,7 +49,7 @@ public function delete($id) /** * Delete the collection * - * @return \Zend\Http\Response + * @return ResponseInterface */ public function deleteList($data) { @@ -62,9 +64,9 @@ public function deleteList($data) } } - $response = $this->getResponse(); - $response->setStatusCode(204); - $response->getHeaders()->addHeaderLine('X-Deleted', 'true'); + $response = $this->getResponse() ?? new Response(); + $response = $response->withStatus(204) + ->withAddedHeader('X-Deleted', 'true'); return $response; } @@ -92,13 +94,13 @@ public function getList() /** * Retrieve the headers for a given resource - * - * @return void */ public function head($id = null) { if ($id) { - $this->getResponse()->getHeaders()->addHeaderLine('X-ZF2-Id', $id); + $this->getEvent()->setResponse( + ($this->getResponse() ?? new Response())->withAddedHeader('X-ZF2-Id', $id) + ); } if ($this->headResponse) { @@ -109,13 +111,12 @@ public function head($id = null) /** * Return list of allowed HTTP methods * - * @return \Zend\Http\Response + * @return ResponseInterface */ public function options() { - $response = $this->getResponse(); - $headers = $response->getHeaders(); - $headers->addHeaderLine('Allow', 'GET, POST, PUT, DELETE, PATCH, HEAD, TRACE'); + $response = $this->getResponse() ?? new Response(); + $response = $response->withAddedHeader('Allow', 'GET, POST, PUT, DELETE, PATCH, HEAD, TRACE'); return $response; } diff --git a/test/Controller/TestAsset/UneventfulController.php b/test/Controller/TestAsset/UneventfulController.php index cb8a1cde0..68cc04e88 100644 --- a/test/Controller/TestAsset/UneventfulController.php +++ b/test/Controller/TestAsset/UneventfulController.php @@ -9,13 +9,13 @@ namespace ZendTest\Mvc\Controller\TestAsset; -use Zend\Stdlib\DispatchableInterface; -use Zend\Stdlib\RequestInterface; -use Zend\Stdlib\ResponseInterface as Response; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Zend\Mvc\Controller\Dispatchable; -class UneventfulController implements DispatchableInterface +class UneventfulController implements Dispatchable { - public function dispatch(RequestInterface $request, Response $response = null) + public function dispatch(ServerRequestInterface $request, ResponseInterface $response = null) { } } From ec0a67578dab898ad1f9e379c32d2fa12845bf63 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 26 Nov 2017 10:30:55 +1000 Subject: [PATCH 15/51] Drop request and response factories --- src/Container/RequestFactory.php | 30 ------------------------ src/Container/ResponseFactory.php | 30 ------------------------ src/Container/ServiceListenerFactory.php | 4 ---- test/Container/RequestFactoryTest.php | 25 -------------------- test/Container/ResponseFactoryTest.php | 25 -------------------- 5 files changed, 114 deletions(-) delete mode 100644 src/Container/RequestFactory.php delete mode 100644 src/Container/ResponseFactory.php delete mode 100644 test/Container/RequestFactoryTest.php delete mode 100644 test/Container/ResponseFactoryTest.php diff --git a/src/Container/RequestFactory.php b/src/Container/RequestFactory.php deleted file mode 100644 index e2711a026..000000000 --- a/src/Container/RequestFactory.php +++ /dev/null @@ -1,30 +0,0 @@ - 'config', 'HttpDefaultRenderingStrategy' => View\Http\DefaultRenderingStrategy::class, 'MiddlewareListener' => 'Zend\Mvc\MiddlewareListener', - 'request' => 'Request', - 'response' => 'Response', 'RouteListener' => 'Zend\Mvc\RouteListener', 'SendResponseListener' => 'Zend\Mvc\SendResponseListener', 'View' => 'Zend\View\View', @@ -76,8 +74,6 @@ class ServiceListenerFactory implements FactoryInterface 'HttpViewManager' => 'Zend\Mvc\Container\HttpViewManagerFactory', 'InjectTemplateListener' => 'Zend\Mvc\Container\InjectTemplateListenerFactory', 'PaginatorPluginManager' => 'Zend\Mvc\Container\PaginatorPluginManagerFactory', - 'Request' => 'Zend\Mvc\Container\RequestFactory', - 'Response' => 'Zend\Mvc\Container\ResponseFactory', 'ViewHelperManager' => 'Zend\Mvc\Container\ViewHelperManagerFactory', View\Http\DefaultRenderingStrategy::class => DefaultRenderingStrategyFactory::class, 'ViewFeedStrategy' => 'Zend\Mvc\Container\ViewFeedStrategyFactory', diff --git a/test/Container/RequestFactoryTest.php b/test/Container/RequestFactoryTest.php deleted file mode 100644 index 9969b7928..000000000 --- a/test/Container/RequestFactoryTest.php +++ /dev/null @@ -1,25 +0,0 @@ -prophesize(ContainerInterface::class)->reveal(), 'Request'); - $this->assertInstanceOf(HttpRequest::class, $request); - } -} diff --git a/test/Container/ResponseFactoryTest.php b/test/Container/ResponseFactoryTest.php deleted file mode 100644 index 485990997..000000000 --- a/test/Container/ResponseFactoryTest.php +++ /dev/null @@ -1,25 +0,0 @@ -prophesize(ContainerInterface::class)->reveal(), 'Response'); - $this->assertInstanceOf(HttpResponse::class, $response); - } -} From da30103c84588fbae2f03671f15412b4750092b1 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 1 Dec 2017 04:21:49 +1000 Subject: [PATCH 16/51] Initial PSR-7 refactoring for dispatch listener --- src/DispatchListener.php | 32 ++++++++++--------------------- test/DispatchListenerTest.php | 28 +++++++++++++-------------- test/TestAsset/PathController.php | 16 +++++++--------- 3 files changed, 30 insertions(+), 46 deletions(-) diff --git a/src/DispatchListener.php b/src/DispatchListener.php index c0d2df72b..713e8ad7e 100644 --- a/src/DispatchListener.php +++ b/src/DispatchListener.php @@ -12,7 +12,7 @@ use ArrayObject; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; use Zend\ServiceManager\Exception\InvalidServiceException; use Zend\Stdlib\ArrayUtils; @@ -77,19 +77,18 @@ public function attach(EventManagerInterface $events, $priority = 1) public function onDispatch(MvcEvent $e) { if (null !== $e->getResult()) { - return; + return null; } - $routeMatch = $e->getRouteMatch(); - $controllerName = $routeMatch instanceof RouteMatch - ? $routeMatch->getParam('controller', 'not-found') + $routeResult = $e->getRequest()->getAttribute(RouteResult::class); + $controllerName = $routeResult instanceof RouteResult + ? $routeResult->getMatchedParams()['controller'] ?? 'not-found' : 'not-found'; $application = $e->getApplication(); $events = $application->getEventManager(); $controllerManager = $this->controllerManager; - $return = null; // Query abstract controllers, too! if (! $controllerManager->has($controllerName)) { $return = $this->marshalControllerNotFoundEvent( @@ -124,9 +123,6 @@ public function onDispatch(MvcEvent $e) } catch (\Throwable $exception) { $return = $this->marshalBadControllerEvent($controllerName, $e, $application, $exception); return $this->complete($return, $e); - } catch (\Exception $exception) { // @TODO clean up once PHP 7 requirement is enforced - $return = $this->marshalBadControllerEvent($controllerName, $e, $application, $exception); - return $this->complete($return, $e); } if ($controller instanceof InjectApplicationEventInterface) { @@ -134,25 +130,17 @@ public function onDispatch(MvcEvent $e) } $request = $e->getRequest(); - $response = $application->getResponse(); - $caughtException = null; try { - $return = $controller->dispatch($request, $response); + $return = $controller->dispatch($request); } catch (\Throwable $ex) { - $caughtException = $ex; - } catch (\Exception $ex) { // @TODO clean up once PHP 7 requirement is enforced - $caughtException = $ex; - } - - if ($caughtException !== null) { $e->setName(MvcEvent::EVENT_DISPATCH_ERROR); $e->setError(Application::ERROR_EXCEPTION); $e->setController($controllerName); $e->setControllerClass(get_class($controller)); - $e->setParam('exception', $caughtException); + $e->setParam('exception', $ex); - $return = $application->getEventManager()->triggerEvent($e)->last(); + $return = $events->triggerEvent($e)->last(); if (! $return) { $return = $e->getResult(); } @@ -168,8 +156,7 @@ public function reportMonitorEvent(MvcEvent $e) { $error = $e->getError(); $exception = $e->getParam('exception'); - // @TODO clean up once PHP 7 requirement is enforced - if ($exception instanceof \Exception || $exception instanceof \Throwable) { + if ($exception instanceof \Throwable) { zend_monitor_custom_event_ex( $error, $exception->getMessage(), @@ -193,6 +180,7 @@ protected function complete($return, MvcEvent $event) $return = new ArrayObject($return, ArrayObject::ARRAY_AS_PROPS); } } + // @TODO should this set $return as a response into mvc event? $event->setResult($return); return $return; } diff --git a/test/DispatchListenerTest.php b/test/DispatchListenerTest.php index ed576d415..2cf5d0ca0 100644 --- a/test/DispatchListenerTest.php +++ b/test/DispatchListenerTest.php @@ -10,37 +10,34 @@ namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; -use Zend\Http\Request; -use Zend\Http\Response; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\DispatchListener; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\ResponseInterface; use Zend\View\Model\ModelInterface; class DispatchListenerTest extends TestCase { - public function createMvcEvent($controllerMatched) + public function createMvcEvent(string $controllerMatched) { - $response = new Response(); - $routeMatch = $this->prophesize(RouteMatch::class); - $routeMatch->getParam('controller', 'not-found')->willReturn('path'); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); - $eventManager = new EventManager(); + $routeResult = RouteResult::fromRouteMatch(['controller' => $controllerMatched]); + $request = $request->withAttribute(RouteResult::class, $routeResult); + $eventManager = new EventManager(); $application = $this->prophesize(Application::class); $application->getEventManager()->willReturn($eventManager); - $application->getResponse()->willReturn($response); $event = new MvcEvent(); - $event->setRequest(new Request()); - $event->setResponse($response); + $event->setRequest($request); $event->setApplication($application->reveal()); - $event->setRouteMatch($routeMatch->reveal()); return $event; } @@ -62,7 +59,8 @@ public function testControllerManagerUsingAbstractFactory() $return = $listener->onDispatch($event); $this->assertEmpty($log, var_export($log, true)); - $this->assertSame($event->getResponse(), $return); + // @TODO should response be set in mvc event? + // $this->assertSame($event->getResponse(), $return); $this->assertSame(200, $return->getStatusCode()); } @@ -124,7 +122,7 @@ public function alreadySetMvcEventResultProvider() [$this], [$this->createMock(ModelInterface::class)], [$this->createMock(ResponseInterface::class)], - [$this->createMock(Response::class)], + [new Response()], [['view model data' => 'as an array']], [['foo' => new \stdClass()]], ['a response string'], diff --git a/test/TestAsset/PathController.php b/test/TestAsset/PathController.php index 3a82ea397..d03aca84b 100644 --- a/test/TestAsset/PathController.php +++ b/test/TestAsset/PathController.php @@ -9,18 +9,16 @@ namespace ZendTest\Mvc\TestAsset; -use Zend\Stdlib\DispatchableInterface; -use Zend\Stdlib\RequestInterface as Request; -use Zend\Stdlib\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; +use Zend\Diactoros\Response; +use Zend\Mvc\Controller\Dispatchable; -class PathController implements DispatchableInterface +class PathController implements Dispatchable { - public function dispatch(Request $request, Response $response = null) + public function dispatch(Request $request) { - if (! $response) { - $response = new HttpResponse(); - } - $response->setContent(__METHOD__); + $response = new Response(); + $response->getBody()->write(__METHOD__); return $response; } } From 0799603fe5bc84b4932e8f8f1649c00363510f05 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 1 Dec 2017 05:10:52 +1000 Subject: [PATCH 17/51] Initial PSR-7 refactoring for http method listener --- src/HttpMethodListener.php | 37 +++++++++++++++------------------ test/HttpMethodListenerTest.php | 28 ++++--------------------- 2 files changed, 21 insertions(+), 44 deletions(-) diff --git a/src/HttpMethodListener.php b/src/HttpMethodListener.php index 917d65d25..af3e800f5 100644 --- a/src/HttpMethodListener.php +++ b/src/HttpMethodListener.php @@ -9,10 +9,11 @@ namespace Zend\Mvc; +use Fig\Http\Message\RequestMethodInterface as RequestMethod; +use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; -use Zend\Http\Request as HttpRequest; -use Zend\Http\Response as HttpResponse; class HttpMethodListener extends AbstractListenerAggregate { @@ -20,16 +21,16 @@ class HttpMethodListener extends AbstractListenerAggregate * @var array */ protected $allowedMethods = [ - HttpRequest::METHOD_CONNECT, - HttpRequest::METHOD_DELETE, - HttpRequest::METHOD_GET, - HttpRequest::METHOD_HEAD, - HttpRequest::METHOD_OPTIONS, - HttpRequest::METHOD_PATCH, - HttpRequest::METHOD_POST, - HttpRequest::METHOD_PUT, - HttpRequest::METHOD_PROPFIND, - HttpRequest::METHOD_TRACE, + RequestMethod::METHOD_HEAD, + RequestMethod::METHOD_GET, + RequestMethod::METHOD_POST, + RequestMethod::METHOD_PUT, + RequestMethod::METHOD_PATCH, + RequestMethod::METHOD_DELETE, + RequestMethod::METHOD_OPTIONS, + RequestMethod::METHOD_TRACE, + RequestMethod::METHOD_CONNECT, + 'PROPFIND', ]; /** @@ -68,16 +69,11 @@ public function attach(EventManagerInterface $events, $priority = 1) /** * @param MvcEvent $e - * @return null|HttpResponse + * @return null|ResponseInterface */ - public function onRoute(MvcEvent $e) + public function onRoute(MvcEvent $e) : ?ResponseInterface { $request = $e->getRequest(); - $response = $e->getResponse(); - - if (! $request instanceof HttpRequest || ! $response instanceof HttpResponse) { - return null; - } $method = $request->getMethod(); @@ -85,7 +81,8 @@ public function onRoute(MvcEvent $e) return null; } - $response->setStatusCode(405); + $response = $e->getResponse() ?? new Response(); + $response = $response->withStatus(405); return $response; } diff --git a/test/HttpMethodListenerTest.php b/test/HttpMethodListenerTest.php index 8bd545505..43c1c3409 100644 --- a/test/HttpMethodListenerTest.php +++ b/test/HttpMethodListenerTest.php @@ -10,13 +10,10 @@ namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManagerInterface; -use Zend\Http\Request as HttpRequest; -use Zend\Http\Response as HttpResponse; use Zend\Mvc\HttpMethodListener; use Zend\Mvc\MvcEvent; -use Zend\Stdlib\Request; -use Zend\Stdlib\Response; /** * @covers Zend\Mvc\HttpMethodListener @@ -66,26 +63,11 @@ public function testDoesntAttachIfDisabled() $this->listener->attach($eventManager); } - public function testOnRouteDoesNothingIfNotHttpEnvironment() - { - $event = new MvcEvent(); - $event->setRequest(new Request()); - - $this->assertNull($this->listener->onRoute($event)); - - $event->setRequest(new HttpRequest()); - $event->setResponse(new Response()); - - $this->assertNull($this->listener->onRoute($event)); - } - public function testOnRouteDoesNothingIfIfMethodIsAllowed() { $event = new MvcEvent(); - $request = new HttpRequest(); - $request->setMethod('foo'); + $request = new ServerRequest([], [], null, 'FOO', 'php://memory'); $event->setRequest($request); - $event->setResponse(new HttpResponse()); $this->listener->setAllowedMethods(['foo']); @@ -95,14 +77,12 @@ public function testOnRouteDoesNothingIfIfMethodIsAllowed() public function testOnRouteReturns405ResponseIfMethodNotAllowed() { $event = new MvcEvent(); - $request = new HttpRequest(); - $request->setMethod('foo'); + $request = new ServerRequest([], [], null, 'FOO', 'php://memory'); $event->setRequest($request); - $event->setResponse(new HttpResponse()); $response = $this->listener->onRoute($event); - $this->assertInstanceOf(HttpResponse::class, $response); + $this->assertNotNull($response); $this->assertSame(405, $response->getStatusCode()); } } From fab24c3b6d08d38c586726bb48e859573416b9fe Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 1 Dec 2017 06:15:10 +1000 Subject: [PATCH 18/51] Initial PSR-7 refactoring for middleware listener --- src/MiddlewareListener.php | 50 ++++------ test/MiddlewareListenerTest.php | 164 +++++++++++++------------------- 2 files changed, 85 insertions(+), 129 deletions(-) diff --git a/src/MiddlewareListener.php b/src/MiddlewareListener.php index 146437baa..4d2080c64 100644 --- a/src/MiddlewareListener.php +++ b/src/MiddlewareListener.php @@ -9,18 +9,16 @@ namespace Zend\Mvc; -use Interop\Container\ContainerInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; -use Psr\Http\Message\ResponseInterface as PsrResponseInterface; +use Psr\Container\ContainerInterface; +use Interop\Http\Server\MiddlewareInterface; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface as PsrServerRequestInterface; +use Zend\Diactoros\Response; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Exception\InvalidMiddlewareException; use Zend\Mvc\Exception\ReachedFinalHandlerException; use Zend\Mvc\Controller\MiddlewareController; -use Zend\Psr7Bridge\Psr7Response; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; use Zend\Stratigility\Delegate\CallableDelegateDecorator; use Zend\Stratigility\MiddlewarePipe; @@ -46,32 +44,29 @@ public function attach(EventManagerInterface $events, $priority = 1) public function onDispatch(MvcEvent $event) { if (null !== $event->getResult()) { - return; + return null; } - $routeMatch = $event->getRouteMatch(); - if (! $routeMatch) { - return; + /** @var RouteResult $routeResult */ + $routeResult = $event->getRequest()->getAttribute(RouteResult::class); + if (! $routeResult) { + return null; } - $middleware = $routeMatch->getParam('middleware', false); + $middleware = $routeResult->getMatchedParams()['middleware'] ?? false; if (false === $middleware) { - return; + return null; } $request = $event->getRequest(); $application = $event->getApplication(); - /* - * @var $response \Zend\Http\Response - */ - $response = $application->getResponse(); - $serviceManager = $application->getServiceManager(); + $serviceManager = $application->getContainer(); - $psr7ResponsePrototype = Psr7Response::fromZend($response); + $responsePrototype = $event->getResponse() ?? new Response(); try { $pipe = $this->createPipeFromSpec( $serviceManager, - $psr7ResponsePrototype, + $responsePrototype, is_array($middleware) ? $middleware : [$middleware] ); } catch (InvalidMiddlewareException $invalidMiddlewareException) { @@ -91,14 +86,12 @@ public function onDispatch(MvcEvent $event) try { $return = (new MiddlewareController( $pipe, - $psr7ResponsePrototype, - $application->getServiceManager()->get('EventManager'), + $responsePrototype, + $application->getContainer()->get('EventManager'), $event - ))->dispatch($request, $response); + ))->dispatch($request); } catch (\Throwable $ex) { $caughtException = $ex; - } catch (\Exception $ex) { // @TODO clean up once PHP 7 requirement is enforced - $caughtException = $ex; } if ($caughtException !== null) { @@ -116,13 +109,8 @@ public function onDispatch(MvcEvent $event) $event->setError(''); - if (! $return instanceof PsrResponseInterface) { - $event->setResult($return); - return $return; - } - $response = Psr7Response::toZend($return); - $event->setResult($response); - return $response; + $event->setResult($return); + return $return; } /** diff --git a/test/MiddlewareListenerTest.php b/test/MiddlewareListenerTest.php index d9b4c8713..2076a2e60 100644 --- a/test/MiddlewareListenerTest.php +++ b/test/MiddlewareListenerTest.php @@ -10,46 +10,43 @@ namespace ZendTest\Mvc; use Interop\Container\ContainerInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; +use Interop\Http\Server\MiddlewareInterface; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response\HtmlResponse; -use Zend\Diactoros\Response as DiactorosResponse; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\SharedEventManager; -use Zend\Http\Request; -use Zend\Http\Response; use Zend\Mvc\Application; +use Zend\Mvc\Controller\Dispatchable; use Zend\Mvc\Exception\InvalidMiddlewareException; use Zend\Mvc\Exception\ReachedFinalHandlerException; use Zend\Mvc\MiddlewareListener; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\DispatchableInterface; use Zend\View\Model\ModelInterface; class MiddlewareListenerTest extends TestCase { - /** - * @var \Prophecy\Prophecy\ObjectProphecy - */ - private $routeMatch; - /** * Create an MvcEvent, populated with everything it needs. * * @param string $middlewareMatched Middleware service matched by routing * @param mixed $middleware Value to return for middleware service + * @param array $matchedParams * @return MvcEvent */ - public function createMvcEvent($middlewareMatched, $middleware = null) + public function createMvcEvent($middlewareMatched, $middleware = null, array $matchedParams = []) { $response = new Response(); - $this->routeMatch = $this->prophesize(RouteMatch::class); - $this->routeMatch->getParam('middleware', false)->willReturn($middlewareMatched); - $this->routeMatch->getParams()->willReturn([]); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + + $matchedParams['middleware'] = $middlewareMatched; + $routeResult = RouteResult::fromRouteMatch($matchedParams); + $request = $request->withAttribute(RouteResult::class, $routeResult); $eventManager = new EventManager(); $serviceManager = new ServiceManager([ @@ -65,14 +62,12 @@ public function createMvcEvent($middlewareMatched, $middleware = null) $application = $this->prophesize(Application::class); $application->getEventManager()->willReturn($eventManager); - $application->getServiceManager()->willReturn($serviceManager); - $application->getResponse()->willReturn($response); + $application->getContainer()->willReturn($serviceManager); $event = new MvcEvent(); - $event->setRequest(new Request()); + $event->setRequest($request); $event->setResponse($response); $event->setApplication($application->reveal()); - $event->setRouteMatch($this->routeMatch->reveal()); return $event; } @@ -123,40 +118,18 @@ public function testSuccessfullyDispatchesHttpInteropMiddleware() $this->assertEquals($expectedOutput, $return->getBody()); } - public function testMatchedRouteParamsAreInjectedToRequestAsAttributes() - { - $matchedRouteParam = uniqid('matched param', true); - $routeAttribute = null; - - $event = $this->createMvcEvent( - 'foo', - function (ServerRequestInterface $request, ResponseInterface $response) use (&$routeAttribute) { - $routeAttribute = $request->getAttribute(RouteMatch::class); - $response->getBody()->write($request->getAttribute('myParam', 'param did not exist')); - return $response; - } - ); - - $this->routeMatch->getParams()->willReturn([ - 'myParam' => $matchedRouteParam, - ]); - - $listener = new MiddlewareListener(); - $return = $listener->onDispatch($event); - $this->assertInstanceOf(Response::class, $return); - $this->assertSame($matchedRouteParam, $return->getBody()); - $this->assertSame($this->routeMatch->reveal(), $routeAttribute); - } - public function testSuccessfullyDispatchesPipeOfCallableAndHttpInteropStyleMiddlewares() { $response = new Response(); - $routeMatch = $this->prophesize(RouteMatch::class); - $routeMatch->getParams()->willReturn([]); - $routeMatch->getParam('middleware', false)->willReturn([ - 'firstMiddleware', - 'secondMiddleware', + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + + $routeResult = RouteResult::fromRouteMatch([ + 'middleware' => [ + 'firstMiddleware', + 'secondMiddleware', + ], ]); + $request = $request->withAttribute(RouteResult::class, $routeResult); $eventManager = new EventManager(); @@ -182,16 +155,14 @@ public function testSuccessfullyDispatchesPipeOfCallableAndHttpInteropStyleMiddl $application = $this->prophesize(Application::class); $application->getEventManager()->willReturn($eventManager); - $application->getServiceManager()->will(function () use ($serviceManager) { + $application->getContainer()->will(function () use ($serviceManager) { return $serviceManager->reveal(); }); - $application->getResponse()->willReturn($response); $event = new MvcEvent(); - $event->setRequest(new Request()); + $event->setRequest($request); $event->setResponse($response); $event->setApplication($application->reveal()); - $event->setRouteMatch($routeMatch->reveal()); $event->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $this->fail(sprintf('dispatch.error triggered when it should not be: %s', var_export($e->getError(), 1))); @@ -201,9 +172,9 @@ public function testSuccessfullyDispatchesPipeOfCallableAndHttpInteropStyleMiddl $return = $listener->onDispatch($event); $this->assertInstanceOf(Response::class, $return); - $this->assertInstanceOf('Zend\Http\Response', $return); + $this->assertInstanceOf(ResponseInterface::class, $return); $this->assertSame(200, $return->getStatusCode()); - $this->assertEquals('firstMiddlewareValue', $return->getBody()); + $this->assertEquals('firstMiddlewareValue', $return->getBody()->__toString()); } public function testTriggersErrorForUncallableMiddleware() @@ -247,9 +218,10 @@ public function testTriggersErrorForExceptionRaisedInMiddleware() public function testCanLoadFromAbstractFactory() { $response = new Response(); - $routeMatch = $this->prophesize(RouteMatch::class); - $routeMatch->getParam('middleware', false)->willReturn('test'); - $routeMatch->getParams()->willReturn([]); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + + $routeResult = RouteResult::fromRouteMatch(['middleware' => 'test']); + $request = $request->withAttribute(RouteResult::class, $routeResult); $eventManager = new EventManager(); @@ -264,14 +236,12 @@ function () { $application = $this->prophesize(Application::class); $application->getEventManager()->willReturn($eventManager); - $application->getServiceManager()->willReturn($serviceManager); - $application->getResponse()->willReturn($response); + $application->getContainer()->willReturn($serviceManager); $event = new MvcEvent(); - $event->setRequest(new Request()); + $event->setRequest($request); $event->setResponse($response); $event->setApplication($application->reveal()); - $event->setRouteMatch($routeMatch->reveal()); $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $this->fail(sprintf('dispatch.error triggered when it should not be: %s', var_export($e->getError(), 1))); @@ -288,27 +258,26 @@ function () { public function testMiddlewareWithNothingPipedReachesFinalHandlerException() { $response = new Response(); - $routeMatch = $this->prophesize(RouteMatch::class); - $routeMatch->getParams()->willReturn([]); - $routeMatch->getParam('middleware', false)->willReturn([]); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + + $routeResult = RouteResult::fromRouteMatch(['middleware' => []]); + $request = $request->withAttribute(RouteResult::class, $routeResult); $eventManager = new EventManager(); $serviceManager = $this->prophesize(ContainerInterface::class); $application = $this->prophesize(Application::class); $application->getEventManager()->willReturn($eventManager); - $application->getServiceManager()->will(function () use ($serviceManager) { + $application->getContainer()->will(function () use ($serviceManager) { return $serviceManager->reveal(); }); - $application->getResponse()->willReturn($response); $serviceManager->get('EventManager')->willReturn($eventManager); $event = new MvcEvent(); - $event->setRequest(new Request()); + $event->setRequest($request); $event->setResponse($response); $event->setApplication($application->reveal()); - $event->setRouteMatch($routeMatch->reveal()); $event->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $this->assertEquals(Application::ERROR_EXCEPTION, $e->getError()); @@ -324,25 +293,24 @@ public function testMiddlewareWithNothingPipedReachesFinalHandlerException() public function testNullMiddlewareThrowsInvalidMiddlewareException() { $response = new Response(); - $routeMatch = $this->prophesize(RouteMatch::class); - $routeMatch->getParams()->willReturn([]); - $routeMatch->getParam('middleware', false)->willReturn([null]); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + + $routeResult = RouteResult::fromRouteMatch(['middleware' => [null]]); + $request = $request->withAttribute(RouteResult::class, $routeResult); $eventManager = new EventManager(); $serviceManager = $this->prophesize(ContainerInterface::class); $application = $this->prophesize(Application::class); $application->getEventManager()->willReturn($eventManager); - $application->getServiceManager()->will(function () use ($serviceManager) { + $application->getContainer()->will(function () use ($serviceManager) { return $serviceManager->reveal(); }); - $application->getResponse()->willReturn($response); $event = new MvcEvent(); - $event->setRequest(new Request()); + $event->setRequest($request); $event->setResponse($response); $event->setApplication($application->reveal()); - $event->setRouteMatch($routeMatch->reveal()); $event->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $this->assertEquals(Application::ERROR_MIDDLEWARE_CANNOT_DISPATCH, $e->getError()); @@ -359,8 +327,11 @@ public function testNullMiddlewareThrowsInvalidMiddlewareException() public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures() { $middlewareName = uniqid('middleware', true); - $routeMatch = new RouteMatch(['middleware' => $middlewareName]); - $response = new DiactorosResponse(); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + + $routeResult = RouteResult::fromRouteMatch(['middleware' => $middlewareName]); + $request = $request->withAttribute(RouteResult::class, $routeResult); + $response = new Response(); /* @var $application Application|\PHPUnit_Framework_MockObject_MockObject */ $application = $this->createMock(Application::class); $eventManager = new EventManager(); @@ -376,18 +347,15 @@ public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures() ], ]); - $application->expects(self::any())->method('getRequest')->willReturn(new Request()); $application->expects(self::any())->method('getEventManager')->willReturn($eventManager); - $application->expects(self::any())->method('getServiceManager')->willReturn($serviceManager); - $application->expects(self::any())->method('getResponse')->willReturn(new Response()); + $application->expects(self::any())->method('getContainer')->willReturn($serviceManager); $middleware->expects(self::once())->method('__invoke')->willReturn($response); $event = new MvcEvent(); - $event->setRequest(new Request()); + $event->setRequest($request); $event->setApplication($application); $event->setError(Application::ERROR_CONTROLLER_CANNOT_DISPATCH); - $event->setRouteMatch($routeMatch); $listener = new MiddlewareListener(); $result = $listener->onDispatch($event); @@ -400,8 +368,11 @@ public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures() public function testValidMiddlewareFiresDispatchableInterfaceEventListeners() { $middlewareName = uniqid('middleware', true); - $routeMatch = new RouteMatch(['middleware' => $middlewareName]); - $response = new DiactorosResponse(); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + + $routeResult = RouteResult::fromRouteMatch(['middleware' => $middlewareName]); + $request = $request->withAttribute(RouteResult::class, $routeResult); + $response = new Response(); /* @var $application Application|\PHPUnit_Framework_MockObject_MockObject */ $application = $this->createMock(Application::class); $sharedManager = new SharedEventManager(); @@ -420,22 +391,19 @@ public function testValidMiddlewareFiresDispatchableInterfaceEventListeners() ], ]); - $application->expects(self::any())->method('getRequest')->willReturn(new Request()); $application->expects(self::any())->method('getEventManager')->willReturn($eventManager); - $application->expects(self::any())->method('getServiceManager')->willReturn($serviceManager); - $application->expects(self::any())->method('getResponse')->willReturn(new Response()); + $application->expects(self::any())->method('getContainer')->willReturn($serviceManager); $middleware->expects(self::once())->method('__invoke')->willReturn($response); $event = new MvcEvent(); - $event->setRequest(new Request()); + $event->setRequest($request); $event->setApplication($application); $event->setError(Application::ERROR_CONTROLLER_CANNOT_DISPATCH); - $event->setRouteMatch($routeMatch); $listener = new MiddlewareListener(); - $sharedManager->attach(DispatchableInterface::class, MvcEvent::EVENT_DISPATCH, $sharedListener); + $sharedManager->attach(Dispatchable::class, MvcEvent::EVENT_DISPATCH, $sharedListener, 9001); $sharedListener->expects(self::once())->method('__invoke')->with($event); $listener->onDispatch($event); @@ -449,7 +417,10 @@ public function testValidMiddlewareFiresDispatchableInterfaceEventListeners() public function testWillNotDispatchWhenAnMvcEventResultIsAlreadySet($alreadySetResult) { $middlewareName = uniqid('middleware', true); - $routeMatch = new RouteMatch(['middleware' => $middlewareName]); + $request = new ServerRequest([], [], null, 'GET', 'php://memory'); + + $routeResult = RouteResult::fromRouteMatch(['middleware' => $middlewareName]); + $request = $request->withAttribute(RouteResult::class, $routeResult); /* @var $application Application|\PHPUnit_Framework_MockObject_MockObject */ $application = $this->createMock(Application::class); $eventManager = new EventManager(); @@ -465,19 +436,16 @@ public function testWillNotDispatchWhenAnMvcEventResultIsAlreadySet($alreadySetR ], ]); - $application->expects(self::any())->method('getRequest')->willReturn(new Request()); $application->expects(self::any())->method('getEventManager')->willReturn($eventManager); - $application->expects(self::any())->method('getServiceManager')->willReturn($serviceManager); - $application->expects(self::any())->method('getResponse')->willReturn(new Response()); + $application->expects(self::any())->method('getContainer')->willReturn($serviceManager); $middleware->expects(self::never())->method('__invoke'); $event = new MvcEvent(); $event->setResult($alreadySetResult); // a result is already there - listener should bail out early - $event->setRequest(new Request()); + $event->setRequest($request); $event->setApplication($application); $event->setError(Application::ERROR_CONTROLLER_CANNOT_DISPATCH); - $event->setRouteMatch($routeMatch); $listener = new MiddlewareListener(); @@ -503,7 +471,7 @@ public function alreadySetMvcEventResultProvider() [new \stdClass()], [$this], [$this->createMock(ModelInterface::class)], - [$this->createMock(Response::class)], + [$this->createMock(ResponseInterface::class)], [['view model data' => 'as an array']], [['foo' => new \stdClass()]], ['a response string'], From d214751f83a16efc27c528804ed407c9980b0e65 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 2 Dec 2017 12:25:40 +1000 Subject: [PATCH 19/51] Initial PSR-7 refactoring for Application --- src/Application.php | 140 +++++++-------- src/ApplicationInterface.php | 28 +-- src/Container/ApplicationFactory.php | 13 +- src/Container/ViewHelperManagerFactory.php | 10 -- src/RouteListener.php | 17 +- .../AllowsReturningEarlyFromRoutingTest.php | 9 +- test/Application/BadControllerTrait.php | 15 +- .../ControllerIsDispatchedTest.php | 8 +- ...hableShouldRaiseDispatchErrorEventTest.php | 14 +- ...ntrollerShouldTriggerDispatchErrorTest.php | 15 +- ...veControllerShouldTriggerExceptionTest.php | 15 +- .../InitializationIntegrationTest.php | 15 +- ...llerTypeShouldTriggerDispatchErrorTest.php | 15 +- .../InvalidControllerTypeTrait.php | 15 +- test/Application/MissingControllerTrait.php | 15 +- test/Application/PathControllerTrait.php | 15 +- test/Application/RoutingSuccessTest.php | 16 +- test/ApplicationTest.php | 164 ++++++++---------- .../ViewHelperManagerFactoryTest.php | 2 - test/TestAsset/MockSendResponseListener.php | 26 --- 20 files changed, 253 insertions(+), 314 deletions(-) delete mode 100644 test/TestAsset/MockSendResponseListener.php diff --git a/src/Application.php b/src/Application.php index 561bd585b..6246b0899 100644 --- a/src/Application.php +++ b/src/Application.php @@ -9,11 +9,19 @@ namespace Zend\Mvc; +use InvalidArgumentException; +use Psr\Container\ContainerInterface; +use Psr\Http\Message\ServerRequestInterface as Request; +use Psr\Http\Message\ResponseInterface; +use UnexpectedValueException; +use Zend\Diactoros\Response; +use Zend\Diactoros\Response\EmitterInterface; +use Zend\Diactoros\Response\SapiEmitter; +use Zend\Diactoros\ServerRequestFactory; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerInterface; +use Zend\Mvc\Emitter\EmitterStack; use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\RequestInterface; -use Zend\Stdlib\ResponseInterface; /** * Main application class for invoking applications @@ -81,38 +89,30 @@ class Application implements protected $events; /** - * @var \Zend\Stdlib\RequestInterface + * @var ContainerInterface */ - protected $request; + protected $container; /** - * @var ResponseInterface + * @var EmitterInterface */ - protected $response; - - /** - * @var ServiceManager - */ - protected $serviceManager; + private $emitter; /** * Constructor * - * @param ServiceManager $serviceManager + * @param ContainerInterface $container * @param null|EventManagerInterface $events - * @param null|RequestInterface $request - * @param null|ResponseInterface $response + * @param EmitterInterface|null $emitter */ public function __construct( - ServiceManager $serviceManager, + ContainerInterface $container, EventManagerInterface $events = null, - RequestInterface $request = null, - ResponseInterface $response = null + EmitterInterface $emitter = null ) { - $this->serviceManager = $serviceManager; - $this->setEventManager($events ?: $serviceManager->get('EventManager')); - $this->request = $request ?: $serviceManager->get('Request'); - $this->response = $response ?: $serviceManager->get('Response'); + $this->container = $container; + $this->setEventManager($events ?: $container->get('EventManager')); + $this->emitter = $emitter; } /** @@ -122,7 +122,7 @@ public function __construct( */ public function getConfig() { - return $this->serviceManager->get('config'); + return $this->container->get('config'); } /** @@ -133,18 +133,18 @@ public function getConfig() * event. * * @param array $listeners List of listeners to attach. - * @return Application + * @return ApplicationInterface */ - public function bootstrap(array $listeners = []) + public function bootstrap(array $listeners = []) : ApplicationInterface { - $serviceManager = $this->serviceManager; + $container = $this->container; $events = $this->events; // Setup default listeners $listeners = array_unique(array_merge($this->defaultListeners, $listeners)); foreach ($listeners as $listener) { - $serviceManager->get($listener)->attach($events); + $container->get($listener)->attach($events); } // Setup MVC Event @@ -152,9 +152,7 @@ public function bootstrap(array $listeners = []) $event->setName(MvcEvent::EVENT_BOOTSTRAP); $event->setTarget($this); $event->setApplication($this); - $event->setRequest($this->request); - $event->setResponse($this->response); - $event->setRouter($serviceManager->get('Router')); + $event->setRouter($container->get('Router')); // Trigger bootstrap events $events->triggerEvent($event); @@ -165,31 +163,11 @@ public function bootstrap(array $listeners = []) /** * Retrieve the service manager * - * @return ServiceManager - */ - public function getServiceManager() - { - return $this->serviceManager; - } - - /** - * Get the request object - * - * @return \Zend\Stdlib\RequestInterface - */ - public function getRequest() - { - return $this->request; - } - - /** - * Get the response object - * - * @return ResponseInterface + * @return ContainerInterface */ - public function getResponse() + public function getContainer() : ContainerInterface { - return $this->response; + return $this->container; } /** @@ -197,7 +175,7 @@ public function getResponse() * * @return MvcEvent */ - public function getMvcEvent() + public function getMvcEvent() : ?MvcEvent { return $this->event; } @@ -206,16 +184,15 @@ public function getMvcEvent() * Set the event manager instance * * @param EventManagerInterface $eventManager - * @return Application + * @return void */ - public function setEventManager(EventManagerInterface $eventManager) + public function setEventManager(EventManagerInterface $eventManager) : void { $eventManager->setIdentifiers([ __CLASS__, get_class($this), ]); $this->events = $eventManager; - return $this; } /** @@ -225,7 +202,7 @@ public function setEventManager(EventManagerInterface $eventManager) * * @return EventManagerInterface */ - public function getEventManager() + public function getEventManager() : EventManagerInterface { return $this->events; } @@ -247,9 +224,9 @@ public function getEventManager() * overridden by modules. * * @param array $configuration - * @return Application + * @return ApplicationInterface */ - public static function init($configuration = []) + public static function init($configuration = []) : ApplicationInterface { // Prepare the service manager $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : []; @@ -286,12 +263,29 @@ public static function init($configuration = []) * discovered controller, and controller class (if known). * Typically, a handler should return a populated Response object * that can be returned immediately. - * @return self + * @param Request|null $request + * @return void */ - public function run() + public function run(Request $request = null) : void + { + try { + $request = $request ?: ServerRequestFactory::fromGlobals(); + } catch (InvalidArgumentException | UnexpectedValueException $e) { + // emit bad request + throw new \Exception('Not implemented'); + } + + $response = $this->handle($request); + + $emitter = $this->getEmitter(); + $emitter->emit($response); + } + + public function handle(Request $request) : ResponseInterface { $events = $this->events; $event = $this->event; + $event->setRequest($request); // Define callback used to determine whether or not to short-circuit $shortCircuit = function ($r) use ($event) { @@ -316,8 +310,7 @@ public function run() $event->setResponse($response); $event->stopPropagation(false); // Clear before triggering $events->triggerEvent($event); - $this->response = $response; - return $this; + return $event->getResponse(); } } @@ -338,15 +331,21 @@ public function run() $event->setResponse($response); $event->stopPropagation(false); // Clear before triggering $events->triggerEvent($event); - $this->response = $response; - return $this; + return $event->getResponse(); } - $response = $this->response; - $event->setResponse($response); return $this->completeRequest($event); } + public function getEmitter() : EmitterInterface + { + if (! $this->emitter) { + $this->emitter = new EmitterStack(); + $this->emitter->push(new SapiEmitter()); + } + return $this->emitter; + } + /** * Complete the request * @@ -354,9 +353,9 @@ public function run() * event object. * * @param MvcEvent $event - * @return Application + * @return MvcEvent */ - protected function completeRequest(MvcEvent $event) + protected function completeRequest(MvcEvent $event) : ResponseInterface { $events = $this->events; $event->setTarget($this); @@ -369,6 +368,7 @@ protected function completeRequest(MvcEvent $event) $event->stopPropagation(false); // Clear before triggering $events->triggerEvent($event); - return $this; + // @TODO handle missing response. Investigate possibility for using middleware delegate + return ($event->getResponse() ?? new Response()); } } diff --git a/src/ApplicationInterface.php b/src/ApplicationInterface.php index 99807c4c6..8cf1b4a31 100644 --- a/src/ApplicationInterface.php +++ b/src/ApplicationInterface.php @@ -9,35 +9,25 @@ namespace Zend\Mvc; +use Interop\Http\Server\RequestHandlerInterface; +use Psr\Container\ContainerInterface; +use Psr\Http\Message\ServerRequestInterface; use Zend\EventManager\EventsCapableInterface; -interface ApplicationInterface extends EventsCapableInterface +interface ApplicationInterface extends EventsCapableInterface, RequestHandlerInterface { /** * Get the locator object * - * @return \Zend\ServiceManager\ServiceLocatorInterface + * @return ContainerInterface */ - public function getServiceManager(); - - /** - * Get the request object - * - * @return \Zend\Stdlib\RequestInterface - */ - public function getRequest(); - - /** - * Get the response object - * - * @return \Zend\Stdlib\ResponseInterface - */ - public function getResponse(); + public function getContainer() : ContainerInterface; /** * Run the application * - * @return self + * @param ServerRequestInterface|null $request + * @return void */ - public function run(); + public function run(ServerRequestInterface $request = null) : void; } diff --git a/src/Container/ApplicationFactory.php b/src/Container/ApplicationFactory.php index 4e261f140..38ac33beb 100644 --- a/src/Container/ApplicationFactory.php +++ b/src/Container/ApplicationFactory.php @@ -10,10 +10,9 @@ namespace Zend\Mvc\Container; use Interop\Container\ContainerInterface; +use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; -use Zend\Mvc\Exception\RuntimeException; use Zend\ServiceManager\Factory\FactoryInterface; -use Zend\ServiceManager\ServiceManager; class ApplicationFactory implements FactoryInterface { @@ -30,15 +29,13 @@ class ApplicationFactory implements FactoryInterface */ public function __invoke(ContainerInterface $container, $name, array $options = null) { - if (! $container instanceof ServiceManager) { - // @TODO convert Application to use ContainerInterface - throw new RuntimeException('Mvc Application requires ServiceManager as ContainerInterface implementation'); - } + $emitter = $container->has(EmitterInterface::class) + ? $container->get(EmitterInterface::class) + : null; return new Application( $container, $container->get('EventManager'), - $container->get('Request'), - $container->get('Response') + $emitter ); } } diff --git a/src/Container/ViewHelperManagerFactory.php b/src/Container/ViewHelperManagerFactory.php index 5a233a0c3..c4728c216 100644 --- a/src/Container/ViewHelperManagerFactory.php +++ b/src/Container/ViewHelperManagerFactory.php @@ -11,7 +11,6 @@ use Interop\Container\ContainerInterface; use Zend\Mvc\Service\AbstractPluginManagerFactory; -use Zend\Router\RouteMatch; use Zend\ServiceManager\AbstractPluginManager; use Zend\ServiceManager\Exception\ServiceNotCreatedException; use Zend\View\Helper as ViewHelper; @@ -93,15 +92,6 @@ private function createUrlHelperFactory(ContainerInterface $services) $helper = new ViewHelper\Url; $helper->setRouter($services->get('HttpRouter')); - $match = $services->get('Application') - ->getMvcEvent() - ->getRouteMatch() - ; - - if ($match instanceof RouteMatch) { - $helper->setRouteMatch($match); - } - return $helper; }; } diff --git a/src/RouteListener.php b/src/RouteListener.php index 1f0ffbfb8..9cc9a4bf4 100644 --- a/src/RouteListener.php +++ b/src/RouteListener.php @@ -11,7 +11,7 @@ use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; class RouteListener extends AbstractListenerAggregate { @@ -36,21 +36,26 @@ public function attach(EventManagerInterface $events, $priority = 1) * Seeds the event with the route match on completion. * * @param MvcEvent $event - * @return null|RouteMatch|mixed + * @return null|RouteResult|mixed */ public function onRoute(MvcEvent $event) { $request = $event->getRequest(); $router = $event->getRouter(); - $routeMatch = $router->match($request); + $routeResult = $router->match($request); - if ($routeMatch instanceof RouteMatch) { - $event->setRouteMatch($routeMatch); - return $routeMatch; + if ($routeResult->isSuccess()) { + foreach ($routeResult->getMatchedParams() as $name => $param) { + $request = $request->withAttribute($name, $param); + } + $request = $request->withAttribute(RouteResult::class, $routeResult); + $event->setRequest($request); + return $routeResult; } $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); $event->setError(Application::ERROR_ROUTER_NO_MATCH); + $event->setParam(RouteResult::class, $routeResult); $target = $event->getTarget(); $results = $target->getEventManager()->triggerEvent($event); diff --git a/test/Application/AllowsReturningEarlyFromRoutingTest.php b/test/Application/AllowsReturningEarlyFromRoutingTest.php index daee26c5f..6757ebb18 100644 --- a/test/Application/AllowsReturningEarlyFromRoutingTest.php +++ b/test/Application/AllowsReturningEarlyFromRoutingTest.php @@ -10,7 +10,8 @@ namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; -use Zend\Http\PhpEnvironment\Response; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\MvcEvent; class AllowsReturningEarlyFromRoutingTest extends TestCase @@ -27,8 +28,8 @@ public function testAllowsReturningEarlyFromRouting() return $response; }); - $result = $application->run(); - $this->assertSame($application, $result); - $this->assertSame($response, $result->getResponse()); + $request = new ServerRequest([], [], 'http://example.local/path', 'GET', 'php://memory'); + $resultResponse = $application->handle($request); + $this->assertSame($response, $resultResponse); } } diff --git a/test/Application/BadControllerTrait.php b/test/Application/BadControllerTrait.php index 8c7f6c88b..cef7d53f3 100644 --- a/test/Application/BadControllerTrait.php +++ b/test/Application/BadControllerTrait.php @@ -10,8 +10,7 @@ namespace ZendTest\Mvc\Application; use ReflectionProperty; -use Zend\Http\PhpEnvironment\Request; -use Zend\Http\PhpEnvironment\Response; +use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\Container\ServiceManagerConfig; @@ -30,7 +29,7 @@ public function prepareApplication() 'router' => [ 'routes' => [ 'path' => [ - 'type' => Router\Http\Literal::class, + 'type' => Router\Route\Literal::class, 'options' => [ 'route' => '/bad', 'defaults' => [ @@ -71,12 +70,13 @@ public function prepareApplication() 'Router' => function ($services) { return $services->get('HttpRouter'); }, + EmitterInterface::class => function () { + $emitter = $this->prophesize(EmitterInterface::class); + return $emitter->reveal(); + }, ], 'invokables' => [ - 'Request' => Request::class, - 'Response' => Response::class, 'ViewManager' => TestAsset\MockViewManager::class, - 'SendResponseListener' => TestAsset\MockSendResponseListener::class, 'BootstrapListener' => TestAsset\StubBootstrapListener::class, ], 'services' => [ @@ -96,9 +96,6 @@ public function prepareApplication() (new ServiceManagerConfig($serviceConfig))->configureServiceManager($services); $application = $services->get('Application'); - $request = $services->get('Request'); - $request->setUri('http://example.local/bad'); - $application->bootstrap(); return $application; } diff --git a/test/Application/ControllerIsDispatchedTest.php b/test/Application/ControllerIsDispatchedTest.php index 06be86ae0..7533253f4 100644 --- a/test/Application/ControllerIsDispatchedTest.php +++ b/test/Application/ControllerIsDispatchedTest.php @@ -10,6 +10,7 @@ namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\MvcEvent; class ControllerIsDispatchedTest extends TestCase @@ -20,8 +21,9 @@ public function testControllerIsDispatchedDuringRun() { $application = $this->prepareApplication(); - $response = $application->run()->getResponse(); - $this->assertContains('PathController', $response->getContent()); - $this->assertContains(MvcEvent::EVENT_DISPATCH, $response->toString()); + $request = new ServerRequest([], [], 'http://example.local/path', 'GET', 'php://memory'); + $response = $application->handle($request); + $this->assertContains('PathController', $response->getBody()->__toString()); + $this->assertContains(MvcEvent::EVENT_DISPATCH, $response->getBody()->__toString()); } } diff --git a/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php b/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php index d3262ce2e..5f0ec10a5 100644 --- a/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php +++ b/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php @@ -10,6 +10,8 @@ namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\MvcEvent; class ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest extends TestCase @@ -23,16 +25,18 @@ public function testExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEvent( { $application = $this->prepareApplication(); - $response = $application->getResponse(); $events = $application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { + $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $exception = $e->getParam('exception'); $this->assertInstanceOf('Exception', $exception); - $response->setContent($exception->getMessage()); + $response = new Response(); + $response->getBody()->write($exception->getMessage()); + $e->setResponse($response); return $response; }); - $application->run(); - $this->assertContains('Raised an exception', $response->getContent()); + $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); + $response = $application->handle($request); + $this->assertContains('Raised an exception', $response->getBody()->__toString()); } } diff --git a/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php b/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php index bbdefcd77..4b56dae65 100644 --- a/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php +++ b/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php @@ -10,6 +10,8 @@ namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; @@ -24,17 +26,18 @@ public function testInabilityToRetrieveControllerShouldTriggerDispatchError() { $application = $this->prepareApplication(); - $response = $application->getResponse(); $events = $application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { + $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $error = $e->getError(); $controller = $e->getController(); - $response->setContent("Code: " . $error . '; Controller: ' . $controller); + $response = new Response(); + $response->getBody()->write("Code: " . $error . '; Controller: ' . $controller); return $response; }); - $application->run(); - $this->assertContains(Application::ERROR_CONTROLLER_NOT_FOUND, $response->getContent()); - $this->assertContains('bad', $response->getContent()); + $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); + $response = $application->handle($request); + $this->assertContains(Application::ERROR_CONTROLLER_NOT_FOUND, $response->getBody()->__toString()); + $this->assertContains('bad', $response->getBody()->__toString()); } } diff --git a/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php b/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php index 38552fd0c..16f4b426c 100644 --- a/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php +++ b/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php @@ -10,6 +10,8 @@ namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; @@ -24,17 +26,18 @@ public function testInabilityToRetrieveControllerShouldTriggerExceptionError() { $application = $this->prepareApplication(); - $response = $application->getResponse(); $events = $application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { + $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $error = $e->getError(); $controller = $e->getController(); - $response->setContent("Code: " . $error . '; Controller: ' . $controller); + $response = new Response(); + $response->getBody()->write("Code: " . $error . '; Controller: ' . $controller); return $response; }); - $application->run(); - $this->assertContains(Application::ERROR_CONTROLLER_NOT_FOUND, $response->getContent()); - $this->assertContains('bad', $response->getContent()); + $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); + $response = $application->handle($request); + $this->assertContains(Application::ERROR_CONTROLLER_NOT_FOUND, $response->getBody()->__toString()); + $this->assertContains('bad', $response->getBody()->__toString()); } } diff --git a/test/Application/InitializationIntegrationTest.php b/test/Application/InitializationIntegrationTest.php index 372d08ba1..9d392f3e1 100644 --- a/test/Application/InitializationIntegrationTest.php +++ b/test/Application/InitializationIntegrationTest.php @@ -10,6 +10,7 @@ namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; @@ -31,17 +32,11 @@ public function testDefaultInitializationWorkflow() $application = Application::init($appConfig); - $request = $application->getRequest(); - $request->setUri('http://example.local/path'); - $request->setRequestUri('/path'); + $request = new ServerRequest([], [], 'http://example.local/path', 'GET', 'php://memory'); - ob_start(); - $application->run(); - $content = ob_get_clean(); + $response = $application->handle($request); - $response = $application->getResponse(); - $this->assertContains('Application\\Controller\\PathController', $response->getContent()); - $this->assertContains('Application\\Controller\\PathController', $content); - $this->assertContains(MvcEvent::EVENT_DISPATCH, $response->toString()); + $this->assertContains('Application\\Controller\\PathController', $response->getBody()->__toString()); + $this->assertContains(MvcEvent::EVENT_DISPATCH, $response->getBody()->__toString()); } } diff --git a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php index 295ab8619..65c10ab43 100644 --- a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php +++ b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php @@ -10,6 +10,8 @@ namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\Response; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; @@ -24,18 +26,19 @@ public function testInvalidControllerTypeShouldTriggerDispatchError() { $application = $this->prepareApplication(); - $response = $application->getResponse(); $events = $application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { + $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $error = $e->getError(); $controller = $e->getController(); $class = $e->getControllerClass(); - $response->setContent("Code: " . $error . '; Controller: ' . $controller . '; Class: ' . $class); + $response = new Response(); + $response->getBody()->write("Code: " . $error . '; Controller: ' . $controller . '; Class: ' . $class); return $response; }); - $application->run(); - $this->assertContains(Application::ERROR_CONTROLLER_INVALID, $response->getContent()); - $this->assertContains('bad', $response->getContent()); + $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); + $response = $application->handle($request); + $this->assertContains(Application::ERROR_CONTROLLER_INVALID, $response->getBody()->__toString()); + $this->assertContains('bad', $response->getBody()->__toString()); } } diff --git a/test/Application/InvalidControllerTypeTrait.php b/test/Application/InvalidControllerTypeTrait.php index a94f541b7..061c622ff 100644 --- a/test/Application/InvalidControllerTypeTrait.php +++ b/test/Application/InvalidControllerTypeTrait.php @@ -11,8 +11,7 @@ use ReflectionProperty; use stdClass; -use Zend\Http\PhpEnvironment\Request; -use Zend\Http\PhpEnvironment\Response; +use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\Container\ServiceManagerConfig; @@ -30,7 +29,7 @@ public function prepareApplication() 'router' => [ 'routes' => [ 'path' => [ - 'type' => Router\Http\Literal::class, + 'type' => Router\Route\Literal::class, 'options' => [ 'route' => '/bad', 'defaults' => [ @@ -70,12 +69,13 @@ public function prepareApplication() 'Router' => function ($services) { return $services->get('HttpRouter'); }, + EmitterInterface::class => function () { + $emitter = $this->prophesize(EmitterInterface::class); + return $emitter->reveal(); + }, ], 'invokables' => [ - 'Request' => Request::class, - 'Response' => Response::class, 'ViewManager' => TestAsset\MockViewManager::class, - 'SendResponseListener' => TestAsset\MockSendResponseListener::class, 'BootstrapListener' => TestAsset\StubBootstrapListener::class, ], 'services' => [ @@ -95,9 +95,6 @@ public function prepareApplication() (new ServiceManagerConfig($serviceConfig))->configureServiceManager($services); $application = $services->get('Application'); - $request = $services->get('Request'); - $request->setUri('http://example.local/bad'); - $application->bootstrap(); return $application; } diff --git a/test/Application/MissingControllerTrait.php b/test/Application/MissingControllerTrait.php index 455ce9cee..0791260e9 100644 --- a/test/Application/MissingControllerTrait.php +++ b/test/Application/MissingControllerTrait.php @@ -10,8 +10,7 @@ namespace ZendTest\Mvc\Application; use ReflectionProperty; -use Zend\Http\PhpEnvironment\Request; -use Zend\Http\PhpEnvironment\Response; +use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Container\ServiceManagerConfig; use Zend\Mvc\Container\ServiceListenerFactory; @@ -28,7 +27,7 @@ public function prepareApplication() 'router' => [ 'routes' => [ 'path' => [ - 'type' => Router\Http\Literal::class, + 'type' => Router\Route\Literal::class, 'options' => [ 'route' => '/bad', 'defaults' => [ @@ -58,12 +57,13 @@ public function prepareApplication() 'Router' => function ($services) { return $services->get('HttpRouter'); }, + EmitterInterface::class => function () { + $emitter = $this->prophesize(EmitterInterface::class); + return $emitter->reveal(); + }, ], 'invokables' => [ - 'Request' => Request::class, - 'Response' => Response::class, 'ViewManager' => TestAsset\MockViewManager::class, - 'SendResponseListener' => TestAsset\MockSendResponseListener::class, 'BootstrapListener' => TestAsset\StubBootstrapListener::class, ], 'services' => [ @@ -83,9 +83,6 @@ public function prepareApplication() (new ServiceManagerConfig($serviceConfig))->configureServiceManager($services); $application = $services->get('Application'); - $request = $services->get('Request'); - $request->setUri('http://example.local/bad'); - $application->bootstrap(); return $application; } diff --git a/test/Application/PathControllerTrait.php b/test/Application/PathControllerTrait.php index 6626830f6..505383536 100644 --- a/test/Application/PathControllerTrait.php +++ b/test/Application/PathControllerTrait.php @@ -10,8 +10,7 @@ namespace ZendTest\Mvc\Application; use ReflectionProperty; -use Zend\Http\PhpEnvironment\Request; -use Zend\Http\PhpEnvironment\Response; +use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\Container\ServiceManagerConfig; @@ -29,7 +28,7 @@ public function prepareApplication() 'router' => [ 'routes' => [ 'path' => [ - 'type' => Router\Http\Literal::class, + 'type' => Router\Route\Literal::class, 'options' => [ 'route' => '/path', 'defaults' => [ @@ -69,12 +68,13 @@ public function prepareApplication() 'Router' => function ($services) { return $services->get('HttpRouter'); }, + EmitterInterface::class => function () { + $emitter = $this->prophesize(EmitterInterface::class); + return $emitter->reveal(); + }, ], 'invokables' => [ - 'Request' => Request::class, - 'Response' => Response::class, 'ViewManager' => TestAsset\MockViewManager::class, - 'SendResponseListener' => TestAsset\MockSendResponseListener::class, 'BootstrapListener' => TestAsset\StubBootstrapListener::class, ], 'services' => [ @@ -96,9 +96,6 @@ public function prepareApplication() (new ServiceManagerConfig($serviceConfig))->configureServiceManager($services); $application = $services->get('Application'); - $request = $services->get('Request'); - $request->setUri('http://example.local/path'); - $application->bootstrap(); return $application; } diff --git a/test/Application/RoutingSuccessTest.php b/test/Application/RoutingSuccessTest.php index 08c96065a..2989d7a9e 100644 --- a/test/Application/RoutingSuccessTest.php +++ b/test/Application/RoutingSuccessTest.php @@ -10,8 +10,9 @@ namespace ZendTest\Mvc\Application; use PHPUnit\Framework\TestCase; +use Zend\Diactoros\ServerRequest; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; +use Zend\Router\RouteResult; class RoutingSuccessTest extends TestCase { @@ -24,13 +25,14 @@ public function testRoutingIsExcecutedDuringRun() $log = []; $application->getEventManager()->attach(MvcEvent::EVENT_ROUTE, function ($e) use (&$log) { - $match = $e->getRouteMatch(); - $this->assertInstanceOf(RouteMatch::class, $match, 'Did not receive expected route match'); - $log['route-match'] = $match; + $result = $e->getRequest()->getAttribute(RouteResult::class); + $this->assertInstanceOf(RouteResult::class, $result, 'Did not receive expected route match'); + $log['route-result'] = $result; }, -100); - $application->run(); - $this->assertArrayHasKey('route-match', $log); - $this->assertInstanceOf(RouteMatch::class, $log['route-match']); + $request = new ServerRequest([], [], 'http://example.local/path', 'GET', 'php://memory'); + $resultResponse = $application->handle($request); + $this->assertArrayHasKey('route-result', $log); + $this->assertInstanceOf(RouteResult::class, $log['route-result']); } } diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index 2d8586683..d13d3c641 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -10,14 +10,16 @@ namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseInterface; use ReflectionMethod; use ReflectionProperty; use stdClass; +use Zend\Diactoros\Response; +use Zend\Diactoros\Response\EmitterInterface; +use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\SharedEventManager; use Zend\EventManager\Test\EventListenerIntrospectionTrait; -use Zend\Http\PhpEnvironment; -use Zend\Http\PhpEnvironment\Response; use Zend\ModuleManager\Listener\ConfigListener; use Zend\ModuleManager\ModuleEvent; use Zend\Mvc\Application; @@ -26,9 +28,9 @@ use Zend\Mvc\Container\ServiceManagerConfig; use Zend\Mvc\Container\ServiceListenerFactory; use Zend\Router; +use Zend\Router\RouteResult; use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\ArrayUtils; -use Zend\Stdlib\ResponseInterface; use Zend\View\Model\ViewModel; class ApplicationTest extends TestCase @@ -61,14 +63,15 @@ public function setUp() $serviceConfig, [ 'invokables' => [ - 'Request' => PhpEnvironment\Request::class, - 'Response' => PhpEnvironment\Response::class, 'ViewManager' => TestAsset\MockViewManager::class, - 'SendResponseListener' => TestAsset\MockSendResponseListener::class, 'BootstrapListener' => TestAsset\StubBootstrapListener::class, ], 'factories' => [ 'Router' => Router\RouterFactory::class, + EmitterInterface::class => function () { + $emitter = $this->prophesize(EmitterInterface::class); + return $emitter->reveal(); + }, ], 'services' => [ 'config' => [], @@ -106,17 +109,6 @@ public function getConfigListener() }); } - public function testRequestIsPopulatedFromServiceManager() - { - $request = $this->serviceManager->get('Request'); - $this->assertSame($request, $this->application->getRequest()); - } - - public function testResponseIsPopulatedFromServiceManager() - { - $response = $this->serviceManager->get('Response'); - $this->assertSame($response, $this->application->getResponse()); - } public function testEventManagerIsPopulated() { @@ -138,7 +130,7 @@ public function testEventManagerListensOnApplicationContext() public function testServiceManagerIsPopulated() { - $this->assertSame($this->serviceManager, $this->application->getServiceManager()); + $this->assertSame($this->serviceManager, $this->application->getContainer()); } public function testConfigIsPopulated() @@ -189,7 +181,6 @@ public function bootstrapRegistersListenersProvider() 'route' => ['RouteListener' , MvcEvent::EVENT_ROUTE , 'onRoute', false], 'dispatch' => ['DispatchListener' , MvcEvent::EVENT_DISPATCH , 'onDispatch', false], 'middleware' => ['MiddlewareListener' , MvcEvent::EVENT_DISPATCH , 'onDispatch', false], - 'send_response' => ['SendResponseListener' , MvcEvent::EVENT_FINISH , 'sendResponse', false], 'view_manager' => ['ViewManager' , MvcEvent::EVENT_BOOTSTRAP , 'onBootstrap', false], 'http_method' => ['HttpMethodListener' , MvcEvent::EVENT_ROUTE , 'onRoute', false], 'bootstrap' => ['BootstrapListener' , MvcEvent::EVENT_BOOTSTRAP , 'onBootstrap', true ], @@ -232,13 +223,11 @@ public function testBootstrapRegistersConfiguredMvcEvent() $event = $this->application->getMvcEvent(); $this->assertInstanceOf(MvcEvent::class, $event); - $request = $this->application->getRequest(); - $response = $this->application->getResponse(); $router = $this->serviceManager->get('HttpRouter'); $this->assertFalse($event->isError()); - $this->assertSame($request, $event->getRequest()); - $this->assertSame($response, $event->getResponse()); + $this->assertNull($event->getRequest()); + $this->assertNull($event->getResponse()); $this->assertSame($router, $event->getRouter()); $this->assertSame($this->application, $event->getApplication()); $this->assertSame($this->application, $event->getTarget()); @@ -246,11 +235,8 @@ public function testBootstrapRegistersConfiguredMvcEvent() public function setupPathController($addService = true) { - $request = $this->serviceManager->get('Request'); - $request->setUri('http://example.local/path'); - $router = $this->serviceManager->get('HttpRouter'); - $route = Router\Http\Literal::factory([ + $route = Router\Route\Literal::factory([ 'route' => '/path', 'defaults' => [ 'controller' => 'path', @@ -276,11 +262,8 @@ public function setupPathController($addService = true) public function setupActionController() { - $request = $this->serviceManager->get('Request'); - $request->setUri('http://example.local/sample'); - $router = $this->serviceManager->get('HttpRouter'); - $route = Router\Http\Literal::factory([ + $route = Router\Route\Literal::factory([ 'route' => '/sample', 'defaults' => [ 'controller' => 'sample', @@ -303,11 +286,8 @@ public function setupActionController() public function setupBadController($addService = true, $action = 'test') { - $request = $this->serviceManager->get('Request'); - $request->setUri('http://example.local/bad'); - $router = $this->serviceManager->get('HttpRouter'); - $route = Router\Http\Literal::factory([ + $route = Router\Route\Literal::factory([ 'route' => '/bad', 'defaults' => [ 'controller' => 'bad', @@ -334,12 +314,17 @@ public function testFinishEventIsTriggeredAfterDispatching() { $application = $this->setupActionController(); $application->getEventManager()->attach(MvcEvent::EVENT_FINISH, function ($e) { - return $e->getResponse()->setContent($e->getResponse()->getBody() . 'foobar'); + $response = new Response(); + $response->getBody()->write('foobar'); + $e->setResponse($response); }); - $application->run(); + + $request = new ServerRequest([], [], 'http://example.local/sample', 'GET', 'php://memory'); + + $application->run($request); $this->assertContains( 'foobar', - $this->application->getResponse()->getBody(), + $this->application->getMvcEvent()->getResponse()->getBody()->__toString(), 'The "finish" event was not triggered ("foobar" not in response)' ); } @@ -354,17 +339,23 @@ public function testRoutingFailureShouldTriggerDispatchError() $event = $application->getMvcEvent(); $event->setRouter($router); - $response = $application->getResponse(); $events = $application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { + $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $error = $e->getError(); - $response->setContent("Code: " . $error); + $response = new Response(); + $response->getBody()->write("Code: " . $error); + $e->setResponse($response); return $response; }); - $application->run(); + $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); + + $application->run($request); $this->assertTrue($event->isError()); - $this->assertContains(Application::ERROR_ROUTER_NO_MATCH, $response->getContent()); + $this->assertContains( + Application::ERROR_ROUTER_NO_MATCH, + $application->getMvcEvent()->getResponse()->getBody()->__toString() + ); } /** @@ -373,15 +364,16 @@ public function testRoutingFailureShouldTriggerDispatchError() public function testLocatorExceptionShouldTriggerDispatchError() { $application = $this->setupPathController(false); - $controllerLoader = $application->getServiceManager()->get('ControllerManager'); + $controllerLoader = $application->getContainer()->get('ControllerManager'); $response = new Response(); $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { return $response; }); - $result = $application->run(); - $this->assertSame($application, $result, get_class($result)); - $this->assertSame($response, $result->getResponse(), get_class($result)); + $request = new ServerRequest([], [], 'http://example.local/path', 'GET', 'php://memory'); + + $resultResponse = $application->handle($request); + $this->assertSame($response, $resultResponse); } /** @@ -391,16 +383,18 @@ public function testLocatorExceptionShouldTriggerDispatchError() public function testPhp7ErrorRaisedInDispatchableShouldRaiseDispatchErrorEvent() { $this->setupBadController(true, 'test-php7-error'); - $response = $this->application->getResponse(); $events = $this->application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { + $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $exception = $e->getParam('exception'); - $response->setContent($exception->getMessage()); + $response = new Response(); + $response->getBody()->write($exception->getMessage()); return $response; }); - $this->application->run(); - $this->assertContains('Raised an error', $response->getContent()); + $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); + + $response = $this->application->handle($request); + $this->assertContains('Raised an error', $response->getBody()->__toString()); } /** @@ -413,15 +407,16 @@ public function testFailureForRouteToReturnRouteMatchShouldPopulateEventError() $event = $application->getMvcEvent(); $event->setRouter($router); - $response = $application->getResponse(); $events = $application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { + $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { $error = $e->getError(); - $response->setContent("Code: " . $error); + $response = new Response(); + $response->getBody()->write("Code: " . $error); return $response; }); - $application->run(); + $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); + $application->handle($request); $this->assertTrue($event->isError()); $this->assertEquals(Application::ERROR_ROUTER_NO_MATCH, $event->getError()); } @@ -432,10 +427,9 @@ public function testFailureForRouteToReturnRouteMatchShouldPopulateEventError() public function testFinishShouldRunEvenIfRouteEventReturnsResponse() { $this->application->bootstrap(); - $response = $this->application->getResponse(); $events = $this->application->getEventManager(); - $events->attach(MvcEvent::EVENT_ROUTE, function ($e) use ($response) { - return $response; + $events->attach(MvcEvent::EVENT_ROUTE, function ($e) { + return new Response(); }, 100); $token = new stdClass; @@ -454,11 +448,10 @@ public function testFinishShouldRunEvenIfRouteEventReturnsResponse() public function testFinishShouldRunEvenIfDispatchEventReturnsResponse() { $this->application->bootstrap(); - $response = $this->application->getResponse(); $events = $this->application->getEventManager(); $events->clearListeners(MvcEvent::EVENT_ROUTE); - $events->attach(MvcEvent::EVENT_DISPATCH, function ($e) use ($response) { - return $response; + $events->attach(MvcEvent::EVENT_DISPATCH, function ($e) { + return new Response(); }, 100); $token = new stdClass; @@ -476,20 +469,20 @@ public function testApplicationShouldBeEventTargetAtFinishEvent() $application = $this->setupActionController(); $events = $application->getEventManager(); - $response = $application->getResponse(); - $events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($response) { - $response->setContent("EventClass: " . get_class($e->getTarget())); - return $response; + $events->attach(MvcEvent::EVENT_FINISH, function ($e) { + $response = new Response(); + $response->getBody()->write("EventClass: " . get_class($e->getTarget())); + $e->setResponse($response); }); - $application->run(); - $this->assertContains(Application::class, $response->getContent()); + $request = new ServerRequest([], [], 'http://example.local/sample', 'GET', 'php://memory'); + $response = $application->handle($request); + $this->assertContains(Application::class, $response->getBody()->__toString()); } public function testOnDispatchErrorEventPassedToTriggersShouldBeTheOriginalOne() { $application = $this->setupPathController(false); - $controllerManager = $application->getServiceManager()->get('ControllerManager'); $model = $this->createMock(ViewModel::class); $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($model) { $e->setResult($model); @@ -507,11 +500,10 @@ public function testReturnsResponseFromListenerWhenRouteEventShortCircuits() { $this->application->bootstrap(); $testResponse = new Response(); - $response = $this->application->getResponse(); $events = $this->application->getEventManager(); $events->clearListeners(MvcEvent::EVENT_DISPATCH); $events->attach(MvcEvent::EVENT_ROUTE, function ($e) use ($testResponse) { - $testResponse->setContent('triggered'); + $testResponse->getBody()->write('triggered'); return $testResponse; }, 100); @@ -532,11 +524,10 @@ public function testReturnsResponseFromListenerWhenDispatchEventShortCircuits() { $this->application->bootstrap(); $testResponse = new Response(); - $response = $this->application->getResponse(); $events = $this->application->getEventManager(); $events->clearListeners(MvcEvent::EVENT_ROUTE); $events->attach(MvcEvent::EVENT_DISPATCH, function ($e) use ($testResponse) { - $testResponse->setContent('triggered'); + $testResponse->getBody()->write('triggered'); return $testResponse; }, 100); @@ -550,17 +541,6 @@ public function testReturnsResponseFromListenerWhenDispatchEventShortCircuits() $this->assertTrue($triggered); } - public function testCompleteRequestShouldReturnApplicationInstance() - { - $r = new ReflectionMethod($this->application, 'completeRequest'); - $r->setAccessible(true); - - $this->application->bootstrap(); - $event = $this->application->getMvcEvent(); - $result = $r->invoke($this->application, $event); - $this->assertSame($this->application, $result); - } - public function testFailedRoutingShouldBePreventable() { $this->application->bootstrap(); @@ -578,7 +558,10 @@ public function testFailedRoutingShouldBePreventable() $routeMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { $event->stopPropagation(true); - $event->setRouteMatch(new Router\RouteMatch([])); + $request = $event->getRequest(); + $event->setRequest( + $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch([])) + ); })); $dispatchMock->expects($this->once())->method('__invoke')->will($this->returnValue($response)); $finishMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { @@ -613,7 +596,10 @@ public function testCanRecoverFromApplicationError() $errorMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { $event->stopPropagation(true); - $event->setRouteMatch(new Router\RouteMatch([])); + $request = $event->getRequest(); + $event->setRequest( + $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch([])) + ); $event->setError(''); })); $routeMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { @@ -651,10 +637,8 @@ public function testEventPropagationStatusIsClearedBetweenEventsDuringRun($event { $event = new MvcEvent(); $event->setTarget($this->application); - $event->setApplication($this->application) - ->setRequest($this->application->getRequest()) - ->setResponse($this->application->getResponse()) - ->setRouter($this->serviceManager->get('Router')); + $event->setApplication($this->application); + $event->setRouter($this->serviceManager->get('Router')); $event->stopPropagation(true); // Intentionally not calling bootstrap; setting mvc event diff --git a/test/Container/ViewHelperManagerFactoryTest.php b/test/Container/ViewHelperManagerFactoryTest.php index 15ead72c6..f69679a94 100644 --- a/test/Container/ViewHelperManagerFactoryTest.php +++ b/test/Container/ViewHelperManagerFactoryTest.php @@ -10,11 +10,9 @@ namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; -use Zend\Http\PhpEnvironment\Request; use Zend\Mvc\Application; use Zend\Mvc\Container\ViewHelperManagerFactory; use Zend\Mvc\MvcEvent; -use Zend\Router\RouteMatch; use Zend\Router\RouteStackInterface; use Zend\ServiceManager\ServiceManager; use Zend\View\Helper; diff --git a/test/TestAsset/MockSendResponseListener.php b/test/TestAsset/MockSendResponseListener.php deleted file mode 100644 index 02d4f5c1d..000000000 --- a/test/TestAsset/MockSendResponseListener.php +++ /dev/null @@ -1,26 +0,0 @@ -listeners[] = $events->attach(MvcEvent::EVENT_FINISH, [$this, 'sendResponse'], -10000); - } - - public function sendResponse($e) - { - } -} From 6c078bf3aa0261762fc0f21f3ecad7cc306a12eb Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Wed, 27 Dec 2017 15:41:05 +1000 Subject: [PATCH 20/51] Add temporary request/response wrappers for view --- src/View/Http/DefaultRenderingStrategy.php | 15 +++--- src/View/RequestWrapper.php | 55 ++++++++++++++++++++ src/View/ResponseWrapper.php | 59 ++++++++++++++++++++++ 3 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 src/View/RequestWrapper.php create mode 100644 src/View/ResponseWrapper.php diff --git a/src/View/Http/DefaultRenderingStrategy.php b/src/View/Http/DefaultRenderingStrategy.php index cf19047d7..3469d55bc 100644 --- a/src/View/Http/DefaultRenderingStrategy.php +++ b/src/View/Http/DefaultRenderingStrategy.php @@ -10,10 +10,13 @@ namespace Zend\Mvc\View\Http; use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; +use Zend\Mvc\View\RequestWrapper; +use Zend\Mvc\View\ResponseWrapper; use Zend\View\Model\ModelInterface as ViewModel; use Zend\View\View; @@ -96,10 +99,9 @@ public function render(MvcEvent $e) : ?ResponseInterface $view = $this->view; // @TODO fix after view is updated - $view->setRequest($request); - $view->setResponse($response); - - $caughtException = null; + $responseWrapper = new ResponseWrapper($response ?? new Response()); + $view->setRequest(new RequestWrapper($request)); + $view->setResponse($responseWrapper); try { $view->render($viewModel); @@ -112,11 +114,12 @@ public function render(MvcEvent $e) : ?ResponseInterface $events = $application->getEventManager(); $e->setError(Application::ERROR_EXCEPTION); - $e->setParam('exception', $caughtException); + $e->setParam('exception', $ex); $e->setName(MvcEvent::EVENT_RENDER_ERROR); $events->triggerEvent($e); } - return $response; + $e->setResponse($responseWrapper->getResponse()); + return $responseWrapper->getResponse(); } } diff --git a/src/View/RequestWrapper.php b/src/View/RequestWrapper.php new file mode 100644 index 000000000..9121616bf --- /dev/null +++ b/src/View/RequestWrapper.php @@ -0,0 +1,55 @@ +request = $request; + } + + public function getRequest() : Request + { + return $this->request; + } + + public function setRequest(Request $request) : void + { + $this->request = $request; + } + + /** + * Set content + * + * @param mixed $content + * @return mixed + */ + public function setContent($content) + { + } + + /** + * Get content + * + * @return mixed + */ + public function getContent() + { + return $this->request->getBody()->__toString(); + } +} diff --git a/src/View/ResponseWrapper.php b/src/View/ResponseWrapper.php new file mode 100644 index 000000000..659e4f1eb --- /dev/null +++ b/src/View/ResponseWrapper.php @@ -0,0 +1,59 @@ +response = $response; + } + + public function getResponse() : ResponseInterface + { + return $this->response; + } + + public function setResponse(ResponseInterface $response) : void + { + $this->response = $response; + } + + /** + * Set content + * + * @param mixed $content + * @return mixed + */ + public function setContent($content) + { + $stream = new Stream('php://memory', 'wb+'); + $stream->write($content); + $this->response = $this->response->withBody($stream); + } + + /** + * Get content + * + * @return mixed + */ + public function getContent() + { + return $this->response->getBody()->__toString(); + } +} From f12a4388efc04a0d67cb45c5a8c70df9f9650d59 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Wed, 27 Dec 2017 16:55:25 +1000 Subject: [PATCH 21/51] Drop module manager from direct dependencies --- composer.json | 1 - composer.lock | 122 +------------------------------------------------- 2 files changed, 1 insertion(+), 122 deletions(-) diff --git a/composer.json b/composer.json index de41acd2a..cd5a412c7 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "psr/http-message": "^1.0", "zendframework/zend-diactoros": "^1.7", "zendframework/zend-eventmanager": "^3.2", - "zendframework/zend-modulemanager": "^2.8", "zendframework/zend-router": "dev-make-mvc-great-again", "zendframework/zend-servicemanager": "^3.3", "zendframework/zend-stdlib": "^3.1", diff --git a/composer.lock b/composer.lock index 576808c8e..c9ec41160 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "8158e75ff14b1f3c77dc719aa9e5f4fc", + "content-hash": "8b5201bd45f72189384f07eecc76ff68", "packages": [ { "name": "container-interop/container-interop", @@ -186,66 +186,6 @@ ], "time": "2016-08-06T14:39:51+00:00" }, - { - "name": "zendframework/zend-config", - "version": "3.1.0", - "source": { - "type": "git", - "url": "https://github.com/zendframework/zend-config.git", - "reference": "a12e4a592bf66d9629b84960e268f3752e53abe4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-config/zipball/a12e4a592bf66d9629b84960e268f3752e53abe4", - "reference": "a12e4a592bf66d9629b84960e268f3752e53abe4", - "shasum": "" - }, - "require": { - "ext-json": "*", - "php": "^5.6 || ^7.0", - "psr/container": "^1.0", - "zendframework/zend-stdlib": "^2.7.7 || ^3.1" - }, - "conflict": { - "container-interop/container-interop": "<1.2.0" - }, - "require-dev": { - "malukenho/docheader": "^0.1.5", - "phpunit/phpunit": "^5.7 || ^6.0", - "zendframework/zend-coding-standard": "~1.0.0", - "zendframework/zend-filter": "^2.7.1", - "zendframework/zend-i18n": "^2.7.3", - "zendframework/zend-servicemanager": "^2.7.8 || ^3.2.1" - }, - "suggest": { - "zendframework/zend-filter": "^2.7.1; install if you want to use the Filter processor", - "zendframework/zend-i18n": "^2.7.3; install if you want to use the Translator processor", - "zendframework/zend-servicemanager": "^2.7.8 || ^3.2.1; if you need an extensible plugin manager for use with the Config Factory" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.1-dev", - "dev-develop": "3.2-dev" - } - }, - "autoload": { - "psr-4": { - "Zend\\Config\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "provides a nested object property based user interface for accessing this configuration data within application code", - "homepage": "https://github.com/zendframework/zend-config", - "keywords": [ - "config", - "zf2" - ], - "time": "2017-02-22T14:31:10+00:00" - }, { "name": "zendframework/zend-diactoros", "version": "1.7.0", @@ -396,66 +336,6 @@ ], "time": "2015-06-03T14:05:47+00:00" }, - { - "name": "zendframework/zend-modulemanager", - "version": "2.8.2", - "source": { - "type": "git", - "url": "https://github.com/zendframework/zend-modulemanager.git", - "reference": "394df6e12248ac430a312d4693f793ee7120baa6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-modulemanager/zipball/394df6e12248ac430a312d4693f793ee7120baa6", - "reference": "394df6e12248ac430a312d4693f793ee7120baa6", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0", - "zendframework/zend-config": "^3.1 || ^2.6", - "zendframework/zend-eventmanager": "^3.2 || ^2.6.3", - "zendframework/zend-stdlib": "^3.1 || ^2.7" - }, - "require-dev": { - "phpunit/phpunit": "^6.0.8 || ^5.7.15", - "zendframework/zend-coding-standard": "~1.0.0", - "zendframework/zend-console": "^2.6", - "zendframework/zend-di": "^2.6", - "zendframework/zend-loader": "^2.5", - "zendframework/zend-mvc": "^3.0 || ^2.7", - "zendframework/zend-servicemanager": "^3.0.3 || ^2.7.5" - }, - "suggest": { - "zendframework/zend-console": "Zend\\Console component", - "zendframework/zend-loader": "Zend\\Loader component if you are not using Composer autoloading for your modules", - "zendframework/zend-mvc": "Zend\\Mvc component", - "zendframework/zend-servicemanager": "Zend\\ServiceManager component" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev", - "dev-develop": "2.8-dev" - } - }, - "autoload": { - "psr-4": { - "Zend\\ModuleManager\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Modular application system for zend-mvc applications", - "homepage": "https://github.com/zendframework/zend-modulemanager", - "keywords": [ - "ZendFramework", - "modulemanager", - "zf" - ], - "time": "2017-12-02T06:11:18+00:00" - }, { "name": "zendframework/zend-router", "version": "dev-make-mvc-great-again", From 8a3e2e76f9720d553284668784e6c8b7dfeb1bc0 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 28 Dec 2017 17:53:28 +1000 Subject: [PATCH 22/51] Drop ModuleManager from Application --- src/Application.php | 128 +++--- test/ApplicationTest.php | 822 +++++++++++++++++---------------------- test/ContainerTrait.php | 51 +++ 3 files changed, 479 insertions(+), 522 deletions(-) create mode 100644 test/ContainerTrait.php diff --git a/src/Application.php b/src/Application.php index 6246b0899..0ee62d135 100644 --- a/src/Application.php +++ b/src/Application.php @@ -18,10 +18,13 @@ use Zend\Diactoros\Response\EmitterInterface; use Zend\Diactoros\Response\SapiEmitter; use Zend\Diactoros\ServerRequestFactory; +use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerInterface; +use Zend\EventManager\ListenerAggregateInterface; use Zend\Mvc\Emitter\EmitterStack; -use Zend\ServiceManager\ServiceManager; +use Zend\Mvc\View\Http\ViewManager; +use Zend\Router\RouteStackInterface; /** * Main application class for invoking applications @@ -70,13 +73,18 @@ class Application implements * @var array */ protected $defaultListeners = [ - 'RouteListener', - 'MiddlewareListener', - 'DispatchListener', - 'HttpMethodListener', - 'ViewManager', + RouteListener::class, + MiddlewareListener::class, + DispatchListener::class, + HttpMethodListener::class, + ViewManager::class, ]; + /** + * @var string[]|ListenerAggregateInterface[] + */ + private $listeners = []; + /** * MVC event token * @var MvcEvent @@ -98,21 +106,43 @@ class Application implements */ private $emitter; + /** + * @var RouteStackInterface + */ + private $router; + + /** + * If application was bootstrapped + * + * @var bool + */ + private $bootstrapped = false; + /** * Constructor * - * @param ContainerInterface $container - * @param null|EventManagerInterface $events - * @param EmitterInterface|null $emitter + * @param ContainerInterface $container IoC container from which to pull services + * @param RouteStackInterface $router Configured router for RouteListener + * @param EventManagerInterface|null $events + * @param EmitterInterface|null $emitter Response emitter to use when `run()` + * is invoked + * @param array $listeners Extra listeners to attach on bootstrap + * Can be container keys or instances of ListenerAggregateInterface */ public function __construct( ContainerInterface $container, + RouteStackInterface $router, EventManagerInterface $events = null, - EmitterInterface $emitter = null + EmitterInterface $emitter = null, + array $listeners = [] ) { $this->container = $container; - $this->setEventManager($events ?: $container->get('EventManager')); + $this->router = $router; + $this->setEventManager($events ?? new EventManager()); $this->emitter = $emitter; + $this->listeners = $listeners; + + // @TODO response prototype? } /** @@ -129,35 +159,37 @@ public function getConfig() * Bootstrap the application * * Defines and binds the MvcEvent, and passes it the request, response, and - * router. Attaches the ViewManager as a listener. Triggers the bootstrap + * router. Attaches default listeners. Triggers the bootstrap * event. - * - * @param array $listeners List of listeners to attach. - * @return ApplicationInterface */ - public function bootstrap(array $listeners = []) : ApplicationInterface + public function bootstrap() : void { - $container = $this->container; - $events = $this->events; - - // Setup default listeners - $listeners = array_unique(array_merge($this->defaultListeners, $listeners)); + if ($this->bootstrapped) { + return; + } + $events = $this->events; + // @TODO may be move this to constructor + $listeners = array_unique(array_merge($this->defaultListeners, $this->listeners), \SORT_REGULAR); foreach ($listeners as $listener) { - $container->get($listener)->attach($events); + if ($listener instanceof ListenerAggregateInterface) { + $listener->attach($events); + continue; + } + $this->container->get($listener)->attach($events); } // Setup MVC Event - $this->event = $event = new MvcEvent(); + $this->event = $event = new MvcEvent(); $event->setName(MvcEvent::EVENT_BOOTSTRAP); $event->setTarget($this); $event->setApplication($this); - $event->setRouter($container->get('Router')); + $event->setRouter($this->router); // Trigger bootstrap events $events->triggerEvent($event); - return $this; + $this->bootstrapped = true; } /** @@ -207,48 +239,6 @@ public function getEventManager() : EventManagerInterface return $this->events; } - /** - * Static method for quick and easy initialization of the Application. - * - * If you use this init() method, you cannot specify a service with the - * name of 'ApplicationConfig' in your service manager config. This name is - * reserved to hold the array from application.config.php. - * - * The following services can only be overridden from application.config.php: - * - * - ModuleManager - * - SharedEventManager - * - EventManager & Zend\EventManager\EventManagerInterface - * - * All other services are configured after module loading, thus can be - * overridden by modules. - * - * @param array $configuration - * @return ApplicationInterface - */ - public static function init($configuration = []) : ApplicationInterface - { - // Prepare the service manager - $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : []; - $smConfig = new Container\ServiceManagerConfig($smConfig); - - $serviceManager = new ServiceManager(); - $smConfig->configureServiceManager($serviceManager); - $serviceManager->setService('ApplicationConfig', $configuration); - - // Load modules - $serviceManager->get('ModuleManager')->loadModules(); - - // Prepare list of listeners to bootstrap - $listenersFromAppConfig = isset($configuration['listeners']) ? $configuration['listeners'] : []; - $config = $serviceManager->get('config'); - $listenersFromConfigService = isset($config['listeners']) ? $config['listeners'] : []; - - $listeners = array_unique(array_merge($listenersFromConfigService, $listenersFromAppConfig)); - - return $serviceManager->get('Application')->bootstrap($listeners); - } - /** * Run the application * @@ -283,7 +273,11 @@ public function run(Request $request = null) : void public function handle(Request $request) : ResponseInterface { + if (! $this->bootstrapped) { + $this->bootstrap(); + } $events = $this->events; + // @TODO revisit later for multi-request improvements $event = $this->event; $event->setRequest($request); diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index d13d3c641..79b89acfa 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -10,114 +10,107 @@ namespace ZendTest\Mvc; use PHPUnit\Framework\TestCase; -use Psr\Http\Message\ResponseInterface; -use ReflectionMethod; +use Prophecy\Prophecy\ObjectProphecy; use ReflectionProperty; -use stdClass; use Zend\Diactoros\Response; use Zend\Diactoros\Response\EmitterInterface; +use Zend\Diactoros\Response\SapiEmitter; use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; +use Zend\EventManager\ListenerAggregateInterface; use Zend\EventManager\SharedEventManager; use Zend\EventManager\Test\EventListenerIntrospectionTrait; -use Zend\ModuleManager\Listener\ConfigListener; -use Zend\ModuleManager\ModuleEvent; use Zend\Mvc\Application; -use Zend\Mvc\Controller\ControllerManager; +use Zend\Mvc\DispatchListener; +use Zend\Mvc\Emitter\EmitterStack; +use Zend\Mvc\HttpMethodListener; +use Zend\Mvc\MiddlewareListener; use Zend\Mvc\MvcEvent; -use Zend\Mvc\Container\ServiceManagerConfig; -use Zend\Mvc\Container\ServiceListenerFactory; -use Zend\Router; +use Zend\Mvc\RouteListener; +use Zend\Mvc\View\Http\ViewManager; use Zend\Router\RouteResult; -use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\ArrayUtils; -use Zend\View\Model\ViewModel; +use Zend\Router\RouteStackInterface; +/** + * @covers \Zend\Mvc\Application + */ class ApplicationTest extends TestCase { use EventListenerIntrospectionTrait; + use ContainerTrait; /** - * @var ServiceManager + * @var Application */ - protected $serviceManager; + private $application; /** - * @var Application + * @var ObjectProphecy + */ + private $container; + + /** + * @var ObjectProphecy + */ + private $router; + + /** + * @var ObjectProphecy */ - protected $application; + private $emitter; + + /** + * @var EventManager + */ + private $events; + + /** + * @var array + */ + private $listeners = []; public function setUp() { - $serviceListener = new ServiceListenerFactory(); - $r = new ReflectionProperty($serviceListener, 'defaultServiceConfig'); - $r->setAccessible(true); - $serviceConfig = $r->getValue($serviceListener); + $this->container = $this->mockContainerInterface(); - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - (new Router\ConfigProvider())->getDependencyConfig() - ); + $this->router = $this->prophesize(RouteStackInterface::class); + $this->emitter = $this->prophesize(EmitterInterface::class); + $this->events = new EventManager(new SharedEventManager()); - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - [ - 'invokables' => [ - 'ViewManager' => TestAsset\MockViewManager::class, - 'BootstrapListener' => TestAsset\StubBootstrapListener::class, - ], - 'factories' => [ - 'Router' => Router\RouterFactory::class, - EmitterInterface::class => function () { - $emitter = $this->prophesize(EmitterInterface::class); - return $emitter->reveal(); - }, - ], - 'services' => [ - 'config' => [], - 'ApplicationConfig' => [ - 'modules' => [ - 'Zend\Router', - ], - 'module_listener_options' => [ - 'config_cache_enabled' => false, - 'cache_dir' => 'data/cache', - 'module_paths' => [], - ], - ], - ], - ] - ); - $this->serviceManager = new ServiceManager(); - (new ServiceManagerConfig($serviceConfig))->configureServiceManager($this->serviceManager); - $this->serviceManager->setAllowOverride(true); - $this->application = $this->serviceManager->get('Application'); - } + $this->injectServiceInContainer($this->container, 'config', []); - public function getConfigListener() - { - $manager = $this->serviceManager->get('ModuleManager'); - $listeners = $this->getArrayOfListenersForEvent(ModuleEvent::EVENT_LOAD_MODULE, $manager->getEventManager()); - return array_reduce($listeners, function ($found, $listener) { - if ($found || ! is_array($listener)) { - return $found; - } - $listener = array_shift($listener); - if ($listener instanceof ConfigListener) { - return $listener; - } - }); - } + $route = $this->prophesize(RouteListener::class); + $this->injectServiceInContainer($this->container, RouteListener::class, $route->reveal()); + $this->listeners[RouteListener::class] = $route; + + $dispatch = $this->prophesize(DispatchListener::class); + $this->injectServiceInContainer($this->container, DispatchListener::class, $dispatch->reveal()); + $this->listeners[DispatchListener::class] = $dispatch; + + $middleware = $this->prophesize(MiddlewareListener::class); + $this->injectServiceInContainer($this->container, MiddlewareListener::class, $middleware->reveal()); + $this->listeners[MiddlewareListener::class] = $middleware; + + $viewManager = $this->prophesize(ViewManager::class); + $this->injectServiceInContainer($this->container, ViewManager::class, $viewManager->reveal()); + $this->listeners[ViewManager::class] = $viewManager; + $httpMethod = $this->prophesize(HttpMethodListener::class); + $this->injectServiceInContainer($this->container, HttpMethodListener::class, $httpMethod->reveal()); + $this->listeners[HttpMethodListener::class] = $httpMethod; + + $this->application = new Application( + $this->container->reveal(), + $this->router->reveal(), + $this->events, + $this->emitter->reveal() + ); + } public function testEventManagerIsPopulated() { - $events = $this->serviceManager->get('EventManager'); - $sharedEvents = $events->getSharedManager(); - $appEvents = $this->application->getEventManager(); - $this->assertInstanceOf(EventManager::class, $appEvents); - $this->assertNotSame($events, $appEvents); - $this->assertSame($sharedEvents, $appEvents->getSharedManager()); + $appEvents = $this->application->getEventManager(); + $this->assertSame($this->events, $appEvents); } public function testEventManagerListensOnApplicationContext() @@ -128,19 +121,20 @@ public function testEventManagerListensOnApplicationContext() $this->assertEquals($expected, array_values($identifiers)); } - public function testServiceManagerIsPopulated() + public function testContainerIsPopulated() { - $this->assertSame($this->serviceManager, $this->application->getContainer()); + $this->assertSame($this->container->reveal(), $this->application->getContainer()); } - public function testConfigIsPopulated() + public function testConfigIsAProxyToContainer() { - $smConfig = $this->serviceManager->get('config'); + $this->container->get('config') + ->shouldBeCalled() + ->willReturn(['container' => 'config']); $appConfig = $this->application->getConfig(); $this->assertEquals( - $smConfig, - $appConfig, - sprintf('SM config: %s; App config: %s', var_export($smConfig, true), var_export($appConfig, true)) + ['container' => 'config'], + $appConfig ); } @@ -155,65 +149,54 @@ public function testEventsAreEmptyAtFirst() $this->assertAttributeEquals([], 'identifiers', $sharedEvents); } - /** - * @param string $listenerServiceName - * @param string $event - * @param string $method - * - * @dataProvider bootstrapRegistersListenersProvider - */ - public function testBootstrapRegistersListeners($listenerServiceName, $event, $method, $isCustom = false) + public function testBootstrapRegistersListeners() { - $listenerService = $this->serviceManager->get($listenerServiceName); - $this->application->bootstrap($isCustom ? (array) $listenerServiceName : []); - $events = $this->application->getEventManager(); - - $foundListener = false; - $listeners = $this->getArrayOfListenersForEvent($event, $events); - $this->assertContains([$listenerService, $method], $listeners); - } + foreach ($this->listeners as $listener) { + $listener->attach($this->events)->shouldBeCalled(); + } - public function bootstrapRegistersListenersProvider() - { - // @codingStandardsIgnoreStart - // [ Service Name, Event, Method, isCustom ] - return [ - 'route' => ['RouteListener' , MvcEvent::EVENT_ROUTE , 'onRoute', false], - 'dispatch' => ['DispatchListener' , MvcEvent::EVENT_DISPATCH , 'onDispatch', false], - 'middleware' => ['MiddlewareListener' , MvcEvent::EVENT_DISPATCH , 'onDispatch', false], - 'view_manager' => ['ViewManager' , MvcEvent::EVENT_BOOTSTRAP , 'onBootstrap', false], - 'http_method' => ['HttpMethodListener' , MvcEvent::EVENT_ROUTE , 'onRoute', false], - 'bootstrap' => ['BootstrapListener' , MvcEvent::EVENT_BOOTSTRAP , 'onBootstrap', true ], - ]; - // @codingStandardsIgnoreEnd + $this->application->bootstrap(); } public function testBootstrapAlwaysRegistersDefaultListeners() { + $application = new Application( + $this->container->reveal(), + $this->router->reveal(), + $this->events, + $this->emitter->reveal(), + ['Custom'] + ); + $r = new ReflectionProperty($this->application, 'defaultListeners'); $r->setAccessible(true); - $defaultListenersNames = $r->getValue($this->application); - $defaultListeners = []; - foreach ($defaultListenersNames as $defaultListenerName) { - $defaultListeners[] = $this->serviceManager->get($defaultListenerName); + $defaultListeners = $r->getValue($this->application); + foreach ($defaultListeners as $defaultListenerName) { + $custom = $this->prophesize(ListenerAggregateInterface::class); + $custom->attach($this->events)->shouldBeCalled(); + $this->injectServiceInContainer($this->container, $defaultListenerName, $custom->reveal()); } - $this->application->bootstrap(['BootstrapListener']); - $eventManager = $this->application->getEventManager(); + $custom = $this->prophesize(ListenerAggregateInterface::class); + $custom->attach($this->events)->shouldBeCalled(); + $this->injectServiceInContainer($this->container, 'Custom', $custom->reveal()); - $registeredListeners = []; - foreach ($this->getEventsFromEventManager($eventManager) as $event) { - foreach ($this->getListenersForEvent($event, $eventManager) as $listener) { - if (is_array($listener)) { - $listener = array_shift($listener); - } - $registeredListeners[] = $listener; - } - } + $application->bootstrap(); + } - foreach ($defaultListeners as $defaultListener) { - $this->assertContains($defaultListener, $registeredListeners); - } + public function testBootstrapAttachesInstanceOfListenerAggregate() + { + $custom = $this->prophesize(ListenerAggregateInterface::class); + $custom->attach($this->events)->shouldBeCalled(); + $application = new Application( + $this->container->reveal(), + $this->router->reveal(), + $this->events, + $this->emitter->reveal(), + [$custom->reveal()] + ); + + $application->bootstrap(); } public function testBootstrapRegistersConfiguredMvcEvent() @@ -223,274 +206,255 @@ public function testBootstrapRegistersConfiguredMvcEvent() $event = $this->application->getMvcEvent(); $this->assertInstanceOf(MvcEvent::class, $event); - $router = $this->serviceManager->get('HttpRouter'); - $this->assertFalse($event->isError()); $this->assertNull($event->getRequest()); $this->assertNull($event->getResponse()); - $this->assertSame($router, $event->getRouter()); + $this->assertSame($this->router->reveal(), $event->getRouter()); $this->assertSame($this->application, $event->getApplication()); $this->assertSame($this->application, $event->getTarget()); } - public function setupPathController($addService = true) + public function testBootstrapTriggersBootstrapEvent() { - $router = $this->serviceManager->get('HttpRouter'); - $route = Router\Route\Literal::factory([ - 'route' => '/path', - 'defaults' => [ - 'controller' => 'path', - ], - ]); - $router->addRoute('path', $route); - $this->serviceManager->setService('HttpRouter', $router); - $this->serviceManager->setService('Router', $router); - - if ($addService) { - $this->services->addFactory('ControllerManager', function ($services) { - return new ControllerManager($services, ['factories' => [ - 'path' => function () { - return new TestAsset\PathController; - }, - ]]); - }); - } - + $called = false; + $this->application->getEventManager()->attach( + MvcEvent::EVENT_BOOTSTRAP, + function ($e) use (&$called) { + $this->assertInstanceOf(MvcEvent::class, $e); + $called = true; + } + ); $this->application->bootstrap(); - return $this->application; + $this->assertTrue($called); } - public function setupActionController() + public function testBootstrapTriggersOnlyOnce() { - $router = $this->serviceManager->get('HttpRouter'); - $route = Router\Route\Literal::factory([ - 'route' => '/sample', - 'defaults' => [ - 'controller' => 'sample', - 'action' => 'test', - ], - ]); - $router->addRoute('sample', $route); - - $this->serviceManager->setFactory('ControllerManager', function ($services) { - return new ControllerManager($services, ['factories' => [ - 'sample' => function () { - return new Controller\TestAsset\SampleController(); - }, - ]]); - }); - + $called = 0; + $this->application->getEventManager()->attach( + MvcEvent::EVENT_BOOTSTRAP, + function ($e) use (&$called) { + $this->assertInstanceOf(MvcEvent::class, $e); + $called++; + } + ); + $this->application->bootstrap(); $this->application->bootstrap(); - return $this->application; + $this->assertEquals(1, $called); } - public function setupBadController($addService = true, $action = 'test') + public function testHandleTriggersBootstrapImplicitly() { - $router = $this->serviceManager->get('HttpRouter'); - $route = Router\Route\Literal::factory([ - 'route' => '/bad', - 'defaults' => [ - 'controller' => 'bad', - 'action' => $action, - ], - ]); - $router->addRoute('bad', $route); - - if ($addService) { - $this->serviceManager->setFactory('ControllerManager', function ($services) { - return new ControllerManager($services, ['factories' => [ - 'bad' => function () { - return new Controller\TestAsset\BadController(); - }, - ]]); - }); - } + $called = false; + $this->application->getEventManager()->attach( + MvcEvent::EVENT_BOOTSTRAP, + function ($e) use (&$called) { + $called = true; + } + ); + $request = new ServerRequest([], [], 'http://example.local/', 'GET', 'php://memory'); + $this->application->handle($request); + $this->assertTrue($called); + } + public function testRequestAndResponseAreNotAvailableDuringBootstrap() + { + $this->application->getEventManager()->attach( + MvcEvent::EVENT_BOOTSTRAP, + function (MvcEvent $e) { + $this->assertNull($e->getRequest()); + $this->assertNull($e->getResponse()); + } + ); $this->application->bootstrap(); - return $this->application; } - public function testFinishEventIsTriggeredAfterDispatching() + public function testRequestIsAvailableForRouteEvent() { - $application = $this->setupActionController(); - $application->getEventManager()->attach(MvcEvent::EVENT_FINISH, function ($e) { - $response = new Response(); - $response->getBody()->write('foobar'); - $e->setResponse($response); - }); - - $request = new ServerRequest([], [], 'http://example.local/sample', 'GET', 'php://memory'); - - $application->run($request); - $this->assertContains( - 'foobar', - $this->application->getMvcEvent()->getResponse()->getBody()->__toString(), - 'The "finish" event was not triggered ("foobar" not in response)' + $this->application->getEventManager()->attach( + MvcEvent::EVENT_ROUTE, + function (MvcEvent $e) { + $this->assertNotNull($e->getRequest()); + } ); + $request = new ServerRequest([], [], 'http://example.local/', 'GET', 'php://memory'); + $this->application->handle($request); } - /** - * @group error-handling - */ - public function testRoutingFailureShouldTriggerDispatchError() + public function testRequestIsAvailableForDispatchEvent() { - $application = $this->setupBadController(); - $router = new Router\SimpleRouteStack(); - $event = $application->getMvcEvent(); - $event->setRouter($router); - - $events = $application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { - $error = $e->getError(); - $response = new Response(); - $response->getBody()->write("Code: " . $error); - $e->setResponse($response); - return $response; - }); - - $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); - - $application->run($request); - $this->assertTrue($event->isError()); - $this->assertContains( - Application::ERROR_ROUTER_NO_MATCH, - $application->getMvcEvent()->getResponse()->getBody()->__toString() + $this->application->getEventManager()->attach( + MvcEvent::EVENT_ROUTE, + function (MvcEvent $e) { + $this->assertNotNull($e->getRequest()); + } ); + $request = new ServerRequest([], [], 'http://example.local/', 'GET', 'php://memory'); + $this->application->handle($request); } - /** - * @group error-handling - */ - public function testLocatorExceptionShouldTriggerDispatchError() + public function testHandleTriggersEventsInOrder() { - $application = $this->setupPathController(false); - $controllerLoader = $application->getContainer()->get('ControllerManager'); - $response = new Response(); - $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { - return $response; - }); + $this->application->bootstrap(); - $request = new ServerRequest([], [], 'http://example.local/path', 'GET', 'php://memory'); + $expected = [ + MvcEvent::EVENT_ROUTE, + MvcEvent::EVENT_DISPATCH, + MvcEvent::EVENT_RENDER, + MvcEvent::EVENT_FINISH, + ]; + $triggered = []; + $this->application->getEventManager()->attach( + '*', + function (MvcEvent $e) use (&$triggered) { + $triggered[] = $e->getName(); + } + ); - $resultResponse = $application->handle($request); - $this->assertSame($response, $resultResponse); + $request = new ServerRequest([], [], 'http://example.local/', 'GET', 'php://memory'); + $this->application->handle($request); + $this->assertEquals($expected, $triggered); } /** - * @requires PHP 7.0 - * @group error-handling + * @group ZF2-171 */ - public function testPhp7ErrorRaisedInDispatchableShouldRaiseDispatchErrorEvent() + public function testFinishShouldTriggerEvenIfRouteEventReturnsResponse() { - $this->setupBadController(true, 'test-php7-error'); - $events = $this->application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { - $exception = $e->getParam('exception'); - $response = new Response(); - $response->getBody()->write($exception->getMessage()); - return $response; - }); + $this->application->bootstrap(); - $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); + $expected = [ + MvcEvent::EVENT_ROUTE, + MvcEvent::EVENT_FINISH, + ]; + $triggered = []; + $this->application->getEventManager()->attach( + '*', + function (MvcEvent $e) use (&$triggered) { + $triggered[] = $e->getName(); + }, + 100 + ); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_ROUTE, + function (MvcEvent $e) { + return new Response(); + } + ); - $response = $this->application->handle($request); - $this->assertContains('Raised an error', $response->getBody()->__toString()); + $request = new ServerRequest([], [], 'http://example.local/', 'GET', 'php://memory'); + $this->application->handle($request); + $this->assertEquals($expected, $triggered); } /** - * @group error-handling + * @group ZF2-171 */ - public function testFailureForRouteToReturnRouteMatchShouldPopulateEventError() + public function testRenderAndFinishShouldTriggerRunEvenIfRouteEventSetsError() { - $application = $this->setupBadController(); - $router = new Router\SimpleRouteStack(); - $event = $application->getMvcEvent(); - $event->setRouter($router); - - $events = $application->getEventManager(); - $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { - $error = $e->getError(); - $response = new Response(); - $response->getBody()->write("Code: " . $error); - return $response; - }); - - $request = new ServerRequest([], [], 'http://example.local/bad', 'GET', 'php://memory'); - $application->handle($request); - $this->assertTrue($event->isError()); - $this->assertEquals(Application::ERROR_ROUTER_NO_MATCH, $event->getError()); + $this->application->bootstrap(); + + $expected = [ + MvcEvent::EVENT_ROUTE, + MvcEvent::EVENT_RENDER, + MvcEvent::EVENT_FINISH, + ]; + $triggered = []; + $this->application->getEventManager()->attach( + '*', + function (MvcEvent $e) use (&$triggered) { + $triggered[] = $e->getName(); + }, + 100 + ); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_ROUTE, + function (MvcEvent $e) { + $e->setError('Route error'); + } + ); + + $request = new ServerRequest([], [], 'http://example.local/', 'GET', 'php://memory'); + $this->application->handle($request); + $this->assertEquals($expected, $triggered); } /** * @group ZF2-171 */ - public function testFinishShouldRunEvenIfRouteEventReturnsResponse() + public function testFinishShouldTriggerEvenIfDispatchEventReturnsResponse() { $this->application->bootstrap(); - $events = $this->application->getEventManager(); - $events->attach(MvcEvent::EVENT_ROUTE, function ($e) { - return new Response(); - }, 100); - - $token = new stdClass; - $events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($token) { - $token->foo = 'bar'; - }); - - $this->application->run(); - $this->assertTrue(isset($token->foo)); - $this->assertEquals('bar', $token->foo); + + $expected = [ + MvcEvent::EVENT_ROUTE, + MvcEvent::EVENT_DISPATCH, + MvcEvent::EVENT_FINISH, + ]; + $triggered = []; + $this->application->getEventManager()->attach( + '*', + function (MvcEvent $e) use (&$triggered) { + $triggered[] = $e->getName(); + }, + 100 + ); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_DISPATCH, + function (MvcEvent $e) { + return new Response(); + } + ); + + $request = new ServerRequest([], [], 'http://example.local/', 'GET', 'php://memory'); + $this->application->handle($request); + $this->assertEquals($expected, $triggered); } /** * @group ZF2-171 */ - public function testFinishShouldRunEvenIfDispatchEventReturnsResponse() + public function testRenderAndFinishShouldTriggerEvenIfDispatchEventSetsError() { $this->application->bootstrap(); - $events = $this->application->getEventManager(); - $events->clearListeners(MvcEvent::EVENT_ROUTE); - $events->attach(MvcEvent::EVENT_DISPATCH, function ($e) { - return new Response(); - }, 100); - - $token = new stdClass; - $events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($token) { - $token->foo = 'bar'; - }); - - $this->application->run(); - $this->assertTrue(isset($token->foo)); - $this->assertEquals('bar', $token->foo); + + $expected = [ + MvcEvent::EVENT_ROUTE, + MvcEvent::EVENT_DISPATCH, + MvcEvent::EVENT_RENDER, + MvcEvent::EVENT_FINISH, + ]; + $triggered = []; + $this->application->getEventManager()->attach( + '*', + function (MvcEvent $e) use (&$triggered) { + $triggered[] = $e->getName(); + }, + 100 + ); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_DISPATCH, + function (MvcEvent $e) { + $e->setError('Dispatch error'); + } + ); + + $request = new ServerRequest([], [], 'http://example.local/', 'GET', 'php://memory'); + $this->application->handle($request); + $this->assertEquals($expected, $triggered); } public function testApplicationShouldBeEventTargetAtFinishEvent() { - $application = $this->setupActionController(); - - $events = $application->getEventManager(); - $events->attach(MvcEvent::EVENT_FINISH, function ($e) { - $response = new Response(); - $response->getBody()->write("EventClass: " . get_class($e->getTarget())); - $e->setResponse($response); - }); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_FINISH, + function (MvcEvent $e) { + $this->assertSame($this->application, $e->getTarget()); + } + ); $request = new ServerRequest([], [], 'http://example.local/sample', 'GET', 'php://memory'); - $response = $application->handle($request); - $this->assertContains(Application::class, $response->getBody()->__toString()); - } - - public function testOnDispatchErrorEventPassedToTriggersShouldBeTheOriginalOne() - { - $application = $this->setupPathController(false); - $model = $this->createMock(ViewModel::class); - $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($model) { - $e->setResult($model); - }); - - $application->run(); - $event = $application->getMvcEvent(); - $this->assertInstanceOf(ViewModel::class, $event->getResult()); + $this->application->handle($request); } /** @@ -500,21 +464,22 @@ public function testReturnsResponseFromListenerWhenRouteEventShortCircuits() { $this->application->bootstrap(); $testResponse = new Response(); - $events = $this->application->getEventManager(); - $events->clearListeners(MvcEvent::EVENT_DISPATCH); - $events->attach(MvcEvent::EVENT_ROUTE, function ($e) use ($testResponse) { - $testResponse->getBody()->write('triggered'); - return $testResponse; - }, 100); - - $triggered = false; - $events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($testResponse, &$triggered) { - $this->assertSame($testResponse, $e->getResponse()); - $triggered = true; - }); - - $this->application->run(); - $this->assertTrue($triggered); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_ROUTE, + function ($e) use ($testResponse) { + return $testResponse; + } + ); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_FINISH, + function (MvcEvent $e) use ($testResponse) { + $this->assertSame($testResponse, $e->getResponse()); + } + ); + + $request = new ServerRequest([], [], 'http://example.local/sample', 'GET', 'php://memory'); + $response = $this->application->handle($request); + $this->assertSame($testResponse, $response); } /** @@ -524,102 +489,51 @@ public function testReturnsResponseFromListenerWhenDispatchEventShortCircuits() { $this->application->bootstrap(); $testResponse = new Response(); - $events = $this->application->getEventManager(); - $events->clearListeners(MvcEvent::EVENT_ROUTE); - $events->attach(MvcEvent::EVENT_DISPATCH, function ($e) use ($testResponse) { - $testResponse->getBody()->write('triggered'); - return $testResponse; - }, 100); - - $triggered = false; - $events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($testResponse, &$triggered) { - $this->assertSame($testResponse, $e->getResponse()); - $triggered = true; - }); - - $this->application->run(); - $this->assertTrue($triggered); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_DISPATCH, + function ($e) use ($testResponse) { + return $testResponse; + } + ); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_FINISH, + function (MvcEvent $e) use ($testResponse) { + $this->assertSame($testResponse, $e->getResponse()); + } + ); + + $request = new ServerRequest([], [], 'http://example.local/sample', 'GET', 'php://memory'); + $response = $this->application->handle($request); + $this->assertSame($testResponse, $response); } - public function testFailedRoutingShouldBePreventable() + public function testRunInvokesEmitterForResponse() { - $this->application->bootstrap(); - - $response = $this->createMock(ResponseInterface::class); - $finishMock = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) - ->getMock(); - $routeMock = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) - ->getMock(); - $dispatchMock = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) - ->getMock(); - - $routeMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { - $event->stopPropagation(true); - $request = $event->getRequest(); - $event->setRequest( - $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch([])) - ); - })); - $dispatchMock->expects($this->once())->method('__invoke')->will($this->returnValue($response)); - $finishMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { - $event->stopPropagation(true); - })); - - $this->application->getEventManager()->attach(MvcEvent::EVENT_ROUTE, $routeMock, 100); - $this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, $dispatchMock, 100); - $this->application->getEventManager()->attach(MvcEvent::EVENT_FINISH, $finishMock, 100); - - $this->application->run(); - $this->assertSame($response, $this->application->getMvcEvent()->getResponse()); + $response = new Response(); + $this->application->getEventManager()->attach( + MvcEvent::EVENT_DISPATCH, + function () use ($response) { + return $response; + } + ); + $this->emitter->emit($response)->shouldBeCalled(); + $request = new ServerRequest([], [], 'http://example.local/sample', 'GET', 'php://memory'); + $this->application->run($request); } - public function testCanRecoverFromApplicationError() + public function testApplicationConfiguresDefaultEmitterIfNoneInjected() { - $this->application->bootstrap(); + $application = new Application( + $this->container->reveal(), + $this->router->reveal(), + $this->events, + null + ); - $response = $this->createMock(ResponseInterface::class); - $errorMock = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) - ->getMock(); - $finishMock = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) - ->getMock(); - $routeMock = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) - ->getMock(); - $dispatchMock = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) - ->getMock(); - - $errorMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { - $event->stopPropagation(true); - $request = $event->getRequest(); - $event->setRequest( - $request->withAttribute(RouteResult::class, RouteResult::fromRouteMatch([])) - ); - $event->setError(''); - })); - $routeMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { - $event->stopPropagation(true); - $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); - $event->setError(Application::ERROR_ROUTER_NO_MATCH); - return $event->getApplication()->getEventManager()->triggerEvent($event)->last(); - })); - $dispatchMock->expects($this->once())->method('__invoke')->will($this->returnValue($response)); - $finishMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { - $event->stopPropagation(true); - })); - - $this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, $errorMock, 100); - $this->application->getEventManager()->attach(MvcEvent::EVENT_ROUTE, $routeMock, 100); - $this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, $dispatchMock, 100); - $this->application->getEventManager()->attach(MvcEvent::EVENT_FINISH, $finishMock, 100); - - $this->application->run(); - $this->assertSame($response, $this->application->getMvcEvent()->getResponse()); + $emitter = $application->getEmitter(); + $this->assertInstanceOf(EmitterStack::class, $emitter); + $this->assertCount(1, $emitter); + $this->assertInstanceOf(SapiEmitter::class, $emitter[0]); } public function eventPropagation() @@ -635,35 +549,33 @@ public function eventPropagation() */ public function testEventPropagationStatusIsClearedBetweenEventsDuringRun($events) { - $event = new MvcEvent(); - $event->setTarget($this->application); - $event->setApplication($this->application); - $event->setRouter($this->serviceManager->get('Router')); + $this->application->bootstrap(); + $event = $this->application->getMvcEvent(); $event->stopPropagation(true); - // Intentionally not calling bootstrap; setting mvc event - $r = new ReflectionProperty($this->application, 'event'); - $r->setAccessible(true); - $r->setValue($this->application, $event); - // Setup listeners that stop propagation, but do nothing else $marker = []; foreach ($events as $event) { $marker[$event] = true; } - $marker = (object) $marker; - $listener = function ($e) use ($marker) { - $marker->{$e->getName()} = $e->propagationIsStopped(); + $listener = function (MvcEvent $e) use (&$marker) { + $marker[$e->getName()] = $e->propagationIsStopped(); $e->stopPropagation(true); }; foreach ($events as $event) { $this->application->getEventManager()->attach($event, $listener); } - $this->application->run(); + $request = new ServerRequest([], [], 'http://example.local/sample', 'GET', 'php://memory'); + $this->application->handle($request); foreach ($events as $event) { - $this->assertFalse($marker->{$event}, sprintf('Assertion failed for event "%s"', $event)); + $this->assertFalse($marker[$event], sprintf('Assertion failed for event "%s"', $event)); } } + + public function testBadRequestShouldEmitAppropriateResponse() + { + $this->markTestIncomplete('Not implemented'); + } } diff --git a/test/ContainerTrait.php b/test/ContainerTrait.php new file mode 100644 index 000000000..070c89d49 --- /dev/null +++ b/test/ContainerTrait.php @@ -0,0 +1,51 @@ +prophesize(ContainerInterface::class); + $container->has(Argument::type('string'))->willReturn(false); + + return $container; + } + + /** + * Inject a service into the container mock. + * + * Adjust `has('service')` and `get('service')` returns. + * + * @param ObjectProphecy $container + * @param string $serviceName + * @param mixed $service + * @return void + */ + protected function injectServiceInContainer(ObjectProphecy $container, $serviceName, $service) + { + $container->has($serviceName)->willReturn(true); + $container->get($serviceName)->willReturn($service); + } +} From 5967c6a8ca1bce84160d005e1ce089e68c82a35f Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 28 Dec 2017 22:38:15 +1000 Subject: [PATCH 23/51] Drop ModuleManager factory --- src/Container/ModuleManagerFactory.php | 88 -------------------------- 1 file changed, 88 deletions(-) delete mode 100644 src/Container/ModuleManagerFactory.php diff --git a/src/Container/ModuleManagerFactory.php b/src/Container/ModuleManagerFactory.php deleted file mode 100644 index e4282e414..000000000 --- a/src/Container/ModuleManagerFactory.php +++ /dev/null @@ -1,88 +0,0 @@ -get('ApplicationConfig'); - $listenerOptions = new ListenerOptions($configuration['module_listener_options']); - $defaultListeners = new DefaultListenerAggregate($listenerOptions); - $serviceListener = $container->get('ServiceListener'); - - $serviceListener->addServiceManager( - $container, - 'service_manager', - 'Zend\ModuleManager\Feature\ServiceProviderInterface', - 'getServiceConfig' - ); - - $serviceListener->addServiceManager( - 'ControllerManager', - 'controllers', - 'Zend\ModuleManager\Feature\ControllerProviderInterface', - 'getControllerConfig' - ); - $serviceListener->addServiceManager( - 'ControllerPluginManager', - 'controller_plugins', - 'Zend\ModuleManager\Feature\ControllerPluginProviderInterface', - 'getControllerPluginConfig' - ); - $serviceListener->addServiceManager( - 'ViewHelperManager', - 'view_helpers', - 'Zend\ModuleManager\Feature\ViewHelperProviderInterface', - 'getViewHelperConfig' - ); - $serviceListener->addServiceManager( - 'RoutePluginManager', - 'route_manager', - 'Zend\ModuleManager\Feature\RouteProviderInterface', - 'getRouteConfig' - ); - - $events = $container->get('EventManager'); - $defaultListeners->attach($events); - $serviceListener->attach($events); - - $moduleEvent = new ModuleEvent; - $moduleEvent->setParam('ServiceManager', $container); - - $moduleManager = new ModuleManager($configuration['modules'], $events); - $moduleManager->setEvent($moduleEvent); - - return $moduleManager; - } -} From 0ada10ac2f1ae1b3ea6df40051bc453e3b91ab88 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 28 Dec 2017 01:11:26 +1000 Subject: [PATCH 24/51] Add new Application factory --- src/Container/ApplicationFactory.php | 28 +++++---- test/Container/ApplicationFactoryTest.php | 76 +++++++++++++++++++++++ 2 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 test/Container/ApplicationFactoryTest.php diff --git a/src/Container/ApplicationFactory.php b/src/Container/ApplicationFactory.php index 38ac33beb..40afa45e5 100644 --- a/src/Container/ApplicationFactory.php +++ b/src/Container/ApplicationFactory.php @@ -9,33 +9,37 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; -use Zend\ServiceManager\Factory\FactoryInterface; -class ApplicationFactory implements FactoryInterface +class ApplicationFactory { /** - * Create the Application service - * - * Creates a Zend\Mvc\Application service, passing it the configuration - * service and the service manager instance. + * Create the Mvc Application * * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return Application + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : Application { $emitter = $container->has(EmitterInterface::class) ? $container->get(EmitterInterface::class) : null; - return new Application( + + $config = $container->get('config'); + $listeners = $config[Application::class]['listeners'] ?? []; + + $application = new Application( $container, + $container->get('Zend\Mvc\Router'), $container->get('EventManager'), - $emitter + $emitter, + $listeners ); + + return $application; } } diff --git a/test/Container/ApplicationFactoryTest.php b/test/Container/ApplicationFactoryTest.php new file mode 100644 index 000000000..bd98c3e2a --- /dev/null +++ b/test/Container/ApplicationFactoryTest.php @@ -0,0 +1,76 @@ +container = $this->mockContainerInterface(); + $this->factory = new ApplicationFactory(); + + $this->router = $this->prophesize(RouteStackInterface::class); + $this->emitter = $this->prophesize(EmitterInterface::class); + $this->events = new EventManager(); + + $this->injectServiceInContainer($this->container, 'Zend\Mvc\Router', $this->router); + $this->injectServiceInContainer($this->container, 'EventManager', $this->events); + $this->injectServiceInContainer($this->container, 'config', []); + } + + public function testInjectsEmitterWhenAvailable() + { + $this->injectServiceInContainer( + $this->container, + EmitterInterface::class, + $this->emitter->reveal() + ); + $app = $this->factory->__invoke($this->container->reveal()); + $this->assertSame($this->emitter->reveal(), $app->getEmitter()); + } +} From 0c0e8451b07c3bc646e49967a80cf3ca91167e38 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 28 Dec 2017 22:00:21 +1000 Subject: [PATCH 25/51] Drop config factory --- src/Container/ConfigFactory.php | 39 --------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/Container/ConfigFactory.php diff --git a/src/Container/ConfigFactory.php b/src/Container/ConfigFactory.php deleted file mode 100644 index bd9b38cd4..000000000 --- a/src/Container/ConfigFactory.php +++ /dev/null @@ -1,39 +0,0 @@ -get('ModuleManager'); - $moduleManager->loadModules(); - $moduleParams = $moduleManager->getEvent()->getParams(); - return $moduleParams['configListener']->getMergedConfig(false); - } -} From 44b338b8927c0caf25bb5ad2c4c85c0a160f96e9 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 28 Dec 2017 22:54:23 +1000 Subject: [PATCH 26/51] Drop ServiceListener factory --- src/Container/ServiceListenerFactory.php | 247 ------------------ test/Container/ServiceListenerFactoryTest.php | 184 ------------- 2 files changed, 431 deletions(-) delete mode 100644 src/Container/ServiceListenerFactory.php delete mode 100644 test/Container/ServiceListenerFactoryTest.php diff --git a/src/Container/ServiceListenerFactory.php b/src/Container/ServiceListenerFactory.php deleted file mode 100644 index 332621324..000000000 --- a/src/Container/ServiceListenerFactory.php +++ /dev/null @@ -1,247 +0,0 @@ - [ - 'application' => 'Application', - 'Config' => 'config', - 'configuration' => 'config', - 'Configuration' => 'config', - 'HttpDefaultRenderingStrategy' => View\Http\DefaultRenderingStrategy::class, - 'MiddlewareListener' => 'Zend\Mvc\MiddlewareListener', - 'RouteListener' => 'Zend\Mvc\RouteListener', - 'SendResponseListener' => 'Zend\Mvc\SendResponseListener', - 'View' => 'Zend\View\View', - 'ViewFeedRenderer' => 'Zend\View\Renderer\FeedRenderer', - 'ViewJsonRenderer' => 'Zend\View\Renderer\JsonRenderer', - 'ViewPhpRendererStrategy' => 'Zend\View\Strategy\PhpRendererStrategy', - 'ViewPhpRenderer' => 'Zend\View\Renderer\PhpRenderer', - 'ViewRenderer' => 'Zend\View\Renderer\PhpRenderer', - 'Zend\Mvc\Controller\PluginManager' => 'ControllerPluginManager', - 'Zend\Mvc\View\Http\InjectTemplateListener' => 'InjectTemplateListener', - 'Zend\View\Renderer\RendererInterface' => 'Zend\View\Renderer\PhpRenderer', - 'Zend\View\Resolver\TemplateMapResolver' => 'ViewTemplateMapResolver', - 'Zend\View\Resolver\TemplatePathStack' => 'ViewTemplatePathStack', - 'Zend\View\Resolver\AggregateResolver' => 'ViewResolver', - 'Zend\View\Resolver\ResolverInterface' => 'ViewResolver', - ], - 'invokables' => [], - 'factories' => [ - 'Application' => ApplicationFactory::class, - 'config' => 'Zend\Mvc\Container\ConfigFactory', - 'ControllerManager' => 'Zend\Mvc\Container\ControllerManagerFactory', - 'ControllerPluginManager' => 'Zend\Mvc\Container\ControllerPluginManagerFactory', - 'DispatchListener' => 'Zend\Mvc\Container\DispatchListenerFactory', - 'HttpExceptionStrategy' => ExceptionStrategyFactory::class, - 'HttpMethodListener' => 'Zend\Mvc\Container\HttpMethodListenerFactory', - 'HttpRouteNotFoundStrategy' => RouteNotFoundStrategyFactory::class, - 'HttpViewManager' => 'Zend\Mvc\Container\HttpViewManagerFactory', - 'InjectTemplateListener' => 'Zend\Mvc\Container\InjectTemplateListenerFactory', - 'PaginatorPluginManager' => 'Zend\Mvc\Container\PaginatorPluginManagerFactory', - 'ViewHelperManager' => 'Zend\Mvc\Container\ViewHelperManagerFactory', - View\Http\DefaultRenderingStrategy::class => DefaultRenderingStrategyFactory::class, - 'ViewFeedStrategy' => 'Zend\Mvc\Container\ViewFeedStrategyFactory', - 'ViewJsonStrategy' => 'Zend\Mvc\Container\ViewJsonStrategyFactory', - 'ViewManager' => 'Zend\Mvc\Container\ViewManagerFactory', - 'ViewResolver' => 'Zend\Mvc\Container\ViewResolverFactory', - 'ViewTemplateMapResolver' => 'Zend\Mvc\Container\ViewTemplateMapResolverFactory', - 'ViewTemplatePathStack' => 'Zend\Mvc\Container\ViewTemplatePathStackFactory', - 'ViewPrefixPathStackResolver' => 'Zend\Mvc\Container\ViewPrefixPathStackResolverFactory', - 'Zend\Mvc\MiddlewareListener' => InvokableFactory::class, - 'Zend\Mvc\RouteListener' => InvokableFactory::class, - 'Zend\Mvc\SendResponseListener' => SendResponseListenerFactory::class, - 'Zend\View\Renderer\FeedRenderer' => InvokableFactory::class, - 'Zend\View\Renderer\JsonRenderer' => InvokableFactory::class, - 'Zend\View\Renderer\PhpRenderer' => ViewPhpRendererFactory::class, - 'Zend\View\Strategy\PhpRendererStrategy' => ViewPhpRendererStrategyFactory::class, - 'Zend\View\View' => ViewFactory::class, - ], - ]; - - /** - * Create the service listener service - * - * Tries to get a service named ServiceListenerInterface from the service - * locator, otherwise creates a ServiceListener instance, passing it the - * container instance and the default service configuration, which can be - * overridden by modules. - * - * It looks for the 'service_listener_options' key in the application - * config and tries to add service/plugin managers as configured. The value - * of 'service_listener_options' must be a list (array) which contains the - * following keys: - * - * - service_manager: the name of the service manage to create as string - * - config_key: the name of the configuration key to search for as string - * - interface: the name of the interface that modules can implement as string - * - method: the name of the method that modules have to implement as string - * - * @param ServiceLocatorInterface $serviceLocator - * @return ServiceListenerInterface - * @throws ServiceNotCreatedException for invalid ServiceListener service - * @throws ServiceNotCreatedException For invalid configurations. - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null) - { - $configuration = $container->get('ApplicationConfig'); - - if ($container->has('ServiceListenerInterface')) { - $serviceListener = $container->get('ServiceListenerInterface'); - } elseif ($container instanceof ServiceManager) { - $serviceListener = new ServiceListener($container); - } else { - // @TODO update ServiceListener to accept ContainerInterface - throw new RuntimeException( - 'Container is not a ServiceManager and ServiceListenerInterface was not provided' - ); - } - - if (! $serviceListener instanceof ServiceListenerInterface) { - throw new ServiceNotCreatedException( - 'The service named ServiceListenerInterface must implement ' - . ServiceListenerInterface::class - ); - } - - $serviceListener->setDefaultServiceConfig($this->defaultServiceConfig); - - if (isset($configuration['service_listener_options'])) { - $this->injectServiceListenerOptions($configuration['service_listener_options'], $serviceListener); - } - - return $serviceListener; - } - - /** - * Validate and inject plugin manager options into the service listener. - * - * @param array $options - * @param ServiceListenerInterface $serviceListener - * @throws ServiceListenerInterface for invalid $options types - */ - private function injectServiceListenerOptions($options, ServiceListenerInterface $serviceListener) - { - if (! is_array($options)) { - throw new ServiceNotCreatedException(sprintf( - 'The value of service_listener_options must be an array, %s given.', - (is_object($options) ? get_class($options) : gettype($options)) - )); - } - - foreach ($options as $key => $newServiceManager) { - $this->validatePluginManagerOptions($newServiceManager, $key); - - $serviceListener->addServiceManager( - $newServiceManager['service_manager'], - $newServiceManager['config_key'], - $newServiceManager['interface'], - $newServiceManager['method'] - ); - } - } - - /** - * Validate the structure and types for plugin manager configuration options. - * - * Ensures all required keys are present in the expected types. - * - * @param array $options - * @param string $name Plugin manager service name; used for exception messages - * @throws ServiceNotCreatedException for any missing configuration options. - * @throws ServiceNotCreatedException for configuration options of invalid types. - */ - private function validatePluginManagerOptions($options, $name) - { - if (! is_array($options)) { - throw new ServiceNotCreatedException(sprintf( - 'Plugin manager configuration for "%s" is invalid; must be an array, received "%s"', - $name, - (is_object($options) ? get_class($options) : gettype($options)) - )); - } - - if (! isset($options['service_manager'])) { - throw new ServiceNotCreatedException(sprintf(self::MISSING_KEY_ERROR, $name, 'service_manager')); - } - - if (! is_string($options['service_manager'])) { - throw new ServiceNotCreatedException(sprintf( - self::VALUE_TYPE_ERROR, - 'service_manager', - gettype($options['service_manager']) - )); - } - - if (! isset($options['config_key'])) { - throw new ServiceNotCreatedException(sprintf(self::MISSING_KEY_ERROR, $name, 'config_key')); - } - - if (! is_string($options['config_key'])) { - throw new ServiceNotCreatedException(sprintf( - self::VALUE_TYPE_ERROR, - 'config_key', - gettype($options['config_key']) - )); - } - - if (! isset($options['interface'])) { - throw new ServiceNotCreatedException(sprintf(self::MISSING_KEY_ERROR, $name, 'interface')); - } - - if (! is_string($options['interface'])) { - throw new ServiceNotCreatedException(sprintf( - self::VALUE_TYPE_ERROR, - 'interface', - gettype($options['interface']) - )); - } - - if (! isset($options['method'])) { - throw new ServiceNotCreatedException(sprintf(self::MISSING_KEY_ERROR, $name, 'method')); - } - - if (! is_string($options['method'])) { - throw new ServiceNotCreatedException(sprintf( - self::VALUE_TYPE_ERROR, - 'method', - gettype($options['method']) - )); - } - } -} diff --git a/test/Container/ServiceListenerFactoryTest.php b/test/Container/ServiceListenerFactoryTest.php deleted file mode 100644 index 0c31bc110..000000000 --- a/test/Container/ServiceListenerFactoryTest.php +++ /dev/null @@ -1,184 +0,0 @@ -sm = $this->getMockBuilder(ServiceManager::class) - ->setMethods(['get']) - ->getMock(); - - $this->factory = new ServiceListenerFactory(); - } - - /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage The value of service_listener_options must be an array, string given. - */ - public function testInvalidOptionType() - { - $this->sm->expects($this->once()) - ->method('get') - ->will($this->returnValue(['service_listener_options' => 'string'])); - - $this->factory->__invoke($this->sm, 'ServiceListener'); - } - - /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, 0 array must contain service_manager key. - */ - public function testMissingServiceManager() - { - $config['service_listener_options'][0]['service_manager'] = null; - $config['service_listener_options'][0]['config_key'] = 'test'; - $config['service_listener_options'][0]['interface'] = 'test'; - $config['service_listener_options'][0]['method'] = 'test'; - - $this->sm->expects($this->once()) - ->method('get') - ->will($this->returnValue($config)); - - $this->factory->__invoke($this->sm, 'ServiceListener'); - } - - /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, service_manager must be a string, - * integer given. - */ - public function testInvalidTypeServiceManager() - { - $config['service_listener_options'][0]['service_manager'] = 1; - $config['service_listener_options'][0]['config_key'] = 'test'; - $config['service_listener_options'][0]['interface'] = 'test'; - $config['service_listener_options'][0]['method'] = 'test'; - - $this->sm->expects($this->once()) - ->method('get') - ->will($this->returnValue($config)); - - $this->factory->__invoke($this->sm, 'ServiceListener'); - } - - /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, 0 array must contain config_key key. - */ - public function testMissingConfigKey() - { - $config['service_listener_options'][0]['service_manager'] = 'test'; - $config['service_listener_options'][0]['config_key'] = null; - $config['service_listener_options'][0]['interface'] = 'test'; - $config['service_listener_options'][0]['method'] = 'test'; - - $this->sm->expects($this->once()) - ->method('get') - ->will($this->returnValue($config)); - - $this->factory->__invoke($this->sm, 'ServiceListener'); - } - - /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, config_key must be a string, integer given. - */ - public function testInvalidTypeConfigKey() - { - $config['service_listener_options'][0]['service_manager'] = 'test'; - $config['service_listener_options'][0]['config_key'] = 1; - $config['service_listener_options'][0]['interface'] = 'test'; - $config['service_listener_options'][0]['method'] = 'test'; - - $this->sm->expects($this->once()) - ->method('get') - ->will($this->returnValue($config)); - - $this->factory->__invoke($this->sm, 'ServiceListener'); - } - - /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, 0 array must contain interface key. - */ - public function testMissingInterface() - { - $config['service_listener_options'][0]['service_manager'] = 'test'; - $config['service_listener_options'][0]['config_key'] = 'test'; - $config['service_listener_options'][0]['interface'] = null; - $config['service_listener_options'][0]['method'] = 'test'; - - $this->sm->expects($this->once()) - ->method('get') - ->will($this->returnValue($config)); - - $this->factory->__invoke($this->sm, 'ServiceListener'); - } - - /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, interface must be a string, integer given. - */ - public function testInvalidTypeInterface() - { - $config['service_listener_options'][0]['service_manager'] = 'test'; - $config['service_listener_options'][0]['config_key'] = 'test'; - $config['service_listener_options'][0]['interface'] = 1; - $config['service_listener_options'][0]['method'] = 'test'; - - $this->sm->expects($this->once()) - ->method('get') - ->will($this->returnValue($config)); - - $this->factory->__invoke($this->sm, 'ServiceListener'); - } - - /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, 0 array must contain method key. - */ - public function testMissingMethod() - { - $config['service_listener_options'][0]['service_manager'] = 'test'; - $config['service_listener_options'][0]['config_key'] = 'test'; - $config['service_listener_options'][0]['interface'] = 'test'; - $config['service_listener_options'][0]['method'] = null; - - $this->sm->expects($this->once()) - ->method('get') - ->will($this->returnValue($config)); - - $this->factory->__invoke($this->sm, 'ServiceListener'); - } - - /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, method must be a string, integer given. - */ - public function testInvalidTypeMethod() - { - $config['service_listener_options'][0]['service_manager'] = 'test'; - $config['service_listener_options'][0]['config_key'] = 'test'; - $config['service_listener_options'][0]['interface'] = 'test'; - $config['service_listener_options'][0]['method'] = 1; - - $this->sm->expects($this->once()) - ->method('get') - ->will($this->returnValue($config)); - - $this->factory->__invoke($this->sm, 'ServiceListener'); - } -} From 0f7147b3cf107317afe54fd8d9bfead6d5b0798b Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 28 Dec 2017 23:04:13 +1000 Subject: [PATCH 27/51] Drop ServiceManager config --- src/Container/ServiceManagerConfig.php | 175 ----------------- test/Container/ServiceManagerConfigTest.php | 198 -------------------- 2 files changed, 373 deletions(-) delete mode 100644 src/Container/ServiceManagerConfig.php delete mode 100644 test/Container/ServiceManagerConfigTest.php diff --git a/src/Container/ServiceManagerConfig.php b/src/Container/ServiceManagerConfig.php deleted file mode 100644 index aed858ce8..000000000 --- a/src/Container/ServiceManagerConfig.php +++ /dev/null @@ -1,175 +0,0 @@ - [], - 'aliases' => [ - 'EventManagerInterface' => EventManager::class, - EventManagerInterface::class => 'EventManager', - ModuleManager::class => 'ModuleManager', - ServiceListener::class => 'ServiceListener', - SharedEventManager::class => 'SharedEventManager', - 'SharedEventManagerInterface' => 'SharedEventManager', - SharedEventManagerInterface::class => 'SharedEventManager', - ], - 'delegators' => [], - 'factories' => [ - 'EventManager' => EventManagerFactory::class, - 'ModuleManager' => ModuleManagerFactory::class, - 'ServiceListener' => ServiceListenerFactory::class, - ], - 'lazy_services' => [], - 'initializers' => [], - 'invokables' => [], - 'services' => [], - 'shared' => [ - 'EventManager' => false, - ], - ]; - - /** - * Constructor - * - * Merges internal arrays with those passed via configuration, and also - * defines: - * - * - factory for the service 'SharedEventManager'. - * - initializer for EventManagerAwareInterface implementations - * - * @param array $config - */ - public function __construct(array $config = []) - { - $this->config['factories']['ServiceManager'] = function ($container) { - return $container; - }; - - $this->config['factories']['SharedEventManager'] = function () { - return new SharedEventManager(); - }; - - $this->config['initializers'] = ArrayUtils::merge($this->config['initializers'], [ - 'EventManagerAwareInitializer' => function ($first, $second) { - if ($first instanceof ContainerInterface) { - $container = $first; - $instance = $second; - } else { - $container = $second; - $instance = $first; - } - - if (! $instance instanceof EventManagerAwareInterface) { - return; - } - - $eventManager = $instance->getEventManager(); - - // If the instance has an EM WITH an SEM composed, do nothing. - if ($eventManager instanceof EventManagerInterface - && $eventManager->getSharedManager() instanceof SharedEventManagerInterface - ) { - return; - } - - $instance->setEventManager($container->get('EventManager')); - }, - ]); - - parent::__construct($config); - } - - /** - * Configure service container. - * - * Uses the configuration present in the instance to configure the provided - * service container. - * - * Before doing so, it adds a "service" entry for the ServiceManager class, - * pointing to the provided service container. - * - * @param ServiceManager $services - * @return ServiceManager - */ - public function configureServiceManager(ServiceManager $services) - { - $this->config['services'][ServiceManager::class] = $services; - - /* - printf("Configuration prior to configuring servicemanager:\n"); - foreach ($this->config as $type => $list) { - switch ($type) { - case 'aliases': - case 'delegators': - case 'factories': - case 'invokables': - case 'lazy_services': - case 'services': - case 'shared': - foreach (array_keys($list) as $name) { - printf(" %s (%s)\n", $name, $type); - } - break; - - case 'initializers': - case 'abstract_factories': - foreach ($list as $callable) { - printf(" %s (%s)\n", (is_object($callable) ? get_class($callable) : $callable), $type); - } - break; - - default: - break; - } - } - */ - - // This is invoked as part of the bootstrapping process, and requires - // the ability to override services. - $services->setAllowOverride(true); - parent::configureServiceManager($services); - $services->setAllowOverride(false); - - return $services; - } - - /** - * Return all service configuration - * - * @return array - */ - public function toArray() - { - return $this->config; - } -} diff --git a/test/Container/ServiceManagerConfigTest.php b/test/Container/ServiceManagerConfigTest.php deleted file mode 100644 index 186d6c75d..000000000 --- a/test/Container/ServiceManagerConfigTest.php +++ /dev/null @@ -1,198 +0,0 @@ -config = new ServiceManagerConfig(); - $this->services = new ServiceManager(); - $this->config->configureServiceManager($this->services); - } - - /** - * @param null|SharedEventManagerInterface - * @return EventManager - */ - protected function createEventManager(SharedEventManagerInterface $sharedManager = null) - { - return new EventManager($sharedManager ?: $this->services->get('SharedEventManager')); - } - - /** - * @group 3786 - */ - public function testEventManagerAwareInterfaceIsNotInjectedIfPresentButSharedManagerIs() - { - $events = $this->createEventManager(); - EventManagerAwareObject::$defaultEvents = $events; - - $this->services->setAlias('EventManagerAwareObject', EventManagerAwareObject::class); - $this->services->setFactory(EventManagerAwareObject::class, InvokableFactory::class); - - $instance = $this->services->get('EventManagerAwareObject'); - $this->assertInstanceOf(EventManagerAwareObject::class, $instance); - $this->assertSame($events, $instance->getEventManager()); - $this->assertSame($this->services->get('SharedEventManager'), $events->getSharedManager()); - } - - /** - * @group 6266 - */ - public function testCanMergeCustomConfigWithDefaultConfig() - { - $custom = [ - 'invokables' => [ - 'foo' => stdClass::class, - ], - 'factories' => [ - 'bar' => function () { - return new stdClass(); - }, - ], - ]; - - $sm = new ServiceManager(); - (new ServiceManagerConfig($custom))->configureServiceManager($sm); - - $this->assertTrue($sm->has('foo')); - $this->assertTrue($sm->has('bar')); - $this->assertTrue($sm->has('ModuleManager')); - } - - /** - * @group 6266 - */ - public function testCanOverrideDefaultConfigWithCustomConfig() - { - $custom = [ - 'invokables' => [ - 'foo' => stdClass::class, - ], - 'factories' => [ - 'ModuleManager' => function () { - return new stdClass(); - }, - ], - ]; - - $sm = new ServiceManager(); - (new ServiceManagerConfig($custom))->configureServiceManager($sm); - - $this->assertTrue($sm->has('foo')); - $this->assertTrue($sm->has('ModuleManager')); - - $this->assertInstanceOf(stdClass::class, $sm->get('ModuleManager')); - } - - /** - * @group 6266 - */ - public function testCanAddDelegators() - { - /* - * Create delegator closure - */ - $delegator = function ($container, $name, $callback, array $options = null) { - $service = $callback(); - $service->bar = 'baz'; - return $service; - }; - - $config = [ - 'aliases' => [ - 'foo' => stdClass::class, - ], - 'factories' => [ - stdClass::class => InvokableFactory::class, - ], - 'delegators' => [ - stdClass::class => [ $delegator ], - ], - ]; - - $sm = new ServiceManager(); - (new ServiceManagerConfig($config))->configureServiceManager($sm); - - $std = $sm->get('foo'); - $this->assertInstanceOf(stdClass::class, $std); - $this->assertEquals('baz', $std->bar); - } - - /** - * @group 6266 - */ - public function testEventManagerInitializerCanBeReplaced() - { - $instance = $this->createMock(EventManagerAwareInterface::class); - $initializer = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) - ->getMock(); - $config = new ServiceManagerConfig([ - 'initializers' => [ - 'EventManagerAwareInitializer' => $initializer, - ], - 'factories' => [ - 'EventManagerAware' => function () use ($instance) { - return $instance; - }, - ], - ]); - $serviceManager = new ServiceManager(); - $config->configureServiceManager($serviceManager); - - $initializer->expects($this->once())->method('__invoke')->with($serviceManager, $instance); - - $instance->expects($this->never())->method('getEventManager'); - $instance->expects($this->never())->method('setEventManager'); - - $serviceManager->get('EventManagerAware'); - } - - /** - * @group 101 - */ - public function testCreatesAFactoryForTheServiceManagerThatReturnsIt() - { - $serviceManager = new ServiceManager(); - $config = new ServiceManagerConfig(); - $config->configureServiceManager($serviceManager); - - $this->assertTrue($serviceManager->has('ServiceManager'), 'Missing ServiceManager service!'); - $this->assertSame($serviceManager, $serviceManager->get('ServiceManager')); - } -} From ed68ff4e239d29aa84baa3ed2e8f0d863d789951 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 29 Dec 2017 02:41:46 +1000 Subject: [PATCH 28/51] Drop no longer relevant initialization test --- .../InitializationIntegrationTest.php | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 test/Application/InitializationIntegrationTest.php diff --git a/test/Application/InitializationIntegrationTest.php b/test/Application/InitializationIntegrationTest.php deleted file mode 100644 index 9d392f3e1..000000000 --- a/test/Application/InitializationIntegrationTest.php +++ /dev/null @@ -1,42 +0,0 @@ - [ - 'Zend\Router', - 'Application', - ], - 'module_listener_options' => [ - 'module_paths' => [ - __DIR__ . '/TestAsset/modules', - ], - ], - ]; - - $application = Application::init($appConfig); - - $request = new ServerRequest([], [], 'http://example.local/path', 'GET', 'php://memory'); - - $response = $application->handle($request); - - $this->assertContains('Application\\Controller\\PathController', $response->getBody()->__toString()); - $this->assertContains(MvcEvent::EVENT_DISPATCH, $response->getBody()->__toString()); - } -} From f4939631a92e381b555befaa83b990a4aee9b6cd Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 29 Dec 2017 02:45:43 +1000 Subject: [PATCH 29/51] Add ConfigProvider --- src/ConfigProvider.php | 143 +++++++++++++++++++++ test/ConfigProviderTest.php | 27 ++++ test/TestAsset/ApplicationConfigHelper.php | 41 ++++++ 3 files changed, 211 insertions(+) create mode 100644 src/ConfigProvider.php create mode 100644 test/ConfigProviderTest.php create mode 100644 test/TestAsset/ApplicationConfigHelper.php diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php new file mode 100644 index 000000000..b6f3e87fe --- /dev/null +++ b/src/ConfigProvider.php @@ -0,0 +1,143 @@ + $this->getDependencyConfig(), + ]; + } + + public function getDependencyConfig() + { + return [ + 'aliases' => [ + 'ControllerManager' => ControllerManager::class, + 'ControllerPluginManager' => ControllerPluginManager::class, + 'DispatchListener' => DispatchListener::class, + 'HttpDefaultRenderingStrategy' => DefaultRenderingStrategy::class, + 'HttpExceptionStrategy' => ExceptionStrategy::class, + 'HttpMethodListener' => HttpMethodListener::class, + 'HttpRouteNotFoundStrategy' => RouteNotFoundStrategy::class, + 'HttpViewManager' => ViewManager::class, + 'InjectTemplateListener' => InjectTemplateListener::class, + 'MiddlewareListener' => MiddlewareListener::class, + 'RouteListener' => RouteListener::class, + 'RoutePluginManager' => RoutePluginManager::class, + 'View' => View::class, + 'ViewFeedRenderer' => FeedRenderer::class, + 'ViewFeedStrategy' => FeedStrategy::class, + 'ViewHelperManager' => HelperPluginManager::class, + 'ViewJsonRenderer' => JsonRenderer::class, + 'ViewJsonStrategy' => JsonStrategy::class, + 'ViewManager' => ViewManager::class, + 'ViewPhpRenderer' => PhpRenderer::class, + 'ViewPhpRendererStrategy' => PhpRendererStrategy::class, + 'ViewPrefixPathStackResolver' => PrefixPathStackResolver::class, + 'ViewRenderer' => PhpRenderer::class, + 'ViewResolver' => 'Zend\Mvc\View\Resolver', + 'ViewTemplateMapResolver' => TemplateMapResolver::class, + 'ViewTemplatePathStack' => TemplatePathStack::class, + 'EventManagerInterface' => 'EventManager', + EventManagerInterface::class => 'EventManager', + 'SharedEventManager' => SharedEventManager::class, + 'SharedEventManagerInterface' => SharedEventManager::class, + 'Zend\Mvc\Router' => 'HttpRouter', + AggregateResolver::class => 'Zend\Mvc\View\Resolver', + EventManagerInterface::class => 'EventManager', + RendererInterface::class => PhpRenderer::class, + ResolverInterface::class => 'Zend\Mvc\View\Resolver', + SharedEventManagerInterface::class => SharedEventManager::class, + ], + 'factories' => [ + 'EventManager' => EventManagerFactory::class, + 'Zend\Mvc\View\Resolver' => ViewResolverFactory::class, + Application::class => ApplicationFactory::class, + ControllerManager::class => ControllerManagerFactory::class, + ControllerPluginManager::class => ControllerPluginManagerFactory::class, + DefaultRenderingStrategy::class => HttpDefaultRenderingStrategyFactory::class, + DispatchListener::class => DispatchListenerFactory::class, + ExceptionStrategy::class => HttpExceptionStrategyFactory::class, + FeedRenderer::class => InvokableFactory::class, + FeedStrategy::class => ViewFeedStrategyFactory::class, + HelperPluginManager::class => ViewHelperManagerFactory::class, + HttpMethodListener::class => HttpMethodListenerFactory::class, + InjectTemplateListener::class => InjectTemplateListenerFactory::class, + JsonRenderer::class => InvokableFactory::class, + JsonStrategy::class => ViewJsonStrategyFactory::class, + MiddlewareListener::class => InvokableFactory::class, + PhpRenderer::class => ViewPhpRendererFactory::class, + PhpRendererStrategy::class => ViewPhpRendererStrategyFactory::class, + PrefixPathStackResolver::class => ViewPrefixPathStackResolverFactory::class, + RouteListener::class => InvokableFactory::class, + RouteNotFoundStrategy::class => HttpRouteNotFoundStrategyFactory::class, + SharedEventManager::class => InvokableFactory::class, + TemplateMapResolver::class => ViewTemplateMapResolverFactory::class, + TemplatePathStack::class => ViewTemplatePathStackFactory::class, + View::class => ViewFactory::class, + ViewManager::class => HttpViewManagerFactory::class, + ], + 'shared' => [ + 'EventManager' => false, + ], + ]; + } +} diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php new file mode 100644 index 000000000..023640a48 --- /dev/null +++ b/test/ConfigProviderTest.php @@ -0,0 +1,27 @@ + Date: Fri, 29 Dec 2017 02:47:23 +1000 Subject: [PATCH 30/51] Fix some tests to work with new Application --- test/Application/BadControllerTrait.php | 78 +++++------------- .../InvalidControllerTypeTrait.php | 79 +++++-------------- test/Application/MissingControllerTrait.php | 68 ++++------------ test/Application/PathControllerTrait.php | 78 +++++------------- .../ViewHelperManagerFactoryTest.php | 1 + test/View/DefaultRendereringStrategyTest.php | 1 + 6 files changed, 79 insertions(+), 226 deletions(-) diff --git a/test/Application/BadControllerTrait.php b/test/Application/BadControllerTrait.php index cef7d53f3..cd8b6ac6b 100644 --- a/test/Application/BadControllerTrait.php +++ b/test/Application/BadControllerTrait.php @@ -9,56 +9,21 @@ namespace ZendTest\Mvc\Application; -use ReflectionProperty; use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; -use Zend\Mvc\Container\ServiceManagerConfig; -use Zend\Mvc\Container\ServiceListenerFactory; +use Zend\Mvc\View\Http\ViewManager; use Zend\Router; -use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\ArrayUtils; use ZendTest\Mvc\Controller\TestAsset\BadController; use ZendTest\Mvc\TestAsset; +use ZendTest\Mvc\TestAsset\ApplicationConfigHelper; trait BadControllerTrait { public function prepareApplication() { - $config = [ - 'router' => [ - 'routes' => [ - 'path' => [ - 'type' => Router\Route\Literal::class, - 'options' => [ - 'route' => '/bad', - 'defaults' => [ - 'controller' => 'bad', - 'action' => 'test', - ], - ], - ], - ], - ], - ]; - - $serviceListener = new ServiceListenerFactory(); - $r = new ReflectionProperty($serviceListener, 'defaultServiceConfig'); - $r->setAccessible(true); - $serviceConfig = $r->getValue($serviceListener); - - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - (new Router\ConfigProvider())->getDependencyConfig() - ); - - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - [ - 'aliases' => [ - 'ControllerLoader' => ControllerManager::class, - 'ControllerManager' => ControllerManager::class, - ], + $config = ApplicationConfigHelper::getConfig([ + 'dependencies' => [ 'factories' => [ ControllerManager::class => function ($services) { return new ControllerManager($services, ['factories' => [ @@ -67,35 +32,32 @@ public function prepareApplication() }, ]]); }, - 'Router' => function ($services) { - return $services->get('HttpRouter'); - }, EmitterInterface::class => function () { $emitter = $this->prophesize(EmitterInterface::class); return $emitter->reveal(); }, ], 'invokables' => [ - 'ViewManager' => TestAsset\MockViewManager::class, - 'BootstrapListener' => TestAsset\StubBootstrapListener::class, + ViewManager::class => TestAsset\MockViewManager::class, ], - 'services' => [ - 'config' => $config, - 'ApplicationConfig' => [ - 'modules' => [], - 'module_listener_options' => [ - 'config_cache_enabled' => false, - 'cache_dir' => 'data/cache', - 'module_paths' => [], + ], + 'router' => [ + 'routes' => [ + 'path' => [ + 'type' => Router\Route\Literal::class, + 'options' => [ + 'route' => '/bad', + 'defaults' => [ + 'controller' => 'bad', + 'action' => 'test', + ], ], ], ], - ] - ); - $services = new ServiceManager(); - (new ServiceManagerConfig($serviceConfig))->configureServiceManager($services); - $application = $services->get('Application'); - + ], + ]); + $container = ApplicationConfigHelper::configureContainer($config); + $application = $container->get(Application::class); $application->bootstrap(); return $application; } diff --git a/test/Application/InvalidControllerTypeTrait.php b/test/Application/InvalidControllerTypeTrait.php index 061c622ff..5b1ca8294 100644 --- a/test/Application/InvalidControllerTypeTrait.php +++ b/test/Application/InvalidControllerTypeTrait.php @@ -9,92 +9,55 @@ namespace ZendTest\Mvc\Application; -use ReflectionProperty; use stdClass; use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; -use Zend\Mvc\Container\ServiceManagerConfig; -use Zend\Mvc\Container\ServiceListenerFactory; +use Zend\Mvc\View\Http\ViewManager; use Zend\Router; -use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\ArrayUtils; use ZendTest\Mvc\TestAsset; +use ZendTest\Mvc\TestAsset\ApplicationConfigHelper; trait InvalidControllerTypeTrait { public function prepareApplication() { - $config = [ - 'router' => [ - 'routes' => [ - 'path' => [ - 'type' => Router\Route\Literal::class, - 'options' => [ - 'route' => '/bad', - 'defaults' => [ - 'controller' => 'bad', - 'action' => 'test', - ], - ], - ], - ], - ], - ]; - - $serviceListener = new ServiceListenerFactory(); - $r = new ReflectionProperty($serviceListener, 'defaultServiceConfig'); - $r->setAccessible(true); - $serviceConfig = $r->getValue($serviceListener); - - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - (new Router\ConfigProvider())->getDependencyConfig() - ); - - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - [ - 'aliases' => [ - 'ControllerLoader' => 'ControllerManager', - ], + $config = ApplicationConfigHelper::getConfig([ + 'dependencies' => [ 'factories' => [ - 'ControllerManager' => function ($services) { + ControllerManager::class => function ($services) { return new ControllerManager($services, ['factories' => [ 'bad' => function () { return new stdClass(); }, ]]); }, - 'Router' => function ($services) { - return $services->get('HttpRouter'); - }, EmitterInterface::class => function () { $emitter = $this->prophesize(EmitterInterface::class); return $emitter->reveal(); }, ], 'invokables' => [ - 'ViewManager' => TestAsset\MockViewManager::class, - 'BootstrapListener' => TestAsset\StubBootstrapListener::class, + ViewManager::class => TestAsset\MockViewManager::class, ], - 'services' => [ - 'config' => $config, - 'ApplicationConfig' => [ - 'modules' => [], - 'module_listener_options' => [ - 'config_cache_enabled' => false, - 'cache_dir' => 'data/cache', - 'module_paths' => [], + ], + 'router' => [ + 'routes' => [ + 'path' => [ + 'type' => Router\Route\Literal::class, + 'options' => [ + 'route' => '/bad', + 'defaults' => [ + 'controller' => 'bad', + 'action' => 'test', + ], ], ], ], - ] - ); - $services = new ServiceManager(); - (new ServiceManagerConfig($serviceConfig))->configureServiceManager($services); - $application = $services->get('Application'); - + ], + ]); + $container = ApplicationConfigHelper::configureContainer($config); + $application = $container->get(Application::class); $application->bootstrap(); return $application; } diff --git a/test/Application/MissingControllerTrait.php b/test/Application/MissingControllerTrait.php index 0791260e9..d313d2e9d 100644 --- a/test/Application/MissingControllerTrait.php +++ b/test/Application/MissingControllerTrait.php @@ -9,21 +9,29 @@ namespace ZendTest\Mvc\Application; -use ReflectionProperty; use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; -use Zend\Mvc\Container\ServiceManagerConfig; -use Zend\Mvc\Container\ServiceListenerFactory; +use Zend\Mvc\View\Http\ViewManager; use Zend\Router; -use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\ArrayUtils; use ZendTest\Mvc\TestAsset; +use ZendTest\Mvc\TestAsset\ApplicationConfigHelper; trait MissingControllerTrait { public function prepareApplication() { - $config = [ + $config = ApplicationConfigHelper::getConfig([ + 'dependencies' => [ + 'factories' => [ + EmitterInterface::class => function () { + $emitter = $this->prophesize(EmitterInterface::class); + return $emitter->reveal(); + }, + ], + 'invokables' => [ + ViewManager::class => TestAsset\MockViewManager::class, + ], + ], 'router' => [ 'routes' => [ 'path' => [ @@ -38,51 +46,9 @@ public function prepareApplication() ], ], ], - ]; - - $serviceListener = new ServiceListenerFactory(); - $r = new ReflectionProperty($serviceListener, 'defaultServiceConfig'); - $r->setAccessible(true); - $serviceConfig = $r->getValue($serviceListener); - - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - (new Router\ConfigProvider())->getDependencyConfig() - ); - - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - [ - 'factories' => [ - 'Router' => function ($services) { - return $services->get('HttpRouter'); - }, - EmitterInterface::class => function () { - $emitter = $this->prophesize(EmitterInterface::class); - return $emitter->reveal(); - }, - ], - 'invokables' => [ - 'ViewManager' => TestAsset\MockViewManager::class, - 'BootstrapListener' => TestAsset\StubBootstrapListener::class, - ], - 'services' => [ - 'config' => $config, - 'ApplicationConfig' => [ - 'modules' => [], - 'module_listener_options' => [ - 'config_cache_enabled' => false, - 'cache_dir' => 'data/cache', - 'module_paths' => [], - ], - ], - ], - ] - ); - $services = new ServiceManager(); - (new ServiceManagerConfig($serviceConfig))->configureServiceManager($services); - $application = $services->get('Application'); - + ]); + $container = ApplicationConfigHelper::configureContainer($config); + $application = $container->get(Application::class); $application->bootstrap(); return $application; } diff --git a/test/Application/PathControllerTrait.php b/test/Application/PathControllerTrait.php index 505383536..ac40a5e44 100644 --- a/test/Application/PathControllerTrait.php +++ b/test/Application/PathControllerTrait.php @@ -9,54 +9,20 @@ namespace ZendTest\Mvc\Application; -use ReflectionProperty; use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; -use Zend\Mvc\Container\ServiceManagerConfig; -use Zend\Mvc\Container\ServiceListenerFactory; +use Zend\Mvc\View\Http\ViewManager; use Zend\Router; -use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\ArrayUtils; use ZendTest\Mvc\TestAsset; +use ZendTest\Mvc\TestAsset\ApplicationConfigHelper; trait PathControllerTrait { public function prepareApplication() { - $config = [ - 'router' => [ - 'routes' => [ - 'path' => [ - 'type' => Router\Route\Literal::class, - 'options' => [ - 'route' => '/path', - 'defaults' => [ - 'controller' => 'path', - ], - ], - ], - ], - ], - ]; - - $serviceListener = new ServiceListenerFactory(); - $r = new ReflectionProperty($serviceListener, 'defaultServiceConfig'); - $r->setAccessible(true); - $serviceConfig = $r->getValue($serviceListener); - - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - (new Router\ConfigProvider())->getDependencyConfig() - ); - - $serviceConfig = ArrayUtils::merge( - $serviceConfig, - [ - 'aliases' => [ - 'ControllerLoader' => ControllerManager::class, - 'ControllerManager' => ControllerManager::class, - ], + $config = ApplicationConfigHelper::getConfig([ + 'dependencies' => [ 'factories' => [ ControllerManager::class => function ($services) { return new ControllerManager($services, ['factories' => [ @@ -65,37 +31,31 @@ public function prepareApplication() }, ]]); }, - 'Router' => function ($services) { - return $services->get('HttpRouter'); - }, EmitterInterface::class => function () { $emitter = $this->prophesize(EmitterInterface::class); return $emitter->reveal(); }, ], 'invokables' => [ - 'ViewManager' => TestAsset\MockViewManager::class, - 'BootstrapListener' => TestAsset\StubBootstrapListener::class, + ViewManager::class => TestAsset\MockViewManager::class, ], - 'services' => [ - 'config' => $config, - 'ApplicationConfig' => [ - 'modules' => [ - 'Zend\Router', - ], - 'module_listener_options' => [ - 'config_cache_enabled' => false, - 'cache_dir' => 'data/cache', - 'module_paths' => [], + ], + 'router' => [ + 'routes' => [ + 'path' => [ + 'type' => Router\Route\Literal::class, + 'options' => [ + 'route' => '/path', + 'defaults' => [ + 'controller' => 'path', + ], ], ], ], - ] - ); - $services = new ServiceManager(); - (new ServiceManagerConfig($serviceConfig))->configureServiceManager($services); - $application = $services->get('Application'); - + ], + ]); + $container = ApplicationConfigHelper::configureContainer($config); + $application = $container->get(Application::class); $application->bootstrap(); return $application; } diff --git a/test/Container/ViewHelperManagerFactoryTest.php b/test/Container/ViewHelperManagerFactoryTest.php index f69679a94..e3df046c2 100644 --- a/test/Container/ViewHelperManagerFactoryTest.php +++ b/test/Container/ViewHelperManagerFactoryTest.php @@ -133,6 +133,7 @@ public function basePathConfiguration() */ public function testBasePathHelperFactoryCanBeInvokedViaShortNameOrFullClassName($name, array $services, $expected) { + $this->markTestIncomplete('Base path handling changed. Needs new tests'); foreach ($services as $key => $value) { if (is_callable($value)) { $this->services->setFactory($key, $value); diff --git a/test/View/DefaultRendereringStrategyTest.php b/test/View/DefaultRendereringStrategyTest.php index 375a5b05b..6aed0d104 100644 --- a/test/View/DefaultRendereringStrategyTest.php +++ b/test/View/DefaultRendereringStrategyTest.php @@ -124,6 +124,7 @@ public function testBypassesRenderingIfResultIsAResponse() public function testTriggersRenderErrorEventInCaseOfRenderingException() { + $this->markTestIncomplete('Tests needs to be updated'); $resolver = new TemplateMapResolver(); $resolver->add('exception', __DIR__ . '/_files/exception.phtml'); $this->renderer->setResolver($resolver); From fe03a8b67f870c713242e1046747195f61770668 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 29 Dec 2017 13:22:27 +1000 Subject: [PATCH 31/51] Refactor Controller factory to use config --- src/ConfigProvider.php | 3 +- src/Container/ControllerManagerFactory.php | 20 +-- .../ControllerManagerFactoryTest.php | 114 +++++------------- test/ContainerTrait.php | 4 +- 4 files changed, 47 insertions(+), 94 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index b6f3e87fe..19126e66b 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -8,14 +8,13 @@ namespace Zend\Mvc; -use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\SharedEventManager; use Zend\EventManager\SharedEventManagerInterface; use Zend\Mvc\Container\ApplicationFactory; +use Zend\Mvc\Container\ControllerManagerFactory; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; -use Zend\Mvc\Service\ControllerManagerFactory; use Zend\Mvc\Service\ControllerPluginManagerFactory; use Zend\Mvc\Service\DispatchListenerFactory; use Zend\Mvc\Service\EventManagerFactory; diff --git a/src/Container/ControllerManagerFactory.php b/src/Container/ControllerManagerFactory.php index ce294a6a7..aedc5ec75 100644 --- a/src/Container/ControllerManagerFactory.php +++ b/src/Container/ControllerManagerFactory.php @@ -9,11 +9,10 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Zend\Mvc\Controller\ControllerManager; -use Zend\ServiceManager\Factory\FactoryInterface; -class ControllerManagerFactory implements FactoryInterface +class ControllerManagerFactory { /** * Create the controller manager service @@ -26,15 +25,16 @@ class ControllerManagerFactory implements FactoryInterface * if the controller implements a setPluginManager() method. * * @param ContainerInterface $container - * @param string $Name - * @param null|array $options * @return ControllerManager */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : ControllerManager { - if ($options) { - return new ControllerManager($container, $options); - } - return new ControllerManager($container); + return new ControllerManager($container, $this->getControllersConfig($container)); + } + + public function getControllersConfig(ContainerInterface $container) : array + { + $config = $container->has('config') ? $container->get('config') : []; + return $config['controllers'] ?? []; } } diff --git a/test/Container/ControllerManagerFactoryTest.php b/test/Container/ControllerManagerFactoryTest.php index da249fff3..5680fb475 100644 --- a/test/Container/ControllerManagerFactoryTest.php +++ b/test/Container/ControllerManagerFactoryTest.php @@ -4,109 +4,61 @@ * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com) * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ - declare(strict_types=1); namespace ZendTest\Mvc\Container; use PHPUnit\Framework\TestCase; -use Zend\EventManager\SharedEventManager; +use Prophecy\Prophecy\ObjectProphecy; use Zend\Mvc\Container\ControllerManagerFactory; -use Zend\Mvc\Container\ControllerPluginManagerFactory; -use Zend\Mvc\Container\EventManagerFactory; -use Zend\ServiceManager\Config; -use Zend\ServiceManager\Exception; -use Zend\ServiceManager\Factory\InvokableFactory; -use Zend\ServiceManager\ServiceManager; -use ZendTest\Mvc\Controller\Plugin\TestAsset\SamplePlugin; -use ZendTest\Mvc\Controller\TestAsset\SampleController; -use ZendTest\Mvc\Service\TestAsset; -use ZendTest\Mvc\Service\TestAsset\InvalidDispatchableClass; +use Zend\Mvc\Controller\Dispatchable; +use ZendTest\Mvc\ContainerTrait; +/** + * @covers \Zend\Mvc\Container\ControllerManagerFactory + */ class ControllerManagerFactoryTest extends TestCase { + use ContainerTrait; + /** - * @var ServiceManager + * @var ObjectProphecy */ - protected $services; + private $container; /** - * @var \Zend\Mvc\Controller\ControllerManager + * @var ControllerManagerFactory */ - protected $loader; + private $factory; public function setUp() { - $loaderFactory = new ControllerManagerFactory(); - $this->defaultServiceConfig = [ - 'aliases' => [ - 'SharedEventManager' => SharedEventManager::class, - ], - 'factories' => [ - 'ControllerManager' => $loaderFactory, - 'ControllerPluginManager' => ControllerPluginManagerFactory::class, - 'EventManager' => EventManagerFactory::class, - SharedEventManager::class => InvokableFactory::class, - ], - 'services' => [ - 'config' => [], - ], - ]; - $this->services = new ServiceManager(); - (new Config($this->defaultServiceConfig))->configureServiceManager($this->services); - } - - public function testCannotLoadInvalidDispatchable() - { - $loader = $this->services->get('ControllerManager'); - - // Ensure the class exists and can be autoloaded - $this->assertTrue(class_exists(InvalidDispatchableClass::class)); - - try { - $loader->get(InvalidDispatchableClass::class); - $this->fail('Retrieving the invalid dispatchable should fail'); - } catch (\Exception $e) { - do { - $this->assertNotContains('Should not instantiate this', $e->getMessage()); - } while ($e = $e->getPrevious()); - } - } - - public function testCannotLoadControllerFromPeer() - { - $services = new ServiceManager(); - (new Config(array_merge_recursive($this->defaultServiceConfig, ['services' => [ - 'foo' => $this, - ]])))->configureServiceManager($services); - $loader = $services->get('ControllerManager'); - - $this->expectException(Exception\ExceptionInterface::class); - $loader->get('foo'); + $this->container = $this->mockContainerInterface(); + $this->factory = new ControllerManagerFactory(); } - public function testControllerLoadedCanBeInjectedWithValuesFromPeer() + public function testInjectsContainerIntoControllerManager() { - $loader = $this->services->get('ControllerManager'); - $loader->setAlias('ZendTest\Dispatchable', TestAsset\Dispatchable::class); - $loader->setFactory(TestAsset\Dispatchable::class, InvokableFactory::class); - - $controller = $loader->get('ZendTest\Dispatchable'); - $this->assertInstanceOf(TestAsset\Dispatchable::class, $controller); - $this->assertSame($this->services->get('EventManager'), $controller->getEventManager()); - $this->assertSame($this->services->get('ControllerPluginManager'), $controller->getPluginManager()); + $container = $this->container->reveal(); + $controllerManager = $this->factory->__invoke($container); + $controllerManager->setFactory('Foo', function ($injectedContainer) use ($container) { + $this->assertSame($container, $injectedContainer); + return $this->prophesize(Dispatchable::class)->reveal(); + }); + $controllerManager->get('Foo'); } - public function testCallPluginWithControllerPluginManager() + public function testPullsControllersConfigFromConfigService() { - $controllerPluginManager = $this->services->get('ControllerPluginManager'); - $controllerPluginManager->setAlias('samplePlugin', SamplePlugin::class); - $controllerPluginManager->setFactory(SamplePlugin::class, InvokableFactory::class); - - $controller = new SampleController; - $controllerPluginManager->setController($controller); - - $plugin = $controllerPluginManager->get('samplePlugin'); - $this->assertEquals($controller, $plugin->getController()); + $this->injectServiceInContainer($this->container, 'config', [ + 'controllers' => [ + 'factories' => [ + 'Foo' => function () { + }, + ] + ] + ]); + $controllerManager = $this->factory->__invoke($this->container->reveal()); + $this->assertTrue($controllerManager->has('Foo')); } } diff --git a/test/ContainerTrait.php b/test/ContainerTrait.php index 070c89d49..05e78cbf7 100644 --- a/test/ContainerTrait.php +++ b/test/ContainerTrait.php @@ -11,7 +11,9 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; -use Psr\Container\ContainerInterface; +use Interop\Container\ContainerInterface; + +// @TODO update to Psr after service manager 4.0 is out /** * Helper methods for mock Psr\Container\ContainerInterface. From 0de36dd6080df4e843fa0acd6a92a575718d8b84 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 29 Dec 2017 15:31:46 +1000 Subject: [PATCH 32/51] Update ControllerManager and its tests --- src/Controller/ControllerManager.php | 4 +- test/Controller/ControllerManagerTest.php | 133 +++++++++++++--------- 2 files changed, 83 insertions(+), 54 deletions(-) diff --git a/src/Controller/ControllerManager.php b/src/Controller/ControllerManager.php index e40db7a4d..fc1037154 100644 --- a/src/Controller/ControllerManager.php +++ b/src/Controller/ControllerManager.php @@ -9,7 +9,7 @@ namespace Zend\Mvc\Controller; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\SharedEventManagerInterface; use Zend\ServiceManager\AbstractPluginManager; @@ -106,6 +106,6 @@ public function injectPluginManager(ContainerInterface $container, $controller) return; } - $controller->setPluginManager($container->get('ControllerPluginManager')); + $controller->setPluginManager($container->get(PluginManager::class)); } } diff --git a/test/Controller/ControllerManagerTest.php b/test/Controller/ControllerManagerTest.php index 97be79208..fca318db0 100644 --- a/test/Controller/ControllerManagerTest.php +++ b/test/Controller/ControllerManagerTest.php @@ -4,99 +4,128 @@ * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com) * @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); declare(strict_types=1); namespace ZendTest\Mvc\Controller; use PHPUnit\Framework\TestCase; -use ReflectionClass; +use Prophecy\Prophecy\ObjectProphecy; +use Psr\Container\ContainerInterface; use Zend\EventManager\EventManager; -use Zend\EventManager\EventManagerInterface; use Zend\EventManager\SharedEventManager; -use Zend\EventManager\SharedEventManagerInterface; use Zend\Mvc\Controller\ControllerManager; -use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; -use Zend\ServiceManager\Config; -use Zend\ServiceManager\Exception\ServiceNotFoundException; -use Zend\ServiceManager\ServiceManager; +use Zend\Mvc\Controller\Dispatchable; +use Zend\Mvc\Controller\PluginManager; +use Zend\ServiceManager\Exception\InvalidServiceException; +use ZendTest\Mvc\ContainerTrait; use ZendTest\Mvc\Controller\TestAsset\SampleController; +/** + * @covers \Zend\Mvc\Controller\ControllerManager + */ class ControllerManagerTest extends TestCase { - public function setUp() - { - $this->sharedEvents = new SharedEventManager; - $this->events = $this->createEventManager($this->sharedEvents); - - $this->services = new ServiceManager(); - (new Config([ - 'factories' => [ - 'ControllerPluginManager' => function ($services) { - return new ControllerPluginManager($services); - }, - ], - 'services' => [ - 'EventManager' => $this->events, - 'SharedEventManager' => $this->sharedEvents, - ], - ]))->configureServiceManager($this->services); - - $this->controllers = new ControllerManager($this->services); - } + use ContainerTrait; + + /** + * @var ObjectProphecy|ContainerInterface + */ + private $container; /** - * @param SharedEventManager - * @return EventManager + * @var ObjectProphecy|PluginManager */ - protected function createEventManager(SharedEventManagerInterface $sharedManager) + private $plugins; + + /** + * @var SharedEventManager + */ + private $sharedEvents; + + /** + * @var EventManager + */ + private $events; + + /** + * @var ControllerManager + */ + private $controllers; + + /** + * @var SampleController + */ + private $controller; + + public function setUp() { - return new EventManager($sharedManager); + $this->container = $this->mockContainerInterface(); + $this->plugins = $this->prophesize(PluginManager::class); + $this->sharedEvents = new SharedEventManager(); + $this->events = new EventManager($this->sharedEvents); + + $this->injectServiceInContainer($this->container, 'EventManager', $this->events); + $this->injectServiceInContainer($this->container, PluginManager::class, $this->plugins->reveal()); + + $this->controllers = new ControllerManager($this->container->reveal()); + $this->controller = new SampleController(); + $this->controllers->setFactory(SampleController::class, function () { + return $this->controller; + }); } public function testCanInjectEventManager() { - $controller = new SampleController(); - - $this->controllers->injectEventManager($this->services, $controller); + $this->container->get('EventManager')->shouldBeCalled(); + $controller = $this->controllers->get(SampleController::class); // The default AbstractController implementation lazy instantiates an EM // instance, which means we need to check that that instance gets injected // with the shared EM instance. $events = $controller->getEventManager(); - $this->assertInstanceOf(EventManagerInterface::class, $events); - $this->assertSame($this->sharedEvents, $events->getSharedManager()); + $this->assertSame($events, $this->events); } public function testCanInjectPluginManager() { - $controller = new SampleController(); + $this->container->get(PluginManager::class)->shouldBeCalled(); + $controller = $this->controllers->get(SampleController::class); - $this->controllers->injectPluginManager($this->services, $controller); - - $this->assertSame($this->services->get('ControllerPluginManager'), $controller->getPluginManager()); + $this->assertSame($this->plugins->reveal(), $controller->getPluginManager()); } public function testInjectEventManagerWillNotOverwriteExistingEventManagerIfItAlreadyHasASharedManager() { - $events = $this->createEventManager($this->sharedEvents); - $controller = new SampleController(); - $controller->setEventManager($events); + $events = new EventManager($this->sharedEvents); + $this->controller->setEventManager($events); - $this->controllers->injectEventManager($this->services, $controller); + $this->container->get('EventManager')->shouldNotBeCalled(); + $controller = $this->controllers->get(SampleController::class); $this->assertSame($events, $controller->getEventManager()); $this->assertSame($this->sharedEvents, $events->getSharedManager()); } - /** - * @covers Zend\ServiceManager\ServiceManager::has - * @covers Zend\ServiceManager\AbstractPluginManager::get - */ - public function testDoNotUsePeeringServiceManagers() + public function testRequiresControllerToBeDispatchable() + { + $this->controllers->setFactory('Foo', function () { + return new \stdClass; + }); + + $this->expectException(InvalidServiceException::class); + $this->expectExceptionMessage(\sprintf('must implement %s', Dispatchable::class)); + $this->controllers->get('Foo'); + } + + public function testInitializersSkipIfDispatchableIsNotPluginOrEventAware() { - $this->assertFalse($this->controllers->has('EventManager')); - $this->expectException(ServiceNotFoundException::class); - $this->controllers->get('EventManager'); + $this->controllers->setFactory('Foo', function () { + return $this->prophesize(Dispatchable::class)->reveal(); + }); + + $this->controllers->get('Foo'); + $this->assertTrue(true, 'No assertions made, no errors expected'); } } From a76ecf40b4d974257b9f3ffe5d472fcb81aeb865 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 29 Dec 2017 17:03:58 +1000 Subject: [PATCH 33/51] Update ControllerPluginManager factory and add tests --- src/ConfigProvider.php | 2 +- .../ControllerPluginManagerFactory.php | 15 ++++- .../ControllerPluginManagerFactoryTest.php | 64 +++++++++++++++++++ 3 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 test/Container/ControllerPluginManagerFactoryTest.php diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 19126e66b..9dda4c578 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -15,7 +15,7 @@ use Zend\Mvc\Container\ControllerManagerFactory; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; -use Zend\Mvc\Service\ControllerPluginManagerFactory; +use Zend\Mvc\Container\ControllerPluginManagerFactory; use Zend\Mvc\Service\DispatchListenerFactory; use Zend\Mvc\Service\EventManagerFactory; use Zend\Mvc\Service\HttpDefaultRenderingStrategyFactory; diff --git a/src/Container/ControllerPluginManagerFactory.php b/src/Container/ControllerPluginManagerFactory.php index a8793b28d..1ea5bdbf1 100644 --- a/src/Container/ControllerPluginManagerFactory.php +++ b/src/Container/ControllerPluginManagerFactory.php @@ -9,10 +9,19 @@ namespace Zend\Mvc\Container; +use Psr\Container\ContainerInterface; use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; -use Zend\Mvc\Service\AbstractPluginManagerFactory; -class ControllerPluginManagerFactory extends AbstractPluginManagerFactory +class ControllerPluginManagerFactory { - const PLUGIN_MANAGER_CLASS = ControllerPluginManager::class; + public function __invoke(ContainerInterface $container) : ControllerPluginManager + { + return new ControllerPluginManager($container, $this->getPluginsConfig($container)); + } + + public function getPluginsConfig(ContainerInterface $container) : array + { + $config = $container->has('config') ? $container->get('config') : []; + return $config['controller_plugins'] ?? []; + } } diff --git a/test/Container/ControllerPluginManagerFactoryTest.php b/test/Container/ControllerPluginManagerFactoryTest.php new file mode 100644 index 000000000..4d83d505e --- /dev/null +++ b/test/Container/ControllerPluginManagerFactoryTest.php @@ -0,0 +1,64 @@ +container = $this->mockContainerInterface(); + $this->factory = new ControllerPluginManagerFactory(); + } + + public function testInjectsContainerIntoPluginManager() + { + $container = $this->container->reveal(); + $pluginManager = $this->factory->__invoke($container); + $pluginManager->setFactory('Foo', function ($injectedContainer) use ($container) { + $this->assertSame($container, $injectedContainer); + return $this->prophesize(PluginInterface::class)->reveal(); + }); + $pluginManager->get('Foo'); + } + + public function testPullsPluginsConfigFromConfigService() + { + $this->injectServiceInContainer($this->container, 'config', [ + 'controller_plugins' => [ + 'factories' => [ + 'Foo' => function () { + }, + ] + ] + ]); + $pluginManager = $this->factory->__invoke($this->container->reveal()); + $this->assertTrue($pluginManager->has('Foo')); + } +} From 9e45700a3b94921a4fa41b4e876609ea22164bb2 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 29 Dec 2017 17:27:49 +1000 Subject: [PATCH 34/51] Update DispatchListener factory and add test --- src/ConfigProvider.php | 2 +- src/Container/DispatchListenerFactory.php | 12 +++--- .../Container/DispatchListenerFactoryTest.php | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 test/Container/DispatchListenerFactoryTest.php diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 9dda4c578..f728a72d0 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -16,7 +16,7 @@ use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; use Zend\Mvc\Container\ControllerPluginManagerFactory; -use Zend\Mvc\Service\DispatchListenerFactory; +use Zend\Mvc\Container\DispatchListenerFactory; use Zend\Mvc\Service\EventManagerFactory; use Zend\Mvc\Service\HttpDefaultRenderingStrategyFactory; use Zend\Mvc\Service\HttpExceptionStrategyFactory; diff --git a/src/Container/DispatchListenerFactory.php b/src/Container/DispatchListenerFactory.php index 05aac4e32..3986b4026 100644 --- a/src/Container/DispatchListenerFactory.php +++ b/src/Container/DispatchListenerFactory.php @@ -9,22 +9,20 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; +use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\DispatchListener; -use Zend\ServiceManager\Factory\FactoryInterface; -class DispatchListenerFactory implements FactoryInterface +class DispatchListenerFactory { /** * Create the default dispatch listener. * * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return DispatchListener */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : DispatchListener { - return new DispatchListener($container->get('ControllerManager')); + return new DispatchListener($container->get(ControllerManager::class)); } } diff --git a/test/Container/DispatchListenerFactoryTest.php b/test/Container/DispatchListenerFactoryTest.php new file mode 100644 index 000000000..688e5f341 --- /dev/null +++ b/test/Container/DispatchListenerFactoryTest.php @@ -0,0 +1,37 @@ +mockContainerInterface(); + $this->injectServiceInContainer( + $container, + ControllerManager::class, + $this->prophesize(ControllerManager::class)->reveal() + ); + $factory = new DispatchListenerFactory(); + + $listener = $factory->__invoke($container->reveal()); + $this->assertInstanceOf(DispatchListener::class, $listener); + } +} From b7e56d40ba72d726a1ee4c7508e89a676e9412a0 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 29 Dec 2017 17:42:13 +1000 Subject: [PATCH 35/51] Update EventManager factory and add test --- src/ConfigProvider.php | 2 +- src/Container/EventManagerFactory.php | 9 ++--- test/Container/EventManagerFactoryTest.php | 44 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 test/Container/EventManagerFactoryTest.php diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index f728a72d0..216e57692 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -17,7 +17,7 @@ use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; use Zend\Mvc\Container\ControllerPluginManagerFactory; use Zend\Mvc\Container\DispatchListenerFactory; -use Zend\Mvc\Service\EventManagerFactory; +use Zend\Mvc\Container\EventManagerFactory; use Zend\Mvc\Service\HttpDefaultRenderingStrategyFactory; use Zend\Mvc\Service\HttpExceptionStrategyFactory; use Zend\Mvc\Service\HttpMethodListenerFactory; diff --git a/src/Container/EventManagerFactory.php b/src/Container/EventManagerFactory.php index deca72a86..a89f7c597 100644 --- a/src/Container/EventManagerFactory.php +++ b/src/Container/EventManagerFactory.php @@ -9,11 +9,10 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Zend\EventManager\EventManager; -use Zend\ServiceManager\Factory\FactoryInterface; -class EventManagerFactory implements FactoryInterface +class EventManagerFactory { /** * Create an EventManager instance @@ -22,11 +21,9 @@ class EventManagerFactory implements FactoryInterface * of SharedEventManager. * * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return EventManager */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : EventManager { $shared = $container->has('SharedEventManager') ? $container->get('SharedEventManager') : null; diff --git a/test/Container/EventManagerFactoryTest.php b/test/Container/EventManagerFactoryTest.php new file mode 100644 index 000000000..2423e0de3 --- /dev/null +++ b/test/Container/EventManagerFactoryTest.php @@ -0,0 +1,44 @@ +mockContainerInterface(); + $factory = new EventManagerFactory(); + + $events = $factory->__invoke($container->reveal()); + $this->assertInstanceOf(EventManager::class, $events); + } + + public function testInjectsSharedEventManagerIfAvailable() + { + $container = $this->mockContainerInterface(); + $factory = new EventManagerFactory(); + $shared = new SharedEventManager(); + $this->injectServiceInContainer($container, 'SharedEventManager', $shared); + + $events = $factory->__invoke($container->reveal()); + $this->assertSame($shared, $events->getSharedManager()); + } +} From 589d58072678229531f465c614caf1ae2860e488 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 29 Dec 2017 18:06:44 +1000 Subject: [PATCH 36/51] Update HttpMethodListener factory and tests --- src/ConfigProvider.php | 2 +- src/Container/HttpMethodListenerFactory.php | 27 ++++-------------- .../HttpMethodListenerFactoryTest.php | 28 +++++++++++-------- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 216e57692..4e1ecf709 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -20,7 +20,7 @@ use Zend\Mvc\Container\EventManagerFactory; use Zend\Mvc\Service\HttpDefaultRenderingStrategyFactory; use Zend\Mvc\Service\HttpExceptionStrategyFactory; -use Zend\Mvc\Service\HttpMethodListenerFactory; +use Zend\Mvc\Container\HttpMethodListenerFactory; use Zend\Mvc\Service\HttpRouteNotFoundStrategyFactory; use Zend\Mvc\Service\HttpViewManagerFactory; use Zend\Mvc\Service\InjectTemplateListenerFactory; diff --git a/src/Container/HttpMethodListenerFactory.php b/src/Container/HttpMethodListenerFactory.php index 6a90dced9..85f3c7cf0 100644 --- a/src/Container/HttpMethodListenerFactory.php +++ b/src/Container/HttpMethodListenerFactory.php @@ -9,31 +9,16 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Zend\Mvc\HttpMethodListener; -use Zend\ServiceManager\Factory\FactoryInterface; -class HttpMethodListenerFactory implements FactoryInterface +class HttpMethodListenerFactory { - /** - * {@inheritdoc} - * @return HttpMethodListener - */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : HttpMethodListener { - $config = $container->get('config'); - - if (! isset($config['http_methods_listener'])) { - return new HttpMethodListener(); - } - - $listenerConfig = $config['http_methods_listener']; - $enabled = array_key_exists('enabled', $listenerConfig) - ? $listenerConfig['enabled'] - : true; - $allowedMethods = (isset($listenerConfig['allowed_methods']) && is_array($listenerConfig['allowed_methods'])) - ? $listenerConfig['allowed_methods'] - : null; + $config = $container->has('config') ? $container->get('config') : []; + $enabled = $config['http_methods_listener']['enabled'] ?? true; + $allowedMethods = $config['http_methods_listener']['allowed_methods'] ?? null; return new HttpMethodListener($enabled, $allowedMethods); } diff --git a/test/Container/HttpMethodListenerFactoryTest.php b/test/Container/HttpMethodListenerFactoryTest.php index 3234fad36..b825b3d0d 100644 --- a/test/Container/HttpMethodListenerFactoryTest.php +++ b/test/Container/HttpMethodListenerFactoryTest.php @@ -9,32 +9,37 @@ namespace ZendTest\Mvc\Container; -use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject as MockObject; +use Prophecy\Prophecy\ObjectProphecy; use Zend\Mvc\Container\HttpMethodListenerFactory; -use Zend\ServiceManager\ServiceLocatorInterface; +use ZendTest\Mvc\ContainerTrait; /** * @covers \Zend\Mvc\Container\HttpMethodListenerFactory */ class HttpMethodListenerFactoryTest extends TestCase { + use ContainerTrait; + + /** + * @var ObjectProphecy + */ + protected $container; + /** - * @var ServiceLocatorInterface|MockObject + * @var HttpMethodListenerFactory */ - protected $serviceLocator; + private $factory; public function setUp() { - $this->serviceLocator = $this->prophesize(ServiceLocatorInterface::class); - $this->serviceLocator->willImplement(ContainerInterface::class); + $this->container = $this->mockContainerInterface(); + $this->factory = new HttpMethodListenerFactory(); } public function testCreateWithDefaults() { - $factory = new HttpMethodListenerFactory(); - $listener = $factory($this->serviceLocator->reveal(), 'HttpMethodListener'); + $listener = $this->factory->__invoke($this->container->reveal()); $this->assertTrue($listener->isEnabled()); $this->assertNotEmpty($listener->getAllowedMethods()); } @@ -46,10 +51,9 @@ public function testCreateWithConfig() 'allowed_methods' => ['FOO', 'BAR'] ]; - $this->serviceLocator->get('config')->willReturn($config); + $this->injectServiceInContainer($this->container, 'config', $config); - $factory = new HttpMethodListenerFactory(); - $listener = $factory($this->serviceLocator->reveal(), 'HttpMethodListener'); + $listener = $this->factory->__invoke($this->container->reveal()); $listenerConfig = $config['http_methods_listener']; From ca7b025c7442fc535236e4a656b3039b8638c8c9 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 30 Dec 2017 07:38:29 +1000 Subject: [PATCH 37/51] Update ViewManager and add test placeholder --- docs/book/services.md | 5 ---- src/ConfigProvider.php | 3 +- src/Container/HttpViewManagerFactory.php | 30 ------------------- src/View/Http/ViewManager.php | 31 ++++++++++---------- test/Container/ViewManagerFactoryTest.php | 35 ----------------------- test/View/Http/ViewManagerTest.php | 24 ++++++++++++++++ 6 files changed, 41 insertions(+), 87 deletions(-) delete mode 100644 src/Container/HttpViewManagerFactory.php delete mode 100644 test/Container/ViewManagerFactoryTest.php create mode 100644 test/View/Http/ViewManagerTest.php diff --git a/docs/book/services.md b/docs/book/services.md index 5cd543c7b..4aaae2508 100644 --- a/docs/book/services.md +++ b/docs/book/services.md @@ -180,11 +180,6 @@ services configured out of the box. the `Config` service, and pulls from the `router` key, configuring a `Zend\Router\Http\TreeRouteStack` instance. -- `HttpViewManager`, mapping to `Zend\Mvc\Container\HttpViewManagerFactory`. - This creates and returns an instance of `Zend\Mvc\View\Http\ViewManager`, - which in turn registers and initializes a number of HTTP-specific view - services. - - `HydratorManager`, mapping to `Zend\Mvc\Service\HydratorManagerFactory`. This creates and returns an instance of `Zend\Stdlib\Hydrator\HydratorPluginManager`, which can be used to manage and persist hydrator instances. diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 4e1ecf709..c44c44c71 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -22,7 +22,6 @@ use Zend\Mvc\Service\HttpExceptionStrategyFactory; use Zend\Mvc\Container\HttpMethodListenerFactory; use Zend\Mvc\Service\HttpRouteNotFoundStrategyFactory; -use Zend\Mvc\Service\HttpViewManagerFactory; use Zend\Mvc\Service\InjectTemplateListenerFactory; use Zend\Mvc\Service\ViewFactory; use Zend\Mvc\Service\ViewFeedStrategyFactory; @@ -132,7 +131,7 @@ public function getDependencyConfig() TemplateMapResolver::class => ViewTemplateMapResolverFactory::class, TemplatePathStack::class => ViewTemplatePathStackFactory::class, View::class => ViewFactory::class, - ViewManager::class => HttpViewManagerFactory::class, + ViewManager::class => InvokableFactory::class, ], 'shared' => [ 'EventManager' => false, diff --git a/src/Container/HttpViewManagerFactory.php b/src/Container/HttpViewManagerFactory.php deleted file mode 100644 index 33a1a0e93..000000000 --- a/src/Container/HttpViewManagerFactory.php +++ /dev/null @@ -1,30 +0,0 @@ -getApplication(); - $services = $application->getContainer(); - $config = $services->get('config'); + $container = $application->getContainer(); + $config = $container->get('config'); $events = $application->getEventManager(); $sharedEvents = $events->getSharedManager(); @@ -98,16 +99,16 @@ public function onBootstrap(MvcEvent $event) : void || $config['view_manager'] instanceof ArrayAccess) ? $config['view_manager'] : []; - $this->services = $services; + $this->container = $container; $this->event = $event; - $routeNotFoundStrategy = $services->get('HttpRouteNotFoundStrategy'); - $exceptionStrategy = $services->get('HttpExceptionStrategy'); - $mvcRenderingStrategy = $services->get('HttpDefaultRenderingStrategy'); + $routeNotFoundStrategy = $container->get(RouteNotFoundStrategy::class); + $exceptionStrategy = $container->get(ExceptionStrategy::class); + $mvcRenderingStrategy = $container->get(DefaultRenderingStrategy::class); $this->injectViewModelIntoPlugin(); - $injectTemplateListener = $services->get('Zend\Mvc\View\Http\InjectTemplateListener'); + $injectTemplateListener = $container->get(InjectTemplateListener::class); $createViewModelListener = new CreateViewModelListener(); $injectViewModelListener = new InjectViewModelListener(); @@ -163,7 +164,7 @@ public function getView() return $this->view; } - $this->view = $this->services->get(View::class); + $this->view = $this->container->get(View::class); return $this->view; } @@ -179,7 +180,7 @@ public function getViewModel() } $this->viewModel = $model = $this->event->getViewModel(); - $layoutTemplate = $this->services->get('HttpDefaultRenderingStrategy')->getLayoutTemplate(); + $layoutTemplate = $this->container->get(DefaultRenderingStrategy::class)->getLayoutTemplate(); $model->setTemplate($layoutTemplate); return $this->viewModel; @@ -215,7 +216,7 @@ protected function registerMvcRenderingStrategies(EventManagerInterface $events) continue; } - $listener = $this->services->get($mvcStrategy); + $listener = $this->container->get($mvcStrategy); if ($listener instanceof ListenerAggregateInterface) { $listener->attach($events, 100); } @@ -254,7 +255,7 @@ protected function registerViewStrategies() : void continue; } - $listener = $this->services->get($strategy); + $listener = $this->container->get($strategy); if ($listener instanceof ListenerAggregateInterface) { $listener->attach($events, 100); } @@ -267,7 +268,7 @@ protected function registerViewStrategies() : void private function injectViewModelIntoPlugin() : void { $model = $this->getViewModel(); - $plugins = $this->services->get('ViewHelperManager'); + $plugins = $this->container->get(HelperPluginManager::class); $plugin = $plugins->get('viewmodel'); $plugin->setRoot($model); } diff --git a/test/Container/ViewManagerFactoryTest.php b/test/Container/ViewManagerFactoryTest.php deleted file mode 100644 index 818b878de..000000000 --- a/test/Container/ViewManagerFactoryTest.php +++ /dev/null @@ -1,35 +0,0 @@ -prophesize(HttpViewManager::class); - $container = $this->prophesize(ContainerInterface::class); - $container->get('HttpViewManager')->will(function () use ($http) { - return $http->reveal(); - }); - return $container->reveal(); - } - - public function testReturnsHttpViewManager() - { - $factory = new ViewManagerFactory(); - $result = $factory($this->createContainer(), 'ViewManager'); - $this->assertInstanceOf(HttpViewManager::class, $result); - } -} diff --git a/test/View/Http/ViewManagerTest.php b/test/View/Http/ViewManagerTest.php new file mode 100644 index 000000000..3bc8cf78e --- /dev/null +++ b/test/View/Http/ViewManagerTest.php @@ -0,0 +1,24 @@ +markTestIncomplete('ViewManager needs tests'); + } +} From 5ebd6a0b9fafbe100f6200c71fbc8e3378b696a7 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 30 Dec 2017 07:45:59 +1000 Subject: [PATCH 38/51] Fix minor test failures --- test/Controller/IntegrationTest.php | 2 +- test/Controller/Plugin/ForwardTest.php | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/Controller/IntegrationTest.php b/test/Controller/IntegrationTest.php index 70221902e..8ce0d2594 100644 --- a/test/Controller/IntegrationTest.php +++ b/test/Controller/IntegrationTest.php @@ -29,7 +29,7 @@ public function setUp() 'SharedEventManager' => $this->sharedEvents, ], 'factories' => [ - 'ControllerPluginManager' => function ($services) { + PluginManager::class => function ($services) { return new PluginManager($services); }, 'EventManager' => function () { diff --git a/test/Controller/Plugin/ForwardTest.php b/test/Controller/Plugin/ForwardTest.php index 7f4f5ab73..e75313e2c 100644 --- a/test/Controller/Plugin/ForwardTest.php +++ b/test/Controller/Plugin/ForwardTest.php @@ -72,10 +72,11 @@ public function setUp() $config = new Config([ 'aliases' => [ - 'ControllerLoader' => 'ControllerManager', + 'ControllerPluginManager' => PluginManager::class, + 'ControllerManager' => ControllerManager::class, ], 'factories' => [ - 'ControllerManager' => function ($services, $name) { + ControllerManager::class => function ($services, $name) { $plugins = $services->get('ControllerPluginManager'); return new ControllerManager($services, ['factories' => [ @@ -86,7 +87,7 @@ public function setUp() }, ]]); }, - 'ControllerPluginManager' => function ($services, $name) { + PluginManager::class => function ($services, $name) { return new PluginManager($services); }, 'EventManager' => function ($services, $name) { @@ -162,7 +163,7 @@ public function testDispatchRaisesDomainExceptionIfCircular() ], 'factories' => [ 'ControllerManager' => function ($services) use ($event) { - $plugins = $services->get('ControllerPluginManager'); + $plugins = $services->get(PluginManager::class); return new ControllerManager($services, ['factories' => [ 'forward' => function ($services) use ($plugins) { @@ -178,7 +179,7 @@ public function testDispatchRaisesDomainExceptionIfCircular() }, ]]); }, - 'ControllerPluginManager' => function ($services) { + PluginManager::class => function ($services) { return new PluginManager($services); }, 'EventManager' => function ($services, $name) { From e7e9db3c7871407088234fe823bf238b7afcb104 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 30 Dec 2017 16:55:45 +1000 Subject: [PATCH 39/51] Drop paginator PluginManager from zend-mvc --- .../PaginatorPluginManagerFactory.php | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 src/Container/PaginatorPluginManagerFactory.php diff --git a/src/Container/PaginatorPluginManagerFactory.php b/src/Container/PaginatorPluginManagerFactory.php deleted file mode 100644 index c77e55bcf..000000000 --- a/src/Container/PaginatorPluginManagerFactory.php +++ /dev/null @@ -1,18 +0,0 @@ - Date: Sat, 30 Dec 2017 18:37:11 +1000 Subject: [PATCH 40/51] Update remaining factories --- src/ConfigProvider.php | 38 ++++----- .../DefaultRenderingStrategyFactory.php | 9 +-- src/Container/ExceptionStrategyFactory.php | 9 +-- .../InjectTemplateListenerFactory.php | 18 ++--- .../RouteNotFoundStrategyFactory.php | 7 +- src/Container/ViewFactory.php | 9 +-- src/Container/ViewFeedStrategyFactory.php | 12 ++- src/Container/ViewHelperManagerFactory.php | 78 +++++++------------ src/Container/ViewJsonStrategyFactory.php | 12 ++- src/Container/ViewManagerConfigTrait.php | 2 +- src/Container/ViewManagerFactory.php | 30 ------- src/Container/ViewPhpRendererFactory.php | 14 ++-- .../ViewPhpRendererStrategyFactory.php | 9 +-- .../ViewPrefixPathStackResolverFactory.php | 19 ++--- src/Container/ViewResolverFactory.php | 31 ++++---- .../ViewTemplateMapResolverFactory.php | 26 +++---- .../ViewTemplatePathStackFactory.php | 38 ++++----- .../InjectTemplateListenerFactoryTest.php | 14 ++-- .../Container/ViewFeedStrategyFactoryTest.php | 22 +++--- .../ViewHelperManagerFactoryTest.php | 4 + .../Container/ViewJsonStrategyFactoryTest.php | 21 +++-- ...ViewPrefixPathStackResolverFactoryTest.php | 17 ++-- 22 files changed, 184 insertions(+), 255 deletions(-) delete mode 100644 src/Container/ViewManagerFactory.php diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index c44c44c71..8ed421c6d 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -13,26 +13,26 @@ use Zend\EventManager\SharedEventManagerInterface; use Zend\Mvc\Container\ApplicationFactory; use Zend\Mvc\Container\ControllerManagerFactory; -use Zend\Mvc\Controller\ControllerManager; -use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; use Zend\Mvc\Container\ControllerPluginManagerFactory; +use Zend\Mvc\Container\DefaultRenderingStrategyFactory; use Zend\Mvc\Container\DispatchListenerFactory; use Zend\Mvc\Container\EventManagerFactory; -use Zend\Mvc\Service\HttpDefaultRenderingStrategyFactory; -use Zend\Mvc\Service\HttpExceptionStrategyFactory; +use Zend\Mvc\Container\ExceptionStrategyFactory; use Zend\Mvc\Container\HttpMethodListenerFactory; -use Zend\Mvc\Service\HttpRouteNotFoundStrategyFactory; -use Zend\Mvc\Service\InjectTemplateListenerFactory; -use Zend\Mvc\Service\ViewFactory; -use Zend\Mvc\Service\ViewFeedStrategyFactory; -use Zend\Mvc\Service\ViewHelperManagerFactory; -use Zend\Mvc\Service\ViewJsonStrategyFactory; -use Zend\Mvc\Service\ViewPhpRendererFactory; -use Zend\Mvc\Service\ViewPhpRendererStrategyFactory; -use Zend\Mvc\Service\ViewPrefixPathStackResolverFactory; -use Zend\Mvc\Service\ViewResolverFactory; -use Zend\Mvc\Service\ViewTemplateMapResolverFactory; -use Zend\Mvc\Service\ViewTemplatePathStackFactory; +use Zend\Mvc\Container\InjectTemplateListenerFactory; +use Zend\Mvc\Container\RouteNotFoundStrategyFactory; +use Zend\Mvc\Container\ViewFactory; +use Zend\Mvc\Container\ViewFeedStrategyFactory; +use Zend\Mvc\Container\ViewHelperManagerFactory; +use Zend\Mvc\Container\ViewJsonStrategyFactory; +use Zend\Mvc\Container\ViewPhpRendererFactory; +use Zend\Mvc\Container\ViewPhpRendererStrategyFactory; +use Zend\Mvc\Container\ViewPrefixPathStackResolverFactory; +use Zend\Mvc\Container\ViewResolverFactory; +use Zend\Mvc\Container\ViewTemplateMapResolverFactory; +use Zend\Mvc\Container\ViewTemplatePathStackFactory; +use Zend\Mvc\Controller\ControllerManager; +use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; use Zend\Mvc\View\Http\DefaultRenderingStrategy; use Zend\Mvc\View\Http\ExceptionStrategy; use Zend\Mvc\View\Http\InjectTemplateListener; @@ -111,9 +111,9 @@ public function getDependencyConfig() Application::class => ApplicationFactory::class, ControllerManager::class => ControllerManagerFactory::class, ControllerPluginManager::class => ControllerPluginManagerFactory::class, - DefaultRenderingStrategy::class => HttpDefaultRenderingStrategyFactory::class, + DefaultRenderingStrategy::class => DefaultRenderingStrategyFactory::class, DispatchListener::class => DispatchListenerFactory::class, - ExceptionStrategy::class => HttpExceptionStrategyFactory::class, + ExceptionStrategy::class => ExceptionStrategyFactory::class, FeedRenderer::class => InvokableFactory::class, FeedStrategy::class => ViewFeedStrategyFactory::class, HelperPluginManager::class => ViewHelperManagerFactory::class, @@ -126,7 +126,7 @@ public function getDependencyConfig() PhpRendererStrategy::class => ViewPhpRendererStrategyFactory::class, PrefixPathStackResolver::class => ViewPrefixPathStackResolverFactory::class, RouteListener::class => InvokableFactory::class, - RouteNotFoundStrategy::class => HttpRouteNotFoundStrategyFactory::class, + RouteNotFoundStrategy::class => RouteNotFoundStrategyFactory::class, SharedEventManager::class => InvokableFactory::class, TemplateMapResolver::class => ViewTemplateMapResolverFactory::class, TemplatePathStack::class => ViewTemplatePathStackFactory::class, diff --git a/src/Container/DefaultRenderingStrategyFactory.php b/src/Container/DefaultRenderingStrategyFactory.php index 58993c4e1..c4914405a 100644 --- a/src/Container/DefaultRenderingStrategyFactory.php +++ b/src/Container/DefaultRenderingStrategyFactory.php @@ -9,22 +9,19 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Zend\Mvc\View\Http\DefaultRenderingStrategy; -use Zend\ServiceManager\Factory\FactoryInterface; use Zend\View\View; -class DefaultRenderingStrategyFactory implements FactoryInterface +class DefaultRenderingStrategyFactory { use ViewManagerConfigTrait; /** * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return DefaultRenderingStrategy */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : DefaultRenderingStrategy { $strategy = new DefaultRenderingStrategy($container->get(View::class)); $config = $this->getConfig($container); diff --git a/src/Container/ExceptionStrategyFactory.php b/src/Container/ExceptionStrategyFactory.php index b4d2ef231..826032e57 100644 --- a/src/Container/ExceptionStrategyFactory.php +++ b/src/Container/ExceptionStrategyFactory.php @@ -9,21 +9,18 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Zend\Mvc\View\Http\ExceptionStrategy; -use Zend\ServiceManager\Factory\FactoryInterface; -class ExceptionStrategyFactory implements FactoryInterface +class ExceptionStrategyFactory { use ViewManagerConfigTrait; /** * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return ExceptionStrategy */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : ExceptionStrategy { $strategy = new ExceptionStrategy(); $config = $this->getConfig($container); diff --git a/src/Container/InjectTemplateListenerFactory.php b/src/Container/InjectTemplateListenerFactory.php index 6f5a2183e..5e0a3c5e6 100644 --- a/src/Container/InjectTemplateListenerFactory.php +++ b/src/Container/InjectTemplateListenerFactory.php @@ -11,26 +11,26 @@ use Interop\Container\ContainerInterface; use Zend\Mvc\View\Http\InjectTemplateListener; -use Zend\ServiceManager\Factory\FactoryInterface; -class InjectTemplateListenerFactory implements FactoryInterface +class InjectTemplateListenerFactory { + use ViewManagerConfigTrait; + /** - * {@inheritDoc} - * * Create and return an InjectTemplateListener instance. * + * @param ContainerInterface $container * @return InjectTemplateListener */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : InjectTemplateListener { $listener = new InjectTemplateListener(); - $config = $container->get('config'); + $config = $this->getConfig($container); - if (isset($config['view_manager']['controller_map']) - && (is_array($config['view_manager']['controller_map'])) + if (isset($config['controller_map']) + && (is_array($config['controller_map'])) ) { - $listener->setControllerMap($config['view_manager']['controller_map']); + $listener->setControllerMap($config['controller_map']); } return $listener; diff --git a/src/Container/RouteNotFoundStrategyFactory.php b/src/Container/RouteNotFoundStrategyFactory.php index c60778885..56698a872 100644 --- a/src/Container/RouteNotFoundStrategyFactory.php +++ b/src/Container/RouteNotFoundStrategyFactory.php @@ -9,11 +9,10 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Zend\Mvc\View\Http\RouteNotFoundStrategy; -use Zend\ServiceManager\Factory\FactoryInterface; -class RouteNotFoundStrategyFactory implements FactoryInterface +class RouteNotFoundStrategyFactory { use ViewManagerConfigTrait; @@ -23,7 +22,7 @@ class RouteNotFoundStrategyFactory implements FactoryInterface * @param null|array $options * @return RouteNotFoundStrategy */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : RouteNotFoundStrategy { $strategy = new RouteNotFoundStrategy(); $config = $this->getConfig($container); diff --git a/src/Container/ViewFactory.php b/src/Container/ViewFactory.php index 015c076b4..6552a4084 100644 --- a/src/Container/ViewFactory.php +++ b/src/Container/ViewFactory.php @@ -9,20 +9,17 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; use Zend\View\Strategy\PhpRendererStrategy; use Zend\View\View; -class ViewFactory implements FactoryInterface +class ViewFactory { /** * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return View */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : View { $view = new View(); $events = $container->get('EventManager'); diff --git a/src/Container/ViewFeedStrategyFactory.php b/src/Container/ViewFeedStrategyFactory.php index 4e102abbd..24595adcf 100644 --- a/src/Container/ViewFeedStrategyFactory.php +++ b/src/Container/ViewFeedStrategyFactory.php @@ -9,11 +9,11 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; +use Zend\View\Renderer\FeedRenderer; use Zend\View\Strategy\FeedStrategy; -class ViewFeedStrategyFactory implements FactoryInterface +class ViewFeedStrategyFactory { /** * Create and return the Feed view strategy @@ -24,12 +24,10 @@ class ViewFeedStrategyFactory implements FactoryInterface * It then attaches the strategy to the View service, at a priority of 100. * * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return FeedStrategy */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : FeedStrategy { - return new FeedStrategy($container->get('ViewFeedRenderer')); + return new FeedStrategy($container->get(FeedRenderer::class)); } } diff --git a/src/Container/ViewHelperManagerFactory.php b/src/Container/ViewHelperManagerFactory.php index c4728c216..86c369eed 100644 --- a/src/Container/ViewHelperManagerFactory.php +++ b/src/Container/ViewHelperManagerFactory.php @@ -9,42 +9,28 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\Mvc\Service\AbstractPluginManagerFactory; -use Zend\ServiceManager\AbstractPluginManager; -use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Psr\Container\ContainerInterface; use Zend\View\Helper as ViewHelper; use Zend\View\HelperPluginManager; -class ViewHelperManagerFactory extends AbstractPluginManagerFactory +class ViewHelperManagerFactory { - const PLUGIN_MANAGER_CLASS = HelperPluginManager::class; - - /** - * An array of helper configuration classes to ensure are on the helper_map stack. - * - * These are *not* imported; that way they can be optional dependencies. - * - * @todo Remove these once their components have Modules defined. - * @var array - */ - protected $defaultHelperMapClasses = []; + use ViewManagerConfigTrait; /** * Create and return the view helper manager * * @param ContainerInterface $container - * @return AbstractPluginManager - * @throws ServiceNotCreatedException + * @return HelperPluginManager */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + public function __invoke(ContainerInterface $container) : HelperPluginManager { - $options = $options ?: []; - $options['factories'] = isset($options['factories']) ? $options['factories'] : []; - $plugins = parent::__invoke($container, $requestedName, $options); + $config = $container->has('config') ? $container->get('config') : []; + $helpers = $config['view_helpers'] ?? []; + $plugins = new HelperPluginManager($container, $helpers); // Override plugin factories - $plugins = $this->injectOverrideFactories($plugins, $container); + $this->injectOverrideFactories($plugins, $container); return $plugins; } @@ -52,12 +38,14 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o /** * Inject override factories into the plugin manager. * - * @param AbstractPluginManager $plugins + * @param HelperPluginManager $plugins * @param ContainerInterface $services - * @return AbstractPluginManager + * @return void */ - private function injectOverrideFactories(AbstractPluginManager $plugins, ContainerInterface $services) + private function injectOverrideFactories(HelperPluginManager $plugins, ContainerInterface $services) { + $override = $plugins->getAllowOverride(); + $plugins->setAllowOverride(true); // Configure URL view helper $urlFactory = $this->createUrlHelperFactory($services); $plugins->setFactory(ViewHelper\Url::class, $urlFactory); @@ -72,8 +60,7 @@ private function injectOverrideFactories(AbstractPluginManager $plugins, Contain $doctypeFactory = $this->createDoctypeHelperFactory($services); $plugins->setFactory(ViewHelper\Doctype::class, $doctypeFactory); $plugins->setFactory('zendviewhelperdoctype', $doctypeFactory); - - return $plugins; + $plugins->setAllowOverride($override); } /** @@ -90,7 +77,7 @@ private function createUrlHelperFactory(ContainerInterface $services) { return function () use ($services) { $helper = new ViewHelper\Url; - $helper->setRouter($services->get('HttpRouter')); + $helper->setRouter($services->get('Zend\Mvc\Router')); return $helper; }; @@ -101,24 +88,19 @@ private function createUrlHelperFactory(ContainerInterface $services) * * Uses configuration and request services to configure the helper. * - * @param ContainerInterface $services + * @param ContainerInterface $container * @return callable */ - private function createBasePathHelperFactory(ContainerInterface $services) + private function createBasePathHelperFactory(ContainerInterface $container) { - return function () use ($services) { - $config = $services->has('config') ? $services->get('config') : []; + return function () use ($container) { $helper = new ViewHelper\BasePath; - if (isset($config['view_manager']) && isset($config['view_manager']['base_path'])) { - $helper->setBasePath($config['view_manager']['base_path']); - return $helper; - } - - $request = $services->get('Request'); + $viewConfig = $this->getConfig($container); - if (is_callable([$request, 'getBasePath'])) { - $helper->setBasePath($request->getBasePath()); + if (isset($viewConfig['base_path'])) { + $helper->setBasePath($viewConfig['base_path']); + return $helper; } return $helper; @@ -131,17 +113,17 @@ private function createBasePathHelperFactory(ContainerInterface $services) * Other view helpers depend on this to decide which spec to generate their tags * based on. This is why it must be set early instead of later in the layout phtml. * - * @param ContainerInterface $services + * @param ContainerInterface $container * @return callable */ - private function createDoctypeHelperFactory(ContainerInterface $services) + private function createDoctypeHelperFactory(ContainerInterface $container) { - return function () use ($services) { - $config = $services->has('config') ? $services->get('config') : []; - $config = isset($config['view_manager']) ? $config['view_manager'] : []; + return function () use ($container) { $helper = new ViewHelper\Doctype; - if (isset($config['doctype']) && $config['doctype']) { - $helper->setDoctype($config['doctype']); + + $viewConfig = $this->getConfig($container); + if (isset($viewConfig['doctype']) && $viewConfig['doctype']) { + $helper->setDoctype($viewConfig['doctype']); } return $helper; }; diff --git a/src/Container/ViewJsonStrategyFactory.php b/src/Container/ViewJsonStrategyFactory.php index b973c36c2..ed6f1ae77 100644 --- a/src/Container/ViewJsonStrategyFactory.php +++ b/src/Container/ViewJsonStrategyFactory.php @@ -9,11 +9,11 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; +use Zend\View\Renderer\JsonRenderer; use Zend\View\Strategy\JsonStrategy; -class ViewJsonStrategyFactory implements FactoryInterface +class ViewJsonStrategyFactory { /** * Create and return the JSON view strategy @@ -24,13 +24,11 @@ class ViewJsonStrategyFactory implements FactoryInterface * It then attaches the strategy to the View service, at a priority of 100. * * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return JsonStrategy */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : JsonStrategy { - $jsonRenderer = $container->get('ViewJsonRenderer'); + $jsonRenderer = $container->get(JsonRenderer::class); $jsonStrategy = new JsonStrategy($jsonRenderer); return $jsonStrategy; } diff --git a/src/Container/ViewManagerConfigTrait.php b/src/Container/ViewManagerConfigTrait.php index a0650bae9..ace17a612 100644 --- a/src/Container/ViewManagerConfigTrait.php +++ b/src/Container/ViewManagerConfigTrait.php @@ -10,7 +10,7 @@ namespace Zend\Mvc\Container; use ArrayAccess; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; trait ViewManagerConfigTrait { diff --git a/src/Container/ViewManagerFactory.php b/src/Container/ViewManagerFactory.php deleted file mode 100644 index bbac26db2..000000000 --- a/src/Container/ViewManagerFactory.php +++ /dev/null @@ -1,30 +0,0 @@ -get('HttpViewManager'); - } -} diff --git a/src/Container/ViewPhpRendererFactory.php b/src/Container/ViewPhpRendererFactory.php index 2016b23b9..dd13b7c12 100644 --- a/src/Container/ViewPhpRendererFactory.php +++ b/src/Container/ViewPhpRendererFactory.php @@ -9,23 +9,21 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; +use Zend\View\HelperPluginManager; use Zend\View\Renderer\PhpRenderer; -class ViewPhpRendererFactory implements FactoryInterface +class ViewPhpRendererFactory { /** * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return PhpRenderer */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : PhpRenderer { $renderer = new PhpRenderer(); - $renderer->setHelperPluginManager($container->get('ViewHelperManager')); - $renderer->setResolver($container->get('ViewResolver')); + $renderer->setHelperPluginManager($container->get(HelperPluginManager::class)); + $renderer->setResolver($container->get('Zend\Mvc\View\Resolver')); return $renderer; } diff --git a/src/Container/ViewPhpRendererStrategyFactory.php b/src/Container/ViewPhpRendererStrategyFactory.php index 550c6b993..8b420f336 100644 --- a/src/Container/ViewPhpRendererStrategyFactory.php +++ b/src/Container/ViewPhpRendererStrategyFactory.php @@ -9,20 +9,17 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; use Zend\View\Renderer\PhpRenderer; use Zend\View\Strategy\PhpRendererStrategy; -class ViewPhpRendererStrategyFactory implements FactoryInterface +class ViewPhpRendererStrategyFactory { /** * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return PhpRendererStrategy */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : PhpRendererStrategy { return new PhpRendererStrategy($container->get(PhpRenderer::class)); } diff --git a/src/Container/ViewPrefixPathStackResolverFactory.php b/src/Container/ViewPrefixPathStackResolverFactory.php index 5ceb59adb..7be49ae69 100644 --- a/src/Container/ViewPrefixPathStackResolverFactory.php +++ b/src/Container/ViewPrefixPathStackResolverFactory.php @@ -9,12 +9,13 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; use Zend\View\Resolver\PrefixPathStackResolver; -class ViewPrefixPathStackResolverFactory implements FactoryInterface +class ViewPrefixPathStackResolverFactory { + use ViewManagerConfigTrait; + /** * Create the template prefix view resolver * @@ -22,18 +23,12 @@ class ViewPrefixPathStackResolverFactory implements FactoryInterface * ['view_manager']['prefix_template_path_stack'] * * @param ContainerInterface $container - * @param string $name - * @param null|array $options * @return PrefixPathStackResolver */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : PrefixPathStackResolver { - $config = $container->get('config'); - $prefixes = []; - - if (isset($config['view_manager']['prefix_template_path_stack'])) { - $prefixes = $config['view_manager']['prefix_template_path_stack']; - } + $config = $this->getConfig($container); + $prefixes = $config['prefix_template_path_stack'] ?? []; return new PrefixPathStackResolver($prefixes); } diff --git a/src/Container/ViewResolverFactory.php b/src/Container/ViewResolverFactory.php index abd326a52..8ea5679b1 100644 --- a/src/Container/ViewResolverFactory.php +++ b/src/Container/ViewResolverFactory.php @@ -9,12 +9,15 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\ServiceManager\Factory\FactoryInterface; -use Zend\View\Resolver as ViewResolver; +use Psr\Container\ContainerInterface; +use Zend\View\Resolver\AggregateResolver; +use Zend\View\Resolver\PrefixPathStackResolver; +use Zend\View\Resolver\RelativeFallbackResolver; use Zend\View\Resolver\ResolverInterface; +use Zend\View\Resolver\TemplateMapResolver; +use Zend\View\Resolver\TemplatePathStack; -class ViewResolverFactory implements FactoryInterface +class ViewResolverFactory { /** * Create the aggregate view resolver @@ -23,28 +26,26 @@ class ViewResolverFactory implements FactoryInterface * map resolver and path stack resolver * * @param ContainerInterface $container - * @param string $name - * @param null|array $options - * @return ViewResolver\AggregateResolver + * @return AggregateResolver */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : AggregateResolver { - $resolver = new ViewResolver\AggregateResolver(); + $resolver = new AggregateResolver(); /* @var $mapResolver ResolverInterface */ - $mapResolver = $container->get('ViewTemplateMapResolver'); + $mapResolver = $container->get(TemplateMapResolver::class); /* @var $pathResolver ResolverInterface */ - $pathResolver = $container->get('ViewTemplatePathStack'); + $pathResolver = $container->get(TemplatePathStack::class); /* @var $prefixPathStackResolver ResolverInterface */ - $prefixPathStackResolver = $container->get('ViewPrefixPathStackResolver'); + $prefixPathStackResolver = $container->get(PrefixPathStackResolver::class); $resolver ->attach($mapResolver) ->attach($pathResolver) ->attach($prefixPathStackResolver) - ->attach(new ViewResolver\RelativeFallbackResolver($mapResolver)) - ->attach(new ViewResolver\RelativeFallbackResolver($pathResolver)) - ->attach(new ViewResolver\RelativeFallbackResolver($prefixPathStackResolver)); + ->attach(new RelativeFallbackResolver($mapResolver)) + ->attach(new RelativeFallbackResolver($pathResolver)) + ->attach(new RelativeFallbackResolver($prefixPathStackResolver)); return $resolver; } diff --git a/src/Container/ViewTemplateMapResolverFactory.php b/src/Container/ViewTemplateMapResolverFactory.php index ea8e83eaa..578e80a9f 100644 --- a/src/Container/ViewTemplateMapResolverFactory.php +++ b/src/Container/ViewTemplateMapResolverFactory.php @@ -9,12 +9,13 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\ServiceManager\Factory\FactoryInterface; -use Zend\View\Resolver as ViewResolver; +use Psr\Container\ContainerInterface; +use Zend\View\Resolver\TemplateMapResolver; -class ViewTemplateMapResolverFactory implements FactoryInterface +class ViewTemplateMapResolverFactory { + use ViewManagerConfigTrait; + /** * Create the template map view resolver * @@ -22,20 +23,15 @@ class ViewTemplateMapResolverFactory implements FactoryInterface * ['view_manager']['template_map'] * * @param ContainerInterface $container - * @param string $name - * @param null|array $options - * @return ViewResolver\TemplateMapResolver + * @return TemplateMapResolver */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : TemplateMapResolver { - $config = $container->get('config'); + $config = $this->getConfig($container); $map = []; - if (is_array($config) && isset($config['view_manager'])) { - $config = $config['view_manager']; - if (is_array($config) && isset($config['template_map'])) { - $map = $config['template_map']; - } + if (is_array($config) && isset($config['template_map'])) { + $map = $config['template_map']; } - return new ViewResolver\TemplateMapResolver($map); + return new TemplateMapResolver($map); } } diff --git a/src/Container/ViewTemplatePathStackFactory.php b/src/Container/ViewTemplatePathStackFactory.php index 081531c57..f68c36eaf 100644 --- a/src/Container/ViewTemplatePathStackFactory.php +++ b/src/Container/ViewTemplatePathStackFactory.php @@ -9,12 +9,13 @@ namespace Zend\Mvc\Container; -use Interop\Container\ContainerInterface; -use Zend\ServiceManager\Factory\FactoryInterface; -use Zend\View\Resolver as ViewResolver; +use Psr\Container\ContainerInterface; +use Zend\View\Resolver\TemplatePathStack; -class ViewTemplatePathStackFactory implements FactoryInterface +class ViewTemplatePathStackFactory { + use ViewManagerConfigTrait; + /** * Create the template path stack view resolver * @@ -23,25 +24,20 @@ class ViewTemplatePathStackFactory implements FactoryInterface * ['view_manager']['default_template_suffix'] * * @param ContainerInterface $container - * @param string $name - * @param null|array $options - * @return ViewResolver\TemplatePathStack + * @return TemplatePathStack */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container) : TemplatePathStack { - $config = $container->get('config'); - - $templatePathStack = new ViewResolver\TemplatePathStack(); - - if (is_array($config) && isset($config['view_manager'])) { - $config = $config['view_manager']; - if (is_array($config)) { - if (isset($config['template_path_stack'])) { - $templatePathStack->addPaths($config['template_path_stack']); - } - if (isset($config['default_template_suffix'])) { - $templatePathStack->setDefaultSuffix($config['default_template_suffix']); - } + $config = $this->getConfig($container); + + $templatePathStack = new TemplatePathStack(); + + if (is_array($config)) { + if (isset($config['template_path_stack'])) { + $templatePathStack->addPaths($config['template_path_stack']); + } + if (isset($config['default_template_suffix'])) { + $templatePathStack->setDefaultSuffix($config['default_template_suffix']); } } diff --git a/test/Container/InjectTemplateListenerFactoryTest.php b/test/Container/InjectTemplateListenerFactoryTest.php index ddc6004d9..aa6e5a73f 100644 --- a/test/Container/InjectTemplateListenerFactoryTest.php +++ b/test/Container/InjectTemplateListenerFactoryTest.php @@ -10,19 +10,21 @@ namespace ZendTest\Mvc\Container; use ArrayObject; -use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; use Zend\Mvc\Container\InjectTemplateListenerFactory; use Zend\Mvc\View\Http\InjectTemplateListener; -use Zend\ServiceManager\ServiceLocatorInterface; +use ZendTest\Mvc\ContainerTrait; /** * Tests for {@see \Zend\Mvc\Container\InjectTemplateListenerFactory} * * @covers \Zend\Mvc\Container\InjectTemplateListenerFactory + * @covers \Zend\Mvc\Container\ViewManagerConfigTrait */ class InjectTemplateListenerFactoryTest extends TestCase { + use ContainerTrait; + public function testFactoryCanCreateInjectTemplateListener() { $this->buildInjectTemplateListenerWithConfig([]); @@ -62,13 +64,11 @@ public function testFactoryCanSetControllerMapViaArrayAccessVM() */ private function buildInjectTemplateListenerWithConfig($config) { - $serviceLocator = $this->prophesize(ServiceLocatorInterface::class); - $serviceLocator->willImplement(ContainerInterface::class); - - $serviceLocator->get('config')->willReturn($config); + $container = $this->mockContainerInterface(); + $this->injectServiceInContainer($container, 'config', $config); $factory = new InjectTemplateListenerFactory(); - $listener = $factory($serviceLocator->reveal(), 'InjectTemplateListener'); + $listener = $factory($container->reveal(), 'InjectTemplateListener'); $this->assertInstanceOf(InjectTemplateListener::class, $listener); diff --git a/test/Container/ViewFeedStrategyFactoryTest.php b/test/Container/ViewFeedStrategyFactoryTest.php index e65b351b4..223313df6 100644 --- a/test/Container/ViewFeedStrategyFactoryTest.php +++ b/test/Container/ViewFeedStrategyFactoryTest.php @@ -9,28 +9,28 @@ namespace ZendTest\Mvc\Container; -use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; use Zend\Mvc\Container\ViewFeedStrategyFactory; use Zend\View\Renderer\FeedRenderer; use Zend\View\Strategy\FeedStrategy; +use ZendTest\Mvc\ContainerTrait; +/** + * @covers \Zend\Mvc\Container\ViewFeedStrategyFactory + */ class ViewFeedStrategyFactoryTest extends TestCase { - private function createContainer() - { - $renderer = $this->prophesize(FeedRenderer::class); - $container = $this->prophesize(ContainerInterface::class); - $container->get('ViewFeedRenderer')->will(function () use ($renderer) { - return $renderer->reveal(); - }); - return $container->reveal(); - } + use ContainerTrait; public function testReturnsFeedStrategy() { + $container = $this->mockContainerInterface(); + $renderer = $this->prophesize(FeedRenderer::class); + $this->injectServiceInContainer($container, FeedRenderer::class, $renderer->reveal()); + $factory = new ViewFeedStrategyFactory(); - $result = $factory($this->createContainer(), 'ViewFeedStrategy'); + + $result = $factory($container->reveal(), 'ViewFeedStrategy'); $this->assertInstanceOf(FeedStrategy::class, $result); } } diff --git a/test/Container/ViewHelperManagerFactoryTest.php b/test/Container/ViewHelperManagerFactoryTest.php index e3df046c2..68e854fec 100644 --- a/test/Container/ViewHelperManagerFactoryTest.php +++ b/test/Container/ViewHelperManagerFactoryTest.php @@ -18,6 +18,10 @@ use Zend\View\Helper; use Zend\View\HelperPluginManager; +/** + * @covers \Zend\Mvc\Container\ViewHelperManagerFactory + * @covers \Zend\Mvc\Container\ViewManagerConfigTrait + */ class ViewHelperManagerFactoryTest extends TestCase { public function setUp() diff --git a/test/Container/ViewJsonStrategyFactoryTest.php b/test/Container/ViewJsonStrategyFactoryTest.php index 2781059c1..9d5b88160 100644 --- a/test/Container/ViewJsonStrategyFactoryTest.php +++ b/test/Container/ViewJsonStrategyFactoryTest.php @@ -9,28 +9,27 @@ namespace ZendTest\Mvc\Container; -use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; use Zend\Mvc\Container\ViewJsonStrategyFactory; use Zend\View\Renderer\JsonRenderer; use Zend\View\Strategy\JsonStrategy; +use ZendTest\Mvc\ContainerTrait; +/** + * @covers \Zend\Mvc\Container\ViewJsonStrategyFactory + */ class ViewJsonStrategyFactoryTest extends TestCase { - private function createContainer() - { - $renderer = $this->prophesize(JsonRenderer::class); - $container = $this->prophesize(ContainerInterface::class); - $container->get('ViewJsonRenderer')->will(function () use ($renderer) { - return $renderer->reveal(); - }); - return $container->reveal(); - } + use ContainerTrait; public function testReturnsJsonStrategy() { + $container = $this->mockContainerInterface(); + $renderer = $this->prophesize(JsonRenderer::class); + $this->injectServiceInContainer($container, JsonRenderer::class, $renderer->reveal()); + $factory = new ViewJsonStrategyFactory(); - $result = $factory($this->createContainer(), 'ViewJsonStrategy'); + $result = $factory($container->reveal()); $this->assertInstanceOf(JsonStrategy::class, $result); } } diff --git a/test/Container/ViewPrefixPathStackResolverFactoryTest.php b/test/Container/ViewPrefixPathStackResolverFactoryTest.php index f041879fb..19d6f0341 100644 --- a/test/Container/ViewPrefixPathStackResolverFactoryTest.php +++ b/test/Container/ViewPrefixPathStackResolverFactoryTest.php @@ -9,20 +9,25 @@ namespace ZendTest\Mvc\Container; -use Interop\Container\ContainerInterface; use PHPUnit\Framework\TestCase; use Zend\Mvc\Container\ViewPrefixPathStackResolverFactory; -use Zend\ServiceManager\ServiceLocatorInterface; use Zend\View\Resolver\PrefixPathStackResolver; +use ZendTest\Mvc\ContainerTrait; +/** + * + * @covers \Zend\Mvc\Container\ViewPrefixPathStackResolverFactory + * @covers \Zend\Mvc\Container\ViewManagerConfigTrait + */ class ViewPrefixPathStackResolverFactoryTest extends TestCase { + use ContainerTrait; + public function testCreateService() { - $serviceLocator = $this->prophesize(ServiceLocatorInterface::class); - $serviceLocator->willImplement(ContainerInterface::class); + $container = $this->mockContainerInterface(); - $serviceLocator->get('config')->willReturn([ + $this->injectServiceInContainer($container, 'config', [ 'view_manager' => [ 'prefix_template_path_stack' => [ 'album/' => [], @@ -31,7 +36,7 @@ public function testCreateService() ]); $factory = new ViewPrefixPathStackResolverFactory(); - $resolver = $factory($serviceLocator->reveal(), 'ViewPrefixPathStackResolver'); + $resolver = $factory($container->reveal(), 'ViewPrefixPathStackResolver'); $this->assertInstanceOf(PrefixPathStackResolver::class, $resolver); } From c4bfacf6714485198d9c8f79144de3d87bfb8a89 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 31 Dec 2017 13:15:55 +1000 Subject: [PATCH 41/51] Fix no response handling in RouteNotFoundStrategy --- src/View/Http/RouteNotFoundStrategy.php | 2 +- test/View/RouteNotFoundStrategyTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/View/Http/RouteNotFoundStrategy.php b/src/View/Http/RouteNotFoundStrategy.php index 187dfb23b..ac8df8fa5 100644 --- a/src/View/Http/RouteNotFoundStrategy.php +++ b/src/View/Http/RouteNotFoundStrategy.php @@ -170,7 +170,7 @@ public function prepareNotFoundViewModel(MvcEvent $e) : void } $response = $e->getResponse(); - if ($response->getStatusCode() != 404) { + if (! $response || $response->getStatusCode() != 404) { // Only handle 404 responses return; } diff --git a/test/View/RouteNotFoundStrategyTest.php b/test/View/RouteNotFoundStrategyTest.php index 9e4cc03b4..6a593070b 100644 --- a/test/View/RouteNotFoundStrategyTest.php +++ b/test/View/RouteNotFoundStrategyTest.php @@ -173,6 +173,21 @@ public function testNon404ResponseDoesNotPrepare404ViewModel() $this->addToAssertionCount(1); } + public function testOnNoResponseDoesNotPrepare404ViewModel() + { + $event = new MvcEvent(); + + $this->strategy->prepareNotFoundViewModel($event); + $model = $event->getResult(); + if ($model instanceof ViewModel) { + $this->assertNotEquals($this->strategy->getNotFoundTemplate(), $model->getTemplate()); + $variables = $model->getVariables(); + $this->assertArrayNotHasKey('message', $variables); + } + + $this->addToAssertionCount(1); + } + public function test404ResponsePrepares404ViewModelWithTemplateFromStrategy() { $response = new Response(); From 15f6270e40b2e494b33393df4fc5c5ed104ffe40 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 13 Jan 2018 13:40:04 +1000 Subject: [PATCH 42/51] Restore previously dropped container factories bits --- src/Container/ApplicationFactory.php | 4 +++- src/Container/ControllerManagerFactory.php | 7 ++++++- src/Container/ControllerPluginManagerFactory.php | 15 ++++++++++++--- src/Container/DefaultRenderingStrategyFactory.php | 11 +++++++++-- src/Container/DispatchListenerFactory.php | 6 +++++- src/Container/EventManagerFactory.php | 6 +++++- src/Container/ExceptionStrategyFactory.php | 4 +++- src/Container/HttpMethodListenerFactory.php | 10 +++++++++- src/Container/InjectTemplateListenerFactory.php | 9 +++++++-- src/Container/RouteNotFoundStrategyFactory.php | 2 +- src/Container/ViewFactory.php | 6 +++++- src/Container/ViewFeedStrategyFactory.php | 6 +++++- src/Container/ViewHelperManagerFactory.php | 14 ++++++++++---- src/Container/ViewJsonStrategyFactory.php | 6 +++++- src/Container/ViewPhpRendererFactory.php | 6 +++++- src/Container/ViewPhpRendererStrategyFactory.php | 6 +++++- .../ViewPrefixPathStackResolverFactory.php | 9 +++++++-- src/Container/ViewResolverFactory.php | 6 +++++- src/Container/ViewTemplateMapResolverFactory.php | 4 +++- src/Container/ViewTemplatePathStackFactory.php | 4 +++- test/Container/ApplicationFactoryTest.php | 3 ++- test/Container/ControllerManagerFactoryTest.php | 5 +++-- .../ControllerPluginManagerFactoryTest.php | 5 +++-- test/Container/DispatchListenerFactoryTest.php | 2 +- test/Container/EventManagerFactoryTest.php | 4 ++-- test/Container/HttpMethodListenerFactoryTest.php | 5 +++-- test/Container/ViewJsonStrategyFactoryTest.php | 2 +- 27 files changed, 128 insertions(+), 39 deletions(-) diff --git a/src/Container/ApplicationFactory.php b/src/Container/ApplicationFactory.php index 40afa45e5..fcd5519bc 100644 --- a/src/Container/ApplicationFactory.php +++ b/src/Container/ApplicationFactory.php @@ -19,11 +19,13 @@ class ApplicationFactory * Create the Mvc Application * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return Application * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : Application + public function __invoke(ContainerInterface $container, string $name, array $options = null) : Application { $emitter = $container->has(EmitterInterface::class) ? $container->get(EmitterInterface::class) diff --git a/src/Container/ControllerManagerFactory.php b/src/Container/ControllerManagerFactory.php index aedc5ec75..24558f4a8 100644 --- a/src/Container/ControllerManagerFactory.php +++ b/src/Container/ControllerManagerFactory.php @@ -25,10 +25,15 @@ class ControllerManagerFactory * if the controller implements a setPluginManager() method. * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return ControllerManager */ - public function __invoke(ContainerInterface $container) : ControllerManager + public function __invoke(ContainerInterface $container, string $name, array $options = null) : ControllerManager { + if (null !== $options) { + return new ControllerManager($container, $options); + } return new ControllerManager($container, $this->getControllersConfig($container)); } diff --git a/src/Container/ControllerPluginManagerFactory.php b/src/Container/ControllerPluginManagerFactory.php index 1ea5bdbf1..42e54b8db 100644 --- a/src/Container/ControllerPluginManagerFactory.php +++ b/src/Container/ControllerPluginManagerFactory.php @@ -10,13 +10,22 @@ namespace Zend\Mvc\Container; use Psr\Container\ContainerInterface; -use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; +use Zend\Mvc\Controller\PluginManager; class ControllerPluginManagerFactory { - public function __invoke(ContainerInterface $container) : ControllerPluginManager + /** + * @param ContainerInterface $container + * @param string $name + * @param array|null $options + * @return PluginManager + */ + public function __invoke(ContainerInterface $container, string $name, array $options = null) : PluginManager { - return new ControllerPluginManager($container, $this->getPluginsConfig($container)); + if (null !== $options) { + return new PluginManager($container, $options); + } + return new PluginManager($container, $this->getPluginsConfig($container)); } public function getPluginsConfig(ContainerInterface $container) : array diff --git a/src/Container/DefaultRenderingStrategyFactory.php b/src/Container/DefaultRenderingStrategyFactory.php index c4914405a..450eb1ff7 100644 --- a/src/Container/DefaultRenderingStrategyFactory.php +++ b/src/Container/DefaultRenderingStrategyFactory.php @@ -19,10 +19,17 @@ class DefaultRenderingStrategyFactory /** * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return DefaultRenderingStrategy + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : DefaultRenderingStrategy - { + public function __invoke( + ContainerInterface $container, + string $name, + array $options = null + ) : DefaultRenderingStrategy { $strategy = new DefaultRenderingStrategy($container->get(View::class)); $config = $this->getConfig($container); diff --git a/src/Container/DispatchListenerFactory.php b/src/Container/DispatchListenerFactory.php index 3986b4026..c0121fd5c 100644 --- a/src/Container/DispatchListenerFactory.php +++ b/src/Container/DispatchListenerFactory.php @@ -19,9 +19,13 @@ class DispatchListenerFactory * Create the default dispatch listener. * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return DispatchListener + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : DispatchListener + public function __invoke(ContainerInterface $container, string $name, array $options = null) : DispatchListener { return new DispatchListener($container->get(ControllerManager::class)); } diff --git a/src/Container/EventManagerFactory.php b/src/Container/EventManagerFactory.php index a89f7c597..ba6a36dbe 100644 --- a/src/Container/EventManagerFactory.php +++ b/src/Container/EventManagerFactory.php @@ -21,9 +21,13 @@ class EventManagerFactory * of SharedEventManager. * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return EventManager + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : EventManager + public function __invoke(ContainerInterface $container, string $name, array $options = null) : EventManager { $shared = $container->has('SharedEventManager') ? $container->get('SharedEventManager') : null; diff --git a/src/Container/ExceptionStrategyFactory.php b/src/Container/ExceptionStrategyFactory.php index 826032e57..b57883142 100644 --- a/src/Container/ExceptionStrategyFactory.php +++ b/src/Container/ExceptionStrategyFactory.php @@ -18,9 +18,11 @@ class ExceptionStrategyFactory /** * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return ExceptionStrategy */ - public function __invoke(ContainerInterface $container) : ExceptionStrategy + public function __invoke(ContainerInterface $container, string $name, array $options = null) : ExceptionStrategy { $strategy = new ExceptionStrategy(); $config = $this->getConfig($container); diff --git a/src/Container/HttpMethodListenerFactory.php b/src/Container/HttpMethodListenerFactory.php index 85f3c7cf0..52186c70b 100644 --- a/src/Container/HttpMethodListenerFactory.php +++ b/src/Container/HttpMethodListenerFactory.php @@ -14,7 +14,15 @@ class HttpMethodListenerFactory { - public function __invoke(ContainerInterface $container) : HttpMethodListener + /** + * @param ContainerInterface $container + * @param string $name + * @param array|null $options + * @return HttpMethodListener + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function __invoke(ContainerInterface $container, string $name, array $options = null) : HttpMethodListener { $config = $container->has('config') ? $container->get('config') : []; $enabled = $config['http_methods_listener']['enabled'] ?? true; diff --git a/src/Container/InjectTemplateListenerFactory.php b/src/Container/InjectTemplateListenerFactory.php index 5e0a3c5e6..e066a703c 100644 --- a/src/Container/InjectTemplateListenerFactory.php +++ b/src/Container/InjectTemplateListenerFactory.php @@ -20,10 +20,15 @@ class InjectTemplateListenerFactory * Create and return an InjectTemplateListener instance. * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return InjectTemplateListener */ - public function __invoke(ContainerInterface $container) : InjectTemplateListener - { + public function __invoke( + ContainerInterface $container, + string $name, + array $options = null + ) : InjectTemplateListener { $listener = new InjectTemplateListener(); $config = $this->getConfig($container); diff --git a/src/Container/RouteNotFoundStrategyFactory.php b/src/Container/RouteNotFoundStrategyFactory.php index 56698a872..60bef95c3 100644 --- a/src/Container/RouteNotFoundStrategyFactory.php +++ b/src/Container/RouteNotFoundStrategyFactory.php @@ -22,7 +22,7 @@ class RouteNotFoundStrategyFactory * @param null|array $options * @return RouteNotFoundStrategy */ - public function __invoke(ContainerInterface $container) : RouteNotFoundStrategy + public function __invoke(ContainerInterface $container, string $name, array $options = null) : RouteNotFoundStrategy { $strategy = new RouteNotFoundStrategy(); $config = $this->getConfig($container); diff --git a/src/Container/ViewFactory.php b/src/Container/ViewFactory.php index 6552a4084..f64473e4f 100644 --- a/src/Container/ViewFactory.php +++ b/src/Container/ViewFactory.php @@ -17,9 +17,13 @@ class ViewFactory { /** * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return View + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : View + public function __invoke(ContainerInterface $container, string $name, array $options = null) : View { $view = new View(); $events = $container->get('EventManager'); diff --git a/src/Container/ViewFeedStrategyFactory.php b/src/Container/ViewFeedStrategyFactory.php index 24595adcf..085dc3aa0 100644 --- a/src/Container/ViewFeedStrategyFactory.php +++ b/src/Container/ViewFeedStrategyFactory.php @@ -24,9 +24,13 @@ class ViewFeedStrategyFactory * It then attaches the strategy to the View service, at a priority of 100. * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return FeedStrategy + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : FeedStrategy + public function __invoke(ContainerInterface $container, string $name, array $options = null) : FeedStrategy { return new FeedStrategy($container->get(FeedRenderer::class)); } diff --git a/src/Container/ViewHelperManagerFactory.php b/src/Container/ViewHelperManagerFactory.php index 86c369eed..2899b0b06 100644 --- a/src/Container/ViewHelperManagerFactory.php +++ b/src/Container/ViewHelperManagerFactory.php @@ -21,13 +21,19 @@ class ViewHelperManagerFactory * Create and return the view helper manager * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return HelperPluginManager + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : HelperPluginManager + public function __invoke(ContainerInterface $container, string $name, array $options = null) : HelperPluginManager { - $config = $container->has('config') ? $container->get('config') : []; - $helpers = $config['view_helpers'] ?? []; - $plugins = new HelperPluginManager($container, $helpers); + if (null === $options) { + $config = $container->has('config') ? $container->get('config') : []; + $options = $config['view_helpers'] ?? []; + } + $plugins = new HelperPluginManager($container, $options); // Override plugin factories $this->injectOverrideFactories($plugins, $container); diff --git a/src/Container/ViewJsonStrategyFactory.php b/src/Container/ViewJsonStrategyFactory.php index ed6f1ae77..5cb93b6be 100644 --- a/src/Container/ViewJsonStrategyFactory.php +++ b/src/Container/ViewJsonStrategyFactory.php @@ -24,9 +24,13 @@ class ViewJsonStrategyFactory * It then attaches the strategy to the View service, at a priority of 100. * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return JsonStrategy + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : JsonStrategy + public function __invoke(ContainerInterface $container, string $name, array $options = null) : JsonStrategy { $jsonRenderer = $container->get(JsonRenderer::class); $jsonStrategy = new JsonStrategy($jsonRenderer); diff --git a/src/Container/ViewPhpRendererFactory.php b/src/Container/ViewPhpRendererFactory.php index dd13b7c12..a20c19a92 100644 --- a/src/Container/ViewPhpRendererFactory.php +++ b/src/Container/ViewPhpRendererFactory.php @@ -17,9 +17,13 @@ class ViewPhpRendererFactory { /** * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return PhpRenderer + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : PhpRenderer + public function __invoke(ContainerInterface $container, string $name, array $options = null) : PhpRenderer { $renderer = new PhpRenderer(); $renderer->setHelperPluginManager($container->get(HelperPluginManager::class)); diff --git a/src/Container/ViewPhpRendererStrategyFactory.php b/src/Container/ViewPhpRendererStrategyFactory.php index 8b420f336..dbf9692a9 100644 --- a/src/Container/ViewPhpRendererStrategyFactory.php +++ b/src/Container/ViewPhpRendererStrategyFactory.php @@ -17,9 +17,13 @@ class ViewPhpRendererStrategyFactory { /** * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return PhpRendererStrategy + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : PhpRendererStrategy + public function __invoke(ContainerInterface $container, string $name, array $options = null) : PhpRendererStrategy { return new PhpRendererStrategy($container->get(PhpRenderer::class)); } diff --git a/src/Container/ViewPrefixPathStackResolverFactory.php b/src/Container/ViewPrefixPathStackResolverFactory.php index 7be49ae69..0ccb78a9e 100644 --- a/src/Container/ViewPrefixPathStackResolverFactory.php +++ b/src/Container/ViewPrefixPathStackResolverFactory.php @@ -23,10 +23,15 @@ class ViewPrefixPathStackResolverFactory * ['view_manager']['prefix_template_path_stack'] * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return PrefixPathStackResolver */ - public function __invoke(ContainerInterface $container) : PrefixPathStackResolver - { + public function __invoke( + ContainerInterface $container, + string $name, + array $options = null + ) : PrefixPathStackResolver { $config = $this->getConfig($container); $prefixes = $config['prefix_template_path_stack'] ?? []; diff --git a/src/Container/ViewResolverFactory.php b/src/Container/ViewResolverFactory.php index 8ea5679b1..cd7c9c05f 100644 --- a/src/Container/ViewResolverFactory.php +++ b/src/Container/ViewResolverFactory.php @@ -26,9 +26,13 @@ class ViewResolverFactory * map resolver and path stack resolver * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return AggregateResolver + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) : AggregateResolver + public function __invoke(ContainerInterface $container, string $name, array $options = null) : AggregateResolver { $resolver = new AggregateResolver(); diff --git a/src/Container/ViewTemplateMapResolverFactory.php b/src/Container/ViewTemplateMapResolverFactory.php index 578e80a9f..7c40c3b39 100644 --- a/src/Container/ViewTemplateMapResolverFactory.php +++ b/src/Container/ViewTemplateMapResolverFactory.php @@ -23,9 +23,11 @@ class ViewTemplateMapResolverFactory * ['view_manager']['template_map'] * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return TemplateMapResolver */ - public function __invoke(ContainerInterface $container) : TemplateMapResolver + public function __invoke(ContainerInterface $container, string $name, array $options = null) : TemplateMapResolver { $config = $this->getConfig($container); $map = []; diff --git a/src/Container/ViewTemplatePathStackFactory.php b/src/Container/ViewTemplatePathStackFactory.php index f68c36eaf..672ec58e3 100644 --- a/src/Container/ViewTemplatePathStackFactory.php +++ b/src/Container/ViewTemplatePathStackFactory.php @@ -24,9 +24,11 @@ class ViewTemplatePathStackFactory * ['view_manager']['default_template_suffix'] * * @param ContainerInterface $container + * @param string $name + * @param array|null $options * @return TemplatePathStack */ - public function __invoke(ContainerInterface $container) : TemplatePathStack + public function __invoke(ContainerInterface $container, string $name, array $options = null) : TemplatePathStack { $config = $this->getConfig($container); diff --git a/test/Container/ApplicationFactoryTest.php b/test/Container/ApplicationFactoryTest.php index bd98c3e2a..e5c9efcc3 100644 --- a/test/Container/ApplicationFactoryTest.php +++ b/test/Container/ApplicationFactoryTest.php @@ -12,6 +12,7 @@ use Psr\Container\ContainerInterface; use Zend\Diactoros\Response\EmitterInterface; use Zend\EventManager\EventManager; +use Zend\Mvc\Application; use Zend\Mvc\Container\ApplicationFactory; use PHPUnit\Framework\TestCase; use Zend\Router\RouteStackInterface; @@ -70,7 +71,7 @@ public function testInjectsEmitterWhenAvailable() EmitterInterface::class, $this->emitter->reveal() ); - $app = $this->factory->__invoke($this->container->reveal()); + $app = $this->factory->__invoke($this->container->reveal(), Application::class); $this->assertSame($this->emitter->reveal(), $app->getEmitter()); } } diff --git a/test/Container/ControllerManagerFactoryTest.php b/test/Container/ControllerManagerFactoryTest.php index 5680fb475..db867796b 100644 --- a/test/Container/ControllerManagerFactoryTest.php +++ b/test/Container/ControllerManagerFactoryTest.php @@ -11,6 +11,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Zend\Mvc\Container\ControllerManagerFactory; +use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\Controller\Dispatchable; use ZendTest\Mvc\ContainerTrait; @@ -40,7 +41,7 @@ public function setUp() public function testInjectsContainerIntoControllerManager() { $container = $this->container->reveal(); - $controllerManager = $this->factory->__invoke($container); + $controllerManager = $this->factory->__invoke($container, ControllerManager::class); $controllerManager->setFactory('Foo', function ($injectedContainer) use ($container) { $this->assertSame($container, $injectedContainer); return $this->prophesize(Dispatchable::class)->reveal(); @@ -58,7 +59,7 @@ public function testPullsControllersConfigFromConfigService() ] ] ]); - $controllerManager = $this->factory->__invoke($this->container->reveal()); + $controllerManager = $this->factory->__invoke($this->container->reveal(), ControllerManager::class); $this->assertTrue($controllerManager->has('Foo')); } } diff --git a/test/Container/ControllerPluginManagerFactoryTest.php b/test/Container/ControllerPluginManagerFactoryTest.php index 4d83d505e..f2a85f10f 100644 --- a/test/Container/ControllerPluginManagerFactoryTest.php +++ b/test/Container/ControllerPluginManagerFactoryTest.php @@ -12,6 +12,7 @@ use Prophecy\Prophecy\ObjectProphecy; use Zend\Mvc\Container\ControllerPluginManagerFactory; use Zend\Mvc\Controller\Plugin\PluginInterface; +use Zend\Mvc\Controller\PluginManager; use ZendTest\Mvc\ContainerTrait; /** @@ -40,7 +41,7 @@ public function setUp() public function testInjectsContainerIntoPluginManager() { $container = $this->container->reveal(); - $pluginManager = $this->factory->__invoke($container); + $pluginManager = $this->factory->__invoke($container, PluginManager::class); $pluginManager->setFactory('Foo', function ($injectedContainer) use ($container) { $this->assertSame($container, $injectedContainer); return $this->prophesize(PluginInterface::class)->reveal(); @@ -58,7 +59,7 @@ public function testPullsPluginsConfigFromConfigService() ] ] ]); - $pluginManager = $this->factory->__invoke($this->container->reveal()); + $pluginManager = $this->factory->__invoke($this->container->reveal(), PluginManager::class); $this->assertTrue($pluginManager->has('Foo')); } } diff --git a/test/Container/DispatchListenerFactoryTest.php b/test/Container/DispatchListenerFactoryTest.php index 688e5f341..c9a2cb030 100644 --- a/test/Container/DispatchListenerFactoryTest.php +++ b/test/Container/DispatchListenerFactoryTest.php @@ -31,7 +31,7 @@ public function testCreateListener() ); $factory = new DispatchListenerFactory(); - $listener = $factory->__invoke($container->reveal()); + $listener = $factory->__invoke($container->reveal(), DispatchListener::class); $this->assertInstanceOf(DispatchListener::class, $listener); } } diff --git a/test/Container/EventManagerFactoryTest.php b/test/Container/EventManagerFactoryTest.php index 2423e0de3..2e14d1bcb 100644 --- a/test/Container/EventManagerFactoryTest.php +++ b/test/Container/EventManagerFactoryTest.php @@ -27,7 +27,7 @@ public function testCreateListener() $container = $this->mockContainerInterface(); $factory = new EventManagerFactory(); - $events = $factory->__invoke($container->reveal()); + $events = $factory->__invoke($container->reveal(), 'EventManager'); $this->assertInstanceOf(EventManager::class, $events); } @@ -38,7 +38,7 @@ public function testInjectsSharedEventManagerIfAvailable() $shared = new SharedEventManager(); $this->injectServiceInContainer($container, 'SharedEventManager', $shared); - $events = $factory->__invoke($container->reveal()); + $events = $factory->__invoke($container->reveal(), 'EventManager'); $this->assertSame($shared, $events->getSharedManager()); } } diff --git a/test/Container/HttpMethodListenerFactoryTest.php b/test/Container/HttpMethodListenerFactoryTest.php index b825b3d0d..441c22eb2 100644 --- a/test/Container/HttpMethodListenerFactoryTest.php +++ b/test/Container/HttpMethodListenerFactoryTest.php @@ -12,6 +12,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Zend\Mvc\Container\HttpMethodListenerFactory; +use Zend\Mvc\HttpMethodListener; use ZendTest\Mvc\ContainerTrait; /** @@ -39,7 +40,7 @@ public function setUp() public function testCreateWithDefaults() { - $listener = $this->factory->__invoke($this->container->reveal()); + $listener = $this->factory->__invoke($this->container->reveal(), HttpMethodListener::class); $this->assertTrue($listener->isEnabled()); $this->assertNotEmpty($listener->getAllowedMethods()); } @@ -53,7 +54,7 @@ public function testCreateWithConfig() $this->injectServiceInContainer($this->container, 'config', $config); - $listener = $this->factory->__invoke($this->container->reveal()); + $listener = $this->factory->__invoke($this->container->reveal(), HttpMethodListener::class); $listenerConfig = $config['http_methods_listener']; diff --git a/test/Container/ViewJsonStrategyFactoryTest.php b/test/Container/ViewJsonStrategyFactoryTest.php index 9d5b88160..b67a43e63 100644 --- a/test/Container/ViewJsonStrategyFactoryTest.php +++ b/test/Container/ViewJsonStrategyFactoryTest.php @@ -29,7 +29,7 @@ public function testReturnsJsonStrategy() $this->injectServiceInContainer($container, JsonRenderer::class, $renderer->reveal()); $factory = new ViewJsonStrategyFactory(); - $result = $factory($container->reveal()); + $result = $factory($container->reveal(), JsonStrategy::class); $this->assertInstanceOf(JsonStrategy::class, $result); } } From 573964f81bda985d8802df007fd71dce8978f0d0 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 26 Jan 2018 06:32:38 +1000 Subject: [PATCH 43/51] Use template for ConfigProviderTest --- src/ConfigProvider.php | 4 ++-- test/ConfigProviderTest.php | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 8ed421c6d..4d34363b0 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -57,14 +57,14 @@ class ConfigProvider { - public function __invoke() + public function __invoke() : array { return [ 'dependencies' => $this->getDependencyConfig(), ]; } - public function getDependencyConfig() + public function getDependencyConfig() : array { return [ 'aliases' => [ diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 023640a48..feb3ff4b4 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -16,12 +16,26 @@ */ class ConfigProviderTest extends TestCase { + private $provider; + + public function setUp() + { + $this->provider = new ConfigProvider(); + } + + public function testInvocationReturnsArray() + { + $config = ($this->provider)(); + $this->assertInternalType('array', $config); + return $config; + } + /** - * @doesNotPerformAssertions + * @depends testInvocationReturnsArray */ - public function testConfigIsSerializable() + public function testReturnedArrayContainsDependencies(array $config) { - $config = new ConfigProvider(); - \serialize($config()); + $this->assertArrayHasKey('dependencies', $config); + $this->assertInternalType('array', $config['dependencies']); } } From 127b73e5f44fb86fb9fa1b30cd75385973078083 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 26 Jan 2018 16:22:51 +1000 Subject: [PATCH 44/51] Update interop server handler to psr --- composer.json | 1 + composer.lock | 55 +++++++++++++++++++++++++++++++++++- src/ApplicationInterface.php | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cd5a412c7..8f7f0cb99 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "fig/http-message-util": "^1.1", "psr/container": "^1.0", "psr/http-message": "^1.0", + "psr/http-server-handler": "^1.0", "zendframework/zend-diactoros": "^1.7", "zendframework/zend-eventmanager": "^3.2", "zendframework/zend-router": "dev-make-mvc-great-again", diff --git a/composer.lock b/composer.lock index c9ec41160..65d30ab99 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "8b5201bd45f72189384f07eecc76ff68", + "content-hash": "83a4acc6c65baffb00e63c8256c2145e", "packages": [ { "name": "container-interop/container-interop", @@ -186,6 +186,59 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "psr/http-server-handler", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-server-handler.git", + "reference": "439d92054dc06097f2406ec074a2627839955a02" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-server-handler/zipball/439d92054dc06097f2406ec074a2627839955a02", + "reference": "439d92054dc06097f2406ec074a2627839955a02", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP server-side request handler", + "keywords": [ + "handler", + "http", + "http-interop", + "psr", + "psr-15", + "psr-7", + "request", + "response", + "server" + ], + "time": "2018-01-22T17:04:15+00:00" + }, { "name": "zendframework/zend-diactoros", "version": "1.7.0", diff --git a/src/ApplicationInterface.php b/src/ApplicationInterface.php index 8cf1b4a31..f159fa964 100644 --- a/src/ApplicationInterface.php +++ b/src/ApplicationInterface.php @@ -9,9 +9,9 @@ namespace Zend\Mvc; -use Interop\Http\Server\RequestHandlerInterface; use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\RequestHandlerInterface; use Zend\EventManager\EventsCapableInterface; interface ApplicationInterface extends EventsCapableInterface, RequestHandlerInterface From ece0378d5b1278c03789b89c0187ead98ff34155 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 26 Jan 2018 16:51:25 +1000 Subject: [PATCH 45/51] Require events and response emitter to be constructor injected --- src/Application.php | 17 +++----- src/Container/ApplicationFactory.php | 13 ++++-- test/ApplicationTest.php | 24 +++-------- test/Container/ApplicationFactoryTest.php | 52 ++++++++++++++++++++++- 4 files changed, 71 insertions(+), 35 deletions(-) diff --git a/src/Application.php b/src/Application.php index 0ee62d135..7a48562ab 100644 --- a/src/Application.php +++ b/src/Application.php @@ -16,13 +16,10 @@ use UnexpectedValueException; use Zend\Diactoros\Response; use Zend\Diactoros\Response\EmitterInterface; -use Zend\Diactoros\Response\SapiEmitter; use Zend\Diactoros\ServerRequestFactory; -use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\ListenerAggregateInterface; -use Zend\Mvc\Emitter\EmitterStack; use Zend\Mvc\View\Http\ViewManager; use Zend\Router\RouteStackInterface; @@ -123,8 +120,8 @@ class Application implements * * @param ContainerInterface $container IoC container from which to pull services * @param RouteStackInterface $router Configured router for RouteListener - * @param EventManagerInterface|null $events - * @param EmitterInterface|null $emitter Response emitter to use when `run()` + * @param EventManagerInterface $events + * @param EmitterInterface $emitter Response emitter to use when `run()` * is invoked * @param array $listeners Extra listeners to attach on bootstrap * Can be container keys or instances of ListenerAggregateInterface @@ -132,13 +129,13 @@ class Application implements public function __construct( ContainerInterface $container, RouteStackInterface $router, - EventManagerInterface $events = null, - EmitterInterface $emitter = null, + EventManagerInterface $events, + EmitterInterface $emitter, array $listeners = [] ) { $this->container = $container; $this->router = $router; - $this->setEventManager($events ?? new EventManager()); + $this->setEventManager($events); $this->emitter = $emitter; $this->listeners = $listeners; @@ -333,10 +330,6 @@ public function handle(Request $request) : ResponseInterface public function getEmitter() : EmitterInterface { - if (! $this->emitter) { - $this->emitter = new EmitterStack(); - $this->emitter->push(new SapiEmitter()); - } return $this->emitter; } diff --git a/src/Container/ApplicationFactory.php b/src/Container/ApplicationFactory.php index fcd5519bc..0c3134739 100644 --- a/src/Container/ApplicationFactory.php +++ b/src/Container/ApplicationFactory.php @@ -11,7 +11,9 @@ use Psr\Container\ContainerInterface; use Zend\Diactoros\Response\EmitterInterface; +use Zend\Diactoros\Response\SapiEmitter; use Zend\Mvc\Application; +use Zend\Mvc\Emitter\EmitterStack; class ApplicationFactory { @@ -27,11 +29,14 @@ class ApplicationFactory */ public function __invoke(ContainerInterface $container, string $name, array $options = null) : Application { - $emitter = $container->has(EmitterInterface::class) - ? $container->get(EmitterInterface::class) - : null; + if ($container->has(EmitterInterface::class)) { + $emitter = $container->get(EmitterInterface::class); + } else { + $emitter = new EmitterStack(); + $emitter->push(new SapiEmitter()); + } - $config = $container->get('config'); + $config = $container->get('config') ?? []; $listeners = $config[Application::class]['listeners'] ?? []; $application = new Application( diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index 79b89acfa..f1c51d1bf 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -14,7 +14,6 @@ use ReflectionProperty; use Zend\Diactoros\Response; use Zend\Diactoros\Response\EmitterInterface; -use Zend\Diactoros\Response\SapiEmitter; use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\ListenerAggregateInterface; @@ -22,13 +21,11 @@ use Zend\EventManager\Test\EventListenerIntrospectionTrait; use Zend\Mvc\Application; use Zend\Mvc\DispatchListener; -use Zend\Mvc\Emitter\EmitterStack; use Zend\Mvc\HttpMethodListener; use Zend\Mvc\MiddlewareListener; use Zend\Mvc\MvcEvent; use Zend\Mvc\RouteListener; use Zend\Mvc\View\Http\ViewManager; -use Zend\Router\RouteResult; use Zend\Router\RouteStackInterface; /** @@ -507,6 +504,12 @@ function (MvcEvent $e) use ($testResponse) { $this->assertSame($testResponse, $response); } + public function testEmitterGetterReturnsInjectedEmitter() + { + $emitter = $this->application->getEmitter(); + $this->assertSame($this->emitter->reveal(), $emitter); + } + public function testRunInvokesEmitterForResponse() { $response = new Response(); @@ -521,21 +524,6 @@ function () use ($response) { $this->application->run($request); } - public function testApplicationConfiguresDefaultEmitterIfNoneInjected() - { - $application = new Application( - $this->container->reveal(), - $this->router->reveal(), - $this->events, - null - ); - - $emitter = $application->getEmitter(); - $this->assertInstanceOf(EmitterStack::class, $emitter); - $this->assertCount(1, $emitter); - $this->assertInstanceOf(SapiEmitter::class, $emitter[0]); - } - public function eventPropagation() { return [ diff --git a/test/Container/ApplicationFactoryTest.php b/test/Container/ApplicationFactoryTest.php index e5c9efcc3..3b08b3820 100644 --- a/test/Container/ApplicationFactoryTest.php +++ b/test/Container/ApplicationFactoryTest.php @@ -11,10 +11,19 @@ use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; use Zend\Diactoros\Response\EmitterInterface; +use Zend\Diactoros\Response\SapiEmitter; use Zend\EventManager\EventManager; +use Zend\EventManager\EventManagerInterface; +use Zend\EventManager\ListenerAggregateInterface; use Zend\Mvc\Application; use Zend\Mvc\Container\ApplicationFactory; use PHPUnit\Framework\TestCase; +use Zend\Mvc\DispatchListener; +use Zend\Mvc\Emitter\EmitterStack; +use Zend\Mvc\HttpMethodListener; +use Zend\Mvc\MiddlewareListener; +use Zend\Mvc\RouteListener; +use Zend\Mvc\View\Http\ViewManager; use Zend\Router\RouteStackInterface; use ZendTest\Mvc\ContainerTrait; @@ -57,7 +66,7 @@ public function setUp() $this->router = $this->prophesize(RouteStackInterface::class); $this->emitter = $this->prophesize(EmitterInterface::class); - $this->events = new EventManager(); + $this->events = $this->prophesize(EventManagerInterface::class); $this->injectServiceInContainer($this->container, 'Zend\Mvc\Router', $this->router); $this->injectServiceInContainer($this->container, 'EventManager', $this->events); @@ -74,4 +83,45 @@ public function testInjectsEmitterWhenAvailable() $app = $this->factory->__invoke($this->container->reveal(), Application::class); $this->assertSame($this->emitter->reveal(), $app->getEmitter()); } + + public function testInjectsNewEmitterStackWhenEmitterNotInContainer() + { + $app = $this->factory->__invoke($this->container->reveal(), Application::class); + $emitter = $app->getEmitter(); + $this->assertInstanceOf(EmitterStack::class, $emitter); + $this->assertCount(1, $emitter); + $this->assertInstanceOf(SapiEmitter::class, $emitter[0]); + } + + public function testInjectsListenersFromConfig() + { + // application default listeners + $route = $this->prophesize(RouteListener::class); + $this->injectServiceInContainer($this->container, RouteListener::class, $route->reveal()); + $dispatch = $this->prophesize(DispatchListener::class); + $this->injectServiceInContainer($this->container, DispatchListener::class, $dispatch->reveal()); + $middleware = $this->prophesize(MiddlewareListener::class); + $this->injectServiceInContainer($this->container, MiddlewareListener::class, $middleware->reveal()); + $viewManager = $this->prophesize(ViewManager::class); + $this->injectServiceInContainer($this->container, ViewManager::class, $viewManager->reveal()); + $httpMethod = $this->prophesize(HttpMethodListener::class); + $this->injectServiceInContainer($this->container, HttpMethodListener::class, $httpMethod->reveal()); + + + $listener = $this->prophesize(ListenerAggregateInterface::class); + $listener->attach($this->events)->shouldBecalled(); + $this->injectServiceInContainer($this->container, 'listenerToInject', $listener->reveal()); + $this->injectServiceInContainer( + $this->container, + 'config', + [ + Application::class => [ + 'listeners' => ['listenerToInject'] + ] + ] + ); + + $app = $this->factory->__invoke($this->container->reveal(), Application::class); + $app->bootstrap(); + } } From f9bad41828714446ca370d4d9abe9e38516289cd Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 26 Jan 2018 17:37:36 +1000 Subject: [PATCH 46/51] Add mutation tester config --- .gitattributes | 1 + .gitignore | 2 ++ infection.json.dist | 11 +++++++++++ 3 files changed, 14 insertions(+) create mode 100644 infection.json.dist diff --git a/.gitattributes b/.gitattributes index 16d8d2934..6b37e6727 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,6 +4,7 @@ /.travis.yml export-ignore /composer.lock export-ignore /docs/ export-ignore +/infection.json.dist export-ignore /mkdocs.yml export-ignore /phpcs.xml export-ignore /phpunit.xml.dist export-ignore diff --git a/.gitignore b/.gitignore index 245087af8..a7677c949 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /clover.xml /coveralls-upload.json /docs/html/ +/infection-log.txt +/infection.json /phpunit.xml /vendor/ /zf-mkdoc-theme.tgz diff --git a/infection.json.dist b/infection.json.dist new file mode 100644 index 000000000..b883a216b --- /dev/null +++ b/infection.json.dist @@ -0,0 +1,11 @@ +{ + "timeout": 10, + "source": { + "directories": [ + "src" + ] + }, + "logs": { + "text": "infection-log.txt" + } +} \ No newline at end of file From 28a9eec18f8e65478ea4d5c64e08e32aff87124a Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Fri, 26 Jan 2018 18:02:42 +1000 Subject: [PATCH 47/51] Mark integration tests as covering nothing and delete dead test code --- .../AllowsReturningEarlyFromRoutingTest.php | 3 + .../ControllerIsDispatchedTest.php | 3 + ...hableShouldRaiseDispatchErrorEventTest.php | 3 + ...ntrollerShouldTriggerDispatchErrorTest.php | 3 + ...veControllerShouldTriggerExceptionTest.php | 3 + ...llerTypeShouldTriggerDispatchErrorTest.php | 3 + test/Application/RoutingSuccessTest.php | 3 + .../TestAsset/modules/Application/Module.php | 31 ----- .../Application/config/module.config.php | 66 ----------- .../Application/Controller/PathController.php | 27 ----- .../view/application/index/index.phtml | 5 - .../modules/Application/view/error/404.phtml | 107 ------------------ .../Application/view/error/index.phtml | 62 ---------- .../Application/view/layout/layout.phtml | 14 --- .../TestAsset/ControllerWithDependencies.php | 34 ------ test/Service/TestAsset/Dispatchable.php | 23 ---- .../TestAsset/EventManagerAwareObject.php | 41 ------- .../TestAsset/InvalidDispatchableClass.php | 20 ---- test/TestAsset/Locator.php | 56 --------- 19 files changed, 21 insertions(+), 486 deletions(-) delete mode 100644 test/Application/TestAsset/modules/Application/Module.php delete mode 100644 test/Application/TestAsset/modules/Application/config/module.config.php delete mode 100644 test/Application/TestAsset/modules/Application/src/Application/Controller/PathController.php delete mode 100644 test/Application/TestAsset/modules/Application/view/application/index/index.phtml delete mode 100644 test/Application/TestAsset/modules/Application/view/error/404.phtml delete mode 100644 test/Application/TestAsset/modules/Application/view/error/index.phtml delete mode 100644 test/Application/TestAsset/modules/Application/view/layout/layout.phtml delete mode 100644 test/Service/TestAsset/ControllerWithDependencies.php delete mode 100644 test/Service/TestAsset/Dispatchable.php delete mode 100644 test/Service/TestAsset/EventManagerAwareObject.php delete mode 100644 test/Service/TestAsset/InvalidDispatchableClass.php delete mode 100644 test/TestAsset/Locator.php diff --git a/test/Application/AllowsReturningEarlyFromRoutingTest.php b/test/Application/AllowsReturningEarlyFromRoutingTest.php index 6757ebb18..6ee6993ec 100644 --- a/test/Application/AllowsReturningEarlyFromRoutingTest.php +++ b/test/Application/AllowsReturningEarlyFromRoutingTest.php @@ -14,6 +14,9 @@ use Zend\Diactoros\ServerRequest; use Zend\Mvc\MvcEvent; +/** + * @coversNothing + */ class AllowsReturningEarlyFromRoutingTest extends TestCase { use PathControllerTrait; diff --git a/test/Application/ControllerIsDispatchedTest.php b/test/Application/ControllerIsDispatchedTest.php index 7533253f4..80d278aa4 100644 --- a/test/Application/ControllerIsDispatchedTest.php +++ b/test/Application/ControllerIsDispatchedTest.php @@ -13,6 +13,9 @@ use Zend\Diactoros\ServerRequest; use Zend\Mvc\MvcEvent; +/** + * @coversNothing + */ class ControllerIsDispatchedTest extends TestCase { use PathControllerTrait; diff --git a/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php b/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php index 5f0ec10a5..972cb9559 100644 --- a/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php +++ b/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php @@ -14,6 +14,9 @@ use Zend\Diactoros\ServerRequest; use Zend\Mvc\MvcEvent; +/** + * @coversNothing + */ class ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest extends TestCase { use BadControllerTrait; diff --git a/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php b/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php index 4b56dae65..906aeed86 100644 --- a/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php +++ b/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php @@ -15,6 +15,9 @@ use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; +/** + * @coversNothing + */ class InabilityToRetrieveControllerShouldTriggerDispatchErrorTest extends TestCase { use MissingControllerTrait; diff --git a/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php b/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php index 16f4b426c..1a3e6163f 100644 --- a/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php +++ b/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php @@ -15,6 +15,9 @@ use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; +/** + * @coversNothing + */ class InabilityToRetrieveControllerShouldTriggerExceptionTest extends TestCase { use MissingControllerTrait; diff --git a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php index 65c10ab43..d15ddf3e0 100644 --- a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php +++ b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php @@ -15,6 +15,9 @@ use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; +/** + * @coversNothing + */ class InvalidControllerTypeShouldTrigerDispatchErrorTest extends TestCase { use InvalidControllerTypeTrait; diff --git a/test/Application/RoutingSuccessTest.php b/test/Application/RoutingSuccessTest.php index 2989d7a9e..9ad096d14 100644 --- a/test/Application/RoutingSuccessTest.php +++ b/test/Application/RoutingSuccessTest.php @@ -14,6 +14,9 @@ use Zend\Mvc\MvcEvent; use Zend\Router\RouteResult; +/** + * @coversNothing + */ class RoutingSuccessTest extends TestCase { use PathControllerTrait; diff --git a/test/Application/TestAsset/modules/Application/Module.php b/test/Application/TestAsset/modules/Application/Module.php deleted file mode 100644 index 59a66d23d..000000000 --- a/test/Application/TestAsset/modules/Application/Module.php +++ /dev/null @@ -1,31 +0,0 @@ - [ - 'namespaces' => [ - __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, - ], - ], - ]; - } -} diff --git a/test/Application/TestAsset/modules/Application/config/module.config.php b/test/Application/TestAsset/modules/Application/config/module.config.php deleted file mode 100644 index f38dee849..000000000 --- a/test/Application/TestAsset/modules/Application/config/module.config.php +++ /dev/null @@ -1,66 +0,0 @@ - [ - 'factories' => [ - 'path' => function () { - return new Controller\PathController(); - }, - ], - ], - 'router' => [ - 'routes' => [ - 'path' => [ - 'type' => 'literal', - 'options' => [ - 'route' => '/path', - 'defaults' => [ - 'controller' => 'path', - ], - ], - ], - ], - ], - 'service_manager' => [ - 'factories' => [ - 'Request' => function () { - return new HttpRequest(); - }, - 'Response' => function () { - return new HttpResponse(); - }, - 'Router' => HttpRouterFactory::class, - 'ViewManager' => HttpViewManagerFactory::class, - ], - ], - 'view_manager' => [ - 'display_not_found_reason' => true, - 'display_exceptions' => true, - 'doctype' => 'HTML5', - 'not_found_template' => 'error/404', - 'exception_template' => 'error/index', - 'template_map' => [ - 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', - 'application/index/index' => __DIR__ . '/../view/application/index/index.phtml', - 'error/404' => __DIR__ . '/../view/error/404.phtml', - 'error/index' => __DIR__ . '/../view/error/index.phtml', - ], - 'template_path_stack' => [ - __DIR__ . '/../view', - ], - ], -]; diff --git a/test/Application/TestAsset/modules/Application/src/Application/Controller/PathController.php b/test/Application/TestAsset/modules/Application/src/Application/Controller/PathController.php deleted file mode 100644 index 09cc1f581..000000000 --- a/test/Application/TestAsset/modules/Application/src/Application/Controller/PathController.php +++ /dev/null @@ -1,27 +0,0 @@ -setContent(__METHOD__); - return $response; - } -} diff --git a/test/Application/TestAsset/modules/Application/view/application/index/index.phtml b/test/Application/TestAsset/modules/Application/view/application/index/index.phtml deleted file mode 100644 index ff98a33ff..000000000 --- a/test/Application/TestAsset/modules/Application/view/application/index/index.phtml +++ /dev/null @@ -1,5 +0,0 @@ -

Home Page

- -

- This is the home page. -

diff --git a/test/Application/TestAsset/modules/Application/view/error/404.phtml b/test/Application/TestAsset/modules/Application/view/error/404.phtml deleted file mode 100644 index f53d90ae7..000000000 --- a/test/Application/TestAsset/modules/Application/view/error/404.phtml +++ /dev/null @@ -1,107 +0,0 @@ -

A 404 error occurred

-

message ?>

- -reason) && $this->reason): ?> - -reason) { - case 'error-controller-cannot-dispatch': - $reasonMessage = 'The requested controller was unable to dispatch the request.'; - break; - case 'error-controller-not-found': - $reasonMessage = 'The requested controller could not be mapped to an existing controller class.'; - break; - case 'error-controller-invalid': - $reasonMessage = 'The requested controller was not dispatchable.'; - break; - case 'error-router-no-match': - $reasonMessage = 'The requested URL could not be matched by routing.'; - break; - default: - $reasonMessage = 'We cannot determine at this time why a 404 was generated.'; - break; -} -?> - -

- - - -controller) && $this->controller): ?> - -
-
Controller:
-
escapeHtml($this->controller) ?> -controller_class) - && $this->controller_class - && $this->controller_class != $this->controller -) { - echo '(' . sprintf('resolves to %s', $this->escapeHtml($this->controller_class)) . ')'; -} -?> -
-
- - - -display_exceptions) && $this->display_exceptions): ?> - -exception) && $this->exception instanceof Exception): ?> -
-

Additional information:

-

exception); ?>

-
-
File:
-
-
exception->getFile() ?>:exception->getLine() ?>
-
-
Message:
-
-
exception->getMessage() ?>
-
-
Stack trace:
-
-
exception->getTraceAsString() ?>
-
-
-exception->getPrevious(); - if ($e) : -?> -
-

Previous exceptions:

-
    - -
  • -

    -
    -
    File:
    -
    -
    getFile() ?>:getLine() ?>
    -
    -
    Message:
    -
    -
    getMessage() ?>
    -
    -
    Stack trace:
    -
    -
    getTraceAsString() ?>
    -
    -
    -
  • - getPrevious(); - endwhile; - ?> -
- - - - -

No Exception available

- - - - diff --git a/test/Application/TestAsset/modules/Application/view/error/index.phtml b/test/Application/TestAsset/modules/Application/view/error/index.phtml deleted file mode 100644 index 5f013493b..000000000 --- a/test/Application/TestAsset/modules/Application/view/error/index.phtml +++ /dev/null @@ -1,62 +0,0 @@ -

An error occurred

-

message ?>

- -display_exceptions) && $this->display_exceptions): ?> - -exception) && $this->exception instanceof Exception): ?> -
-

Additional information:

-

exception); ?>

-
-
File:
-
-
exception->getFile() ?>:exception->getLine() ?>
-
-
Message:
-
-
escapeHtml($this->exception->getMessage()) ?>
-
-
Stack trace:
-
-
escapeHtml($this->exception->getTraceAsString()) ?>
-
-
-exception->getPrevious(); - if ($e) : -?> -
-

Previous exceptions:

-
    - -
  • -

    -
    -
    File:
    -
    -
    getFile() ?>:getLine() ?>
    -
    -
    Message:
    -
    -
    escapeHtml($e->getMessage()) ?>
    -
    -
    Stack trace:
    -
    -
    escapeHtml($e->getTraceAsString()) ?>
    -
    -
    -
  • - getPrevious(); - endwhile; - ?> -
- - - - -

No Exception available

- - - - diff --git a/test/Application/TestAsset/modules/Application/view/layout/layout.phtml b/test/Application/TestAsset/modules/Application/view/layout/layout.phtml deleted file mode 100644 index ac6e48032..000000000 --- a/test/Application/TestAsset/modules/Application/view/layout/layout.phtml +++ /dev/null @@ -1,14 +0,0 @@ -doctype(); ?> - - - - - headTitle('ZF2 Skeleton Application')->setSeparator(' - ')->setAutoEscape(false) ?> - - - -
- content; ?> -
- - diff --git a/test/Service/TestAsset/ControllerWithDependencies.php b/test/Service/TestAsset/ControllerWithDependencies.php deleted file mode 100644 index 24da43149..000000000 --- a/test/Service/TestAsset/ControllerWithDependencies.php +++ /dev/null @@ -1,34 +0,0 @@ -injectedValue = $injected; - } - - public function dispatch(RequestInterface $request, ResponseInterface $response = null) - { - } -} diff --git a/test/Service/TestAsset/Dispatchable.php b/test/Service/TestAsset/Dispatchable.php deleted file mode 100644 index e9f861470..000000000 --- a/test/Service/TestAsset/Dispatchable.php +++ /dev/null @@ -1,23 +0,0 @@ -events; - } -} diff --git a/test/Service/TestAsset/EventManagerAwareObject.php b/test/Service/TestAsset/EventManagerAwareObject.php deleted file mode 100644 index ce278fa2c..000000000 --- a/test/Service/TestAsset/EventManagerAwareObject.php +++ /dev/null @@ -1,41 +0,0 @@ -events = $events; - } - - /** - * @return EventManagerInterface - */ - public function getEventManager() - { - if (! $this->events instanceof EventManagerInterface - && static::$defaultEvents instanceof EventManagerInterface - ) { - $this->setEventManager(static::$defaultEvents); - } - return $this->events; - } -} diff --git a/test/Service/TestAsset/InvalidDispatchableClass.php b/test/Service/TestAsset/InvalidDispatchableClass.php deleted file mode 100644 index 2596c162b..000000000 --- a/test/Service/TestAsset/InvalidDispatchableClass.php +++ /dev/null @@ -1,20 +0,0 @@ -services[$name])) { - throw new ServiceNotFoundException(); - } - - return call_user_func_array($this->services[$name]); - } - - public function has($name) - { - return (isset($this->services[$name])); - } - - public function build($name, array $options = null) - { - if (! isset($this->services[$name])) { - throw new ServiceNotFoundException(); - } - - return call_user_func_array($this->services[$name], $options); - } - - public function add($name, $callback) - { - $this->services[$name] = $callback; - } - - public function remove($name) - { - if (isset($this->services[$name])) { - unset($this->services[$name]); - } - } -} From ee4d66e5656c3f9eba159d37fe9688dca1c96f5f Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 8 Feb 2018 15:15:15 +1000 Subject: [PATCH 48/51] Update MiddlewareListener for stratigility v3 --- composer.json | 2 +- composer.lock | 240 ++++++------------- src/Controller/MiddlewareController.php | 29 +-- src/MiddlewareListener.php | 69 +++--- test/Controller/MiddlewareControllerTest.php | 17 +- test/MiddlewareListenerTest.php | 146 ++++------- test/TestAsset/Middleware.php | 12 +- 7 files changed, 200 insertions(+), 315 deletions(-) diff --git a/composer.json b/composer.json index 8f7f0cb99..3f97f6322 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "phpunit/phpunit": "^7.0", "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-json": "^3.0", - "zendframework/zend-stratigility": "^2.0.1", + "zendframework/zend-stratigility": "3.0.0-alpha3", "zendframework/zend-validator": "^2.10" }, "suggest": { diff --git a/composer.lock b/composer.lock index 65d30ab99..861f00e74 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "83a4acc6c65baffb00e63c8256c2145e", + "content-hash": "eaa53131fde15db34e88843634074898", "packages": [ { "name": "container-interop/container-interop", @@ -734,58 +734,6 @@ ], "time": "2017-07-22T11:58:36+00:00" }, - { - "name": "http-interop/http-middleware", - "version": "0.5.0", - "source": { - "type": "git", - "url": "https://github.com/http-interop/http-middleware.git", - "reference": "b49e1f9f6c584e704317b563302e566b8ce11858" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/http-interop/http-middleware/zipball/b49e1f9f6c584e704317b563302e566b8ce11858", - "reference": "b49e1f9f6c584e704317b563302e566b8ce11858", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "psr/http-message": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Interop\\Http\\Server\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP server-side middleware", - "keywords": [ - "http", - "middleware", - "psr", - "psr-15", - "psr-7", - "request", - "response" - ], - "abandoned": "http-interop/http-server-middleware", - "time": "2017-09-18T15:27:03+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.7.0", @@ -1533,6 +1481,59 @@ ], "time": "2018-02-01T13:11:13+00:00" }, + { + "name": "psr/http-server-middleware", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-server-middleware.git", + "reference": "ea17eb1fb2c8df6db919cc578451a8013c6a0ae5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-server-middleware/zipball/ea17eb1fb2c8df6db919cc578451a8013c6a0ae5", + "reference": "ea17eb1fb2c8df6db919cc578451a8013c6a0ae5", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/http-message": "^1.0", + "psr/http-server-handler": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP server-side middleware", + "keywords": [ + "http", + "http-interop", + "middleware", + "psr", + "psr-15", + "psr-7", + "request", + "response" + ], + "time": "2018-01-22T17:08:31+00:00" + }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.1", @@ -2214,99 +2215,6 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "time": "2017-04-07T12:08:54+00:00" }, - { - "name": "webimpress/composer-extra-dependency", - "version": "0.2.2", - "source": { - "type": "git", - "url": "https://github.com/webimpress/composer-extra-dependency.git", - "reference": "31fa56391d30f03b1180c87610cbe22254780ad9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webimpress/composer-extra-dependency/zipball/31fa56391d30f03b1180c87610cbe22254780ad9", - "reference": "31fa56391d30f03b1180c87610cbe22254780ad9", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1", - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "composer/composer": "^1.5.2", - "mikey179/vfsstream": "^1.6.5", - "phpunit/phpunit": "^5.7.22 || ^6.4.1", - "zendframework/zend-coding-standard": "~1.0.0" - }, - "type": "composer-plugin", - "extra": { - "class": "Webimpress\\ComposerExtraDependency\\Plugin" - }, - "autoload": { - "psr-4": { - "Webimpress\\ComposerExtraDependency\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "description": "Composer plugin to require extra dependencies", - "homepage": "https://github.com/webimpress/composer-extra-dependency", - "keywords": [ - "composer", - "dependency", - "webimpress" - ], - "time": "2017-10-17T17:15:14+00:00" - }, - { - "name": "webimpress/http-middleware-compatibility", - "version": "0.1.4", - "source": { - "type": "git", - "url": "https://github.com/webimpress/http-middleware-compatibility.git", - "reference": "8ed1c2c7523dce0035b98bc4f3a73ca9cd1d3717" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webimpress/http-middleware-compatibility/zipball/8ed1c2c7523dce0035b98bc4f3a73ca9cd1d3717", - "reference": "8ed1c2c7523dce0035b98bc4f3a73ca9cd1d3717", - "shasum": "" - }, - "require": { - "http-interop/http-middleware": "^0.1.1 || ^0.2 || ^0.3 || ^0.4.1 || ^0.5", - "php": "^5.6 || ^7.0", - "webimpress/composer-extra-dependency": "^0.2.2" - }, - "require-dev": { - "phpunit/phpunit": "^5.7.23 || ^6.4.3" - }, - "type": "library", - "extra": { - "dependency": [ - "http-interop/http-middleware" - ] - }, - "autoload": { - "files": [ - "autoload/http-middleware.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "description": "Compatibility library for Draft PSR-15 HTTP Middleware", - "homepage": "https://github.com/webimpress/http-middleware-compatibility", - "keywords": [ - "middleware", - "psr-15", - "webimpress" - ], - "abandoned": "psr/http-server-middleware", - "time": "2017-10-17T17:31:10+00:00" - }, { "name": "webmozart/assert", "version": "1.3.0", @@ -2482,27 +2390,27 @@ }, { "name": "zendframework/zend-stratigility", - "version": "2.1.2", + "version": "3.0.0alpha3", "source": { "type": "git", "url": "https://github.com/zendframework/zend-stratigility.git", - "reference": "7dfec8dee92dad0d01e68365015f2848c250fe9f" + "reference": "e346801682bad999320ee89285b62643f27735a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-stratigility/zipball/7dfec8dee92dad0d01e68365015f2848c250fe9f", - "reference": "7dfec8dee92dad0d01e68365015f2848c250fe9f", + "url": "https://api.github.com/repos/zendframework/zend-stratigility/zipball/e346801682bad999320ee89285b62643f27735a9", + "reference": "e346801682bad999320ee89285b62643f27735a9", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0", + "php": "^7.1", "psr/http-message": "^1.0", - "webimpress/http-middleware-compatibility": "^0.1.3", + "psr/http-server-middleware": "^1.0", "zendframework/zend-escaper": "^2.3" }, "require-dev": { - "malukenho/docheader": "^0.1.5", - "phpunit/phpunit": "^6.0.8 || ^5.7.15", + "malukenho/docheader": "^0.1.6", + "phpunit/phpunit": "^6.5.5", "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-diactoros": "^1.0" }, @@ -2512,11 +2420,18 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1.0-dev", - "dev-develop": "2.2.0-dev" + "dev-master": "3.0-dev", + "dev-develop": "3.1-dev", + "dev-release-3.0.0": "3.0.x-dev" } }, "autoload": { + "files": [ + "src/functions/double-pass-middleware.php", + "src/functions/host.php", + "src/functions/middleware.php", + "src/functions/path.php" + ], "psr-4": { "Zend\\Stratigility\\": "src/" } @@ -2525,14 +2440,16 @@ "license": [ "BSD-3-Clause" ], - "description": "Middleware for PHP", - "homepage": "https://github.com/zendframework/zend-stratigility", + "description": "PSR-7 middleware foundation for building and dispatching middleware pipelines", "keywords": [ + "ZendFramework", "http", "middleware", - "psr-7" + "psr-15", + "psr-7", + "zf" ], - "time": "2017-10-12T13:14:14+00:00" + "time": "2018-02-05T21:18:43+00:00" }, { "name": "zendframework/zend-validator", @@ -2609,7 +2526,8 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "zendframework/zend-router": 20 + "zendframework/zend-router": 20, + "zendframework/zend-stratigility": 15 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Controller/MiddlewareController.php b/src/Controller/MiddlewareController.php index bac347231..d92f85706 100644 --- a/src/Controller/MiddlewareController.php +++ b/src/Controller/MiddlewareController.php @@ -11,11 +11,11 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface as Request; +use Psr\Http\Server\RequestHandlerInterface; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Exception\ReachedFinalHandlerException; use Zend\Mvc\Exception\RuntimeException; use Zend\Mvc\MvcEvent; -use Zend\Stratigility\Delegate\CallableDelegateDecorator; use Zend\Stratigility\MiddlewarePipe; /** @@ -37,21 +37,13 @@ final class MiddlewareController extends AbstractController */ private $pipe; - /** - * @var ResponseInterface - */ - private $responsePrototype; - public function __construct( MiddlewarePipe $pipe, - ResponseInterface $responsePrototype, EventManagerInterface $eventManager, MvcEvent $event ) { $this->eventIdentifier = __CLASS__; $this->pipe = $pipe; - $this->responsePrototype = $responsePrototype; - $this->setEventManager($eventManager); $this->setEvent($event); } @@ -65,15 +57,20 @@ public function onDispatch(MvcEvent $e) { $request = $e->getRequest(); - $result = $this->pipe->process($request, new CallableDelegateDecorator( - function () { + $finalHandler = new class implements RequestHandlerInterface { + /** + * Handle the request and return a response. + */ + public function handle(Request $request) : ResponseInterface + { throw ReachedFinalHandlerException::create(); - }, - $this->responsePrototype - )); + } + }; + + $response = $this->pipe->process($request, $finalHandler); - $e->setResult($result); + $e->setResult($response); - return $result; + return $response; } } diff --git a/src/MiddlewareListener.php b/src/MiddlewareListener.php index 4d2080c64..9d6ca3a83 100644 --- a/src/MiddlewareListener.php +++ b/src/MiddlewareListener.php @@ -10,18 +10,21 @@ namespace Zend\Mvc; use Psr\Container\ContainerInterface; -use Interop\Http\Server\MiddlewareInterface; -use Psr\Http\Message\ResponseInterface; -use Zend\Diactoros\Response; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; +use Throwable; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Exception\InvalidMiddlewareException; -use Zend\Mvc\Exception\ReachedFinalHandlerException; use Zend\Mvc\Controller\MiddlewareController; use Zend\Router\RouteResult; -use Zend\Stratigility\Delegate\CallableDelegateDecorator; +use Zend\Stratigility\Middleware\RequestHandlerMiddleware; use Zend\Stratigility\MiddlewarePipe; +use function is_object; +use function get_class; +use function gettype; + class MiddlewareListener extends AbstractListenerAggregate { /** @@ -30,7 +33,7 @@ class MiddlewareListener extends AbstractListenerAggregate * @param EventManagerInterface $events * @return void */ - public function attach(EventManagerInterface $events, $priority = 1) + public function attach(EventManagerInterface $events, $priority = 1) : void { $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, [$this, 'onDispatch'], 1); } @@ -52,21 +55,18 @@ public function onDispatch(MvcEvent $event) if (! $routeResult) { return null; } - $middleware = $routeResult->getMatchedParams()['middleware'] ?? false; - if (false === $middleware) { + $middleware = $routeResult->getMatchedParams()['middleware'] ?? null; + if (null === $middleware) { return null; } $request = $event->getRequest(); $application = $event->getApplication(); - $serviceManager = $application->getContainer(); - - $responsePrototype = $event->getResponse() ?? new Response(); + $container = $application->getContainer(); try { $pipe = $this->createPipeFromSpec( - $serviceManager, - $responsePrototype, + $container, is_array($middleware) ? $middleware : [$middleware] ); } catch (InvalidMiddlewareException $invalidMiddlewareException) { @@ -81,23 +81,17 @@ public function onDispatch(MvcEvent $event) return $return; } - $caughtException = null; $return = null; try { $return = (new MiddlewareController( $pipe, - $responsePrototype, $application->getContainer()->get('EventManager'), $event ))->dispatch($request); - } catch (\Throwable $ex) { - $caughtException = $ex; - } - - if ($caughtException !== null) { + } catch (Throwable $ex) { $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); $event->setError(Application::ERROR_EXCEPTION); - $event->setParam('exception', $caughtException); + $event->setParam('exception', $ex); $events = $application->getEventManager(); $results = $events->triggerEvent($event); @@ -117,33 +111,44 @@ public function onDispatch(MvcEvent $event) * Create a middleware pipe from the array spec given. * * @param ContainerInterface $serviceLocator - * @param ResponseInterface $responsePrototype * @param array $middlewaresToBePiped * @return MiddlewarePipe * @throws InvalidMiddlewareException */ private function createPipeFromSpec( ContainerInterface $serviceLocator, - ResponseInterface $responsePrototype, array $middlewaresToBePiped - ) { + ) : MiddlewarePipe { $pipe = new MiddlewarePipe(); - $pipe->setResponsePrototype($responsePrototype); foreach ($middlewaresToBePiped as $middlewareToBePiped) { if (null === $middlewareToBePiped) { throw InvalidMiddlewareException::fromNull(); } - $middlewareName = is_string($middlewareToBePiped) ? $middlewareToBePiped : get_class($middlewareToBePiped); - if (is_string($middlewareToBePiped) && $serviceLocator->has($middlewareToBePiped)) { $middlewareToBePiped = $serviceLocator->get($middlewareToBePiped); } - if (! $middlewareToBePiped instanceof MiddlewareInterface && ! is_callable($middlewareToBePiped)) { - throw InvalidMiddlewareException::fromMiddlewareName($middlewareName); + + if ($middlewareToBePiped instanceof MiddlewareInterface) { + $pipe->pipe($middlewareToBePiped); + continue; + } + if ($middlewareToBePiped instanceof RequestHandlerInterface) { + $middlewareToBePiped = new RequestHandlerMiddleware($middlewareToBePiped); + $pipe->pipe($middlewareToBePiped); + continue; } + /* + * callable and auto-invokable is not allowed for security reasons, as middleware parameter + * could potentially come from matched route parameter and middleware + * is fetched from main container. + */ + + $middlewareName = is_string($middlewareToBePiped) + ? $middlewareToBePiped + : (is_object($middlewareToBePiped) ? get_class($middlewareToBePiped) : gettype($middlewareToBePiped)); - $pipe->pipe($middlewareToBePiped); + throw InvalidMiddlewareException::fromMiddlewareName($middlewareName); } return $pipe; } @@ -155,7 +160,7 @@ private function createPipeFromSpec( * @param string $middlewareName * @param MvcEvent $event * @param ApplicationInterface $application - * @param \Exception $exception + * @param Throwable $exception * @return mixed */ protected function marshalInvalidMiddleware( @@ -163,7 +168,7 @@ protected function marshalInvalidMiddleware( $middlewareName, MvcEvent $event, ApplicationInterface $application, - \Exception $exception = null + Throwable $exception = null ) { $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); $event->setError($type); diff --git a/test/Controller/MiddlewareControllerTest.php b/test/Controller/MiddlewareControllerTest.php index b005e9a65..83b9455a6 100644 --- a/test/Controller/MiddlewareControllerTest.php +++ b/test/Controller/MiddlewareControllerTest.php @@ -12,15 +12,16 @@ use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Zend\Diactoros\Response; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Controller\AbstractController; use Zend\Mvc\Controller\Dispatchable; use Zend\Mvc\Controller\MiddlewareController; -use Zend\Mvc\Exception\RuntimeException; use Zend\Mvc\MvcEvent; +use Zend\Stratigility\Middleware\CallableMiddlewareDecorator; use Zend\Stratigility\MiddlewarePipe; /** @@ -33,11 +34,6 @@ class MiddlewareControllerTest extends TestCase */ private $pipe; - /** - * @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $responsePrototype; - /** * @var EventManagerInterface */ @@ -58,7 +54,7 @@ class MiddlewareControllerTest extends TestCase */ protected function setUp() { - $this->pipe = $this->createMock(MiddlewarePipe::class); + $this->pipe = new MiddlewarePipe(); $this->responsePrototype = $this->createMock(ResponseInterface::class); $this->eventManager = $this->createMock(EventManagerInterface::class); $this->event = new MvcEvent(); @@ -66,7 +62,6 @@ protected function setUp() $this->controller = new MiddlewareController( $this->pipe, - $this->responsePrototype, $this->eventManager, $this->event ); @@ -105,7 +100,9 @@ public function testWillDispatchARequestAndResponseWithAGivenPipe() return true; })); - $this->pipe->expects(self::once())->method('process')->willReturn($result); + $this->pipe->pipe(new CallableMiddlewareDecorator(function () use ($result) { + return $result; + })); $controllerResult = $this->controller->dispatch($request); diff --git a/test/MiddlewareListenerTest.php b/test/MiddlewareListenerTest.php index 2076a2e60..fa4f01e4b 100644 --- a/test/MiddlewareListenerTest.php +++ b/test/MiddlewareListenerTest.php @@ -9,11 +9,13 @@ namespace ZendTest\Mvc; +use Exception; use Interop\Container\ContainerInterface; -use Interop\Http\Server\MiddlewareInterface; +use Psr\Http\Server\MiddlewareInterface; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\RequestHandlerInterface; use Zend\Diactoros\Response\HtmlResponse; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequest; @@ -27,6 +29,7 @@ use Zend\Mvc\MvcEvent; use Zend\Router\RouteResult; use Zend\ServiceManager\ServiceManager; +use Zend\Stratigility\Middleware\CallableMiddlewareDecorator; use Zend\View\Model\ModelInterface; class MiddlewareListenerTest extends TestCase @@ -41,14 +44,14 @@ class MiddlewareListenerTest extends TestCase */ public function createMvcEvent($middlewareMatched, $middleware = null, array $matchedParams = []) { - $response = new Response(); + $response = new Response(); $request = new ServerRequest([], [], null, 'GET', 'php://memory'); $matchedParams['middleware'] = $middlewareMatched; $routeResult = RouteResult::fromRouteMatch($matchedParams); $request = $request->withAttribute(RouteResult::class, $routeResult); - $eventManager = new EventManager(); + $eventManager = new EventManager(); $serviceManager = new ServiceManager([ 'factories' => [ 'EventManager' => function () { @@ -74,28 +77,24 @@ public function createMvcEvent($middlewareMatched, $middleware = null, array $ma public function testSuccessfullyDispatchesMiddleware() { - $event = $this->createMvcEvent('path', function ($request, $response) { - $this->assertInstanceOf(ServerRequestInterface::class, $request); - $this->assertInstanceOf(ResponseInterface::class, $response); - $response->getBody()->write('Test!'); + $response = new Response(); + $middleware = new CallableMiddlewareDecorator(function () use ($response) { return $response; }); + $event = $this->createMvcEvent('path', $middleware); $application = $event->getApplication(); $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { - $this->fail(sprintf('dispatch.error triggered when it should not be: %s', var_export($e->getError(), 1))); + $this->fail(sprintf('dispatch.error triggered when it should not be: %s', var_export($e->getError(), true))); }); $listener = new MiddlewareListener(); - $return = $listener->onDispatch($event); - $this->assertInstanceOf(Response::class, $return); - - $this->assertInstanceOf(Response::class, $return); - $this->assertSame(200, $return->getStatusCode()); - $this->assertEquals('Test!', $return->getBody()); + $return = $listener->onDispatch($event); + $this->assertSame($response, $event->getResult()); + $this->assertSame($response, $return); } - public function testSuccessfullyDispatchesHttpInteropMiddleware() + public function testSuccessfullyDispatchesPsrMiddleware() { $expectedOutput = uniqid('expectedOutput', true); @@ -106,11 +105,11 @@ public function testSuccessfullyDispatchesHttpInteropMiddleware() $application = $event->getApplication(); $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { - $this->fail(sprintf('dispatch.error triggered when it should not be: %s', var_export($e->getError(), 1))); + $this->fail(sprintf('dispatch.error triggered when it should not be: %s', var_export($e->getError(), true))); }); $listener = new MiddlewareListener(); - $return = $listener->onDispatch($event); + $return = $listener->onDispatch($event); $this->assertInstanceOf(Response::class, $return); $this->assertInstanceOf(Response::class, $return); @@ -118,68 +117,28 @@ public function testSuccessfullyDispatchesHttpInteropMiddleware() $this->assertEquals($expectedOutput, $return->getBody()); } - public function testSuccessfullyDispatchesPipeOfCallableAndHttpInteropStyleMiddlewares() + public function testTriggersErrorForCallableMiddleware() { - $response = new Response(); - $request = new ServerRequest([], [], null, 'GET', 'php://memory'); - - $routeResult = RouteResult::fromRouteMatch([ - 'middleware' => [ - 'firstMiddleware', - 'secondMiddleware', - ], - ]); - $request = $request->withAttribute(RouteResult::class, $routeResult); - - $eventManager = new EventManager(); - - $serviceManager = $this->prophesize(ContainerInterface::class); - $serviceManager->get('EventManager')->willReturn($eventManager); - $serviceManager->has('firstMiddleware')->willReturn(true); - $serviceManager->get('firstMiddleware')->willReturn(function ($request, $response, $next) { - $this->assertInstanceOf(ServerRequestInterface::class, $request); - $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertTrue(is_callable($next)); - return $next($request->withAttribute('firstMiddlewareAttribute', 'firstMiddlewareValue'), $response); - }); - - $secondMiddleware = $this->createMock(MiddlewareInterface::class); - $secondMiddleware->expects($this->once()) - ->method('process') - ->willReturnCallback(function (ServerRequestInterface $request) { - return new HtmlResponse($request->getAttribute('firstMiddlewareAttribute')); - }); - - $serviceManager->has('secondMiddleware')->willReturn(true); - $serviceManager->get('secondMiddleware')->willReturn($secondMiddleware); - - $application = $this->prophesize(Application::class); - $application->getEventManager()->willReturn($eventManager); - $application->getContainer()->will(function () use ($serviceManager) { - return $serviceManager->reveal(); + $event = $this->createMvcEvent('path', function () { + return new Response(); }); - $event = new MvcEvent(); - $event->setRequest($request); - $event->setResponse($response); - $event->setApplication($application->reveal()); + $application = $event->getApplication(); - $event->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { - $this->fail(sprintf('dispatch.error triggered when it should not be: %s', var_export($e->getError(), 1))); + $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { + $this->assertEquals(Application::ERROR_MIDDLEWARE_CANNOT_DISPATCH, $e->getError()); + $this->assertEquals('Closure', $e->getController()); + return 'FAILED'; }); $listener = new MiddlewareListener(); - $return = $listener->onDispatch($event); - $this->assertInstanceOf(Response::class, $return); - - $this->assertInstanceOf(ResponseInterface::class, $return); - $this->assertSame(200, $return->getStatusCode()); - $this->assertEquals('firstMiddlewareValue', $return->getBody()->__toString()); + $return = $listener->onDispatch($event); + $this->assertEquals('FAILED', $return); } public function testTriggersErrorForUncallableMiddleware() { - $event = $this->createMvcEvent('path'); + $event = $this->createMvcEvent('path'); $application = $event->getApplication(); $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { @@ -189,16 +148,17 @@ public function testTriggersErrorForUncallableMiddleware() }); $listener = new MiddlewareListener(); - $return = $listener->onDispatch($event); + $return = $listener->onDispatch($event); $this->assertEquals('FAILED', $return); } public function testTriggersErrorForExceptionRaisedInMiddleware() { - $exception = new \Exception(); - $event = $this->createMvcEvent('path', function ($request, $response) use ($exception) { + $exception = new Exception(); + $middleware = new CallableMiddlewareDecorator(function () use ($exception) { throw $exception; }); + $event = $this->createMvcEvent('path', $middleware); $application = $event->getApplication(); $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($exception) { @@ -208,7 +168,7 @@ public function testTriggersErrorForExceptionRaisedInMiddleware() }); $listener = new MiddlewareListener(); - $return = $listener->onDispatch($event); + $return = $listener->onDispatch($event); $this->assertEquals('FAILED', $return); } @@ -217,7 +177,7 @@ public function testTriggersErrorForExceptionRaisedInMiddleware() */ public function testCanLoadFromAbstractFactory() { - $response = new Response(); + $response = new Response(); $request = new ServerRequest([], [], null, 'GET', 'php://memory'); $routeResult = RouteResult::fromRouteMatch(['middleware' => 'test']); @@ -244,11 +204,11 @@ function () { $event->setApplication($application->reveal()); $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { - $this->fail(sprintf('dispatch.error triggered when it should not be: %s', var_export($e->getError(), 1))); + $this->fail(sprintf('dispatch.error triggered when it should not be: %s', var_export($e->getError(), true))); }); $listener = new MiddlewareListener(); - $return = $listener->onDispatch($event); + $return = $listener->onDispatch($event); $this->assertInstanceOf(Response::class, $return); $this->assertSame(200, $return->getStatusCode()); @@ -257,7 +217,7 @@ function () { public function testMiddlewareWithNothingPipedReachesFinalHandlerException() { - $response = new Response(); + $response = new Response(); $request = new ServerRequest([], [], null, 'GET', 'php://memory'); $routeResult = RouteResult::fromRouteMatch(['middleware' => []]); @@ -286,13 +246,13 @@ public function testMiddlewareWithNothingPipedReachesFinalHandlerException() }); $listener = new MiddlewareListener(); - $return = $listener->onDispatch($event); + $return = $listener->onDispatch($event); $this->assertEquals('FAILED', $return); } public function testNullMiddlewareThrowsInvalidMiddlewareException() { - $response = new Response(); + $response = new Response(); $request = new ServerRequest([], [], null, 'GET', 'php://memory'); $routeResult = RouteResult::fromRouteMatch(['middleware' => [null]]); @@ -331,11 +291,11 @@ public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures() $routeResult = RouteResult::fromRouteMatch(['middleware' => $middlewareName]); $request = $request->withAttribute(RouteResult::class, $routeResult); - $response = new Response(); + $response = new Response(); /* @var $application Application|\PHPUnit_Framework_MockObject_MockObject */ - $application = $this->createMock(Application::class); - $eventManager = new EventManager(); - $middleware = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); + $application = $this->createMock(Application::class); + $eventManager = new EventManager(); + $middleware = $this->getMockBuilder(MiddlewareInterface::class)->setMethods(['process'])->getMock(); $serviceManager = new ServiceManager([ 'factories' => [ 'EventManager' => function () { @@ -349,7 +309,7 @@ public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures() $application->expects(self::any())->method('getEventManager')->willReturn($eventManager); $application->expects(self::any())->method('getContainer')->willReturn($serviceManager); - $middleware->expects(self::once())->method('__invoke')->willReturn($response); + $middleware->expects(self::once())->method('process')->willReturn($response); $event = new MvcEvent(); @@ -358,7 +318,7 @@ public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures() $event->setError(Application::ERROR_CONTROLLER_CANNOT_DISPATCH); $listener = new MiddlewareListener(); - $result = $listener->onDispatch($event); + $result = $listener->onDispatch($event); self::assertInstanceOf(Response::class, $result); self::assertInstanceOf(Response::class, $event->getResult()); @@ -372,14 +332,14 @@ public function testValidMiddlewareFiresDispatchableInterfaceEventListeners() $routeResult = RouteResult::fromRouteMatch(['middleware' => $middlewareName]); $request = $request->withAttribute(RouteResult::class, $routeResult); - $response = new Response(); + $response = new Response(); /* @var $application Application|\PHPUnit_Framework_MockObject_MockObject */ - $application = $this->createMock(Application::class); - $sharedManager = new SharedEventManager(); + $application = $this->createMock(Application::class); + $sharedManager = new SharedEventManager(); /* @var $sharedListener callable|\PHPUnit_Framework_MockObject_MockObject */ $sharedListener = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); - $eventManager = new EventManager(); - $middleware = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); + $eventManager = new EventManager(); + $middleware = $this->getMockBuilder(MiddlewareInterface::class)->setMethods(['process'])->getMock(); $serviceManager = new ServiceManager([ 'factories' => [ 'EventManager' => function () use ($sharedManager) { @@ -393,7 +353,7 @@ public function testValidMiddlewareFiresDispatchableInterfaceEventListeners() $application->expects(self::any())->method('getEventManager')->willReturn($eventManager); $application->expects(self::any())->method('getContainer')->willReturn($serviceManager); - $middleware->expects(self::once())->method('__invoke')->willReturn($response); + $middleware->expects(self::once())->method('process')->willReturn($response); $event = new MvcEvent(); @@ -422,9 +382,9 @@ public function testWillNotDispatchWhenAnMvcEventResultIsAlreadySet($alreadySetR $routeResult = RouteResult::fromRouteMatch(['middleware' => $middlewareName]); $request = $request->withAttribute(RouteResult::class, $routeResult); /* @var $application Application|\PHPUnit_Framework_MockObject_MockObject */ - $application = $this->createMock(Application::class); - $eventManager = new EventManager(); - $middleware = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); + $application = $this->createMock(Application::class); + $eventManager = new EventManager(); + $middleware = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); $serviceManager = new ServiceManager([ 'factories' => [ 'EventManager' => function () { diff --git a/test/TestAsset/Middleware.php b/test/TestAsset/Middleware.php index da19fe083..a0b125d58 100644 --- a/test/TestAsset/Middleware.php +++ b/test/TestAsset/Middleware.php @@ -11,11 +11,19 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; +use Zend\Diactoros\Response; -class Middleware +class Middleware implements MiddlewareInterface { - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next = null) + /** + * Process an incoming server request and return a response, optionally delegating + * response creation to a handler. + */ + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface { + $response = new Response(); $response->getBody()->write(__CLASS__); return $response; } From 6ccf60cedcbbc31f5e4a292ea6b7887b73553221 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 8 Feb 2018 15:32:03 +1000 Subject: [PATCH 49/51] Add http handler runner --- composer.json | 1 + composer.lock | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3f97f6322..7994474a5 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "psr/http-server-handler": "^1.0", "zendframework/zend-diactoros": "^1.7", "zendframework/zend-eventmanager": "^3.2", + "zendframework/zend-httphandlerrunner": "^1.0", "zendframework/zend-router": "dev-make-mvc-great-again", "zendframework/zend-servicemanager": "^3.3", "zendframework/zend-stdlib": "^3.1", diff --git a/composer.lock b/composer.lock index 861f00e74..c8af484bf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "eaa53131fde15db34e88843634074898", + "content-hash": "5b872e10eb6c5b2512b0533ce4cc1198", "packages": [ { "name": "container-interop/container-interop", @@ -345,6 +345,60 @@ ], "time": "2017-07-11T19:17:22+00:00" }, + { + "name": "zendframework/zend-httphandlerrunner", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-httphandlerrunner.git", + "reference": "9010659232e98c3fbfa575c184f7945e26e20380" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-httphandlerrunner/zipball/9010659232e98c3fbfa575c184f7945e26e20380", + "reference": "9010659232e98c3fbfa575c184f7945e26e20380", + "shasum": "" + }, + "require": { + "php": "^7.1", + "psr/http-message": "^1.0", + "psr/http-message-implementation": "^1.0", + "psr/http-server-handler": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.3", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-diactoros": "^1.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + }, + "zf": { + "config-provider": "Zend\\HttpHandlerRunner\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Zend\\HttpHandlerRunner\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Execute PSR-15 RequestHandlerInterface instances and emit responses they generate.", + "keywords": [ + "ZendFramework", + "components", + "expressive", + "psr-15", + "psr-7", + "zf" + ], + "time": "2018-02-05T14:21:31+00:00" + }, { "name": "zendframework/zend-loader", "version": "2.5.1", From 99a2bf13cf84ce7aaed4e715d139a4d3c4ec0414 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 8 Feb 2018 15:39:20 +1000 Subject: [PATCH 50/51] Drop run() and response emitter from application --- src/Application.php | 50 -------- src/ApplicationInterface.php | 9 -- src/Container/ApplicationFactory.php | 11 -- src/Emitter/EmitterStack.php | 107 ------------------ test/Application/BadControllerTrait.php | 5 - .../InvalidControllerTypeTrait.php | 5 - test/Application/MissingControllerTrait.php | 5 - test/Application/PathControllerTrait.php | 5 - test/ApplicationTest.php | 32 +----- test/Container/ApplicationFactoryTest.php | 30 ----- 10 files changed, 1 insertion(+), 258 deletions(-) delete mode 100644 src/Emitter/EmitterStack.php diff --git a/src/Application.php b/src/Application.php index 7a48562ab..7082152d2 100644 --- a/src/Application.php +++ b/src/Application.php @@ -9,14 +9,10 @@ namespace Zend\Mvc; -use InvalidArgumentException; use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface; -use UnexpectedValueException; use Zend\Diactoros\Response; -use Zend\Diactoros\Response\EmitterInterface; -use Zend\Diactoros\ServerRequestFactory; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\ListenerAggregateInterface; @@ -98,11 +94,6 @@ class Application implements */ protected $container; - /** - * @var EmitterInterface - */ - private $emitter; - /** * @var RouteStackInterface */ @@ -121,8 +112,6 @@ class Application implements * @param ContainerInterface $container IoC container from which to pull services * @param RouteStackInterface $router Configured router for RouteListener * @param EventManagerInterface $events - * @param EmitterInterface $emitter Response emitter to use when `run()` - * is invoked * @param array $listeners Extra listeners to attach on bootstrap * Can be container keys or instances of ListenerAggregateInterface */ @@ -130,13 +119,11 @@ public function __construct( ContainerInterface $container, RouteStackInterface $router, EventManagerInterface $events, - EmitterInterface $emitter, array $listeners = [] ) { $this->container = $container; $this->router = $router; $this->setEventManager($events); - $this->emitter = $emitter; $this->listeners = $listeners; // @TODO response prototype? @@ -236,38 +223,6 @@ public function getEventManager() : EventManagerInterface return $this->events; } - /** - * Run the application - * - * @triggers route(MvcEvent) - * Routes the request, and sets the RouteMatch object in the event. - * @triggers dispatch(MvcEvent) - * Dispatches a request, using the discovered RouteMatch and - * provided request. - * @triggers dispatch.error(MvcEvent) - * On errors (controller not found, action not supported, etc.), - * populates the event with information about the error type, - * discovered controller, and controller class (if known). - * Typically, a handler should return a populated Response object - * that can be returned immediately. - * @param Request|null $request - * @return void - */ - public function run(Request $request = null) : void - { - try { - $request = $request ?: ServerRequestFactory::fromGlobals(); - } catch (InvalidArgumentException | UnexpectedValueException $e) { - // emit bad request - throw new \Exception('Not implemented'); - } - - $response = $this->handle($request); - - $emitter = $this->getEmitter(); - $emitter->emit($response); - } - public function handle(Request $request) : ResponseInterface { if (! $this->bootstrapped) { @@ -328,11 +283,6 @@ public function handle(Request $request) : ResponseInterface return $this->completeRequest($event); } - public function getEmitter() : EmitterInterface - { - return $this->emitter; - } - /** * Complete the request * diff --git a/src/ApplicationInterface.php b/src/ApplicationInterface.php index f159fa964..07d34b391 100644 --- a/src/ApplicationInterface.php +++ b/src/ApplicationInterface.php @@ -10,7 +10,6 @@ namespace Zend\Mvc; use Psr\Container\ContainerInterface; -use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Zend\EventManager\EventsCapableInterface; @@ -22,12 +21,4 @@ interface ApplicationInterface extends EventsCapableInterface, RequestHandlerInt * @return ContainerInterface */ public function getContainer() : ContainerInterface; - - /** - * Run the application - * - * @param ServerRequestInterface|null $request - * @return void - */ - public function run(ServerRequestInterface $request = null) : void; } diff --git a/src/Container/ApplicationFactory.php b/src/Container/ApplicationFactory.php index 0c3134739..0a7f3769a 100644 --- a/src/Container/ApplicationFactory.php +++ b/src/Container/ApplicationFactory.php @@ -10,10 +10,7 @@ namespace Zend\Mvc\Container; use Psr\Container\ContainerInterface; -use Zend\Diactoros\Response\EmitterInterface; -use Zend\Diactoros\Response\SapiEmitter; use Zend\Mvc\Application; -use Zend\Mvc\Emitter\EmitterStack; class ApplicationFactory { @@ -29,13 +26,6 @@ class ApplicationFactory */ public function __invoke(ContainerInterface $container, string $name, array $options = null) : Application { - if ($container->has(EmitterInterface::class)) { - $emitter = $container->get(EmitterInterface::class); - } else { - $emitter = new EmitterStack(); - $emitter->push(new SapiEmitter()); - } - $config = $container->get('config') ?? []; $listeners = $config[Application::class]['listeners'] ?? []; @@ -43,7 +33,6 @@ public function __invoke(ContainerInterface $container, string $name, array $opt $container, $container->get('Zend\Mvc\Router'), $container->get('EventManager'), - $emitter, $listeners ); diff --git a/src/Emitter/EmitterStack.php b/src/Emitter/EmitterStack.php deleted file mode 100644 index 47e9c2e48..000000000 --- a/src/Emitter/EmitterStack.php +++ /dev/null @@ -1,107 +0,0 @@ -emit($response)) { - return null; - } - } - - return false; - } - - /** - * Set an emitter on the stack by index. - * - * @param mixed $index - * @param EmitterInterface $emitter - * @return void - * @throws InvalidArgumentException if not an EmitterInterface instance - */ - public function offsetSet($index, $emitter) - { - $this->validateEmitter($emitter); - parent::offsetSet($index, $emitter); - } - - /** - * Push an emitter to the stack. - * - * @param EmitterInterface $emitter - * @return void - * @throws InvalidArgumentException if not an EmitterInterface instance - */ - public function push($emitter) - { - $this->validateEmitter($emitter); - parent::push($emitter); - } - - /** - * Unshift an emitter to the stack. - * - * @param EmitterInterface $emitter - * @return void - * @throws InvalidArgumentException if not an EmitterInterface instance - */ - public function unshift($emitter) - { - $this->validateEmitter($emitter); - parent::unshift($emitter); - } - - /** - * Validate that an emitter implements EmitterInterface. - * - * @param mixed $emitter - * @return void - * @throws InvalidArgumentException for non-emitter instances - */ - private function validateEmitter($emitter) - { - if (! $emitter instanceof EmitterInterface) { - throw new Exception\InvalidArgumentException(sprintf( - '%s expects an EmitterInterface implementation', - __CLASS__ - )); - } - } -} diff --git a/test/Application/BadControllerTrait.php b/test/Application/BadControllerTrait.php index cd8b6ac6b..f824218ea 100644 --- a/test/Application/BadControllerTrait.php +++ b/test/Application/BadControllerTrait.php @@ -9,7 +9,6 @@ namespace ZendTest\Mvc\Application; -use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\View\Http\ViewManager; @@ -32,10 +31,6 @@ public function prepareApplication() }, ]]); }, - EmitterInterface::class => function () { - $emitter = $this->prophesize(EmitterInterface::class); - return $emitter->reveal(); - }, ], 'invokables' => [ ViewManager::class => TestAsset\MockViewManager::class, diff --git a/test/Application/InvalidControllerTypeTrait.php b/test/Application/InvalidControllerTypeTrait.php index 5b1ca8294..3e041fd85 100644 --- a/test/Application/InvalidControllerTypeTrait.php +++ b/test/Application/InvalidControllerTypeTrait.php @@ -10,7 +10,6 @@ namespace ZendTest\Mvc\Application; use stdClass; -use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\View\Http\ViewManager; @@ -32,10 +31,6 @@ public function prepareApplication() }, ]]); }, - EmitterInterface::class => function () { - $emitter = $this->prophesize(EmitterInterface::class); - return $emitter->reveal(); - }, ], 'invokables' => [ ViewManager::class => TestAsset\MockViewManager::class, diff --git a/test/Application/MissingControllerTrait.php b/test/Application/MissingControllerTrait.php index d313d2e9d..a34d9ef7d 100644 --- a/test/Application/MissingControllerTrait.php +++ b/test/Application/MissingControllerTrait.php @@ -9,7 +9,6 @@ namespace ZendTest\Mvc\Application; -use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\View\Http\ViewManager; use Zend\Router; @@ -23,10 +22,6 @@ public function prepareApplication() $config = ApplicationConfigHelper::getConfig([ 'dependencies' => [ 'factories' => [ - EmitterInterface::class => function () { - $emitter = $this->prophesize(EmitterInterface::class); - return $emitter->reveal(); - }, ], 'invokables' => [ ViewManager::class => TestAsset\MockViewManager::class, diff --git a/test/Application/PathControllerTrait.php b/test/Application/PathControllerTrait.php index ac40a5e44..bd6cfac77 100644 --- a/test/Application/PathControllerTrait.php +++ b/test/Application/PathControllerTrait.php @@ -9,7 +9,6 @@ namespace ZendTest\Mvc\Application; -use Zend\Diactoros\Response\EmitterInterface; use Zend\Mvc\Application; use Zend\Mvc\Controller\ControllerManager; use Zend\Mvc\View\Http\ViewManager; @@ -31,10 +30,6 @@ public function prepareApplication() }, ]]); }, - EmitterInterface::class => function () { - $emitter = $this->prophesize(EmitterInterface::class); - return $emitter->reveal(); - }, ], 'invokables' => [ ViewManager::class => TestAsset\MockViewManager::class, diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index f1c51d1bf..c56b8ffcd 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -13,7 +13,6 @@ use Prophecy\Prophecy\ObjectProphecy; use ReflectionProperty; use Zend\Diactoros\Response; -use Zend\Diactoros\Response\EmitterInterface; use Zend\Diactoros\ServerRequest; use Zend\EventManager\EventManager; use Zend\EventManager\ListenerAggregateInterface; @@ -51,11 +50,6 @@ class ApplicationTest extends TestCase */ private $router; - /** - * @var ObjectProphecy - */ - private $emitter; - /** * @var EventManager */ @@ -71,7 +65,6 @@ public function setUp() $this->container = $this->mockContainerInterface(); $this->router = $this->prophesize(RouteStackInterface::class); - $this->emitter = $this->prophesize(EmitterInterface::class); $this->events = new EventManager(new SharedEventManager()); $this->injectServiceInContainer($this->container, 'config', []); @@ -99,8 +92,7 @@ public function setUp() $this->application = new Application( $this->container->reveal(), $this->router->reveal(), - $this->events, - $this->emitter->reveal() + $this->events ); } @@ -161,7 +153,6 @@ public function testBootstrapAlwaysRegistersDefaultListeners() $this->container->reveal(), $this->router->reveal(), $this->events, - $this->emitter->reveal(), ['Custom'] ); @@ -189,7 +180,6 @@ public function testBootstrapAttachesInstanceOfListenerAggregate() $this->container->reveal(), $this->router->reveal(), $this->events, - $this->emitter->reveal(), [$custom->reveal()] ); @@ -504,26 +494,6 @@ function (MvcEvent $e) use ($testResponse) { $this->assertSame($testResponse, $response); } - public function testEmitterGetterReturnsInjectedEmitter() - { - $emitter = $this->application->getEmitter(); - $this->assertSame($this->emitter->reveal(), $emitter); - } - - public function testRunInvokesEmitterForResponse() - { - $response = new Response(); - $this->application->getEventManager()->attach( - MvcEvent::EVENT_DISPATCH, - function () use ($response) { - return $response; - } - ); - $this->emitter->emit($response)->shouldBeCalled(); - $request = new ServerRequest([], [], 'http://example.local/sample', 'GET', 'php://memory'); - $this->application->run($request); - } - public function eventPropagation() { return [ diff --git a/test/Container/ApplicationFactoryTest.php b/test/Container/ApplicationFactoryTest.php index 3b08b3820..4b5989df5 100644 --- a/test/Container/ApplicationFactoryTest.php +++ b/test/Container/ApplicationFactoryTest.php @@ -10,8 +10,6 @@ use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; -use Zend\Diactoros\Response\EmitterInterface; -use Zend\Diactoros\Response\SapiEmitter; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\ListenerAggregateInterface; @@ -19,7 +17,6 @@ use Zend\Mvc\Container\ApplicationFactory; use PHPUnit\Framework\TestCase; use Zend\Mvc\DispatchListener; -use Zend\Mvc\Emitter\EmitterStack; use Zend\Mvc\HttpMethodListener; use Zend\Mvc\MiddlewareListener; use Zend\Mvc\RouteListener; @@ -49,11 +46,6 @@ class ApplicationFactoryTest extends TestCase */ private $router; - /** - * @var ObjectProphecy|EmitterInterface - */ - private $emitter; - /** * @var EventManager */ @@ -65,34 +57,12 @@ public function setUp() $this->factory = new ApplicationFactory(); $this->router = $this->prophesize(RouteStackInterface::class); - $this->emitter = $this->prophesize(EmitterInterface::class); $this->events = $this->prophesize(EventManagerInterface::class); $this->injectServiceInContainer($this->container, 'Zend\Mvc\Router', $this->router); $this->injectServiceInContainer($this->container, 'EventManager', $this->events); $this->injectServiceInContainer($this->container, 'config', []); } - - public function testInjectsEmitterWhenAvailable() - { - $this->injectServiceInContainer( - $this->container, - EmitterInterface::class, - $this->emitter->reveal() - ); - $app = $this->factory->__invoke($this->container->reveal(), Application::class); - $this->assertSame($this->emitter->reveal(), $app->getEmitter()); - } - - public function testInjectsNewEmitterStackWhenEmitterNotInContainer() - { - $app = $this->factory->__invoke($this->container->reveal(), Application::class); - $emitter = $app->getEmitter(); - $this->assertInstanceOf(EmitterStack::class, $emitter); - $this->assertCount(1, $emitter); - $this->assertInstanceOf(SapiEmitter::class, $emitter[0]); - } - public function testInjectsListenersFromConfig() { // application default listeners From bf93aa5e64e688a4f2bc7a50679c152bac289cae Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Thu, 8 Feb 2018 15:51:24 +1000 Subject: [PATCH 51/51] Drop getConfig() from Application --- src/Application.php | 10 ---------- test/ApplicationTest.php | 11 ----------- 2 files changed, 21 deletions(-) diff --git a/src/Application.php b/src/Application.php index 7082152d2..2cd33ec69 100644 --- a/src/Application.php +++ b/src/Application.php @@ -129,16 +129,6 @@ public function __construct( // @TODO response prototype? } - /** - * Retrieve the application configuration - * - * @return array|object - */ - public function getConfig() - { - return $this->container->get('config'); - } - /** * Bootstrap the application * diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index c56b8ffcd..e9a841ae1 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -115,17 +115,6 @@ public function testContainerIsPopulated() $this->assertSame($this->container->reveal(), $this->application->getContainer()); } - public function testConfigIsAProxyToContainer() - { - $this->container->get('config') - ->shouldBeCalled() - ->willReturn(['container' => 'config']); - $appConfig = $this->application->getConfig(); - $this->assertEquals( - ['container' => 'config'], - $appConfig - ); - } public function testEventsAreEmptyAtFirst() {