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

Commit a5a95c0

Browse files
committed
Use the Zend\Expressive\ROUTE_MIDDLEWARE to retrieve the path-based routing middleware.
In order to make upgrading from v2 easier, we need to ensure that we use the same service name in the application factory as we use in the bootstrap. Since changing the bootstrap requires manual intervention, using the `Zend\Expressive\ROUTE_MIDDLEWARE` constant will present a simpler upgrade, as it resolves to a string matching the v2 middleware service name.
1 parent bf4a4f8 commit a5a95c0

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/Container/ApplicationFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
use Zend\Expressive\Application;
1414
use Zend\Expressive\ApplicationPipeline;
1515
use Zend\Expressive\MiddlewareFactory;
16-
use Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware;
1716
use Zend\HttpHandlerRunner\RequestHandlerRunner;
1817

18+
use const Zend\Expressive\ROUTE_MIDDLEWARE;
19+
1920
/**
2021
* Create an Application instance.
2122
*
@@ -35,7 +36,7 @@ public function __invoke(ContainerInterface $container) : Application
3536
return new Application(
3637
$container->get(MiddlewareFactory::class),
3738
$container->get(ApplicationPipeline::class),
38-
$container->get(PathBasedRoutingMiddleware::class),
39+
$container->get(ROUTE_MIDDLEWARE),
3940
$container->get(RequestHandlerRunner::class)
4041
);
4142
}

src/constants.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
* Should resolve to the Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware
7171
* service.
7272
*
73-
* @deprecated To remove in version 4.0.0.
7473
* @var string
7574
*/
7675
const ROUTE_MIDDLEWARE = __NAMESPACE__ . '\Middleware\RouteMiddleware';

test/Container/ApplicationFactoryTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Zend\HttpHandlerRunner\RequestHandlerRunner;
2020
use Zend\Stratigility\MiddlewarePipeInterface;
2121

22+
use const Zend\Expressive\ROUTE_MIDDLEWARE;
23+
2224
class ApplicationFactoryTest extends TestCase
2325
{
2426
public function testFactoryProducesAnApplication()
@@ -31,7 +33,7 @@ public function testFactoryProducesAnApplication()
3133
$container = $this->prophesize(ContainerInterface::class);
3234
$container->get(MiddlewareFactory::class)->willReturn($middlewareFactory);
3335
$container->get(ApplicationPipeline::class)->willReturn($pipeline);
34-
$container->get(PathBasedRoutingMiddleware::class)->willReturn($routeMiddleware);
36+
$container->get(ROUTE_MIDDLEWARE)->willReturn($routeMiddleware);
3537
$container->get(RequestHandlerRunner::class)->willReturn($runner);
3638

3739
$factory = new ApplicationFactory();

0 commit comments

Comments
 (0)