Laminas Stratigility v3.2.0 Release Notes

Release Date: 2019-06-12 // over 3 years ago
  • โž• Added

    • Nothing.

    ๐Ÿ”„ Changed

    • zendframework/zend-stratigility#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 Laminas\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 Laminas\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.