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

Commit 35344a4

Browse files
committed
Merge branch 'feature/expressive-routecollector' into develop
Close #584
2 parents 889eadd + 5520ab8 commit 35344a4

10 files changed

+45
-124
lines changed

CHANGELOG.md

+7-11
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ All notable changes to this project will be documented in this file, in reverse
6969
`Zend\HttpHandlerRunner\RequestHandlerRunner` instance, using the services
7070
`Zend\Expressive\Application`, `Zend\HttpHandlerRunner\Emitter\EmitterInterface`,
7171
`Zend\Expressive\ServerRequestFactory`, and `Zend\Expressive\ServerRequestErrorResponseGenerator`.
72-
- `RouteMiddlewareFactory`: creates and returns a `Zend\Expressive\Router\PathBasedRoutingMiddleware` instance.
7372
- `ServerRequestFactoryFactory`: creates and returns a `callable` factory for
7473
generating a PSR-7 `ServerRequestInterface` instance; this returned factory is a
7574
dependency for the `Zend\HttpHandlerRunner\RequestHandlerRunner` service.
@@ -146,7 +145,7 @@ All notable changes to this project will be documented in this file, in reverse
146145

147146
- `Zend\Expressive\MiddlewareFactory`
148147
- `Zend\Stratigility\MiddlewarePipe`; this is the pipeline representing the application.
149-
- `Zend\Expressive\Router\PathBasedRoutingMiddleware`
148+
- `Zend\Expressive\Router\RouteCollector`
150149
- `Zend\HttpHandlerRunner\RequestHandlerRunner`
151150

