php
: >=5.5slim/slim
: ^3.0kanellov/config-merge
: dev-masterkanellov/php-events
: ^2.0
In the project folder run
$ ./composer.phar install
to install dependencies.
If you add any dependencies in composer.json
file, run
$ ./composer.phar update
to install new dependencies.
config
: Application main configurationsettings
: Configuration files for Slim Settings (*.local.php
are deployment specific files and ignored by git)
data
: Directory for storing related application filescache
: Directory for cache filesconfig
: Directory to cache merged configurationtemplates
: Twig's autogenerated cache files
db
: 'Database schema and other database related files`log
: Log filestmp
: Temporary directoryuploads
: Directory for uploaded files
module
: Directory for application modulespublic
: Webserver Document rootvendor
: Composer dependencies
config/app.config.php
: Main application configuration. Sets modules and config cache pathconfig/dev.config.php.dist
: Application configuration for development. Create adev.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
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 section.
Also, in this file is defined the path to store the merged settings, that are loaded from config/settings
. See Slim settings files for more information.
<?php
return [
'modules' => [
// Modules definition. Full path for module file
'module/application/bootstrap.php',
],
// Full path for file to store merged configuration
'cache_config' => 'data/cache/config/settings.php',
];
// ?>
acl.global.php
: defines resources, roles and privileges for aclassets_manager.global.php
: defines paths for module assets and public dir for copyingauthentication.global.php
: defines route guards for login and logout routesauthentication.local.php.dist
: defines password salt and encryption algorithm costdb.local.php.dist
: defines databasedebug.global.php
: defines debug log pathglobal.php
: defines basic slim settingsinventory.local.php.dist
: defines the api url for inventory.sch.grldap.local.php.dist
: defines ldap settingsmonolog.global.php
: defines logger settingsnav.global.php
: defines application navigationsch_mm.local.php.dist
: defines api url and credentials for mm.sch.grschools.global.php
: defines settings for schools modulesso.local.php.dist
: defines phpCAS settings for sso.sch.grtwig.global.php
: defines twig settings
Application uses Twig as template engine for rendering html.
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.
Application uses the default Slim\Container
for handling dependencies. See http://www.slimframework.com/docs/concepts/di.html for more information.
Application uses composer's autoloader Composer\Autoload\ClassLoader
to handle class autoloading. See https://github.com/composer/composer/blob/master/doc/01-basic-usage.md#autoloading for more information.
Application uses Knlv\events
function to handle events. See php-events.
After Slim\App
initialization the following events are triggered:
app.autoload
: Modules that listen to this event can setup the class autoloading. Event listener should expect theComposer\Autoload\ClassLoader
instance as argument.app.services
: Modules that listen to this event can register their services in theSlim\Container
Dependency Container.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.
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', 'app.services', function ($stop, $c) {
$c[Module\SomeAction::class] = function ($c) {
return new Module\SomeAction(
// dependencies
);
};
$c[Module\Middleware::class] = function ($c) {
return new Module\Middleware(
//dependencies
);
};
});
$events('on', 'app.bootstrap', function ($app, $c) {
// add middleware
$app->add(Module\Middleware::class);
// register routes
$app->get('/some-path', Module\SomeAction::class)
->setName('some-route');
});
// 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
};
// ?>
Master module that defines the basic services such as:
Slim\Views\Twig
for viewMonolog
for loggerRedBeanPHP
for databaseSlim\Flash\Messages
for flash message serviceSlim\Csrf\Guard
for CSRF protection
It also provides the routes for home and about pages.
gabordemooij/redbean
: ^4.3.1slim/twig-view
: ^2.0slim/csrf
: ^0.6.0slim/flash
: ^0.1.0kanellov/slim-twig-flash
: ^0.1kanellov/assets-manager-middleware
: ^1.0,monolog/monolog
: ^1.13
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.
- application module
- authentication module
- schools module
zendframework/zend-inputfilter
: ^2.0
Module that provides user authentication against database. The module includes the view for login page.
- application module
zendframework/zend-authentication
: ^2.0zendframework/zend-crypt
: ^2.0
The module that provides the acl service and assigns role to users. See acl.global.php
in Slim settings files.
- authentication module
zendframework/zend-permissions-acl
: ^2.0
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.
- application module
It provides the service for retrieving school's rooms and equipment from http://inventory.sch.gr.
guzzlehttp/guzzle
: ^6.1
It initilizes an ldap connection with sch.gr. See ldap.local.php.dist
in Slim settings files.
zendframework/zend-ldap
: ^2.0
Module for retrieving extensive information about school from http://mm.sch.gr.
guzzlehttp/guzzle
: ^6.1
Module that enables SSO with http://sso.sch.gr. Schools use this authentication method.
It overrides login view.
- application module
- authentication module
- authorization module
jasig/phpcas
: 1.3.4
Module that gathers information from the other sch services and stores school's information in local database.
- application module
- authentication module
- sch_inventory module
- sch_ldap module
- sch_mm module
- schools module
This module provides the services, views and javascript for schools to submit the staff, rooms, equipment and software.
- application module
zendframework/zend-inputfilter
: ^2.0
This module overrides staff view of schools module. It allows school user to submit information about teachers using IT in education.
This module ovverides index page by placing a panel with the total numbers of schools registered in application and of submitted application forms.
It also provides the /in_numbers route where total numbers are analyzed by school type.
- schools module
$ cd gredu_labs
$ php -S 0.0.0.0:8888 -t public public/index.php
- Browse to http://localhost:8888
Warning: kanellov/assets-manager-middleware does not work with php-server sapi. Assets from modules will have to be copied in public
directory by hand.
- Slim Framework
- slimphp/Slim-Csrf
- slimphp/Slim-Flash
- kanellov/config-merge
- kanellov/php-events
- kanellov/assets-manager-middleware
- monolog
- zendframework/zend-ldap
- zendframework/zend-authentication
- zendframework/zend-crypt
- zendframework/zend-permissions-acl
- zendframework/zend-inputfilter
- Guzzle, PHP HTTP client
- Twig