-
Notifications
You must be signed in to change notification settings - Fork 196
Updates to zend-expressive-router 3.0.0alpha2 #551
Updates to zend-expressive-router 3.0.0alpha2 #551
Conversation
Also ensures we pin to alpha or greater dependencies everywhere `-dev` dependencies were previously used.
…o their middleware These middleware were moved to the `Zend\Expressive\Router\Middleware` namespace, and now have factories defined in that package. As such, their factories can be removed here, and all references to the classes require updates internally. Since the routing middleware no longer handles 405 conditions, the router integration tests were updated to pipe the new `Zend\Expressive\Router\MethodNotAllowedMiddleware`, and the application config injector now pipes it when piping routing and dispatch middleware in order to ensure the same workflow occurs between versions.
These classes are now present in zend-expressive-router, and thus do not need to be here. This also updates references to these middleware in the router integration test to ensure tests continue to pass.
Renames `Zend\Expressive\Middleware\NotFoundMiddleware` to `Zend\Expressive\Handler\NotFoundHandler`. This is done to allow usage in more contexts. Since it was already acting like a handler, by having it explicitly be one, we can use it as one. The MiddlewareFactory will decorate it as middleware when piped, allowing it to be used in that context as well.
Per the discussion on zendframework/zend-expressive-skeleton#220, this commit converts virtual service names to constants. In each case, the original resolved value of the virtual class name is used as the constant value, but the config provider and factories now refer to the constants instead. Additionally, the `RouterResponseInterface` constant was discovered to be no longer needed, due to the extraction of route-related middleware to the zend-expressive-router package.
Adds a StreamFactory, using the ResponseFactory and its tests as a template; this new factory produces a writable zend-diactoros Stream instance backed by a `php://temp` stream. The factory is then mapped to the `Zend\Expressive\Router\IMPLICIT_HEAD_MIDDLEWARE_STREAM_FACTORY` service.
…es not produce an Application instance Instead of just returning the value, we need to raise an exception in order to warn users that they have applied the delegator factory to a service it cannot decorate.
…tor::createCollectionMapper It was refering to a practice from v2 that will not be allowed in v3. Updated the docblock as well.
{ | ||
$application = $callback(); | ||
if (! $application instanceof Application) { | ||
return $application; | ||
throw new Exception\InvalidServiceException(sprintf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not static method in exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one hasn't had one defined ever. I can add some later, but in most cases, we'll have different messages for every single factory, making it less viable.
* // - entry \Zend\Expressive\Router\DispatchMiddleware::class | ||
* // - entry for \Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware::class | ||
* // - entry for \Zend\Expressive\Router\Middleware\MethodNotAllowedMiddleware::class | ||
* // - entry \Zend\Expressive\Router\Middleware\DispatchMiddleware::class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency should we have entry for...
?
src/constants.php
Outdated
* | ||
* @var string | ||
*/ | ||
const SERVER_REQUEST_ERROR_RESPONSE_GENERATOR = __NAMESPACE__ . '\Expressive\ServerRequestErrorResponseGenerator'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__NAMESPACE__
is Zend\Expressive
, should we have \Expressive
part twice here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch; fixing!
src/constants.php
Outdated
* | ||
* @var string | ||
*/ | ||
const SERVER_REQUEST_FACTORY = __NAMESPACE__ . '\Expressive\ServerRequestFactory'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
test/Router/IntegrationTest.php
Outdated
@@ -103,6 +106,7 @@ private function createApplicationWithGetPost($adapter, $getName = null, $postNa | |||
$router = new $adapter(); | |||
$app = $this->createApplicationFromRouter($router); | |||
$app->pipe(new RouteMiddleware($router, $this->response)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and in many other usages - the second parameter should be remove, RouteMiddleware::__construct
has now one parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another nice catch! Fixing!
Only accepts the router instance as of 3.0.0alpha2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
zend-expressive-router 3.0.0alpha2 renames middleware it previously defined, defines new middleware, and creates a number of new package-level constants for virtual services.
This patch:
RouteMiddlewareFactory
andDispatchMiddlewareFactory
, as these are now provided by the zend-expressive-router package, and registered to the container by that package's config provider.Implicit*Middleware
classes and related factories; these are now provided by the zend-expressive-router package.Middleware\NotFoundMiddleware
toHandler\NotFoundHandler
, and renames its factory accordingly. The class was acting as a handler, and can be used in more contexts as a handler than as middleware.Zend\Expressive\Container\StreamFactory
, for producing empty, writable stream instances.ConfigAggregator
was updated to use the new package-level constants, re-map the various aliases to the new services they refer to, and to add entries for various zend-expressive-router virtual services.ApplicationConfigInjectionDelegator
now raises an exception if the callback provided to it does not produce anApplication
instance.ApplicationConfigInjectionDelegator
changes on exception message to remove details that are not relevant in the 3.0 branch.These should likely be the last breaking changes for this package before the 3.0.0 release.