Skip to content

Commit

Permalink
change default value for session dir adn session middleware improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
zamronypj committed Oct 13, 2021
1 parent f830c6f commit 2d2f878
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ TAbstractSessionManagerFactory = class(TFactory)
public
constructor create(
const cookieName : string = FANO_COOKIE_NAME;
const baseDir : string = '/tmp';
const prefix : string = ''
const baseDir : string = DEFAULT_SESS_DIR;
const prefix : string = DEFAULT_SESS_PREFIX
);

function sessionIdGenerator(const factory : ISessionIdGeneratorFactory) : TAbstractSessionManagerFactory;
Expand All @@ -53,8 +53,8 @@ implementation

constructor TAbstractSessionManagerFactory.create(
const cookieName : string = FANO_COOKIE_NAME;
const baseDir : string = '/tmp';
const prefix : string = ''
const baseDir : string = DEFAULT_SESS_DIR;
const prefix : string = DEFAULT_SESS_PREFIX
);
begin
fCookieName := cookieName;
Expand Down
3 changes: 3 additions & 0 deletions src/Sessions/Implementations/SessionConsts.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ interface
DEFAULT_DATA_COLUMN = 'data';
DEFAULT_EXPIRED_AT_COLUMN = 'expired_at';

DEFAULT_SESS_DIR = '/tmp/';
DEFAULT_SESS_PREFIX = '';

resourcestring

rsSessionExpired = 'Session is expired. Id : %s';
Expand Down
29 changes: 10 additions & 19 deletions src/Sessions/Middlewares/SessionMiddlewareFactoryImpl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ TSessionMiddlewareFactory = class(TFactory, IDependencyFactory)
fCookieFactory : ICookieFactory;
fExpiresInSec : integer;
public
constructor create();
constructor create(const aSessionMgr : ISessionManager);

function expiresInSec(const aExpiresInSec : integer) : TSessionMiddlewareFactory;
function sessionManager(const aSessionMgr : ISessionManager) : TSessionMiddlewareFactory;
function cookieFactory(const aCookieFactory : ICookieFactory) : TSessionMiddlewareFactory;

(*!---------------------------------------
Expand All @@ -53,6 +52,7 @@ implementation

uses

SysUtils,
JsonFileSessionManagerFactoryImpl,
CookieFactoryImpl,
SessionMiddlewareImpl;
Expand All @@ -61,9 +61,15 @@ implementation

EXPIRES_30_MIN = 30 * 60;

constructor TSessionMiddlewareFactory.create();
constructor TSessionMiddlewareFactory.create(const aSessionMgr : ISessionManager);
begin
fSessionMgr := nil;
fSessionMgr := aSessionMgr;

if fSessionMgr = nil then
begin
raise EArgumentNilException.create('Session manager can not be nil');
end;

fCookieFactory := nil;
fExpiresInSec := EXPIRES_30_MIN;
end;
Expand All @@ -76,14 +82,6 @@ implementation
result := self;
end;

function TSessionMiddlewareFactory.sessionManager(
const aSessionMgr : ISessionManager
) : TSessionMiddlewareFactory;
begin
fSessionMgr := aSessionMgr;
result := self;
end;

function TSessionMiddlewareFactory.cookieFactory(
const aCookieFactory : ICookieFactory
) : TSessionMiddlewareFactory;
Expand All @@ -94,14 +92,7 @@ implementation


function TSessionMiddlewareFactory.build(const container : IDependencyContainer) : IDependency;
var sessionManagerFactory : IDependencyFactory;
begin
if fSessionMgr = nil then
begin
sessionManagerFactory := TJsonFileSessionManagerFactory.create();
fSessionMgr := sessionManagerFactory.build(container) as ISessionManager;
end;

if fCookieFactory = nil then
begin
fCookieFactory := TCookieFactory.create();
Expand Down

0 comments on commit 2d2f878

Please sign in to comment.