From b9e4cf009dd2097bc677565e84782227ed28c0bb Mon Sep 17 00:00:00 2001 From: Benoit Colin Date: Thu, 11 Jul 2024 20:26:36 +0200 Subject: [PATCH] feat: allow other environment like OpenBeautyFacts --- src/OpenFoodFactsApiWrapper.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/OpenFoodFactsApiWrapper.php b/src/OpenFoodFactsApiWrapper.php index e28282a..ddaaaf1 100644 --- a/src/OpenFoodFactsApiWrapper.php +++ b/src/OpenFoodFactsApiWrapper.php @@ -8,23 +8,20 @@ class OpenFoodFactsApiWrapper { - protected $parameters; - protected $cache; - public $api; - public function __construct(array $parameters, CacheInterface $cache = null) - { - $this->parameters = $parameters; - $this->cache = $cache; - - $this->api = $this->setupApi(); + public function __construct( + protected array $parameters, + protected ?CacheInterface $cache = null, + string $environment = null + ) { + $this->api = $this->setupApi($environment); } - protected function setupApi($environment = 'food') + protected function setupApi(string $environment = null): Api { return new Api( - $environment, + $environment ?? 'food', $this->parameters['geography'] ?? 'world', null, $this->httpClient(),