Wizard can generate or not the dotEnvConfigure call - if not called, a defuault configuration for dotEnv is provided.

This commit is contained in:
Daniele Teti 2024-04-19 15:58:19 +02:00
parent 46ee03c2e6
commit 453d4571e2
6 changed files with 69 additions and 33 deletions

View File

@ -618,7 +618,6 @@ begin
.AppendLine(' FMVC := TMVCEngine.Create(Self,')
.AppendLine(' procedure(Config: TMVCConfig)')
.AppendLine(' begin')
.AppendLine(' Config.dotEnv := dotEnv; ')
.AppendLine(' // session timeout (0 means session cookie)')
.AppendLine(' Config[TMVCConfigKey.SessionTimeout] := dotEnv.Env(''dmvc.session_timeout'', ''0'');')
.AppendLine(' //default content-type')
@ -836,22 +835,27 @@ begin
.AppendLine(' try')
.AppendLine(' if WebRequestHandler <> nil then')
.AppendLine(' WebRequestHandler.WebModuleClass := WebModuleClass;')
.AppendLine
.AppendLine(' dotEnvConfigure(')
.AppendLine(' function: IMVCDotEnv')
.AppendLine(' begin')
.AppendLine(' Result := NewDotEnv')
.AppendLine(' .UseStrategy(TMVCDotEnvPriority.FileThenEnv)')
.AppendLine(' //if available, by default, loads default environment (.env)')
.AppendLine(' .UseProfile(''test'') //if available loads the test environment (.env.test)')
.AppendLine(' .UseProfile(''prod'') //if available loads the prod environment (.env.prod)')
.AppendLine(' .UseLogger(procedure(LogItem: String)')
.AppendLine(' begin')
.AppendLine(' LogD(''dotEnv: '' + LogItem);')
.AppendLine(' end)')
.AppendLine(' .Build(); //uses the executable folder to look for .env* files')
.AppendLine(' end);')
.AppendLine
.AppendLine;
if Model.B[TConfigKey.program_dotenv] then
begin
Section
.AppendLine(' dotEnvConfigure(')
.AppendLine(' function: IMVCDotEnv')
.AppendLine(' begin')
.AppendLine(' Result := NewDotEnv')
.AppendLine(' .UseStrategy(TMVCDotEnvPriority.FileThenEnv)')
.AppendLine(' //if available, by default, loads default environment (.env)')
.AppendLine(' .UseProfile(''test'') //if available loads the test environment (.env.test)')
.AppendLine(' .UseProfile(''prod'') //if available loads the prod environment (.env.prod)')
.AppendLine(' .UseLogger(procedure(LogItem: String)')
.AppendLine(' begin')
.AppendLine(' LogD(''dotEnv: '' + LogItem);')
.AppendLine(' end)')
.AppendLine(' .Build(); //uses the executable folder to look for .env* files')
.AppendLine(' end);')
.AppendLine;
end;
Section
.AppendLine(' WebRequestHandlerProc.MaxConnections := dotEnv.Env(''dmvc.handler.max_connections'', 1024);')
.AppendLine
.AppendLine('{$IF CompilerVersion >= 34} //SYDNEY+')

View File

@ -56,6 +56,7 @@ type
program_name = 'program.name';
program_default_server_port= 'program.default_server_port';
program_msheap='program.msheap';
program_dotenv='program.dotenv';
controller_unit_name='controller.unit_name';
controller_classname= 'controller.classname';
controller_index_methods_generate= 'controller.index_methods.generate';

View File

@ -3,7 +3,7 @@ object frmDMVCNewProject: TfrmDMVCNewProject
Top = 0
BorderStyle = bsDialog
Caption = 'DelphiMVCFramework :: New Project Wizard'
ClientHeight = 527
ClientHeight = 555
ClientWidth = 710
Color = clBtnFace
Constraints.MinHeight = 145
@ -18,7 +18,7 @@ object frmDMVCNewProject: TfrmDMVCNewProject
OnDestroy = FormDestroy
DesignSize = (
710
527)
555)
TextHeight = 13
object Shape1: TShape
Left = 0
@ -400,7 +400,7 @@ object frmDMVCNewProject: TfrmDMVCNewProject
object lblBook: TLabel
AlignWithMargins = True
Left = 11
Top = 495
Top = 522
Width = 259
Height = 16
Cursor = crHandPoint
@ -437,7 +437,7 @@ object frmDMVCNewProject: TfrmDMVCNewProject
end
object btnOK: TButton
Left = 530
Top = 492
Top = 520
Width = 77
Height = 27
Anchors = [akRight, akBottom]
@ -446,10 +446,11 @@ object frmDMVCNewProject: TfrmDMVCNewProject
ModalResult = 1
TabOrder = 3
OnClick = btnOKClick
ExplicitTop = 492
end
object btnCancel: TButton
Left = 613
Top = 492
Top = 520
Width = 77
Height = 27
Anchors = [akRight, akBottom]
@ -457,6 +458,7 @@ object frmDMVCNewProject: TfrmDMVCNewProject
Caption = 'Cancel'
ModalResult = 2
TabOrder = 4
ExplicitTop = 492
end
object chkAddToProjectGroup: TCheckBox
Left = 24
@ -485,7 +487,7 @@ object frmDMVCNewProject: TfrmDMVCNewProject
end
object Panel2: TPanel
Left = 0
Top = 288
Top = 316
Width = 273
Height = 198
Anchors = [akLeft, akBottom]
@ -495,6 +497,7 @@ object frmDMVCNewProject: TfrmDMVCNewProject
ParentCtl3D = False
ShowCaption = False
TabOrder = 5
ExplicitTop = 288
DesignSize = (
273
198)
@ -695,12 +698,13 @@ object frmDMVCNewProject: TfrmDMVCNewProject
end
object GroupBoxJSONRPC: TGroupBox
Left = 287
Top = 372
Top = 400
Width = 403
Height = 105
Anchors = [akLeft, akRight, akBottom]
Caption = 'JSON-RPC 2.0'
TabOrder = 7
ExplicitTop = 372
DesignSize = (
403
105)
@ -734,16 +738,26 @@ object frmDMVCNewProject: TfrmDMVCNewProject
end
object chkMSHeap: TCheckBox
Left = 24
Top = 266
Top = 294
Width = 206
Height = 17
Anchors = [akLeft, akRight, akBottom]
Caption = 'Use MSHeap on MS Windows'
TabOrder = 8
ExplicitTop = 266
end
object chkCustomConfigDotEnv: TCheckBox
Left = 24
Top = 274
Width = 206
Height = 17
Anchors = [akLeft, akRight, akBottom]
Caption = 'Generate custom .env configuration'
TabOrder = 9
end
object ApplicationEvents: TApplicationEvents
OnIdle = ApplicationEventsIdle
Left = 168
Top = 224
Left = 232
Top = 216
end
end

View File

@ -94,6 +94,7 @@ type
ApplicationEvents: TApplicationEvents;
lblCopyRight: TLabel;
chkMSHeap: TCheckBox;
chkCustomConfigDotEnv: TCheckBox;
procedure chkCreateControllerUnitClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Image1Click(Sender: TObject);
@ -308,6 +309,7 @@ begin
fModel.S[TConfigKey.program_name] := 'TBA';
fModel.S[TConfigKey.program_default_server_port] := GetServerPort.ToString;
fModel.B[TConfigKey.program_msheap] := chkMSHeap.Checked;
fModel.B[TConfigKey.program_dotenv] := chkCustomConfigDotEnv.Checked;
fModel.S[TConfigKey.controller_unit_name] := 'TBA';
fModel.S[TConfigKey.controller_classname] := GetControllerClassName;
fModel.B[TConfigKey.controller_index_methods_generate] := chkCreateIndexMethod.Checked;

View File

@ -786,7 +786,7 @@ uses
MVCFramework.Serializer.JsonDataObjects,
MVCFramework.Serializer.Commons,
MVCFramework.Utils,
System.RegularExpressions;
System.RegularExpressions, MVCFramework.Logger;
var
GlobalAppName, GlobalAppPath, GlobalAppExe: string;
@ -1125,8 +1125,11 @@ end;
procedure TMVCConfig.SetDotEnv(const Value: IMVCdotEnv);
begin
CheckNotFreezed;
fdotEnv := Value;
if FdotEnv <> Value then
begin
CheckNotFreezed;
fdotEnv := Value;
end;
end;
procedure TMVCConfig.SetValue(const AIndex, aValue: string);
@ -1776,7 +1779,6 @@ begin
Result := ReasonStringByHTTPStatusCode(HTTPStatusCode);
end;
procedure dotEnvConfigure(const dotEnvDelegate: TFunc<IMVCDotEnv>);
begin
if GdotEnv <> nil then
@ -1796,9 +1798,21 @@ begin
begin
if not Assigned(GdotEnvDelegate) then
begin
raise EMVCDotEnv.Create('"dotEnvConfigure" not called');
LogI('dotEnvConfigure not called, a default dotEnv instance will be created');
GdotEnv := NewDotEnv
.UseStrategy(TMVCDotEnvPriority.FileThenEnv)
.UseProfile('test')
.UseProfile('prod')
.UseLogger(procedure(LogItem: String)
begin
LogD('dotEnv: ' + LogItem);
end)
.Build();
end
else
begin
GdotEnv := GdotEnvDelegate();
end;
GdotEnv := GdotEnvDelegate();
if GdotEnv = nil then
begin
raise EMVCDotEnv.Create('Delegated passed to "dotEnvConfigure" must return a valid IMVCDotEnv instance');

View File

@ -2565,6 +2565,7 @@ begin
if Assigned(AConfigAction) then
begin
fConfig.dotEnv := dotEnv;
AConfigAction(FConfig);
end;
FConfig.Freeze;