152151
It removes all "getter" methods (as detailed in the "Removed" section of this
@@ -169,8 +168,8 @@ All notable changes to this project will be documented in this file, in reverse
169168

170169
- `route(string $path, $middleware, array $methods = null, string $name) : Route`
171170
passes its `$middleware` argument to the `MiddlewareFactory::prepare()`
172-
method, and then all arguments to the composed `PathBasedRoutingMiddleware`
173-
instance's `route()` method.
171+
method, and then all arguments to the composed `RouteCollector` instance's
172+
`route()` method.
174173

175174
As a result of switching to use the `MiddlewareFactory` to prepare
176175
middleware, you may now route to `RequestHandlerInterface` instances as
@@ -179,8 +178,7 @@ All notable changes to this project will be documented in this file, in reverse
179178
- Each of `get`, `post`, `patch`, `put`, `delete`, and `any` now proxy to
180179
`route()` after marshaling the correct `$methods`.
181180

182-
- `getRoutes() : Route[]` proxies to the composed `PathBasedRoutingMiddleware`
183-
instance.
181+
- `getRoutes() : Route[]` proxies to the composed `RouteCollector` instance.
184182

185183
- `handle(ServerRequestInterface $request) : ResponseInterface` proxies to the
186184
composed `MiddlewarePipe` instance's `handle()` method.
@@ -200,7 +198,7 @@ All notable changes to this project will be documented in this file, in reverse
200198
- `Zend\Stratigility\ApplicationPipeline`, which should resolve to a
201199
`MiddlewarePipe` instance; use the
202200
`Zend\Expressive\Container\ApplicationPipelineFactory`.
203-
- `Zend\Expressive\Router\PathBasedRoutingMiddleware`
201+
- `Zend\Expressive\Router\RouteCollector`
204202
- `Zend\HttpHandlerRunner\RequestHandlerRunner`
205203

206204
- [#581](https://github.com/zendframework/zend-expressive/pull/581)
@@ -274,9 +272,7 @@ All notable changes to this project will be documented in this file, in reverse
274272

275273
- [#543](https://github.com/zendframework/zend-expressive/pull/543) removes the
276274
class `Zend\Expressive\Middleware\RouteMiddleware`. Use the
277-
`PathBasedRoutingMiddleware` or `RouteMiddleware` from zend-expressive-router
278-
instead; the factory `Zend\Expressive\Container\RouteMiddlewareFactory` will
279-
return a `PathBasedRoutingMiddleware` instance for you.
275+
`RouteMiddleware` from zend-expressive-router instead.
280276

281277
- [#543](https://github.com/zendframework/zend-expressive/pull/543) removes the
282278
class `Zend\Expressive\Middleware\DispatchMiddleware`. Use the
@@ -291,7 +287,7 @@ All notable changes to this project will be documented in this file, in reverse
291287
- [#543](https://github.com/zendframework/zend-expressive/pull/543) removes the
292288
following methods from `Zend\Expressive\Application`:
293289

294-
- `pipeRoutingMiddleware()`: use `pipe(\Zend\Expressive\Router\PathBasedRoutingMiddleware::class)` instead.
290+
- `pipeRoutingMiddleware()`: use `pipe(\Zend\Expressive\Router\RouteMiddleware::class)` instead.
295291
- `pipeDispatchMiddleware()`: use `pipe(\Zend\Expressive\Router\DispatchMiddleware::class)` instead.
296292
- `getContainer()`
297293
- `getDefaultDelegate()`: ensure you pipe middleware or a request handler

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"psr/container": "^1.0",
2828
"psr/http-message": "^1.0.1",
2929
"psr/http-server-middleware": "^1.0",
30-
"zendframework/zend-expressive-router": "^3.0.0rc4",
30+
"zendframework/zend-expressive-router": "^3.0.0rc5",
3131
"zendframework/zend-expressive-template": "^2.0.0alpha1",
3232
"zendframework/zend-httphandlerrunner": "^1.0.1",
3333
"zendframework/zend-stratigility": "^3.0.0rc1"

composer.lock

+10-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Application.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Psr\Http\Message\ServerRequestInterface;
1414
use Psr\Http\Server\MiddlewareInterface;
1515
use Psr\Http\Server\RequestHandlerInterface;
16-
use Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware;
16+
use Zend\Expressive\Router\RouteCollector;
1717
use Zend\HttpHandlerRunner\RequestHandlerRunner;
1818
use Zend\Stratigility\MiddlewarePipeInterface;
1919

@@ -32,7 +32,7 @@ class Application implements MiddlewareInterface, RequestHandlerInterface
3232
private $pipeline;
3333

3434
/**
35-
* @var PathBasedRoutingMiddleware
35+
* @var RouteCollector
3636
*/
3737
private $routes;
3838

@@ -44,7 +44,7 @@ class Application implements MiddlewareInterface, RequestHandlerInterface
4444
public function __construct(
4545
MiddlewareFactory $factory,
4646
MiddlewarePipeInterface $pipeline,
47-
PathBasedRoutingMiddleware $routes,
47+
RouteCollector $routes,
4848
RequestHandlerRunner $runner
4949
) {
5050
$this->factory = $factory;

src/ConfigProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getDependencies() : array
4040
IMPLICIT_HEAD_MIDDLEWARE => Router\Middleware\ImplicitHeadMiddleware::class,
4141
IMPLICIT_OPTIONS_MIDDLEWARE => Router\Middleware\ImplicitOptionsMiddleware::class,
4242
NOT_FOUND_MIDDLEWARE => Handler\NotFoundHandler::class,
43-
ROUTE_MIDDLEWARE => Router\Middleware\PathBasedRoutingMiddleware::class,
43+
ROUTE_MIDDLEWARE => Router\Middleware\RouteMiddleware::class,
4444
],
4545
'factories' => [
4646
Application::class => Container\ApplicationFactory::class,

src/Container/ApplicationFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Zend\Expressive\Application;
1414
use Zend\Expressive\ApplicationPipeline;
1515
use Zend\Expressive\MiddlewareFactory;
16-
use Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware;
16+
use Zend\Expressive\Router\RouteCollector;
1717
use Zend\HttpHandlerRunner\RequestHandlerRunner;
1818

1919
/**
@@ -25,7 +25,7 @@
2525
* - Zend\Expressive\MiddlewareFactory.
2626
* - Zend\Expressive\ApplicationPipeline, which should resolve to a
2727
* Zend\Stratigility\MiddlewarePipeInterface instance.
28-
* - Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware.
28+
* - Zend\Expressive\Router\RouteCollector.
2929
* - Zend\HttpHandler\RequestHandlerRunner.
3030
*/
3131
class ApplicationFactory
@@ -35,7 +35,7 @@ public function __invoke(ContainerInterface $container) : Application
3535
return new Application(
3636
$container->get(MiddlewareFactory::class),
3737
$container->get(ApplicationPipeline::class),
38-
$container->get(PathBasedRoutingMiddleware::class),
38+
$container->get(RouteCollector::class),
3939
$container->get(RequestHandlerRunner::class)
4040
);
4141
}

test/ApplicationTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use TypeError;
2020
use Zend\Expressive\Application;
2121
use Zend\Expressive\MiddlewareFactory;
22-
use Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware as RouteMiddleware;
2322
use Zend\Expressive\Router\Route;
23+
use Zend\Expressive\Router\RouteCollector;
2424
use Zend\HttpHandlerRunner\RequestHandlerRunner;
2525
use Zend\Stratigility\Middleware\PathMiddlewareDecorator;
2626
use Zend\Stratigility\MiddlewarePipe;
@@ -32,7 +32,7 @@ public function setUp()
3232
{
3333
$this->factory = $this->prophesize(MiddlewareFactory::class);
3434
$this->pipeline = $this->prophesize(MiddlewarePipeInterface::class);
35-
$this->routes = $this->prophesize(RouteMiddleware::class);
35+
$this->routes = $this->prophesize(RouteCollector::class);
3636
$this->runner = $this->prophesize(RequestHandlerRunner::class);
3737

3838
$this->app = new Application(
@@ -333,7 +333,7 @@ public function testAnyMethodPassesNullForMethodWhenAllArgumentsPresent($middlew
333333
$this->assertSame($route, $this->app->any('/foo', $middleware, 'foo'));
334334
}
335335

336-
public function testGetRoutesProxiesToRouteMiddleware()
336+
public function testGetRoutesProxiesToRouteCollector()
337337
{
338338
$route = $this->prophesize(Route::class)->reveal();
339339
$this->routes->getRoutes()->willReturn([$route]);

test/Container/ApplicationConfigInjectionDelegatorTest.php

+9-84
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
use Zend\Expressive\MiddlewareFactory;
2626
use Zend\Expressive\Router\Middleware\DispatchMiddleware;
2727
use Zend\Expressive\Router\Middleware\MethodNotAllowedMiddleware;
28-
use Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware;
28+
use Zend\Expressive\Router\Middleware\RouteMiddleware;
2929
use Zend\Expressive\Router\Route;
30+
use Zend\Expressive\Router\RouteCollector;
3031
use Zend\Expressive\Router\RouterInterface;
3132
use Zend\HttpHandlerRunner\RequestHandlerRunner;
3233
use Zend\Stratigility\MiddlewarePipe;
@@ -46,7 +47,10 @@ class ApplicationConfigInjectionDelegatorTest extends TestCase
4647
/** @var MethodNotAllowedMiddleware|ObjectProphecy */
4748
private $methodNotAllowedMiddleware;
4849

49-
/** @var PathBasedRoutingMiddleware */
50+
/** @var RouteCollector */
51+
private $routeCollector;
52+
53+
/** @var RouteMiddleware */
5054
private $routeMiddleware;
5155

5256
/** @var RouterInterface|ObjectProphecy */
@@ -56,10 +60,8 @@ public function setUp()
5660
{
5761
$this->container = $this->mockContainerInterface();
5862
$this->router = $this->prophesize(RouterInterface::class);
59-
$this->routeMiddleware = new PathBasedRoutingMiddleware(
60-
$this->router->reveal(),
61-
new Response()
62-
);
63+
$this->routeCollector = new RouteCollector($this->router->reveal());
64+
$this->routeMiddleware = new RouteMiddleware($this->router->reveal());
6365
$this->dispatchMiddleware = $this->prophesize(DispatchMiddleware::class)->reveal();
6466
$this->methodNotAllowedMiddleware = $this->prophesize(MethodNotAllowedMiddleware::class)->reveal();
6567
}
@@ -73,7 +75,7 @@ public function createApplication()
7375
return new Application(
7476
$factory,
7577
$pipeline,
76-
$this->routeMiddleware,
78+
$this->routeCollector,
7779
$runner
7880
);
7981
}
@@ -139,63 +141,6 @@ public static function assertPipelineContainsInstanceOf($class, $pipeline, $mess
139141
Assert::assertThat($found, Assert::isTrue(), $message);
140142
}
141143

142-
public static function assertRouteMiddleware(MiddlewareInterface $middleware)
143-
{
144-
if ($middleware instanceof PathBasedRoutingMiddleware) {
145-
Assert::assertInstanceOf(PathBasedRoutingMiddleware::class, $middleware);
146-
return;
147-
}
148-
149-
if (! $middleware instanceof Middleware\LazyLoadingMiddleware) {
150-
Assert::fail('Middleware is not an instance of PathBasedRoutingMiddleware');
151-
}
152-
153-
Assert::assertAttributeSame(
154-
PathBasedRoutingMiddleware::class,
155-
'middlewareName',
156-
$middleware,
157-
'Middleware is not an instance of PathBasedRoutingMiddleware'
158-
);
159-
}
160-
161-
public static function assertDispatchMiddleware(MiddlewareInterface $middleware)
162-
{
163-
if ($middleware instanceof DispatchMiddleware) {
164-
Assert::assertInstanceOf(DispatchMiddleware::class, $middleware);
165-
return;
166-
}
167-
168-
if (! $middleware instanceof Middleware\LazyLoadingMiddleware) {
169-
Assert::fail('Middleware is not an instance of DispatchMiddleware');
170-
}
171-
172-
Assert::assertAttributeSame(
173-
DispatchMiddleware::class,
174-
'middlewareName',
175-
$middleware,
176-
'Middleware is not an instance of DispatchMiddleware'
177-
);
178-
}
179-
180-
public static function assertMethodNotAllowedMiddleware(MiddlewareInterface $middleware)
181-
{
182-
if ($middleware instanceof MethodNotAllowedMiddleware) {
183-
Assert::assertInstanceOf(MethodNotAllowedMiddleware::class, $middleware);
184-
return;
185-
}
186-
187-
if (! $middleware instanceof Middleware\LazyLoadingMiddleware) {
188-
Assert::fail('Middleware is not an instance of MethodNotAllowedMiddleware');
189-
}
190-
191-
Assert::assertAttributeSame(
192-
MethodNotAllowedMiddleware::class,
193-
'middlewareName',
194-
$middleware,
195-
'Middleware is not an instance of MethodNotAllowedMiddleware'
196-
);
197-
}
198-
199144
public function callableMiddlewares()
200145
{
201146
return [
@@ -416,16 +361,6 @@ public function testInjectRoutesFromConfigWillSkipSpecsThatOmitPath()
416361
],
417362
];
418363
$this->container->has('config')->willReturn(false);
419-
$this->injectServiceInContainer(
420-
$this->container,
421-
PathBasedRoutingMiddleware::class,
422-
$this->routeMiddleware
423-
);
424-
$this->injectServiceInContainer(
425-
$this->container,
426-
DispatchMiddleware::class,
427-
$this->dispatchMiddleware
428-
);
429364

430365
$app = $this->createApplication();
431366

@@ -447,16 +382,6 @@ public function testInjectRoutesFromConfigWillSkipSpecsThatOmitMiddleware()
447382
],
448383
];
449384
$this->container->has('config')->willReturn(false);
450-
$this->injectServiceInContainer(
451-
$this->container,
452-
PathBasedRoutingMiddleware::class,
453-
$this->routeMiddleware
454-
);
455-
$this->injectServiceInContainer(
456-
$this->container,
457-
DispatchMiddleware::class,
458-
$this->dispatchMiddleware
459-
);
460385

461386
$app = $this->createApplication();
462387

0 commit comments

Comments
 (0)