Site-Proximo/openfoodfacts-php-0.2.3/examples/01-basic_api_usage/cached_example.php
2020-08-22 11:34:59 +02:00

13 lines
537 B
PHP

use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;
include '../../vendor/autoload.php';
$logger = new \Monolog\Logger('test');
$httpClient = new \GuzzleHttp\Client();
// the PSR-6 cache object that you want to use (you might also use a PSR-16 Interface Object directly)
$psr6Cache = new FilesystemAdapter();
$psr16Cache = new Psr16Cache($psr6Cache);
$api = new \OpenFoodFacts\Api('food', 'world', $logger, $httpClient, $psr16Cache);
$product = $api->getProduct(rand(1, 50));