2024-05-05 23:34:06 +02:00
< ? php
/*
* This file is part of Part - DB ( https :// github . com / Part - DB / Part - DB - symfony ) .
*
* Copyright ( C ) 2019 - 2024 Jan Böhmer ( https :// github . com / jbtronics )
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
declare ( strict_types = 1 );
namespace App\Settings\InfoProviderSystem ;
use Jbtronics\SettingsBundle\Settings\Settings ;
use Jbtronics\SettingsBundle\Settings\SettingsParameter ;
use Symfony\Component\Validator\Constraints as Assert ;
2024-05-10 00:55:14 +02:00
use Symfony\Component\Translation\TranslatableMessage as TM ;
2024-05-05 23:34:06 +02:00
2024-05-10 00:55:14 +02:00
#[Settings(label: new TM("settings.ips.mouser"))]
2024-05-05 23:34:06 +02:00
class MouserSettings
{
2024-05-10 00:55:14 +02:00
#[SettingsParameter(label: new TM("settings.ips.mouser.apiKey"), description: new TM("settings.ips.mouser.apiKey.help"), formOptions: ["help_html" => true], envVar: "PROVIDER_MOUSER_KEY")]
2024-05-05 23:34:06 +02:00
public ? string $apiKey = null ;
/** @var int The number of results to get from Mouser while searching (please note that this value is max 50) */
2024-05-10 00:55:14 +02:00
#[SettingsParameter(label: new TM("settings.ips.mouser.searchLimit"), description: new TM("settings.ips.mouser.searchLimit.help"), envVar: "int:PROVIDER_MOUSER_SEARCH_LIMIT")]
2024-05-05 23:34:06 +02:00
#[Assert\Range(min: 1, max: 50)]
public int $searchLimit = 50 ;
/** @var MouserSearchOptions Filter search results by RoHS compliance and stock availability */
2024-05-10 00:55:14 +02:00
#[SettingsParameter(label: new TM("settings.ips.mouser.searchOptions"), description: new TM("settings.ips.mouser.searchOptions.help"), envVar: "PROVIDER_MOUSER_SEARCH_OPTION", envVarMapper: [self::class, "mapSearchOptionEnvVar"])]
2024-05-05 23:34:06 +02:00
public MouserSearchOptions $searchOption = MouserSearchOptions :: NONE ;
/** @ var bool It is recommended to leave this set to 'true' . The option is not really documented by Mouser :
* Used when searching for keywords in the language specified when you signed up for Search API . */
2024-05-10 00:55:14 +02:00
//TODO: Put this into some expert mode only
2024-05-05 23:34:06 +02:00
#[SettingsParameter(envVar: "bool:PROVIDER_MOUSER_SEARCH_WITH_SIGNUP_LANGUAGE")]
public bool $searchWithSignUpLanguage = true ;
public static function mapSearchOptionEnvVar ( ? string $value ) : MouserSearchOptions
{
if ( ! $value ) {
return MouserSearchOptions :: NONE ;
}
return MouserSearchOptions :: tryFrom ( $value ) ? ? MouserSearchOptions :: NONE ;
}
}