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

Commit 072d6b0

Browse files
committed
Merging develop to master in preparation for 3.1.0 release.
2 parents e28f3bd + 012484c commit 072d6b0

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 3.1.0 - 2018-06-05
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Changed
12+
13+
- [#76](https://github.com/zendframework/zend-expressive-router/pull/76) modifies the `RouteMiddlewareFactory` to allow specifying a string
14+
`$routererviceName` to its constructor. This change allows having discrete
15+
factory instances for generating route middleware that use different router
16+
instances.
17+
18+
### Deprecated
19+
20+
- Nothing.
21+
22+
### Removed
23+
24+
- Nothing.
25+
26+
### Fixed
27+
28+
- Nothing.
29+
530
## 3.0.4 - TBD
631

732
### Added

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
},
5252
"extra": {
5353
"branch-alias": {
54-
"dev-master": "3.0.x-dev",
55-
"dev-develop": "3.1.x-dev"
54+
"dev-master": "3.1.x-dev",
55+
"dev-develop": "3.2.x-dev"
5656
},
5757
"zf": {
5858
"config-provider": "Zend\\Expressive\\Router\\ConfigProvider"

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Middleware/RouteMiddlewareFactory.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,41 @@
2323
*/
2424
class RouteMiddlewareFactory
2525
{
26+
/** @var string */
27+
private $routerServiceName;
28+
29+
/**
30+
* Allow serialization
31+
*/
32+
public static function __set_state(array $data) : self
33+
{
34+
return new self(
35+
$data['routerServiceName'] ?? RouterInterface::class
36+
);
37+
}
38+
39+
/**
40+
* Provide the name of the router service to use when creating the route
41+
* middleware.
42+
*/
43+
public function __construct(string $routerServiceName = RouterInterface::class)
44+
{
45+
$this->routerServiceName = $routerServiceName;
46+
}
47+
2648
/**
2749
* @throws MissingDependencyException if the RouterInterface service is
2850
* missing.
2951
*/
3052
public function __invoke(ContainerInterface $container) : RouteMiddleware
3153
{
32-
if (! $container->has(RouterInterface::class)) {
54+
if (! $container->has($this->routerServiceName)) {
3355
throw MissingDependencyException::dependencyForService(
34-
RouterInterface::class,
56+
$this->routerServiceName,
3557
RouteMiddleware::class
3658
);
3759
}
3860

39-
return new RouteMiddleware($container->get(RouterInterface::class));
61+
return new RouteMiddleware($container->get($this->routerServiceName));
4062
}
4163
}

test/Middleware/RouteMiddlewareFactoryTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,27 @@ public function testFactoryProducesRouteMiddlewareWhenAllDependenciesPresent()
4949

5050
$this->assertInstanceOf(RouteMiddleware::class, $middleware);
5151
}
52+
53+
public function testFactoryAllowsSpecifyingRouterServiceViaConstructor()
54+
{
55+
$router = $this->prophesize(RouterInterface::class)->reveal();
56+
$this->container->has(Router::class)->willReturn(true);
57+
$this->container->get(Router::class)->willReturn($router);
58+
59+
$factory = new RouteMiddlewareFactory(Router::class);
60+
61+
$middleware = $factory($this->container->reveal());
62+
63+
$this->assertInstanceOf(RouteMiddleware::class, $middleware);
64+
$this->assertAttributeSame($router, 'router', $middleware);
65+
}
66+
67+
public function testFactoryIsSerializable()
68+
{
69+
$factory = RouteMiddlewareFactory::__set_state([
70+
'routerServiceName' => Router::class,
71+
]);
72+
73+
$this->assertAttributeSame(Router::class, 'routerServiceName', $factory);
74+
}
5275
}

0 commit comments

Comments
 (0)