Releases: zendframework/zend-stratigility
zend-stratigility 3.2.0
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 of
Zend\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.
zend-stratigility 3.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.
zend-stratigility 3.0.3
Added
- #184 adds support for PHP 7.3.
Changed
- Nothing.
Deprecated
- Nothing.
Removed
- Nothing.
Fixed
- Nothing.
zend-stratigility 3.0.2
Added
- Nothing.
Changed
- Nothing.
Deprecated
- Nothing.
Removed
- #177 removes a conditional from
Zend\Stratigility\Middleware\ErrorHandler
that can
never be reached.
Fixed
- Nothing.
zend-stratigility 2.2.2
Added
- Nothing.
Changed
- Nothing.
Deprecated
- Nothing.
Removed
- Nothing.
Fixed
- #169 fixes an issue with how the PathMiddlewareDecorator attempts to truncate the path
when the path is matched case insensitively. Previously, an exception was incorrectly raised;
now it identifies and truncates correctly.
zend-stratigility 3.0.1
Added
- Nothing.
Changed
- Nothing.
Deprecated
- Nothing.
Removed
- Nothing.
Fixed
-
#165 fixes an
issue with thePathMiddlewareDecorator
whereby it was using the original
request when invoking the handler it creates, instead of prepending the
configured path prefix to the request URI created. With the fix, if middleware
alters the request path passed to the handler, the changes will now propagate
to later middleware. As an example:new PathMiddlewareDecorator('/api', middleware(function ($request, $handler) { $uri = $request->getUri(); if (! preg_match('#^/v\d+/#', $uri->getPath())) { $request = $request->withUri($uri->withPath('/v1' . $uri->getPath())); } return $handler->handle($request); }));
For the request path
/api/books
, the above will now correctly result in
/api/v1/books
being propagated to lower layers of the application, instead
of/api/books
.
zend-stratigility 2.2.1
Added
- Nothing.
Changed
- Nothing.
Deprecated
- Nothing.
Removed
- Nothing.
Fixed
-
#167 fixes an
issue with thePathMiddlewareDecorator
whereby it was using the original
request when invoking the handler it creates, instead of prepending the
configured path prefix to the request URI created. With the fix, if middleware
alters the request path passed to the handler, the changes will now propagate
to later middleware. As an example:new PathMiddlewareDecorator('/api', middleware(function ($request, $handler) { $uri = $request->getUri(); if (! preg_match('#^/v\d+/#', $uri->getPath())) { $request = $request->withUri($uri->withPath('/v1' . $uri->getPath())); } return $handler->handle($request); }));
For the request path
/api/books
, the above will now correctly result in
/api/v1/books
being propagated to lower layers of the application, instead of
/api/books
.
zend-stratigility 3.0.0
Added
-
#146 adds a new interface,
Zend\Stratigility\MiddlewarePipeInterface
. It extends the PSR-15MiddlewareInterface
andRequestHandlerInterface
, and defines one additional method,pipe(MiddlewareInterface $middleware) : void
. -
#150 adds a new class,
Zend\Stratigility\Middleware\RequestHandlerMiddleware
. The class implements the PSR-15RequestHandlerInterface
andMiddlewareInterface
, and accepts a single constructor argument, aRequestHandlerInterface
instance. Each of itshandle()
andprocess()
methods proxy to the composed request handler'shandle()
method, returning its result.This class can be useful for adapting request handlers to use within pipelines.
-
#142 adds a new class,
Zend\Stratigility\Middleware\HostMiddlewareDecorator
, which provides host segregation functionality for middleware, allowing conditional execution of middleware only if the requested host matches a configured host.// Only process $middleware if the request host matches 'example.com': $pipeline->pipe(new HostMiddlewareDecorator('example.com', $middleware));
Additionally, the patch provides a utility function,
Zend\Stratigility\host()
, to simplify the above declaration:$pipeline->pipe(host('example.com', $middleware));
-
#128 adds a marker interface,
Zend\Stratigility\Exception\ExceptionInterface
; all package exceptions now implement this interface, allowing you to catch all package-related exceptions by typehinting against it.
Changed
-
#145 updates the component to implement and consume ONLY PSR-15 interfaces; http-interop interfaces and callable middleware are no longer directly supported (though Stratigility provides decorators for the latter in order to cast them to PSR-15 implementations).
-
#134 and #146 modify
MiddlewarePipe
in two ways: it now implements the newMiddlewarePipeInterface
, and is marked asfinal
, disallowing direct extension. Either decorate an instance in a customMiddlewarePipeInterface
implementation, or create a custom PSR-15MiddlewareInterface
implementation if piping is not necessary or will allow additional types. -
#155 modifies each of the following classes to mark them
final
:Zend\Stratigility\Middleware\CallableMiddlewareDecorator
Zend\Stratigility\Middleware\DoublePassMiddlewareDecorator
Zend\Stratigility\Middleware\HostMiddlewareDecorator
Zend\Stratigility\Middleware\NotFoundHandler
Zend\Stratigility\Middleware\OriginalMessages
Zend\Stratigility\Middleware\PathMiddlewareDecorator
Zend\Stratigility\Middleware\RequestHandlerMiddleware
Zend\Stratigility\Next
-
#134, #145, and #146 update
MiddlewarePipe
to implementPsr\Http\Server\RequestHandlerInterface
. Calling it will cause it to pull the first middleware off the queue and create aNext
implementation that uses the remaining queue as the request handler; it then processes the middleware. -
#134 removes the ability to specify a path when calling
pipe()
; use thePathMiddlewareDecorator
orpath()
utility function to pipe middleware with path segregation. -
#153 modifies the first argument of the
Zend\Expressive\Middleware\ErrorHandler
andNotFoundHandler
classes. Previously, they each expected aPsr\Http\Message\ResponseInterface
instance; they now both expect a PHP callable capable of producing such an instance. This change was done to simplify re-use of a service for producing unique response instances within dependency injection containers. -
#157 marks the package as conflicting with zendframework/zend-diactoros versions less than 1.7.1. This is due to the fact that that version provides a bugfix for its
Uri::getHost()
implementation that ensures it follows the PSR-7 and IETF RFC 3986 specifications.
Deprecated
- Nothing.
Removed
-
#163 removes
Zend\Stratigility\Middleware\PathRequestHandlerDecorator
, as it was deprecated in 2.2, and no longer used with the 3.0 code base. -
#122 removes support for PHP versions 5.6, 7.0, as well as HHVM.
-
#122 removes the following classes:
Zend\Stratigility\Delegate\CallableDelegateDecorator
Zend\Stratigility\Exception\InvalidRequestTypeException
Zend\Stratigility\Exception\MissingResponsePrototypeException
Zend\Stratigility\MiddlewareInterface
Zend\Stratigility\Middleware\CallableInteropMiddlewareWrapper
Zend\Stratigility\Middleware\CallableMiddlewareWrapper
Zend\Stratigility\Middleware\CallableMiddlewareWrapperFactory
Zend\Stratigility\NoopFinalHandler
-
#134 removes the class
Zend\Stratigility\Route
. This was an internal message passed between aMiddlewarePipe
andNext
instance, and its removal should not affect end users. -
#134 removes
Zend\Stratigility\Exception\InvalidMiddlewareException
, as the exception is no longer raised byMiddlewarePipe
.
Fixed
- Nothing.
zend-stratigility 2.2.0
Added
-
#140 adds the class
Zend\Stratigility\Middleware\CallableMiddlewareDecorator
for the purpose of decorating callable, standards-signature middleware for use with aMiddlewarePipe
instance. Instantiate it directly, passing the callable middleware as the sole argument, or use theZend\Stratigility\middleware()
utility function to generate the instance:middleware($callable)
. -
#140 adds the class
Zend\Stratigility\Middleware\DoublePassMiddlewareDecorator
for the purpose of decorating callable, double-pass middleware for use with aMiddlewarePipe
instance. Instantiate it directly, passing the callable middleware and a response instance as arguments, or use theZend\Stratigility\doublePassMiddleware()
utility function to generate the instance:doublePassMiddleware($callable, $response)
. -
#140 adds the class
Zend\Stratigility\Middleware\PathMiddlewareDecorator
for the purposes of creating path-segregated middleware. The constructor expects a string path literal as the first argument, and anInterop\Http\Server\MiddlewareInterface
instance for the second argument. Alternately, use theZend\Stratigility\path()
utility function to generate the instance:path('/foo', $middleware)
.This decorator class replaces usage of the
$path
argument toMiddlewarePipe::pipe()
, and should be used to ensure your application is forwards-compatible with the upcoming version 3 release.
Changed
- Nothing.
Deprecated
-
#140 deprecates the class
Zend\Stratigility\Route
. This class is an internal detail, and will be removed in version 3.0.0. -
#140 deprecates the class
Zend\Stratigility\Exception\InvalidMiddlewareException
. This class will be removed in version 3.0.0 as it will no longer be necessary due to typehint usage. -
#140 deprecates the class
Zend\Stratigility\Exception\InvalidRequestTypeException
as it is no longer used by the package. It will be removed in version 3.0.0. -
#140 deprecates the class
Zend\Stratigility\Middleware\CallableInteropMiddlewareWrapper
as it is based on interfaces that will no longer be used starting in version 3.0.0. It will be removed in version 3.0.0. Please use the new classZend\Stratigility\Middleware\CallableMiddlewareDecorator
, or the utility functionmiddleware()
, to decorate callable standards-signature middleware. -
#140 deprecates the class
Zend\Stratigility\Middleware\CallableMiddlewareWrapper
as it is based on interfaces that will no longer be used starting in version 3.0.0. It will be removed in version 3.0.0. Please use the new classZend\Stratigility\Middleware\DoublePassMiddlewareDecorator
, or the utility functiondoublePassMiddleware()
, to decorate callable double pass middleware. -
#140 deprecates the class
Zend\Stratigility\Middleware\CallableMiddlewareWrapperFactory
as the class it is associated will be removed starting in version 3.0.0. The class will be removed in version 3.0.0. -
#140 deprecates the class
Zend\Stratigility\NoopFinalHandler
as the class will be removed starting in version 3.0.0. -
#140 deprecates the two-argument form of
Zend\Stratigility\MiddlewarePipe::pipe()
. If you need to perform path segregation, use theZend\Stratigility\Middleware\PathMiddlewareDecorator
class and/or theZend\Stratigility\path()
function to decorate your middleware in order to provide path segregation. -
#140 deprecates the piping of double pass middleware directly to
pipe()
; decorate your double-pass middleware usingZend\Stratigility\Middleware\DoublePassMiddleware
orZend\Stratigility\doublePassMiddleware()
prior to piping. -
#159 deprecates
Zend\Stratigility\MiddlewarePipe::setCallableMiddlewareDecorator()
. UseZend\Stratigility\doublePassMiddleware()
orZend\Stratigility\Middleware\DoublePassMiddleware
prior to passing your double-pass middleware toMiddlewarePipe::pipe()
. -
#159 deprecates
Zend\Stratigility\MiddlewarePipe::setResponsePrototype()
. This was used only to seed an instance ofZend\Stratigility\Middleware\CallableMiddlewareWrapperFactory
previously; pass your response prototype directly to a new instance ofZend\Stratigility\Middleware\DoublePassMiddleware
or the ``Zend\Stratigility\doublePassMiddleware()` function instead. -
#159 deprecates
Zend\Stratigility\MiddlewarePipe::hasResponsePrototype()
.
Removed
- Nothing.
Fixed
- Nothing.
zend-stratigility 2.2.0rc3
Added
- Nothing.
Changed
- Nothing.
Deprecated
- Nothing.
Removed
- Nothing.
Fixed
- Fixes the signature of
PathRequestHandlerDecorator::process()
to typehint against the PSR-7ServerRequestInterface
, and notRequestInterface
.