Nested pipeline - how to

expressive

#1

Hi, I’m using the new version zend expressive 3 and I’m trying to create a nested pipeline with a factory.

My pipeline is created with a delegator:


public function __invoke(ContainerInterface $container, $serviceName, callable $callback) {
  $app = $callback();
  // ...
  $app->pipe(NestedPipelineMiddleware::class);
  //...
 }

My NestedPipelineFactory contains the following code:

class NestedPipelineFactory {
public function __invoke(ContainerInterface $container) {
		$middlewareFactory = $container->get(\Zend\Expressive\MiddlewareFactory::class);
		return $middlewareFactory->pipeline(OneSubMiddleware::class, SecondSubMiddleware::class);
	}
}

I followed this guide https://docs.zendframework.com/zend-expressive/v3/features/container/middleware-factory/

When I run this code the following error appears:

Zend\\Stratigility\\MiddlewarePipe cannot handle request; no middleware available to process the request

I found that if the code in the NestedPipelineFactory is moved directly inside the delegator class all works, but I don’t like it.

Can anyone give me some hints on the error?

Thanks!


#2

After looking in detail it appears I only needed to add the PathMiddlewareDecorator function.

So the working code inside the NestedPipelineFactory look like that:

use function Zend\Stratigility\path;

class NestedPipelineFactory {
public function __invoke(ContainerInterface $container) {
		$middlewareFactory = $container->get(\Zend\Expressive\MiddlewareFactory::class);
		return path('/', $middlewareFactory->pipeline(OneSubMiddleware::class, SecondSubMiddleware::class));
	}
}