Commit f9c9a6a3 authored by Vassilis Kanellopoulos's avatar Vassilis Kanellopoulos
Browse files

updated file

parent 4e0904cf
# Development guide
# Application description and Development guide
## Requirements
- `php`: >=5.5
- `slim/slim`: ^3.0
- `kanellov/config-merge`: dev-master
- `kanellov/php-events`: ^2.0
## Install dependencies via composer
......@@ -16,26 +23,304 @@ to install new dependencies.
## Directory structure
- `app`: Application code
- `app/src`: All class files that follow the psr-4 autoloading standard (_see autoload in composer.json_)
- `app/templates`: Twig template files
- `config`: Configuration files (_\*.local.php are deployment specific files and ignored by git_)
- `data/cache/twig`: Twig's autogenerated cache files
- `data/log`: Log files
- `config`: Application main configuration
- `settings`: Configuration files for Slim Settings (_`*.local.php` are deployment specific files and ignored by git_)
- `data`: Directory for storing related application files
- `cache`: Directory for cache files
- `config`: Directory to cache merged configuration
- `templates`: Twig's autogenerated cache files
- `db`: 'Database schema and other database related files`
- `log`: Log files
- `tmp`: Temporary directory
- `uploads`: Directory for uploaded files
- `module`: Directory for application modules
- `public`: Webserver Document root
- `test`: Unit test files
- `vendor`: Composer dependencies
## Special files
- `public\index.php`: Appliction entry point
- `config\{,*.}{global,local}.php`: Configuration files; \*.global.php are loaded first and then can be overriden by \*.local.php
- `app/dependencies.php`: Wiring dependencies
- `app/middleware.php`: Application middleware
- `app/routes.php`: All application routes
- `config/app.config.php`: Main application configuration. Sets modules and config cache path
- `config/dev.config.php.dist`: Application configuration for development. Create a `dev.config.php` to include development related modules and to disable config caching.
- `config/settings/{,*.}{global,local}.php`: Configuration files for Slim settings; `*.global.php` are loaded first and then can be overridden by `*.local.php`
- `public/index.php`: Application entry point
## Application configuration and settings
### Application config
Modules to include are defined in `config/app.config.php` file.
The order of module definition matters if a module depends from another. For example, if ModuleA depends on ModuleB, ModuleB must be defined before ModuleA.
_More information about modules in [Modular application skeleton](#modular-application-skeleton) section._
Also, in this file is defined the path to store the merged settings, that are loaded from `config/settings`. See [Slim settings files](#slim-settings-files) for more information.
``` php
return [
'modules' => [
// Modules definition. Full path for module file
// Full path for file to store merged configuration
'cache_config' => 'data/cache/config/settings.php',
// ?>
### Slim settings files
- ``: defines resources, roles and privileges for acl
- ``: defines paths for module assets and public dir for copying
- ``: defines route guards for login and logout routes
- `authentication.local.php.dist`: defines password salt and encryption algorithm cost
- `db.local.php.dist`: defines database
- ``: defines debug log path
- `global.php`: defines basic slim settings
- `inventory.local.php.dist`: defines the api url for
- `ldap.local.php.dist`: defines ldap settings
- ``: defines logger settings
- ``: defines application navigation
- `sch_mm.local.php.dist`: defines api url and credentials for
- ``: defines settings for schools module
- `sso.local.php.dist`: defines phpCAS settings for
- ``: defines twig settings
## Html rendering and Templates
Application uses [Twig]( as template engine for rendering html.
## Modular application skeleton
Application is base on [Slim Framework]( and is implemented in a modular way. There are some key concepts that should be taken in mind, in order to implement a fully functional module.
### Dependency Container
Application uses the default `Slim\Container` for handling dependencies. See for more information.
### Autoloading
Application uses composer's autoloader `Composer\Autoload\ClassLoader` to handle class autoloading. See for more information.
### Application events
Application uses `Knlv\events` function to handle events. See [php-events](
After `Slim\App` initialization the following events are triggered:
1. `app.autoload`: Modules that listen to this event can setup the class autoloading. Event listener should expect the `Composer\Autoload\ClassLoader` instance as argument.
2. ``: Modules that listen to this event can register their services in the `Slim\Container` Dependency Container.
3. `app.bootstrap`: When this event is triggered, autoloading is completed and dependency container should contain all registered services. Modules listening for this event can register routes, or override services in the Dependency Container.
### How to define a module
A module is defined with a file which should return a Closure.
Here is a typical module implementation:
``` php
return function (Slim\App $app) {
// module initialization code
$container = $app->getContainer();
$events = $container->get('events');
$events('on', 'app.autoload', function ($autoloader) {
// register autoloading for module classes
$autoloader->addPsr4('Module\\', __DIR__ . '/src');
$events('on', '', function ($stop, $c) {
$c[Module\SomeAction::class] = function ($c) {
return new Module\SomeAction(
// dependencies
$c[Module\Middleware::class] = function ($c) {
return new Module\Middleware(
$events('on', 'app.bootstrap', function ($app, $c) {
// add middleware
// register routes
$app->get('/some-path', Module\SomeAction::class)
// To add middleware for an existing route provided by some other module,
// you must ensure that the route exists. Low listener priority ensures
// that the app.bootstrap listeners are executed and all routes exist.
$events('on', 'app.bootstrap', function ($app, $c) {
$route = $c->get('router')->getNamedRoute('some-other-route');
$route->add(function ($req, $res, $next) {
// middleware logic
}, -100); // low priority
// ?>
## Existing Modules
### application
Master module that defines the basic services such as:
- `Slim\Views\Twig` for view
- `Monolog` for logger
- `RedBeanPHP` for database
- `Slim\Flash\Messages` for flash message service
- `Slim\Csrf\Guard` for CSRF protection
It also provides the routes for home and about pages.
#### Dependencies
- `gabordemooij/redbean`: ^4.3.1
- `slim/twig-view`: ^2.0
- `slim/csrf`: ^0.6.0
- `slim/flash`: ^0.1.0
- `kanellov/slim-twig-flash`: ^0.1
- `monolog/monolog`: ^1.13
### application_form
Module that is responsible for application form submission by schools. It renders the form and stores the submitted form in database.
It also overrides schools index view by appending application form information.
#### Dependencies
- application module
- authentication module
- schools module
- `zendframework/zend-inputfilter`: ^2.0
### assets_manager
A module that is responsible to serve asset files, like css and js from within module's directory. See [`` in Slim settings files](#slim-settings-files).
#### Dependencies
### authentication
Module that provides user authentication against database. The module includes the view for login page.
#### Dependencies
- application module
- `zendframework/zend-authentication`: ^2.0
- `zendframework/zend-crypt`: ^2.0
### authorization
The module that provides the acl service and assigns role to users. See [`` in Slim settings files](#slim-settings-files).
#### Dependencies
- authentication module
- `zendframework/zend-permissions-acl`: ^2.0
### debug
This module should only be enabled during development and in a production deployment. It provides a debug logger and enables extensive information in error messages.
#### Dependencies
- application module
### sch_inventory
It provides the service for retrieving school's rooms and equipment from
#### Dependencies
- `guzzlehttp/guzzle`: ^6.1
### sch_ldap
It initilizes an ldap connection with See [`ldap.local.php.dist` in Slim settings files](#slim-settings-files).
#### Dependencies
- `zendframework/zend-ldap`: ^2.0
### sch_mm
Module for retrieving extensive information about school from
#### Dependencies
- `guzzlehttp/guzzle`: ^6.1
### sch_sso
Module that enables SSO with Schools use this authentication method.
It overrides login view.
#### Dependencies
- application module
- authentication module
- authorization module
- `jasig/phpcas`: 1.3.4
### sch_sync
Module that gathers information from the other sch services and stores school's information in local database.
#### Dependencies
- application module
- authentication module
- sch_inventory module
- sch_ldap module
- sch_mm module
- schools module
### schools
This module provides the services, views and javascript for schools to submit the staff, rooms, equipment and software.
#### Dependencies
- application module
- `zendframework/zend-inputfilter`: ^2.0
## Run it:
1. `$ cd gredu_labs`
2. `$ php -S -t public public/index.php`
3. Browse to http://localhost:8888
**Warning:** assets_manager module does not work with php-server sapi. Assets from modules will have to be copied in `public` directory by hand.
## Links
- [Slim Framework](
- [slimphp/Slim-Csrf](
- [slimphp/Slim-Flash](
- [kanellov/config-merge](
- [kanellov/php-events](
- [monolog](
- [zendframework/zend-ldap](
- [zendframework/zend-authentication](
- [zendframework/zend-crypt](
- [zendframework/zend-permissions-acl](
- [zendframework/zend-inputfilter](
- [Guzzle, PHP HTTP client](
- [Twig](
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment