22
33namespace librarianphp \Web ;
44
5- use Librarian \ContentType ;
5+ use Librarian \Provider \ ContentServiceProvider ;
66use Librarian \Provider \TwigServiceProvider ;
77use Librarian \Response ;
8- use Librarian \Provider \ContentServiceProvider ;
98use Librarian \WebController ;
109
1110/**
1211 * Class StaticController
1312 * Renders content from the data dirs
14- * @package App\Command\Web
1513 */
1614class ContentController extends WebController
1715{
@@ -26,40 +24,40 @@ public function handle(): void
2624 $ request = $ this ->getRequest ();
2725
2826 try {
29- $ content = $ content_provider ->fetch ($ request ->getRoute () . '/ ' . $ request ->getSlug ());
27+ $ content = $ content_provider ->fetch ($ request ->getRoute (). '/ ' . $ request ->getSlug ());
3028
3129 if ($ content === null ) {
3230 $ page = 1 ;
3331 $ limit = $ this ->getApp ()->config ->posts_per_page ?? 10 ;
3432 $ params = $ this ->getRequest ()->getParams ();
3533
36- if (key_exists ('page ' , $ params )) {
34+ if (array_key_exists ('page ' , $ params )) {
3735 $ page = $ params ['page ' ];
3836 }
3937
4038 $ start = ($ page * $ limit ) - $ limit ;
41- $ contentType = $ content_provider ->getContentType ($ request ->getRoute ());
39+ $ contentType = $ content_provider ->getContentType ($ request ->getPath ());
4240 $ content_list = $ content_provider ->fetchFrom ($ contentType , $ start , $ limit );
4341 $ response = new Response ($ twig ->render ('content/listing.html.twig ' , [
4442 'content_list ' => $ content_list ,
4543 'total_pages ' => $ content_provider ->fetchTotalPages ($ limit ),
4644 'current_page ' => $ page ,
4745 'base_url ' => $ request ->getRoute (),
48- 'content_type ' => $ contentType
46+ 'content_type ' => $ contentType,
4947 ]));
5048
5149 $ response ->output ();
50+
5251 return ;
5352 }
5453 } catch (\Exception $ e ) {
5554 Response::redirect ('/notfound ' );
5655 }
5756
5857 $ output = $ twig ->render ('content/single.html.twig ' , [
59- 'content ' => $ content
58+ 'content ' => $ content,
6059 ]);
6160
62-
6361 $ response = new Response ($ output );
6462 $ response ->output ();
6563 }
0 commit comments