44
55namespace Light \Blog \Handler ;
66
7- use Fig \Http \Message \StatusCodeInterface ;
87use Laminas \Diactoros \Response \HtmlResponse ;
98use Light \App \Helper \Paginator ;
10- use Light \Blog \Entity \Category ;
119use Light \Blog \Repository \CategoryRepository ;
10+ use Light \Blog \Service \BlogServiceInterface ;
1211use Mezzio \Template \TemplateRendererInterface ;
1312use Psr \Http \Message \ResponseInterface ;
1413use Psr \Http \Message \ServerRequestInterface ;
@@ -20,6 +19,7 @@ class GetCategoryResourceHandler implements RequestHandlerInterface
2019 public function __construct (
2120 protected TemplateRendererInterface $ template ,
2221 protected CategoryRepository $ categoryRepository ,
22+ protected BlogServiceInterface $ blogService ,
2323 ) {
2424 }
2525
@@ -29,10 +29,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
2929 $ categories = $ this ->categoryRepository ->getCategories ();
3030 $ category = $ this ->categoryRepository ->getCategoryResource ($ categorySlug );
3131 if ($ category === null ) {
32- return $ this ->notFound ($ categories );
32+ return $ this ->blogService -> notFound ($ categories );
3333 }
3434 if (! $ category ->isVisible ()) {
35- return $ this ->gone ($ categories );
35+ return $ this ->blogService -> gone ($ categories );
3636 }
3737 $ meta = $ category ;
3838
@@ -55,33 +55,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
5555 );
5656 return new HtmlResponse ($ html );
5757 } catch (Throwable $ e ) {
58- return $ this ->notFound ($ categories );
58+ return $ this ->blogService -> notFound ($ categories );
5959 }
6060 }
61-
62- /**
63- * @param Category[] $categories
64- */
65- private function notFound (array $ categories ): HtmlResponse
66- {
67- return new HtmlResponse (
68- $ this ->template ->render ('error::404 ' , [
69- 'categories ' => $ categories ,
70- ]),
71- StatusCodeInterface::STATUS_NOT_FOUND
72- );
73- }
74-
75- /**
76- * @param Category[] $categories
77- */
78- private function gone (array $ categories ): HtmlResponse
79- {
80- return new HtmlResponse (
81- $ this ->template ->render ('error::410 ' , [
82- 'categories ' => $ categories ,
83- ]),
84- StatusCodeInterface::STATUS_GONE
85- );
86- }
8761}
0 commit comments