2017-09-20 7 views
0

私はZendの表情豊かなネストされたアプリケーションを使用しようとしているので、私はこのブログの記事次のようだ: https://framework.zend.com/blog/2017-03-15-nested-middleware-in-expressive.htmlZendの表現のネストされたアプリケーション

問題はミドルウェアの工場内にあるように見えます:

class CreateBookMiddlewareFactory 
{ 
    public function __invoke(ContainerInterface $container) 
    { 
     $nested = new Application(
      $container->get(RouterInterface::class), 
      $container 
     ); 

     $nested->pipe(AuthenticationMiddleware::class); 
     $nested->pipe(ContentValidationMiddleware::class); 
     $nested->pipe(BodyParamsMiddleware::class); 
     $nested->pipe(BookValidationMiddleware::class); 
     $nested->pipe(CreateBookMiddleware::class); 

     return $nested; 
    } 
} 

私たちは工場にいるので、CreateBookMiddlewareをここにパイプに追加することはできません。 ...それは別のネストされたアプリケーションを作成するファクトリを呼び出します新しいネストされたアプリケーションを作成し、工場を呼び出しますパイピングので

(!) Fatal error: Maximum function nesting level of '256' reached, aborting! in /var/www/project/vendor/zendframework/zend-stratigility/src/Next.php on line 
    158 

は、私は、このブログの記事から右の届かないものがありますか?

答えて

2

工場名はCreateBookMiddlewareFactoryです。そして__invokeの内部には$nested->pipe(CreateBookMiddleware::class);があります。あなたの設定にもよりますが、通常はCreateBookMiddlewareFactoryがCreateBookMiddlewareの工場になります。だから、それはループを張っている。

blogpostとまったく同じコードを使用しているので、私はそのブログ記事の誤りだと思っています。私はそれが最後の委任者の工場の例のようであったはずだと思います:最後の$nested->pipe(CreateBookMiddleware::class);なし。

ブログ投稿の投稿者に通知しました。

編集:ブログの記事は、この修正プログラムで更新されます:

namespace Acme\Api; 

use Acme\AuthenticationMiddleware; 
use Acme\ContentNegotiationMiddleware; 
use Psr\Container\ContainerInterface; 
use Zend\Expressive\Application; 
use Zend\Expressive\Helper\BodyParams\BodyParamsMiddleware; 
use Zend\Expressive\Router\RouterInterface; 

class CreateBookMiddlewareFactory 
{ 
    public function __invoke(ContainerInterface $container) 
    { 
     $nested = new Application(
      $container->get(RouterInterface::class), 
      $container 
     ); 

     $nested->pipe(AuthenticationMiddleware::class); 
     $nested->pipe(ContentValidationMiddleware::class); 
     $nested->pipe(BodyParamsMiddleware::class); 
     $nested->pipe(BookValidationMiddleware::class); 

     // If dependencies are needed, pull them from the container and pass 
     // them to the constructor: 
     $nested->pipe(new CreateBookMiddleware()); 

     return $nested; 
    } 
} 
0

私は明確化のため@xtreamwayz答えを受け入れました。しかし、ここで私はそれがうまく作ら方法は次のとおりです。それはちょうど今のポストに固定しています正確にどのようにされて

class CreateBookMiddlewareFactory 
{ 
    public function __invoke(ContainerInterface $container) 
    { 
     $nested = new Application(
      $container->get(RouterInterface::class), 
      $container 
     ); 

     $nested->pipe($container->get(AuthenticationMiddleware::class)); 
     $nested->pipe($container->get(ContentValidationMiddleware::class)); 
     $nested->pipe($container->get(BodyParamsMiddleware::class)); 
     $nested->pipe($container->get(BookValidationMiddleware::class)); 
     // instanciate the new class, so it will not call the factory again 
     $nested->pipe(new CreateBookMiddleware()); 

     return $nested; 
    } 
} 
+0

:https://github.com/zendframework/zf3-web/commit/2ae14d151e512b13506c4f854ad6a811d9a74af0 – xtreamwayz

関連する問題