src/Controller/VimeoController.php line 25

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Contracts\Cache\CacheInterface;
  8. use Symfony\Contracts\Cache\ItemInterface;
  9. use Vimeo\Exceptions\VimeoRequestException;
  10. use Vimeo\Vimeo;
  11. /**
  12.  * @Route("/video")
  13.  */
  14. class VimeoController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/dsides", name="app_vimeo")
  18.      * @throws VimeoRequestException
  19.      * @throws \Psr\Cache\InvalidArgumentException
  20.      */
  21.     public function index(Request $requestCacheInterface $cache): Response
  22.     {
  23.         $client = new Vimeo(
  24.             $this->getParameter('app.vimeo.client_id'),
  25.             $this->getParameter('app.vimeo.client.secret'),
  26.             $this->getParameter('app.vimeo.access.public')
  27.         );
  28.         $responses $cache->get('vimeo_dsides', function (ItemInterface $item) use ($client) {
  29.             $item->expiresAfter(345600);
  30.             return $client->request('/me/videos',[
  31.                 'per_page' => 20,
  32.                 'filter_tag' => 'site',
  33.                 'sort'=>'date',
  34.                 'direction'=>'desc'], 'GET');
  35.         });
  36.         $body $responses['body'];
  37.         $request->attributes->set('id''dsides_video');
  38.         return $this->render('vimeo/index.html.twig', [
  39.             'video' => $body,
  40.         ]);
  41.     }
  42. }