src/AppBundle/Controller/Prismic/BlogPostController.php line 58

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller\Prismic;
  3. use AppBundle\Prismic\BlogPostRepository;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Component\HttpFoundation\Request;
  8. /**
  9.  * @Route("/blog")
  10.  */
  11. class BlogPostController extends Controller
  12. {
  13.     /**
  14.      * @var BlogPostRepository
  15.      */
  16.     private $repository;
  17.     /**
  18.      * @param BlogPostRepository $blogPostRepository
  19.      */
  20.     public function __construct(BlogPostRepository $blogPostRepository)
  21.     {
  22.         $this->repository $blogPostRepository;
  23.     }
  24.     /**
  25.      * @Route("/", name="blog_post_index")
  26.      * @Template("blog_post/index.html.twig")
  27.      *
  28.      * @return array
  29.      */
  30.     public function index(Request $request): array
  31.     {
  32.         $device $this->get('mobile_detect.mobile_detector');
  33.         $pageSize 18;
  34.         if ($device->isMobile()) {
  35.             $pageSize 10;
  36.         }
  37.         $page $request->query->get('page'1);
  38.         return [
  39.             'blogPosts' => $this->repository->findAllOrderedByPublicationDate($pageSize$page),
  40.         ];
  41.     }
  42.     /**
  43.      * @Route("/{uid}", name="blog_post_show")
  44.      * @Template("blog_post/show.html.twig")
  45.      *
  46.      * @return array
  47.      */
  48.     public function show(string $uid): array
  49.     {
  50.         return [
  51.             'blogPost' => $this->repository->findOneByUid($uid),
  52.         ];
  53.     }
  54. }