diff options
| author | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-15 18:15:37 +0300 |
|---|---|---|
| committer | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-15 18:15:37 +0300 |
| commit | 59cd40235bf4746a119421609b25d7e9b7f65f83 (patch) | |
| tree | 35a4929d59ed87b97219ea992e4cbcdc994a78d5 | |
| parent | 0d983359abb511f75aa5f0b2b498b97728eb25a3 (diff) | |
| download | gyraf1gov-59cd40235bf4746a119421609b25d7e9b7f65f83.tar.gz gyraf1gov-59cd40235bf4746a119421609b25d7e9b7f65f83.tar.bz2 gyraf1gov-59cd40235bf4746a119421609b25d7e9b7f65f83.zip | |
refactoring framework defaults
| -rw-r--r-- | Dockerfile | 1 | ||||
| -rw-r--r-- | core/classes/Database.php | 2 | ||||
| -rw-r--r-- | core/config/anom_settings.php | 209 | ||||
| -rw-r--r-- | core/config/init.php | 11 | ||||
| -rw-r--r-- | core/config/xx--anom_settings.php | 66 | ||||
| -rw-r--r-- | core/config/xx--constants.php (renamed from core/config/constants.php) | 0 | ||||
| -rw-r--r-- | core/helpers/autoload.php | 2 | ||||
| -rw-r--r-- | env.example (renamed from core/auth/env.example) | 0 | ||||
| -rw-r--r-- | public/app/config/setup-application.php (renamed from public/app/config/app_constants.php) | 252 | ||||
| -rw-r--r-- | public/app/config/setup-framework.php | 469 | ||||
| -rw-r--r-- | public/app/routes/api.php | 46 | ||||
| -rw-r--r-- | public/app/routes/frontend.php | 6 | ||||
| -rw-r--r-- | public/index.php | 26 | ||||
| -rwxr-xr-x | tests/settings.php | 1 |
14 files changed, 600 insertions, 491 deletions
@@ -51,6 +51,7 @@ COPY core /var/www/core COPY storage /var/www/storage # Copy configuration files for the container (application based) +COPY .env /var/www/ COPY docker /var/www/docker COPY tests /var/www/tests COPY composer.json /var/www/ diff --git a/core/classes/Database.php b/core/classes/Database.php index 0a8a10a..9de9872 100644 --- a/core/classes/Database.php +++ b/core/classes/Database.php @@ -125,7 +125,7 @@ class Database { } // keep rowCount (valid for INSERT, UPDATE, DELETE) - $this->rowCount = $stmt->rowCount(); + $this->rowCount = $stmt->rowCount(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); diff --git a/core/config/anom_settings.php b/core/config/anom_settings.php deleted file mode 100644 index 03e4cc5..0000000 --- a/core/config/anom_settings.php +++ /dev/null @@ -1,209 +0,0 @@ -<?php -/** CONFIGURATION PARAMETRES - * ----------------------------------------------------------------------------- - * - * Here you can find all the setup paramaters that define - * key-decisions of your application; - * - * ex. Session driver, Cache driver, Cookies Policy etc; - * - * Other supplamentary constants (ex. Session options according to the driver, - * Cookie properties according to the application's specs) shall be defined - * into the ~/public/app/config/app_constants.php - * - * - * NOTE: - * You may rewrite the defines setting any values manualy - * SETTING anom CONSTANTS VIA an `.env` FILE IS HIGHLY RECOMMENDED (for safety) - * The default env file is saved into `~/core/auth` folder - * - * ----------------------------------------------------------------------------- - */ - -if (file_exists("../core/auth/.env")) { - $ini = parse_ini_file("../core/auth/.env"); -} - - - - -/** ENVIRONMENT constant - * ----------------------------------------------------------------------------- - * - * define application's environment stage; [PRODUCTION|develpment|testing|*] - * seting this constant to 'PRODUCTION' eliminates debuggin comments; - * - * DO NOT FORGET to change this setting when deploying to a different stage - * - * ----------------------------------------------------------------------------- - */ - -define('PRODUCTION', ($ini['ENVIRONMENT'] == 'production') ); - - - - -/** APPLICATION NAMES AND URL DEFAULTS - * ----------------------------------------------------------------------------- - * - * NOTE: - * if .env file exists ... do not touch anything - * else ... replace $env[*] values with your setup - * - * ----------------------------------------------------------------------------- - */ - -define('APP_NAME', $ini['APP_NAME']); // Application Name (how developer refers to it) - -define('APP_VERSION', $ini['APP_VERSION']); // Application version (major_version + subversion_class) - // keep it simple, ex: '1.alfa' -or- '1.beta' -or- '2.rc' - -define('SITE_URL', $ini['ANOM_HOSTNAME']); - - - - -/** APPLICATION PATHS - * ----------------------------------------------------------------------------- - * - * Obligarory: - * These are needed in order to run the bare minimum MVC system - * They also make code easier to read - * - * NOTE: - * most likely won't need to change any of these subsection defines; - * still the framework makes easy for the developer - * to change the Views and/or the Tests diectrory; - * - * ----------------------------------------------------------------------------- - */ - -define('APP_ROOT', $ini['APP_ROOT'] ?? dirname(get_included_files()[0]) ); - -define('URL_ROOT', '/'); - -define('INIT_APPLICATION', '../core/config/init.php'); - -define('VIEWS_DIRECTORY', $ini['VIEWS_DIRECTORY'] ?? (APP_ROOT.'/app/views/')); - -define('TESTS_DIRECTORY', $ini['TESTS_DIRECTORY'] ?? (APP_ROOT."/../tests/")); - - - - -/** AUTOLOADER ///////////////////////////////////////////////////////////////// - * ----------------------------------------------------------------------------- - * - * An autoloader for classes is required; - * - * - ** OPTION 1: COMPOSER - * ----------------------------------------------------------------------------- - * Composer is recommended and makes much more than simple autoloding - * ----------------------------------------------------------------------------- - */ - -define('AUTOLOADER' , '../vendor/autoload.php'); - -/** OPTION 2: Custom Autoloader - * ----------------------------------------------------------------------------- - * If Composer is not supported, another autoloading proccess required - * Comment/Disable the 1st option and uncomment/Enable the next line - * ----------------------------------------------------------------------------- - * - * NOTE: if the custom autoloadet is used - * then you need to defing CLASSPATHS constant-array too; - */ - -# define('AUTOLOADER' , '../core/helpers/autoload.php'); - - - - -/** SESSION HANDLING - * ---------------------------------------------------------------------------- - * - * there are several session drivers for session handling: - * - * 'DefaultSession' : uses the default (file-based) php session management - * 'FileSession' : defines a custom file-based session mechanism - * 'DatabaseSession' : mechanism that stores Session data into a DataBase - * ---------------------------------------------------------------------------- - */ - -define('SESSION_DRIVER', $ini['SESSION_DRIVER']); - - - - -/** COOKIE SETTINGS - * ----------------------------------------------------------------------------- - * - * Define cookie policy (cookie sharing and securing) - * - * recomended values for production environment: - * COOKIE_SECURE=true - * COOKIE_SAMESITE='Strict' - * - * NOTE: - * on development environment COOKIE_SECURE has to be false - * in order for the test server to use them from http://locahost - * - * for more info about cookie policy read: - * https://www.php.net/manual/en/function.session-set-cookie-params.php - * - * ----------------------------------------------------------------------------- - */ - -define('COOKIE_SECURE', PRODUCTION); // Secure cookie policy [true|false] - -define('COOKIE_SAMESITE', $ini['COOKIE_SAMESITE'] ?? 'Strict'); // SameSite cookie policy [Strict|Lax|None] - -# define('COOKIE_DOMAIN', $env['ANOM_HOSTNAME']); // domain to be visible on - - - - -/* ADVANCED OPTIMIZATION /////////////////////////////////////////////////////// - * ----------------------------------------------------------------------------- - * - * APP_CACHE defines the cache-driver; - * accepted values are the name of the Cache-interface impementations (the exact - * names of the classes) - * - * 'FileCache' : caching in filesystem; fair if caching on HDD; great on SSD - * 'RedisCache' : caching in Redis server; generally recommended if available - * 'MemCachedCache' : caching in Memcached server; recommended if available - * - * NOTE: FileCache on a NVMe SDD is the fastest option; - * Redis and Memcached are really-fast caching options and are available for - * scaling horizontaly your application (eache one has it's own strngths; - * study, then choose the one that fulfills your needs; - * ----------------------------------------------------------------------------- - */ - -define('CACHE_DRIVER', $ini['CACHE_DRIVER']); - - - - -/** HOTFIX: (needs refactoring) */ - -// CONNECTIONS ... - -define('FILECACHE_PATH', APP_ROOT.'/../storage/cache/'); // if CACHE_DRIVER is set to 'FileCache' - -define('MEDIA_STORAGE_ROOT', APP_ROOT.'/../storage/uploads/'); // Media files root directory - -# define('REDIS_HOST', '127.0.0.1'); // if CACHE_DRIVER is set to 'RedisCache' - -# define('MEMCAHCED_SERVER', '127.0.0.1'); // if CACHE_DRIVER is set to 'MemCached' - - - - -/** CREDENTIALS - * ----------------------------------------------------------------------------- - */ - -
\ No newline at end of file diff --git a/core/config/init.php b/core/config/init.php index 589a486..40624d3 100644 --- a/core/config/init.php +++ b/core/config/init.php @@ -18,14 +18,9 @@ // setup error-handliing // ----------------------------------------------------------------------------- -require_once '../core/helpers/error_handling.php'; +require_once APP_ROOT.'/core/helpers/error_handling.php'; -// depricated: -/// // Load rendering sub-system -/// // ----------------------------------------------------------------------------- -/// require_once RENDERING_SYSTEM; - // Setup Application Engiine // ----------------------------------------------------------------------------- @@ -55,10 +50,10 @@ Registry::set('REQUEST', new Request()); // (these patterns use some of the project's central objects (Registry, // Cache, Database), so laod them after. // ----------------------------------------------------------------------------- -require_once '../core/helpers/design_patterns.php'; +require_once APP_ROOT.'/core/helpers/design_patterns.php'; // Add Routes // ----------------------------------------------------------------------------- -require_once 'app/config/init_routes.php'; // initialize routes +require_once WEB_ROOT.'/app/config/init_routes.php'; // initialize routes diff --git a/core/config/xx--anom_settings.php b/core/config/xx--anom_settings.php new file mode 100644 index 0000000..06fe5af --- /dev/null +++ b/core/config/xx--anom_settings.php @@ -0,0 +1,66 @@ +<?php + + + + + + + + + + + + + + + + + + + + + + +/* ADVANCED OPTIMIZATION /////////////////////////////////////////////////////// + * ----------------------------------------------------------------------------- + * + * APP_CACHE defines the cache-driver; + * accepted values are the name of the Cache-interface impementations (the exact + * names of the classes) + * + * 'FileCache' : caching in filesystem; fair if caching on HDD; great on SSD + * 'RedisCache' : caching in Redis server; generally recommended if available + * 'MemCachedCache' : caching in Memcached server; recommended if available + * + * NOTE: FileCache on a NVMe SDD is the fastest option; + * Redis and Memcached are really-fast caching options and are available for + * scaling horizontaly your application (eache one has it's own strngths; + * study, then choose the one that fulfills your needs; + * ----------------------------------------------------------------------------- + */ + +define('CACHE_DRIVER', $env['CACHE_DRIVER'] ?? 'FileCache'); + + + + +/** HOTFIX: (needs refactoring) */ + +// CONNECTIONS ... + +define('FILECACHE_PATH', APP_ROOT.'/storage/cache/'); // if CACHE_DRIVER is set to 'FileCache' + +define('MEDIA_STORAGE_ROOT', APP_ROOT.'/storage/uploads/'); // Media files root directory + +# define('REDIS_HOST', '127.0.0.1'); // if CACHE_DRIVER is set to 'RedisCache' + +# define('MEMCAHCED_SERVER', '127.0.0.1'); // if CACHE_DRIVER is set to 'MemCached' + + + + +/** CREDENTIALS + * ----------------------------------------------------------------------------- + */ + +
\ No newline at end of file diff --git a/core/config/constants.php b/core/config/xx--constants.php index d2ecc41..d2ecc41 100644 --- a/core/config/constants.php +++ b/core/config/xx--constants.php diff --git a/core/helpers/autoload.php b/core/helpers/autoload.php index c4359c6..c72c335 100644 --- a/core/helpers/autoload.php +++ b/core/helpers/autoload.php @@ -18,7 +18,7 @@ spl_autoload_register( // check all possible classPaths for class foreach(CLASSPATHS as $key => $basePath) { - $file = APP_ROOT . $basePath . $classPath .'.php'; + $file = WEB_ROOT . $basePath . $classPath .'.php'; // if class-file exist, include it if (file_exists($file)) { diff --git a/core/auth/env.example b/env.example index fd47dd8..fd47dd8 100644 --- a/core/auth/env.example +++ b/env.example diff --git a/public/app/config/app_constants.php b/public/app/config/setup-application.php index 6974bd8..ec9a7bb 100644 --- a/public/app/config/app_constants.php +++ b/public/app/config/setup-application.php @@ -1,256 +1,28 @@ <?php -/** Custom Application Constants +/** SETUP APPLICATION * ----------------------------------------------------------------------------- + * + * Define application specific constants * - * Constants defined for your current application: - * - * 1. Main constants (Names, Labels, securoty defaults, etc) - * - * 2. Credentials and sub-configuration of main services - * - * 3. Other custom constants - * - * ----------------------------------------------------------------------------- - */ - -/** Preload environmental file - * Setting up main constants via en envoronment file is HIGHLY RECOMMENDED; - * - * read ini file if exist - */ -if (file_exists("../core/auth/.env")) { - $env = parse_ini_file("../core/auth/.env"); -} - - - - - -## ----------------------------------------------------------------------------- -## -## - - - -- -- --- M A I N C O N S T A N T S --- -- -- - - - -## Main constants (names, labels, default roles, security defaults, etc -## -## ----------------------------------------------------------------------------- - - - -/** Main default constants / strings / names / etc - * ----------------------------------------------------------------------------- - */ - -define('SITE_TITLE', 'schoolGov'); // Site Title (the end-users' title) - - - -/** Autoload paths - * ----------------------------------------------------------------------------- - * - * CLASSPATHS : array of paths where classes are saved - * - * NOTE: - * if the custom autoloader is used (instead of composer's) - * then you need to defing CLASSPATHS constant-array too; - * - * In most cases you won't need this, - * so comment the next lines out of the code-base - * - * ----------------------------------------------------------------------------- - */ -# define('CLASSPATHS', array( -# '/../core/classes/', // core classes -# '/app/controllers/', // controller classes -# '/app/models/', // model classes -# '/app/extends/', // extending core classes -# '/../vendor/' // vendor/dependency classes -# ) -# ); - - - -/** FileSession Path - * --- -- -- - - - - * if FileSession is selected, a path for session-files is needed - * - * TODO: - * also, the hybrid sessioning (in progress) will need this setting - * - * NOTE: - * DefaultSession is also file-based but to not need a file-path setting - * (php will handle any file-needed actions to the file-system) - */ - -# define('FILESESSION_PATH', '../storage/session'); - - - -/** Session and cookie names - * --- -- -- - - - - */ -define('SESSION_NAME', 'offticket'); // cookie for session (office ticket) -define('CONNECTION_COOKIE', 'con'); // cookie for connection -define('MAX_SESSION_LIFE', 2*60*60); // maximum session lifetime (2 hours) - - - -/** SECURITY SETTINGS /////////////////////////////////////////////////////////// - * ----------------------------------------------------------------------------- - * - * Cross Site Request Forgery - * --- - * Enables a CSRF cookie token to be set. When set to TRUE, token will be - * checked on a submitted form. If you are accepting user data, it is strongly - * recommended CSRF protection be enabled. - * ----------------------------------------------------------------------------- + * ----------------------------------------------------------------------------- */ -define('CSRF_PROTECTION', false); - -define('CSRF_TOKEN_NAME', 'csrf_test_name'); // token name - -define('CSRF_COOKIE_NAME', 'csrf_cookie_name'); // cookie name - -define('CSRF_EXPIRE', 7200); // The number in seconds the token should expire. - -define('CSRF_REGENERATE', TRUE); // Regenerate token on every submission - -define('CSRF_EXCLUDE_URIS', array()); // Array of URIs which ignore CSRF checks - - - - -## ----------------------------------------------------------------------------- -## -## - - - -- -- --- C O N N E C T I O N C R E D E N T I A L S --- -- -- - - - -## -## ----------------------------------------------------------------------------- - - - -/** SERVICE PARAMETRES - * ----------------------------------------------------------------------------- - * - * Connection parametres and credentials for accssing services - * needed by the application; Such services may be.. - * - * - RDBMS - * -- MySQL - * -- PotgresSQL - * - * - Caching services - * -- Redis - * -- MemCached - * - * Edit only the constants needed by the application; - * Comment those you do not need; - * - * ///////////////////////////////////////////////////////////////////////////// - */ - -/** DATABASE CONNECTION PARAMETRES - * ----------------------------------------------------------------------------- - * Production and staging environments may use different databases. - * - * A safe practice is to keep credentials outside plain files like this one - * in environmental variable or other secret file etc. - * - * Uncomment/enable each group of definitions suits your case to define - * the credentials needed for accessing the database - */ - -define('DB_NAME', $ini['DB_NAME']); - -define('DB_USER', $ini['DB_USER']); - -define('DB_PASS', $ini['DB_PASS']); - -/** NOTE: - * PDO_HOST can be a hostname/port combination -or- a unix socket - * - * ...examples: - * define('PDO_HOST', 'host=/localhost') ## hostname case - * define('PDO_HOST', 'host=/localhost;port=3456') ## hostname/port case - * define('PDO_HOST', 'unix_socket=/sql/ex123:europe:some-db'); ## unix socket - * define('PDO_HOST', 'unix_socket=/cloudsql/name-123456:europe-west4:name-db-eu'); - */ - -define('PDO_HOST', $ini['PDO_HOST']); - -define('DB_TIMEZONE', "SET time_zone = 'Europe/Athens'"); - - - - -/** CACHED SERVICES - * - * impemented services: - * - * - File Cache - * - Redis - * - Memcached - * - * NOTE: - * Both Redis and Memcached configurations are given as a template to work on; - * In most cases the default values should do the job -- of course you need to - * read the README file (check the project's root); - * As these caching services are not fully tested you may need to ochestrate - * the services in detail or edit the connection strings into the core classes - * (hosted under the '/core/classes/cacher' folder) - */ - - define('FILECACHE_PATH', APP_ROOT.'/../storage/cache/'); // if CACHE_DRIVER is set to 'FileCache' - - define('MEDIA_STORAGE_ROOT', APP_ROOT.'/../storage/uploads/'); // Media files root directory - - - - # define('MEMCAHCED_SERVER', '127.0.0.1'); // if CACHE_DRIVER is set to 'MemCached' - -/** REDIS SERVICE - * ----------------------------------------------------------------------------- - * Most of the times Redis is running on 'localhost' (host = '127.0.0.1') - * When implemented via anom's docker-composer (redis via bridge) then you need - * do declare the hostname as 'redis' - */ - -# define('REDIS_HOST', '127.0.0.1'); // if CACHE_DRIVER is set to 'RedisCache' -# if (!defined('REDIS_HOST')) define('REDIS_HOST', 'redis'); -# -# if (!defined('REDIS_PORT')) define('REDIS_PORT', 6379); -# -# if (!defined('REDIS_PASS')) define('REDIS_PASS', null); - - -/** MEMCACHED - * ----------------------------------------------------------------------------- - * Memcached looks very much like Redis (plus, both are serving from RAM) - * Usualy Memcashed is running localy so host is 'localhost' ('127.0.0.1') - * If you use the framework's docker-composer implementation then - * the hostname is 'anomemcached' - */ - -# if (!defined('MEMCACHE_HOST')) define('MEMCACHE_HOST', 'anomemcached'); - - - - +// email setup ///////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- -/** email setup - * --- -- -- - - - - */ - // SMTP + // SMTP define('MAIL_MAILER', $env['MAIL_MAILER']); define('MAIL_HOST', $env['MAIL_HOST']); define('MAIL_PORT', $env['MAIL_PORT']); define('MAIL_USERNAME', $env['MAIL_USERNAME']); define('MAIL_PASSWORD', $env['MAIL_PASSWORD']); define('MAIL_ENCRYPTION', $env['MAIL_ENCRYPTION']); - // Mailjet + // Mailjet define('MAILJET_APIKEY', $env['MAILJET_APIKEY']); // apikey define('MAILJET_SECRET', $env['MAILJET_SECRET']); // secret define('MAILJET_TICKET', $env['MAILJET_TICKET']); // apikey:secret - // sender info + // sender info define('MAIL_FROM_NAME', $env['MAIL_FROM_NAME']); define('NO_REPLY_EMAIL', $env['NO_REPLY_EMAIL']); define('REPLY_TO_EMAIL', $env['REPLY_TO_EMAIL']); @@ -366,8 +138,8 @@ define ('PETITION_TYPE', [ -// forms -// --- -- -- - - - +// the forms /////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- // registration/activation form (from invitation) // --- @@ -704,5 +476,3 @@ define('PENALTY_FORM', [ ] ] ]); - - diff --git a/public/app/config/setup-framework.php b/public/app/config/setup-framework.php new file mode 100644 index 0000000..63eb486 --- /dev/null +++ b/public/app/config/setup-framework.php @@ -0,0 +1,469 @@ +<?php +/** CONFIGURATION PARAMETRES + * ----------------------------------------------------------------------------- + * + * Here you can find all the setup paramaters that define + * key-decisions of your application; + * + * ex. Session driver, Cache driver, Cookies Policy etc; + * + * Other supplamentary constants according to your application's logic + * shall be defined at the end of this file, or in some extra file(s), + * ex: ~/public/app/config/setup-application.php + * + * + * NOTE: + * You may rewrite the defines setting any values manualy; + * SETTING anom CONSTANTS VIA an `.env` FILE IS HIGHLY RECOMMENDED; + * The default `.env` file is saved into project's root + * + * ----------------------------------------------------------------------------- + */ + + +/** Preload environmental file + * ----------------------------------------------------------------------------- + * + * Setting up main constants via en envoronment file is HIGHLY RECOMMENDED; + * read ini file if exist + * + * ----------------------------------------------------------------------------- + */ +if (file_exists(APP_ROOT ."/.env")) { + $env = parse_ini_file(APP_ROOT. "/.env"); +} + + + + +## ----------------------------------------------------------------------------- +## +## - - - -- -- --- M A I N C O N S T A N T S --- -- -- - - - +## Main constants (names, labels, security options, optimzation defaults etc) +## +## ----------------------------------------------------------------------------- + + + +/** ENVIRONMENT constant + * ----------------------------------------------------------------------------- + * + * define application's environment stage; [PRODUCTION|staging|develpment|testing|*] + * seting this constant to 'PRODUCTION' eliminates debuggin comments; + * + * DO NOT FORGET to change this setting when deploying to a different stage + * + * ----------------------------------------------------------------------------- + */ + +define('PRODUCTION', ($env['ENVIRONMENT'] == 'PRODUCTION') ); + + + + +/** APPLICATION NAMES AND URL DEFAULTS + * ----------------------------------------------------------------------------- + * + * NOTE: + * if the `.env` file exists ... do not touch anything + * else ... replace $env[*] values with your setup/defaults + * + * ----------------------------------------------------------------------------- + */ + + // Application Name (how developer refers to it) +define('APP_NAME', $env['APP_NAME'] ?? 'anom.App'); + + // Site Title (the end-users' title) +define('SITE_TITLE', 'schoolGov'); + + // Application version (major_version + subversion_class) keep it simple +define('APP_VERSION', $env['APP_VERSION']); // ex: '1.alfa' -or- '2.rc' etc. + + // root url of the web app +define('SITE_URL', $env['ANOM_HOSTNAME']); + + + + +/** APPLICATION PATHS + * ----------------------------------------------------------------------------- + * + * Obligarory: + * These are needed in order to run the bare minimum MVC system + * They also make code easier to read + * + * NOTE: + * most likely you do not need to change any of these subsection defines; + * + * ----------------------------------------------------------------------------- + */ + +define('URL_ROOT', '/'); + +define('INIT_APPLICATION', APP_ROOT.'/core/config/init.php'); + +define('VIEWS_DIRECTORY', $env['VIEWS_DIRECTORY'] ?? (WEB_ROOT.'/app/views/')); + +define('TESTS_DIRECTORY', $env['TESTS_DIRECTORY'] ?? (APP_ROOT."/tests/")); + + + + +/** AUTOLOADER ///////////////////////////////////////////////////////////////// + * ----------------------------------------------------------------------------- + * + * An autoloader for classes is required; + * + * + ** OPTION 1: COMPOSER + * ----------------------------------------------------------------------------- + * Composer is recommended and makes much more than simple autoloding + * ----------------------------------------------------------------------------- + */ + +define('AUTOLOADER' , APP_ROOT.'/vendor/autoload.php'); + +/** OPTION 2: Custom Autoloader + * ----------------------------------------------------------------------------- + * If Composer is not supported, another autoloading proccess required + * Comment/Disable the 1st option and uncomment/Enable the next line + * ----------------------------------------------------------------------------- + * + * NOTE: if the custom autoloadet is used + * then you need to defing CLASSPATHS constant-array too; + */ + +# define('AUTOLOADER' , '../core/helpers/autoload.php'); + +/** Autoload paths + * ----------------------------------------------------------------------------- + * + * CLASSPATHS : array of paths where classes are saved + * + * NOTE: + * if the custom autoloader is used (instead of composer's) + * then you need to defing CLASSPATHS constant-array too; + * + * In most cases you won't need this, + * so comment the next lines out of the code-base + * + * ----------------------------------------------------------------------------- + */ +# define('CLASSPATHS', array( +# APP_ROOT .'/core/classes/', // core classes +# WEB_ROOT .'/app/controllers/', // controller classes +# WEB_ROOT .'/app/models/', // model classes +# WEB_ROOT .'/app/extends/', // extending core classes +# APP_ROOT .'/vendor/' // vendor/dependency classes +# ) +# ); + + + + +/** SESSION HANDLING + * ----------------------------------------------------------------------------- + * + * there are several session drivers for session handling: + * + * 'DefaultSession' : uses the default (file-based) php session management + * 'FileSession' : defines a custom file-based session mechanism + * 'DatabaseSession' : mechanism that stores Session data into a DataBase + * ----------------------------------------------------------------------------- + */ + +define('SESSION_DRIVER', $env['SESSION_DRIVER'] ?? 'DefaultSession'); + + + +/** FileSession Path + * --- -- -- - - - + * if FileSession is selected, a path for session-files is needed + * + * TODO: + * also, the hybrid sessioning (in progress) will need this setting + * + * NOTE: + * DefaultSession is also file-based but to not need a file-path setting + * (php will handle any file-needed actions to the file-system) + */ + +# define('FILESESSION_PATH', '../storage/session'); + + + +/** COOKIE SETTINGS + * ----------------------------------------------------------------------------- + * + * Define cookie policy (cookie sharing and securing) + * + * recomended values for production environment: + * COOKIE_SECURE=true + * COOKIE_SAMESITE='Strict' + * + * NOTE: + * on development environment COOKIE_SECURE has to be false + * in order for the test server to use them from http://locahost + * + * for more info about cookie policy read: + * https://www.php.net/manual/en/function.session-set-cookie-params.php + * + * ----------------------------------------------------------------------------- + */ + +define('COOKIE_SECURE', PRODUCTION); // Secure cookie policy [true|false] + +define('COOKIE_SAMESITE', $env['COOKIE_SAMESITE'] ?? 'Strict'); // SameSite cookie policy [Strict|Lax|None] + +# define('COOKIE_DOMAIN', $env['ANOM_HOSTNAME']); // domain to be visible on + + + + +/** Session and cookie names + * ----------------------------------------------------------------------------- + */ +define('SESSION_NAME', 'offticket'); // cookie for session (office ticket) +define('CONNECTION_COOKIE', 'con'); // cookie for connection +define('MAX_SESSION_LIFE', 2*60*60); // maximum session lifetime (2 hours) + + + +/** SECURITY SETTINGS /////////////////////////////////////////////////////////// + * ----------------------------------------------------------------------------- + * + * Cross Site Request Forgery + * --- + * Enables a CSRF cookie token to be set. When set to TRUE, token will be + * checked on a submitted form. If you are accepting user data, it is strongly + * recommended CSRF protection be enabled. + * ----------------------------------------------------------------------------- + */ + +define('CSRF_PROTECTION', false); + +define('CSRF_TOKEN_NAME', 'csrf_test_name'); // token name + +define('CSRF_COOKIE_NAME', 'csrf_cookie_name'); // cookie name + +define('CSRF_EXPIRE', 7200); // The number in seconds the token should expire. + +define('CSRF_REGENERATE', TRUE); // Regenerate token on every submission + +define('CSRF_EXCLUDE_URIS', array()); // Array of URIs which ignore CSRF checks + + + + +/* ADVANCED OPTIMIZATION /////////////////////////////////////////////////////// + * ----------------------------------------------------------------------------- + * + * APP_CACHE defines the cache-driver; + * accepted values are the name of the Cache-interface impementations (the exact + * names of the classes) + * + * 'FileCache' : caching in filesystem; fair if caching on HDD; great on SSD + * 'RedisCache' : caching in Redis server; generally recommended if available + * 'MemCachedCache' : caching in Memcached server; recommended if available + * + * NOTE: FileCache on a NVMe SDD is the fastest option; + * Redis and Memcached are really-fast caching options and are available for + * scaling horizontaly your application (eache one has it's own strngths; + * study, then choose the one that fulfills your needs; + * ----------------------------------------------------------------------------- + */ + +define('CACHE_DRIVER', $env['CACHE_DRIVER'] ?? 'FileCache'); + + + + + +## ----------------------------------------------------------------------------- +## +## - - - -- -- --- C O N N E C T I O N C R E D E N T I A L S --- -- -- - - - +## +## ----------------------------------------------------------------------------- + + + +/** SERVICE PARAMETRES + * ----------------------------------------------------------------------------- + * + * Connection parametres and credentials for accssing services + * needed by the application; Such services may be.. + * + * - RDBMS + * -- MySQL + * -- PotgresSQL + * + * - Caching services + * -- Redis + * -- MemCached + * + * Edit only the constants needed by the application; + * Comment those you do not need; + * + * ///////////////////////////////////////////////////////////////////////////// + */ + +/** DATABASE CONNECTION PARAMETRES + * ----------------------------------------------------------------------------- + * Production and staging environments may use different databases. + * + * A safe practice is to keep credentials outside plain files like this one + * in environmental variable or other secret file etc. + * + * Uncomment/enable each group of definitions suits your case to define + * the credentials needed for accessing the database + */ + +define('DB_NAME', $env['DB_NAME']); + +define('DB_USER', $env['DB_USER']); + +define('DB_PASS', $env['DB_PASS']); + +/** NOTE: + * PDO_HOST can be a hostname/port combination -or- a unix socket + * + * ...examples: + * define('PDO_HOST', 'host=/localhost') ## hostname case + * define('PDO_HOST', 'host=/localhost;port=3456') ## hostname/port case + * define('PDO_HOST', 'unix_socket=/sql/ex123:europe:some-db'); ## unix socket + * define('PDO_HOST', 'unix_socket=/cloudsql/name-123456:europe-west4:name-db-eu'); + */ + +define('PDO_HOST', $env['PDO_HOST']); + +define('DB_TIMEZONE', "SET time_zone = 'Europe/Athens'"); + + + + +/** CACHED SERVICES + * ----------------------------------------------------------------------------- + * + * impemented services: + * - File Cache + * - Redis + * - Memcached + * + * NOTE: + * Both Redis and Memcached configurations are given as a template to work on; + * In most cases the default values should do the job -- of course you need to + * read the README file (check the project's root); + * As these caching services are not fully tested you may need to ochestrate + * the services in detail or edit the connection strings into the core classes + * (hosted under the '/core/classes/cacher' folder) + * + * ----------------------------------------------------------------------------- + */ + +define('FILECACHE_PATH', APP_ROOT.'/storage/cache/'); // if CACHE_DRIVER is set to 'FileCache' + +define('MEDIA_STORAGE_ROOT', APP_ROOT.'/storage/uploads/'); // Media files root directory + + +// CONNECTIONS (if Redis or Memcached is selected) ... + + +# define('REDIS_HOST', '127.0.0.1'); // if CACHE_DRIVER is set to 'RedisCache' + +# define('MEMCAHCED_SERVER', '127.0.0.1'); // if CACHE_DRIVER is set to 'MemCached' + + + # define('MEMCAHCED_SERVER', '127.0.0.1'); // if CACHE_DRIVER is set to 'MemCached' + +/** REDIS SERVICE + * ----------------------------------------------------------------------------- + * Most of the times Redis is running on 'localhost' (host = '127.0.0.1') + * When implemented via anom's docker-composer (redis via bridge) then you need + * do declare the hostname as 'redis' + */ + +# define('REDIS_HOST', '127.0.0.1'); // if CACHE_DRIVER is set to 'RedisCache' +# if (!defined('REDIS_HOST')) define('REDIS_HOST', 'redis'); +# +# if (!defined('REDIS_PORT')) define('REDIS_PORT', 6379); +# +# if (!defined('REDIS_PASS')) define('REDIS_PASS', null); + + +/** MEMCACHED + * ----------------------------------------------------------------------------- + * Memcached looks very much like Redis (plus, both are serving from RAM) + * Usualy Memcashed is running localy so host is 'localhost' ('127.0.0.1') + * If you use the framework's docker-composer implementation then + * the hostname is 'anomemcached' + */ + +# if (!defined('MEMCACHE_HOST')) define('MEMCACHE_HOST', 'anomemcached'); + + + + + + + + +/** General Scope Constants + * ----------------------------------------------------------------------------- + * + * needed by the framework for common tasks + * + * Anom suggests: + * + Common Content Types, and + * + Proxy flags + * + * ----------------------------------------------------------------------------- + */ + +/** COMMON CONTENT TYPES + * ----------------------------------------------------------------------------- + */ +define('COMMON_CONTENT_TYPES', array( + // text,css + 'text/html; charset=UTF-8', 'text/css', + // json + 'application/json; charset=utf-8', + // javascript + 'application/javascript; charset=utf-8', + // images + 'image/png', 'image/jpeg', 'image/web', + // pdf + 'application/pdf', + // word + 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + // excel + 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + // rar + 'application/vnd.rar', 'application/x-rar-compressed', 'application/octet-stream', + // zip + 'application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/octet-stream', + ) +); + + +/** PROXY_FLAGS + * ----------------------------------------------------------------------------- + * These options represend altered/non-default behaviour + * and will be resolved bitwise, so use powers of 2 + * ----------------------------------------------------------------------------- + */ +define('PROXY_CACHE_ERRORS', 1); // cache result even if error +define('PROXY_IGNORE_CACHE', 2); // ignore cache if exist +define('PROXY_DO_NOT_CACHE', 4); // do not cache result + + + +/** need even more constants? + * ----------------------------------------------------------------------------- + * + * Append them here, + * or require an extra `constants definition` file + * + * ----------------------------------------------------------------------------- + */ +require_once WEB_ROOT.'/app/config/setup-application.php';
\ No newline at end of file diff --git a/public/app/routes/api.php b/public/app/routes/api.php index 94ae2a6..dd0fecf 100644 --- a/public/app/routes/api.php +++ b/public/app/routes/api.php @@ -12,33 +12,29 @@ use app\controllers\api\Doc_api; */ -// api: tree of product-categories -Route::add('/api/tree', - function() { Doc_api::tree(); }, - 'get' -); +// depricated: (not needed) // api: database documentation -Route::add('/api/doc', - function() { Doc_api::dbDoc(); }, - 'get' -); - -Route::add('/api/url/([0-9a-zA-Z-_\/]*)', - function($url) { Common_api::category_by_url($url); } -); - -// route: /api/table -Route::add('/api/([0-9a-zA-Z-_]*)', - function($table) { Common_api::table($table); }, - 'get' -); - -// route: /api/table/{id} -Route::add('/api/([0-9a-zA-Z-_]*)/([0-9]*)', - function($table, $id) { Common_api::record($table, $id); }, - 'get' -); +// Route::add('/api/doc', +// function() { Doc_api::dbDoc(); }, +// 'get' +// ); +// +// Route::add('/api/url/([0-9a-zA-Z-_\/]*)', +// function($url) { Common_api::category_by_url($url); } +// ); +// +// // route: /api/table +// Route::add('/api/([0-9a-zA-Z-_]*)', +// function($table) { Common_api::table($table); }, +// 'get' +// ); +// +// // route: /api/table/{id} +// Route::add('/api/([0-9a-zA-Z-_]*)/([0-9]*)', +// function($table, $id) { Common_api::record($table, $id); }, +// 'get' +// ); diff --git a/public/app/routes/frontend.php b/public/app/routes/frontend.php index b0e064b..f10f29d 100644 --- a/public/app/routes/frontend.php +++ b/public/app/routes/frontend.php @@ -17,10 +17,16 @@ Route::add('/invitation/([0-9]*)', function($id) { Auth::invitation($id); }); +// new petition Route::add('/petition/([0-9a-z\-_]*)', function($tag) { Office::request_petition($tag); }); +// existing petition +Route::add('/petition/([0-9a-z\-_]*)/([0-9a-f]*)', function($tag) { + Office::filter_request_petition($tag, $id); +}); + // Error pages //////////////////////////////////////////////////////////////////////////////// diff --git a/public/index.php b/public/index.php index 92b825a..5c84e97 100644 --- a/public/index.php +++ b/public/index.php @@ -12,20 +12,30 @@ * And as long as you write code using secure practices, * it will be secure. * - * Copyleft: George Halkiadalos + * Copyleft: George Halkiadakis * Licence: BSD * \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ * ----------------------------------------------------------------------------- */ -// Load parametres: -// contants and constant arrays + + +// specify base paths // ----------------------------------------------------------------------------- -require_once '../core/config/constants.php'; // general constants +$dir = explode('/', __DIR__); +$pub = array_pop($dir); -require_once '../core/config/anom_settings.php'; // core framework constants +define('APP_ROOT', implode('/',$dir)); // root of application (public's parent) -require_once 'app/config/app_constants.php'; // application constants +define('WEB_ROOT', APP_ROOT.'/'.$pub); // root of public directory + + + +// Load parametres: +// contants and constant arrays +// ----------------------------------------------------------------------------- + +require_once WEB_ROOT.'/app/config/setup-framework.php'; // application constants @@ -34,17 +44,20 @@ require_once 'app/config/app_constants.php'; // application constants require_once AUTOLOADER; + // Enable sessions // ----------------------------------------------------------------------------- $session = new (SESSION_DRIVER)(); // Start a new session + // prepare output control and benchmarking // ----------------------------------------------------------------------------- ob_start(); // handle output if (!PRODUCTION) Benchmark::add_spot('start'); // benchmark request's life + // Initialize Application // finalize framework; handle credentials; setup app-engine; insert routes // ----------------------------------------------------------------------------- @@ -58,6 +71,7 @@ require_once INIT_APPLICATION; Route::run(Registry::get('REQUEST')); // Run baby, run! + if (!PRODUCTION) Benchmark::add_spot('end'); // request ended if (!PRODUCTION) Benchmark::render_report(); // echo benchmark report ob_flush(); // flush output diff --git a/tests/settings.php b/tests/settings.php index 20cdde6..050cbfa 100755 --- a/tests/settings.php +++ b/tests/settings.php @@ -12,6 +12,7 @@ print_r([ 'app_name' => APP_NAME ?? 'undefined', 'site_title' => SITE_TITLE ?? 'undefined', 'appRoot' => APP_ROOT, + 'webRoot' => WEB_ROOT, 'views' => VIEWS_DIRECTORY, 'init' => INIT_APPLICATION, 'site_url' => SITE_URL ?? 'undefined', |
