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

Provide utility functions for decorating non-standard middleware #136

Conversation

weierophinney
Copy link
Member

Per discussion on #134, this patch provides two utility functions for decorating non-standard middleware.

closure() allows decorating callables that follow the PSR-15 middleware interface signature via a CallableMiddlewareDecorator instance:

function Zend\Stratigility\closure(
    callable $middleware
) : Zend\Stratigility\Middleware\CallableMiddlewareDecorator

doublePass() allows decorating callables that follow the double-pass middleware signature (function ($request, $response, callable $next)) via a DoublePassMiddlewareDecorator instance:

function Zend\Stratigility\doublePass(
    callable $middleware,
    Psr\Http\Message\ResponseInterface $response = null
) : Zend\Stratigility\Middleware\DoublePassMiddlewareDecorator

The doublePass() function optionally takes a second argument, a response prototype, for use cases where zend-diactoros is not being used as a PSR-7 implementation.

TODO

@weierophinney weierophinney added this to the 3.0.0alpha2 milestone Jan 10, 2018
* <code>
* $pipeline->pipe(doublePass(function ($req, $handler) {
* // do some work
* }, $responsePrototype));
Copy link
Member

Choose a reason for hiding this comment

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

Closing tag </code> is missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed and force pushed update.

@weierophinney weierophinney force-pushed the feature/utility-decorator-functions branch from cccbd62 to c7d3fa5 Compare January 10, 2018 21:09
*/
function closure(callable $middleware) : Middleware\CallableMiddlewareDecorator
{
return Middleware\CallableMiddlewareDecorator($middleware);

Choose a reason for hiding this comment

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

new is missing?

*/
function doublePass(callable $middleware, ResponseInterface $response = null) : Middleware\DoublePassMiddlewareDecorator
{
return Middleware\DoublePassMiddlewareDecorator($middleware, $response);

Choose a reason for hiding this comment

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

new is missing?

*/
function doublePass(callable $middleware, ResponseInterface $response = null) : Middleware\DoublePassMiddlewareDecorator
{
return Middleware\DoublePassMiddlewareDecorator($middleware, $response);

Choose a reason for hiding this comment

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

new is missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great eye! Fixed and pushed!

@franzliedke franzliedke mentioned this pull request Jan 12, 2018
@danizord
Copy link

@weierophinney I feel like the name middleware(function ($request, $handler) {}) would look more readable than closure(function($request, $handler) {}). What do you think? Same for doublePassMiddleware().

Also, I'd suggest creating a requestHandler() for closure implementations of RequestHandlerInterface as well. If you agree I can send a PR. :)

@weierophinney
Copy link
Member Author

Also, I'd suggest creating a requestHandler() for closure implementations of RequestHandlerInterface as well. If you agree I can send a PR. :)

I'm not sure we have much of a need for it within Stratigility itself. Where would you see developers using this, exactly?

@weierophinney
Copy link
Member Author

I feel like the name middleware(function ($request, $handler) {}) would look more readable than closure(function($request, $handler) {}). What do you think? Same for doublePassMiddleware().

I suppose; if we do, would you have us change the path() utility function to pathMiddleware() as well? (Asking, so I know whether or not to update #134!)

`closure()` acts as a convenience wrapper around instantiation of a
`CallableMiddlewareDecorator` instance.
`Zend\Stratigility\doublePass` provides a convenience wrapper around
creation of a DoublePassMiddlewareDecorator instance.
@weierophinney weierophinney force-pushed the feature/utility-decorator-functions branch from 38de813 to 457a6d3 Compare January 15, 2018 22:27
- `closure` => `middleware`
- `doublePass` => `doublePassMiddleware`
Each is now documented in the API documentation, the migration
documentation, and the chapters on middleare creation.
@weierophinney weierophinney merged commit 7caa54a into zendframework:release-3.0.0 Jan 15, 2018
weierophinney added a commit that referenced this pull request Jan 15, 2018
@weierophinney
Copy link
Member Author

Thanks, @danizord, for the feedback; renamed the functions "middleware" and "doublePassMiddleware".

@weierophinney weierophinney deleted the feature/utility-decorator-functions branch January 15, 2018 22:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants