Skip to content

Commit

Permalink
Update June 10, 2023
Browse files Browse the repository at this point in the history
- Added 2 more pre-defined variables (Database_URL and Secret_Key)
- Changed Development function to isDevelopment to enhance the semantic of the function
  • Loading branch information
rafael-figueiredo-alves committed Jun 11, 2023
1 parent 13cd5e6 commit c704bba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Demo/uDemo.pas
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ procedure TForm2.Button2Click(Sender: TObject);

procedure TForm2.Button3Click(Sender: TObject);
begin
//Outro exemplo de variável direta, neste caso útil para determinar que o ambiente é ou não de desenvolvimento
if DotEnv.Development then
//Outro exemplo de variável direta, neste caso útil para determinar que o ambiente é ou não de desenvolvimento (variável é DEVELOPMENT com valores "True" ou "False")
if DotEnv.isDevelopment then
LAmbiente.Caption := 'Desenvolvimento'
else
LAmbiente.Caption := 'Produção';
Expand Down
53 changes: 48 additions & 5 deletions src/DotEnv4Delphi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface
NUMBER_OF_PROCESSORS, OS, PATH, PATHEXT, PROCESSOR_ARCHITECTURE, PROCESSOR_IDENTIFIER, PROCESSOR_LEVEL,
PROCESSOR_REVISION, PROGRAMFILES, SESSIONNAME, SYSTEMDRIVE, SYSTEMROOT, TEMP, TMP, USERDOMAIN, USERNAME, USERPROFILE,
WINDIR, DB_USERNAME, DBUSERNAME, DBPORT, DB_PORT, PORT, HOSTNAME, DB_HOST, DB_USER, DBHOST, DBUSER, DBPASS, DB_PASS,
PASSWORD, DBPASSWORD, BASE_URL, TOKEN, API_TOKEN, CONNECTIONSTRING, DEVELOPMENT);
PASSWORD, DBPASSWORD, BASE_URL, TOKEN, API_TOKEN, CONNECTIONSTRING, DEVELOPMENT, DATABASE_URL, SECRET_KEY);
{$EndRegion}

{$Region 'DotEnv4Delphi´s interface'}
Expand All @@ -28,7 +28,9 @@ interface
function DBHost: string;
function DBPassword: string;
function ConnectionString: string;
function Development: Boolean;
function isDevelopment: Boolean;
function DatabaseURL: string;
function SecretKey: string;
function GetVersion: string;
end;
{$EndRegion}
Expand Down Expand Up @@ -58,14 +60,19 @@ TDotEnv4Delphi = class(TInterfacedObject, iDotEnv4Delphi)
function DBHost: string;
function DBPassword: string;
function ConnectionString: string;
function Development: Boolean;
function isDevelopment: Boolean;
function DatabaseURL: string;
function SecretKey: string;
function GetVersion: string;
end;
{$EndRegion}

var
DotEnv: iDotEnv4Delphi;

const
fVersion = '1.2.0';

implementation

uses
Expand All @@ -80,6 +87,24 @@ function TDotEnv4Delphi.ReadValueFromEnvFile(const key: string): string;
EnvDict.TryGetValue(key.ToUpper, Result);
end;

function TDotEnv4Delphi.SecretKey: string;
var
fSecret: string;
begin
fSecret := Env('SECRET_KEY');

if fSecret = EmptyStr then
fSecret := Env('Secret_Key');

if fSecret = EmptyStr then
fSecret := Env('SecretKey');

if fSecret = EmptyStr then
fSecret := Env('SECRETKEY');

Result := fSecret;
end;

function TDotEnv4Delphi.Token: string;
begin
Result := Env('TOKEN');
Expand Down Expand Up @@ -154,6 +179,24 @@ constructor TDotEnv4Delphi.Create;
ReadEnvFile;
end;

function TDotEnv4Delphi.DatabaseURL: string;
var
fDBURL: string;
begin
fDBURL := Env('DATABASE_URL');

if fDBURL = EmptyStr then
fDBURL := Env('Database_URL');

if fDBURL = EmptyStr then
fDBURL := Env('DatabaseURL');

if fDBURL = EmptyStr then
fDBURL := Env('Database_URL');

Result := fDBURL;
end;

function TDotEnv4Delphi.DBHost: string;
var
db_host: string;
Expand Down Expand Up @@ -196,7 +239,7 @@ destructor TDotEnv4Delphi.Destroy;
inherited;
end;

function TDotEnv4Delphi.Development: Boolean;
function TDotEnv4Delphi.isDevelopment: Boolean;
var
Dev: string;
begin
Expand All @@ -218,7 +261,7 @@ function TDotEnv4Delphi.Env(const EnvVar: TEnvVar): string;

function TDotEnv4Delphi.GetVersion: string;
begin
Result := '1.1.0';
Result := fVersion;
end;

function TDotEnv4Delphi.Hostname: string;
Expand Down

0 comments on commit c704bba

Please sign in to comment.