pipeErrorHandler() public méthode

Middleware piped may be either callables or service names. Middleware specified as services will be wrapped in a closure similar to the following: function ($error, $request, $response, $next) use ($container, $middleware) { $invokable = $container->get($middleware); if (! is_callable($invokable)) { throw new Exception\InvalidMiddlewareException(sprintf( 'Lazy-loaded middleware "%s" is not invokable', $middleware )); } return $invokable($error, $request, $response, $next); }; This is done to delay fetching the middleware until it is actually used; the upshot is that you will not be notified if the service is invalid to use as middleware until runtime. Once middleware detection and wrapping (if necessary) is complete, proxies to pipe().
public pipeErrorHandler ( string | callable $path, null | string | callable $middleware = null ) : self
$path string | callable Either a URI path prefix, or middleware.
$middleware null | string | callable Middleware
Résultat self
 /**
  * @group lazy-piping
  */
 public function testAllowsPipingErrorMiddlewareAsServiceNameWithPath()
 {
     $middleware = function ($error, $req, $res, $next) {
         return 'invoked';
     };
     $container = $this->prophesize(ContainerInterface::class);
     $container->has('foo')->willReturn(true);
     $container->get('foo')->willReturn($middleware);
     $app = new Application($this->router->reveal(), $container->reveal());
     $app->pipeErrorHandler('/foo', 'foo');
     $r = new ReflectionProperty($app, 'pipeline');
     $r->setAccessible(true);
     $pipeline = $r->getValue($app);
     $route = $pipeline->dequeue();
     $this->assertInstanceOf('Zend\\Stratigility\\Route', $route);
     $handler = $route->handler;
     $this->assertEquals('invoked', $handler('foo', 'bar', 'baz', 'bat'));
 }