1. Go to this page and download the library: Download zuruuh/blagues-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zuruuh / blagues-api example snippets
declare(strict_types=1);
use BlaguesApi\Factory\BlaguesApiFactory;
$blaguesApi = BlaguesApiFactory::create($_ENV['TOKEN']);
$joke = $blaguesApi->getRandom(); // Renvoies une instance de la classe BlaguesApi\Model\Joke
var_dump($joke->getJoke()); // Renvoie le contenu de la blague.
var_dump($joke->getAnswer()); // Renvoie la réponse à la blague si il y en a une.
declare(strict_types=1);
use BlaguesApi\Model\Joke;
use BlaguesApi\Factory\BlaguesApiFactory;
$blaguesApi = BlaguesApiFactory::create($_ENV['TOKEN']);
$joke = $blaguesApi->getById(1234);
dump($joke->getId()); // renvoies 1234
$joke = $blaguesApi->getRandom([Joke::TYPE_DARK]); // Récuperes une blague aléatoire de n'importe quel type excepté `Joke::TYPE_DARK`.
$joke = $blaguesApi->getByType(Joke::TYPE_DEV); // Récuperes une blague aléatoire de type `Joke::TYPE_DEV`.
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use BlaguesApi\Factory\BlaguesApiFactory;
class JokeController extends AbstractController
{
#[Route('/joke')]
public function jokeAction(#[Autowire('%env(BLAGUES_API_TOKEN)%')] string $blaguesApiToken): Response
{
$blaguesApi = BlaguesApiFactory::create($blaguesApiToken);
$joke = $blaguesApi->getRandom();
return $this->render('template/joke.html.twig', [
'joke' => $joke,
]);
}
}
// src/Controller/JokeController
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use BlaguesApi\BlaguesApiInterface;
class JokeController extends AbstractController
{
#[Route('/joke')]
public function jokeAction(BlaguesApiInterface $blaguesApi): Response
{
$joke = $blaguesApi->getRandom();
return $this->render('template/joke.html.twig', [
'joke' => $joke,
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.