From 95ef97fcc2d2e39a183c5458be8e4db1b785a78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 22 Feb 2024 23:32:12 +0100 Subject: [PATCH] Added possibility to enable/disable the LCSC provider --- .env | 7 +++++++ config/services.yaml | 4 ++++ .../InfoProviderSystem/Providers/LCSCProvider.php | 8 ++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 85f25ae8..48c35b1d 100644 --- a/.env +++ b/.env @@ -168,6 +168,13 @@ PROVIDER_MOUSER_SEARCH_LIMIT=50 # Used when searching for keywords in the language specified when you signed up for Search API. PROVIDER_MOUSER_SEARCH_WITH_SIGNUP_LANGUAGE='true' +# LCSC Provider: +# LCSC does not provide an offical API, so this used the API LCSC uses to render their webshop. +# LCSC did not intended the use of this API and it could break any time, so use it at your own risk. + +# We dont require an API key for LCSC, just set this to 1 to enable LCSC support +PROVIDER_LCSC_ENABLED=0 + ################################################################################## # EDA integration related settings ################################################################################## diff --git a/config/services.yaml b/config/services.yaml index e31356c5..e10b4ebb 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -307,6 +307,10 @@ services: $options: '%env(string:PROVIDER_MOUSER_SEARCH_OPTION)%' $search_limit: '%env(int:PROVIDER_MOUSER_SEARCH_LIMIT)%' + App\Services\InfoProviderSystem\Providers\LCSCProvider: + arguments: + $enabled: '%env(bool:PROVIDER_LCSC_ENABLED)%' + #################################################################################################################### # API system #################################################################################################################### diff --git a/src/Services/InfoProviderSystem/Providers/LCSCProvider.php b/src/Services/InfoProviderSystem/Providers/LCSCProvider.php index 6f005c73..98f680f9 100755 --- a/src/Services/InfoProviderSystem/Providers/LCSCProvider.php +++ b/src/Services/InfoProviderSystem/Providers/LCSCProvider.php @@ -38,7 +38,7 @@ class LCSCProvider implements InfoProviderInterface public const DISTRIBUTOR_NAME = 'LCSC'; - public function __construct(private readonly HttpClientInterface $lcscClient) + public function __construct(private readonly HttpClientInterface $lcscClient, private bool $enabled = true) { } @@ -47,9 +47,9 @@ class LCSCProvider implements InfoProviderInterface { return [ 'name' => 'LCSC', - 'description' => 'This provider uses the LCSC API to search for parts.', + 'description' => 'This provider uses the (unofficial) LCSC API to search for parts.', 'url' => 'https://www.lcsc.com/', - 'disabled_help' => 'This provider is enabled by default' + 'disabled_help' => 'Set PROVIDER_LCSC_ENABLED to 1 (or true) in your environment variable config.' ]; } @@ -61,7 +61,7 @@ class LCSCProvider implements InfoProviderInterface // This provider is always active public function isActive(): bool { - return true; + return $this->enabled; } /**