Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zamronypj committed Jan 5, 2020
2 parents fa87eee + 535382b commit be129af
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 104 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Expand Up @@ -57,11 +57,11 @@ bin/unit/*
!bin/unit/README.md

#----------------------------------------------
# Ignore FreePascal built-in console IDE generated files
# Ignore Free Pascal built-in console IDE generated files
#----------------------------------------------
fp.dir

#----------------------------------------------
# Ignore Lazarus local files (user-specific info)
#----------------------------------------------
*.lps
*.lps
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -235,14 +235,14 @@ When running `build.sh` script, you may encounter following warning:
/usr/bin/ld: warning: public/link.res contains output sections; did you forget -T?
```

This is known issue between FreePascal and GNU Linker. See
This is known issue between Free Pascal and GNU Linker. See
[FAQ: link.res syntax error, or "did you forget -T?"](https://www.freepascal.org/faq.var#unix-ld219)

However, this warning is minor and can be ignored. It does not affect output executable.

### Issue with unsynchronized compiled unit with unit source

Sometime FreePascal can not compile your code because, for example, you deleted a
Sometime Free Pascal can not compile your code because, for example, you deleted a
unit source code (.pas) but old generated unit (.ppu, .o, .a files) still there
or when you switch between git branches. Solution is to remove those files.

Expand Down
2 changes: 1 addition & 1 deletion build.cfg.sample
Expand Up @@ -9,7 +9,7 @@
#----------------------------------------------
# User configuration that applies to both
# development and production environment
# Please see FreePascal Documentation for available
# Please see Free Pascal Documentation for available
# compiler configurations
#----------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions build.dev.cfg.sample
Expand Up @@ -8,7 +8,7 @@

#----------------------------------------------
# User configuration for development build
# Please see FreePascal Documentation for available
# Please see Free Pascal Documentation for available
# compiler switch configurations
#----------------------------------------------

Expand Down Expand Up @@ -76,7 +76,7 @@
#----------------------------------------------
# Verbose unit searching info,
# Remove comment, in case unit file is not found
# so FreePascal will output verbose message where
# so Free Pascal will output verbose message where
# it tries to look for unit file
#----------------------------------------------
#-vut
#-vut
4 changes: 2 additions & 2 deletions build.prod.cfg.sample
Expand Up @@ -8,7 +8,7 @@

#----------------------------------------------
# User configuration for production build
# Please see FreePascal Documentation for available
# Please see Free Pascal Documentation for available
# compiler switch configurations
#----------------------------------------------

Expand Down Expand Up @@ -58,4 +58,4 @@
# Strip all debug information and symbols
# from output executable
#----------------------------------------------
-Xs
-Xs
51 changes: 21 additions & 30 deletions src/App/User/Controllers/Factories/UserControllerFactory.pas
Expand Up @@ -35,40 +35,31 @@ implementation
UserController;

function TUserControllerFactory.build(const container : IDependencyContainer) : IDependency;
var routeMiddlewares : IMiddlewareCollectionAware;
config : IAppConfiguration;
var config : IAppConfiguration;
viewParams : IViewParameters;
begin
routeMiddlewares := container.get('routeMiddlewares') as IMiddlewareCollectionAware;
try
//get instance of application from dependency container
config := container.get('config') as IAppConfiguration;
//get instance of application from dependency container
config := container.get('config') as IAppConfiguration;

//get new instance of viewParams from dependency container
viewParams := container.get('viewParams') as IViewParameters;
//get new instance of viewParams from dependency container
viewParams := container.get('viewParams') as IViewParameters;

//set some value. Following command will replace
//any {{baseUrl}} {{appName}} in template HTML with actual
//value from json configuration
viewParams
.setVar('baseUrl', config.getString('baseUrl'))
.setVar('appName', config.getString('appName'));
//set some value. Following command will replace
//any {{baseUrl}} {{appName}} in template HTML with actual
//value from json configuration
viewParams
.setVar('baseUrl', config.getString('baseUrl'))
.setVar('appName', config.getString('appName'));

//create the controller
result := TUserController.create(
routeMiddlewares.getBefore(),
routeMiddlewares.getAfter(),

//use userListingView as view
//see views.dependencies.inc
container.get('userListingView') as IView,
viewParams,
//use model registered in userListModel
//see models.dependencies.inc
container.get('userListModel') as IModelReader
);
finally
routeMiddlewares := nil;
end;
//create the controller
result := TUserController.create(
//use userListingView as view
//see views.dependencies.inc
container.get('userListingView') as IView,
viewParams,
//use model registered in userListModel
//see models.dependencies.inc
container.get('userListModel') as IModelReader
);
end;
end.
18 changes: 8 additions & 10 deletions src/App/User/Controllers/UserController.pas
Expand Up @@ -23,35 +23,32 @@ interface
*
* @author Zamrony P. Juhara <zamronypj@yahoo.com>
*------------------------------------------------*)
TUserController = class(TController, IDependency)
TUserController = class(TController)
private
userList : IModelReader;
public
constructor create(
const beforeMiddlewares : IMiddlewareCollection;
const afterMiddlewares : IMiddlewareCollection;
const viewInst : IView;
const viewParamsInst : IViewParameters;
const userListModel : IModelReader
);
destructor destroy(); override;
function handleRequest(
const request : IRequest;
const response : IResponse
const response : IResponse;
const args : IRouteArgsReader
) : IResponse; override;
end;

implementation

constructor TUserController.create(
const beforeMiddlewares : IMiddlewareCollection;
const afterMiddlewares : IMiddlewareCollection;
const viewInst : IView;
const viewParamsInst : IViewParameters;
const userListModel : IModelReader
);
begin
inherited create(beforeMiddlewares, afterMiddlewares, viewInst, viewParamsInst);
inherited create(viewInst, viewParamsInst);
userList := userListModel;
end;

Expand All @@ -62,13 +59,14 @@ implementation
end;

function TUserController.handleRequest(
const request : IRequest;
const response : IResponse
const request : IRequest;
const response : IResponse;
const args : IRouteArgsReader
) : IResponse;
begin
{---put your code here---}
userList.read();
result := inherited handleRequest(request, response);
result := inherited handleRequest(request, response, args);
end;

end.
27 changes: 0 additions & 27 deletions src/Dependencies/main.dependencies.inc
Expand Up @@ -6,33 +6,6 @@
* @license [[LICENSE_URL]] ([[LICENSE]])
*------------------------------------------------------------- *)

{-----------------------------------------------
register middleware list for each routes that
does nothing,
need to be use factory so each route will have
different middleware list
Replace with TMiddlewareCollectionAwareFactory to support middleware
or replace with your own implementation if required
------------------------------------------------}
container.factory('routeMiddlewares', TNullMiddlewareCollectionAwareFactory.create());

{-----------------------------------------------
register application simple router instance
Replace with your own implementation if required
------------------------------------------------}
container.add('router', TSimpleRouterFactory.create());

{-----------------------------------------------
setup application request dispatcher
replace with TDispatcherDispatcherFactory if middleware support is requred
------------------------------------------------}
container.add(
'dispatcher',
TSimpleDispatcherFactory.create(
container.get('router') as IRouteMatcher
)
);

{-----------------------------------------------
register application configuration
------------------------------------------------}
Expand Down
4 changes: 2 additions & 2 deletions src/Routes/User/routes.inc
Expand Up @@ -6,5 +6,5 @@
* @license [[LICENSE_URL]] ([[LICENSE]])
*------------------------------------------------------------- *)

router.get('/user', container.get('userController') as IRouteHandler);
router.get('/', container.get('userController') as IRouteHandler);
router.get('/user', container.get('userController') as IRequestHandler);
router.get('/', container.get('userController') as IRequestHandler);
9 changes: 4 additions & 5 deletions src/app.pas
Expand Up @@ -21,10 +21,9 @@
*
* @author AUTHOR_NAME <author@email.tld>
*------------------------------------------------*)
appInstance := TBootstrapApp.create(
TDependencyContainer.create(TDependencyList.create()),
TCGIEnvironment.create(),
TErrorHandler.create()
appInstance := TCgiWebApplication.create(
TAppServiceProvider.create(),
TAppRoutes.create()
);
appInstance.run();
end.
end.
36 changes: 17 additions & 19 deletions src/bootstrap.pas
Expand Up @@ -15,11 +15,17 @@ interface

type

TBootstrapApp = class(TFanoWebApplication)
protected
procedure buildDependencies(const container : IDependencyContainer); override;
procedure buildRoutes(const container : IDependencyContainer); override;
function initDispatcher(const container : IDependencyContainer) : IDispatcher; override;
TAppServiceProvider = class(TBasicAppServiceProvider)
public
procedure register(const container : IDependencyContainer); override;
end;

TAppRoutes = class(TRouteBuilder)
public
procedure buildRoutes(
const container : IDependencyContainer;
const router : IRouter
); override;
end;

implementation
Expand All @@ -39,24 +45,16 @@ implementation
FooterViewFactory;


procedure TBootstrapApp.buildDependencies(const container : IDependencyContainer);
procedure TAppServiceProvider.register(const container : IDependencyContainer);
begin
{$INCLUDE Dependencies/dependencies.inc}
end;

procedure TBootstrapApp.buildRoutes(const container : IDependencyContainer);
var router : IRouter;
begin
router := container.get('router') as IRouter;
try
{$INCLUDE Routes/routes.inc}
finally
router := nil;
end;
end;

function TBootstrapApp.initDispatcher(const container : IDependencyContainer) : IDispatcher;
procedure TAppRoutes.buildRoutes(
const container : IDependencyContainer;
const router : IRouter
);
begin
result := container.get('dispatcher') as IDispatcher;
{$INCLUDE Routes/routes.inc}
end;
end.
2 changes: 1 addition & 1 deletion vendor/fano
Submodule fano updated 761 files

0 comments on commit be129af

Please sign in to comment.