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

Commit 9d2f1db

Browse files
committed
Consume zend-router as a module/config provider
This patch updates the `ServiceListener` to remove all router entries, in favor of consuming zend-router as a module/configuration provider. For tests to pass, this required changes to test setup entries to do one of the following: - add the `Zend\Router` module to the list of active modules, relying on the `ModuleManager` to aggregate and configure its factories. - pull dependency configuration from the zend-router `ConfigProvider` when setting up initial dependencies for minimal tests that do not use the `ModuleManager` for application initialization.
1 parent 3651cb4 commit 9d2f1db

9 files changed

+38
-25
lines changed

src/Service/ServiceListenerFactory.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Zend\ModuleManager\Listener\ServiceListenerInterface;
1717
use Zend\Mvc\Application;
1818
use Zend\Mvc\View;
19-
use Zend\Router;
2019
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
2120
use Zend\ServiceManager\FactoryInterface;
2221
use Zend\ServiceManager\Factory\InvokableFactory;
@@ -77,8 +76,6 @@ class ServiceListenerFactory implements FactoryInterface
7776
'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory',
7877
'ConsoleAdapter' => 'Zend\Mvc\Service\ConsoleAdapterFactory',
7978
'ConsoleExceptionStrategy' => ConsoleExceptionStrategyFactory::class,
80-
// @todo Re-enable (and re-map) once zend-mvc-console is ready
81-
// 'ConsoleRouter' => ConsoleRouterFactory::class,
8279
'ConsoleRouteNotFoundStrategy' => ConsoleRouteNotFoundStrategyFactory::class,
8380
'ConsoleViewManager' => 'Zend\Mvc\Service\ConsoleViewManagerFactory',
8481
'DependencyInjector' => DiFactory::class,
@@ -92,7 +89,6 @@ class ServiceListenerFactory implements FactoryInterface
9289
'HttpExceptionStrategy' => HttpExceptionStrategyFactory::class,
9390
'HttpMethodListener' => 'Zend\Mvc\Service\HttpMethodListenerFactory',
9491
'HttpRouteNotFoundStrategy' => HttpRouteNotFoundStrategyFactory::class,
95-
'HttpRouter' => Router\Http\HttpRouterFactory::class,
9692
'HttpViewManager' => 'Zend\Mvc\Service\HttpViewManagerFactory',
9793
'HydratorManager' => 'Zend\Mvc\Service\HydratorManagerFactory',
9894
'InjectTemplateListener' => 'Zend\Mvc\Service\InjectTemplateListenerFactory',
@@ -103,8 +99,6 @@ class ServiceListenerFactory implements FactoryInterface
10399
'PaginatorPluginManager' => 'Zend\Mvc\Service\PaginatorPluginManagerFactory',
104100
'Request' => 'Zend\Mvc\Service\RequestFactory',
105101
'Response' => 'Zend\Mvc\Service\ResponseFactory',
106-
'Router' => Router\RouterFactory::class,
107-
'RoutePluginManager' => Router\RoutePluginManagerFactory::class,
108102
'SerializerAdapterManager' => 'Zend\Mvc\Service\SerializerAdapterPluginManagerFactory',
109103
'TranslatorPluginManager' => 'Zend\Mvc\Service\TranslatorPluginManagerFactory',
110104
'ValidatorManager' => 'Zend\Mvc\Service\ValidatorManagerFactory',
@@ -317,6 +311,5 @@ private function injectV3Aliases()
317311
$this->defaultServiceConfig['aliases']['Config'] = 'config';
318312
$this->defaultServiceConfig['aliases']['request'] = 'Request';
319313
$this->defaultServiceConfig['aliases']['response'] = 'Response';
320-
$this->defaultServiceConfig['aliases']['router'] = 'Router';
321314
}
322315
}

test/Application/BadControllerTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public function prepareApplication()
4747
$r->setAccessible(true);
4848
$serviceConfig = $r->getValue($serviceListener);
4949

50+
$serviceConfig = ArrayUtils::merge(
51+
$serviceConfig,
52+
(new Router\ConfigProvider())->getDependencyConfig()
53+
);
54+
5055
$serviceConfig = ArrayUtils::merge(
5156
$serviceConfig,
5257
[

test/Application/InitializationIntegrationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function testDefaultInitializationWorkflow()
2020
{
2121
$appConfig = [
2222
'modules' => [
23+
'Zend\Router',
2324
'Application',
2425
],
2526
'module_listener_options' => [

test/Application/InvalidControllerTypeTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public function prepareApplication()
4747
$r->setAccessible(true);
4848
$serviceConfig = $r->getValue($serviceListener);
4949

50+
$serviceConfig = ArrayUtils::merge(
51+
$serviceConfig,
52+
(new Router\ConfigProvider())->getDependencyConfig()
53+
);
54+
5055
$serviceConfig = ArrayUtils::merge(
5156
$serviceConfig,
5257
[

test/Application/MissingControllerTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function prepareApplication()
4545
$r->setAccessible(true);
4646
$serviceConfig = $r->getValue($serviceListener);
4747

48+
$serviceConfig = ArrayUtils::merge(
49+
$serviceConfig,
50+
(new Router\ConfigProvider())->getDependencyConfig()
51+
);
52+
4853
$serviceConfig = ArrayUtils::merge(
4954
$serviceConfig,
5055
[

test/Application/PathControllerTrait.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function prepareApplication()
4545
$r->setAccessible(true);
4646
$serviceConfig = $r->getValue($serviceListener);
4747

48+
$serviceConfig = ArrayUtils::merge(
49+
$serviceConfig,
50+
(new Router\ConfigProvider())->getDependencyConfig()
51+
);
52+
4853
$serviceConfig = ArrayUtils::merge(
4954
$serviceConfig,
5055
[
@@ -74,7 +79,9 @@ public function prepareApplication()
7479
'services' => [
7580
'config' => $config,
7681
'ApplicationConfig' => [
77-
'modules' => [],
82+
'modules' => [
83+
'Zend\Router',
84+
],
7885
'module_listener_options' => [
7986
'config_cache_enabled' => false,
8087
'cache_dir' => 'data/cache',

test/ApplicationTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public function setUp()
4949
$r->setAccessible(true);
5050
$serviceConfig = $r->getValue($serviceListener);
5151

52+
$serviceConfig = ArrayUtils::merge(
53+
$serviceConfig,
54+
(new Router\ConfigProvider())->getDependencyConfig()
55+
);
56+
5257
$serviceConfig = ArrayUtils::merge(
5358
$serviceConfig,
5459
[
@@ -65,7 +70,9 @@ public function setUp()
6570
'services' => [
6671
'config' => [],
6772
'ApplicationConfig' => [
68-
'modules' => [],
73+
'modules' => [
74+
'Zend\Router',
75+
],
6976
'module_listener_options' => [
7077
'config_cache_enabled' => false,
7178
'cache_dir' => 'data/cache',

test/Service/ServiceListenerFactoryTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,4 @@ public function testDefinesExpectedResponseFactories()
259259
$this->assertArrayHasKey('response', $config['aliases'], 'Missing "response" alias from default service config');
260260
// @codingStandardsIgnoreEnd
261261
}
262-
263-
public function testDefinesExpectedRouterAliases()
264-
{
265-
if (! $this->isServiceManagerV3()) {
266-
$this->markTestSkipped('Router aliases are only defined under zend-servicemanager v3');
267-
}
268-
269-
$r = new ReflectionProperty($this->factory, 'defaultServiceConfig');
270-
$r->setAccessible(true);
271-
$config = $r->getValue($this->factory);
272-
273-
$this->assertArrayHasKey('aliases', $config, 'Missing aliases from default service config');
274-
$this->assertArrayHasKey('router', $config['aliases'], 'Missing "router" alias from default service config');
275-
}
276262
}

test/Service/TranslatorServiceFactoryTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public function testSetsPluginManagerFromServiceLocatorBasedOnConfiguration()
9393
//minimum bootstrap
9494
$applicationConfig = [
9595
'module_listener_options' => [],
96-
'modules' => [],
96+
'modules' => [
97+
'Zend\Router',
98+
],
9799
];
98100
$config = new ServiceManagerConfig(['services' => [
99101
'ApplicationConfig' => $applicationConfig,
@@ -131,7 +133,9 @@ public function testReturnsTranslatorBasedOnConfigurationWhenNoTranslatorInterfa
131133
//minimum bootstrap
132134
$applicationConfig = [
133135
'module_listener_options' => [],
134-
'modules' => [],
136+
'modules' => [
137+
'Zend\Router',
138+
],
135139
];
136140
$config = new ServiceManagerConfig(['services' => [
137141
'ApplicationConfig' => $applicationConfig,

0 commit comments

Comments
 (0)