zend-stratigility v3.2.0 Release Notes

Release Date: 2019-06-12 // over 2 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 of Zend\Stratigility\Next, which encapsulates the middleware pipeline and advances through it on each call to handle().

    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 to handle() within the same scope will therefore result in the exception Zend\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 the MiddlewarePipe as a fallback handler during
      handle() operations.

    ๐Ÿ”„ Changed

    ๐ŸŽ #178 provides some performance improvements to MiddlewarePipe::handle() by
    having it create an instance of EmptyPipelineHandler to use as a fallback
    ๐Ÿ– handler when it calls process() 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.