File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33declare (strict_types=1 );
44
55use Dot \ErrorHandler \ErrorHandlerInterface ;
6+ use Light \App \Middleware \PoweredByMiddleware ;
67use Mezzio \Application ;
78use Mezzio \Handler \NotFoundHandler ;
89use Mezzio \Helper \ServerUrlMiddleware ;
1819 // all Exceptions.
1920 $ app ->pipe (ErrorHandlerInterface::class);
2021 $ app ->pipe (ServerUrlMiddleware::class);
22+ $ app ->pipe (PoweredByMiddleware::class);
2123
2224 // Pipe more middleware here that you want to execute on every request:
2325 // - bootstrapping
Original file line number Diff line number Diff line change 1616use Light \App \Factory \GetFeedViewHandlerFactory ;
1717use Light \App \Factory \GetIndexViewHandlerFactory ;
1818use Light \App \Factory \GetMarkdownArticleHandlerFactory ;
19+ use Light \App \Factory \PoweredByMiddlewareFactory ;
1920use Light \App \Handler \GetFeedViewHandler ;
2021use Light \App \Handler \GetIndexViewHandler ;
2122use Light \App \Handler \GetMarkdownArticleHandler ;
23+ use Light \App \Middleware \PoweredByMiddleware ;
2224use Light \App \Resolver \EntityListenerResolver ;
2325use Light \App \Service \FeedGenerator ;
2426use Mezzio \Application ;
@@ -118,6 +120,7 @@ public function getDependencies(): array
118120 GetFeedViewHandler::class => GetFeedViewHandlerFactory::class,
119121 GetMarkdownArticleHandler::class => GetMarkdownArticleHandlerFactory::class,
120122 FeedGenerator::class => FeedGeneratorFactory::class,
123+ PoweredByMiddleware::class => PoweredByMiddlewareFactory::class,
121124 ],
122125 'aliases ' => [
123126 EntityManager::class => 'doctrine.entity_manager.orm_default ' ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Light \App \Factory ;
6+
7+ use Light \App \Middleware \PoweredByMiddleware ;
8+ use Psr \Container \ContainerInterface ;
9+
10+ class PoweredByMiddlewareFactory
11+ {
12+ public function __invoke (ContainerInterface $ container ): PoweredByMiddleware
13+ {
14+ $ config = $ container ->get ('config ' );
15+
16+ return new PoweredByMiddleware ($ config ['application ' ]['meta ' ]['siteName ' ] ?? '' );
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Light \App \Middleware ;
6+
7+ use Psr \Http \Message \ResponseInterface ;
8+ use Psr \Http \Message \ServerRequestInterface ;
9+ use Psr \Http \Server \MiddlewareInterface ;
10+ use Psr \Http \Server \RequestHandlerInterface ;
11+
12+ class PoweredByMiddleware implements MiddlewareInterface
13+ {
14+ public function __construct (private readonly string $ siteName )
15+ {
16+ }
17+
18+ public function process (ServerRequestInterface $ request , RequestHandlerInterface $ handler ): ResponseInterface
19+ {
20+ $ response = $ handler ->handle ($ request );
21+
22+ if ($ this ->siteName === '' ) {
23+ return $ response ;
24+ }
25+
26+ return $ response ->withHeader ('X-Powered-By ' , $ this ->siteName );
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments