zend-stratigility v3.2.0 Release Notes
Release Date: 2019-06-12 // over 4 years ago-
โ Added
- Nothing.
๐ Changed
- #186 adds a safeguard to middleware pipes to prevent them from being called multiple times within the same middleware. As an example, consider the following middleware:
public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ) : Response Interface { $session = $request->getAttribute('session'); if (! $session) { $response = $handler->handle($request); } // Inject another attribute before handling $response = $handler->handle($request->withAttribute( 'sessionWasEnabled', true ); return $response; }
When using Stratigility, the
$handler
is an instance ofZend\Stratigility\Next
, which encapsulates the middleware pipeline and advances through it on each call tohandle()
.The example demonstrates a subtle error: the response from the first conditional should have been returned, but wasn't, which has led to invoking the handler a second time. This scenario can have unexpected behaviors, including always returning a "not found" response, or returning a response from a handler that was not supposed to execute (as an earlier middleware already returned early in the original call).
These bugs are hard to locate, as calling
handle()
is a normal part of any middleware, and multiple conditional calls to it are a standard workflow.With this new version,
Next
will pass a clone of itself to the next middleware in the pipeline, and unset its own internal pipeline queue. Any subsequent requests tohandle()
within the same scope will therefore result in the exceptionZend\Stratigility\Exception\MiddlewarePipeNextHandlerAlreadyCalledException
.If you depended on calling
$handler->handle()
multiple times in succession within middleware, we recommend that you compose the specific pipeline(s) and/or handler(s) you wish to call as class dependencies.๐ Deprecated
- Nothing.
โ Removed
- Nothing.
๐ Fixed
- Nothing.
Previous changes from v3.1.0
-
โ Added
- #178 adds the class
Zend\Stratigility\EmptyPipelineHandler
, which raises an
EmptyPipelineException
when it handles an incoming request. It's primary
purpose is for use in theMiddlewarePipe
as a fallback handler during
handle()
operations.
๐ Changed
๐ #178 provides some performance improvements to
MiddlewarePipe::handle()
by
having it create an instance ofEmptyPipelineHandler
to use as a fallback
๐ handler when it callsprocess()
on itself. This prevents cloning of the
pipeline in this scenario, which is used when it acts as an application
entrypoint.๐ #185 removes the "final" declaration from the
ErrorHandler
class, to allow
โ more easily mocking it for testing.๐ Deprecated
- Nothing.
โ Removed
- Nothing.
๐ Fixed
- Nothing.
- #178 adds the class