Set envVarMode to override everywhere

This commit is contained in:
Jan Böhmer 2025-07-06 22:00:46 +02:00
parent dc81a5b361
commit 423cdf6ca2
9 changed files with 80 additions and 36 deletions

View file

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Settings\InfoProviderSystem;
use App\Settings\SettingsIcon;
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Symfony\Component\Validator\Constraints as Assert;
@ -33,22 +34,25 @@ use Symfony\Component\Translation\TranslatableMessage as TM;
#[SettingsIcon("fa-plug")]
class MouserSettings
{
#[SettingsParameter(label: new TM("settings.ips.mouser.apiKey"), description: new TM("settings.ips.mouser.apiKey.help"), formOptions: ["help_html" => true], envVar: "PROVIDER_MOUSER_KEY")]
#[SettingsParameter(label: new TM("settings.ips.mouser.apiKey"), description: new TM("settings.ips.mouser.apiKey.help"),
formOptions: ["help_html" => true], envVar: "PROVIDER_MOUSER_KEY", envVarMode: EnvVarMode::OVERWRITE)]
public ?string $apiKey = null;
/** @var int The number of results to get from Mouser while searching (please note that this value is max 50) */
#[SettingsParameter(label: new TM("settings.ips.mouser.searchLimit"), description: new TM("settings.ips.mouser.searchLimit.help"), envVar: "int:PROVIDER_MOUSER_SEARCH_LIMIT")]
#[SettingsParameter(label: new TM("settings.ips.mouser.searchLimit"), description: new TM("settings.ips.mouser.searchLimit.help"),
envVar: "int:PROVIDER_MOUSER_SEARCH_LIMIT", envVarMode: EnvVarMode::OVERWRITE)]
#[Assert\Range(min: 1, max: 50)]
public int $searchLimit = 50;
/** @var MouserSearchOptions Filter search results by RoHS compliance and stock availability */
#[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"])]
#[SettingsParameter(label: new TM("settings.ips.mouser.searchOptions"), description: new TM("settings.ips.mouser.searchOptions.help"),
envVar: "PROVIDER_MOUSER_SEARCH_OPTION", envVarMode: EnvVarMode::OVERWRITE, envVarMapper: [self::class, "mapSearchOptionEnvVar"])]
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. */
//TODO: Put this into some expert mode only
#[SettingsParameter(envVar: "bool:PROVIDER_MOUSER_SEARCH_WITH_SIGNUP_LANGUAGE")]
//#[SettingsParameter(envVar: "bool:PROVIDER_MOUSER_SEARCH_WITH_SIGNUP_LANGUAGE")]
public bool $searchWithSignUpLanguage = true;
public static function mapSearchOptionEnvVar(?string $value): MouserSearchOptions