<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class BlogInfoController extends AbstractController
{
    /**
     * @Route("/blog-info/{refkeyblog}", name="blog_info")
     */
    public function index(Request $request)
    {

        $uri = $request->getUri();

        $ref = $request->get('refkeyblog');

        $locale = $request->getLocale();

        $curl = curl_init();
        curl_setopt_array($curl, array(

            CURLOPT_URL => "https://admin.telheirodoinfante.com/api/getContentArticle/$ref/$locale",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => array(
                "cache-control: no-cache"
            ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        $blog_info = json_decode($response);



        return $this->render('blog_info/index.html.twig', [
            'controller_name' => 'Blog Info',
            'blog_info' => $blog_info,
            'full_url' => $uri
        ]);
    }
}
