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

Updates to zend-expressive-router 3.0.0alpha2 #551

Conversation

weierophinney
Copy link
Member

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:

  • Removes:
    • the RouteMiddlewareFactory and DispatchMiddlewareFactory, as these are now provided by the zend-expressive-router package, and registered to the container by that package's config provider.
    • the Implicit*Middleware classes and related factories; these are now provided by the zend-expressive-router package.
  • Renames:
    • the Middleware\NotFoundMiddleware to Handler\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.
  • Adds:
    • Zend\Expressive\Container\StreamFactory, for producing empty, writable stream instances.
    • Package-level constants by which virtual services may be referenced. In all cases, these refer to the FQCN variants previously used to ensure the old values continue to resolve; however, users are encouraged to use the new constants instead, as they will resolve, and because their docblocks will provide context for usage.
  • Changes:
    • The 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.
    • The ApplicationConfigInjectionDelegator now raises an exception if the callback provided to it does not produce an Application instance.
    • The 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.

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(
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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... ?

*
* @var string
*/
const SERVER_REQUEST_ERROR_RESPONSE_GENERATOR = __NAMESPACE__ . '\Expressive\ServerRequestErrorResponseGenerator';
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch; fixing!

*
* @var string
*/
const SERVER_REQUEST_FACTORY = __NAMESPACE__ . '\Expressive\ServerRequestFactory';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

@@ -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));
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nice catch! Fixing!

Copy link
Member

@michalbundyra michalbundyra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants