diff options
| author | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-08 17:21:17 +0300 |
|---|---|---|
| committer | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-08 17:21:17 +0300 |
| commit | d5936455d6d5d32a5e0ca88096d663bade444549 (patch) | |
| tree | a3afef704c64c2b2133c0e6408c997f86c6731aa | |
| parent | 7e22b5bc5328652ae7e91ad799b48820474660ed (diff) | |
| download | gyraf1gov-d5936455d6d5d32a5e0ca88096d663bade444549.tar.gz gyraf1gov-d5936455d6d5d32a5e0ca88096d663bade444549.tar.bz2 gyraf1gov-d5936455d6d5d32a5e0ca88096d663bade444549.zip | |
refactoring anom-parametres setup
| -rw-r--r-- | core/config/anom_settings.php | 320 | ||||
| -rw-r--r-- | public/app/config/app_constants.php | 70 | ||||
| -rw-r--r-- | public/app/routes/api.php | 28 | ||||
| -rwxr-xr-x | tests/settings.php | 27 |
4 files changed, 244 insertions, 201 deletions
diff --git a/core/config/anom_settings.php b/core/config/anom_settings.php index 6713771..7dc09b4 100644 --- a/core/config/anom_settings.php +++ b/core/config/anom_settings.php @@ -1,122 +1,168 @@ <?php - -/** CONFIGURATION PATAMETRES +/** CONFIGURATION PARAMETRES * ----------------------------------------------------------------------------- - * This is the first file you need to setup - * in order to start a new application + * + * 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 manualy setting any values manualy - * Here we propose that you use an .env file (with is a very safe option) - * the env file is saved into `/core/auth` folder + * 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"); } -// DEFINE WHETTHER THE APP RUNS ON PRODUCTION -// Don't forget to change this setting -// when deploying to a different stage -// ----------------------------------------------------------------------------- - -# // define by OS parameter -# if (getenv('ENVIRONMENT')) { -# if (getenv('ENVIRONMENT') == 'PRODUCTION') { -# define('PRODUCTION', true); -# } else { -# define('PRODUCTION', false); -# } -# } - -# define by .env file + + + +/** 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') ); -// Custom Names //////////////////////////////////////////////////////////////// -// ----------------------------------------------------------------------------- -define('APP_NAME', 'e-Classroom'); // Application Name +/** 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']); -define('APP_VERSION', 'v0.2'); // Application version -/** APPLICATION PATHS /////////////////////////////////////////////////////////// +/** APPLICATION PATHS * ----------------------------------------------------------------------------- * - * Obligarory + * Obligarory: * These are needed in order to run the bare minimum MVC system * They also make code easier to read * * NOTE: - * probably you don't need to chage these defines + * 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', dirname(get_included_files()[0]) ); +define('APP_ROOT', $ini['APP_ROOT'] ?? dirname(get_included_files()[0]) ); define('URL_ROOT', '/'); -define('CREDENTIALS', '../core/config/credentials.php'); - define('INIT_APPLICATION', '../core/config/init.php'); -define('RENDERING_SYSTEM', '../core/helpers/render.php'); +define('VIEWS_DIRECTORY', $ini['VIEWS_DIRECTORY'] ?? (APP_ROOT.'/app/views/')); + +define('TESTS_DIRECTORY', $ini['TESTS_DIRECTORY'] ?? (APP_ROOT."/../tests/")); -define('VIEWS_DIRECTORY', APP_ROOT.'/app/views/'); -define('TESTS_DIRECTORY', APP_ROOT."/../tests/"); /** AUTOLOADER ///////////////////////////////////////////////////////////////// * ----------------------------------------------------------------------------- + * * An autoloader for classes is required; * * - * OPTION 1: COMPOSER + ** OPTION 1: COMPOSER + * ----------------------------------------------------------------------------- * Composer is recommended and makes much more than simple autoloding + * ----------------------------------------------------------------------------- */ + define('AUTOLOADER' , '../vendor/autoload.php'); -/** ... - * - * OPTION 2: Custom Autoloader +/** 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'); -/** CLASSPATHS : array of paths where classes are saved - * Needed only when the custom autoloader is used - * (like autoload.classmap section of Composer) + + + +/** 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('CLASSPATHS', array( -# '/../core/classes/', -# '/app/controllers/', -# '/app/models/', -# '/../vendor/' -# ) -# ); +define('SESSION_DRIVER', $ini['SESSION_DRIVER']); - /** 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', 'DefaultSession'); + +/** 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 + + -// if FileSession is selected, a path for session-files is needed -# define('FILESESSION_PATH', '../storage/session'); /* ADVANCED OPTIMIZATION /////////////////////////////////////////////////////// * ----------------------------------------------------------------------------- @@ -135,25 +181,13 @@ define('SESSION_DRIVER', 'DefaultSession'); * study, then choose the one that fulfills your needs; * ----------------------------------------------------------------------------- */ + +define('CACHE_DRIVER', $ini['CACHE_DRIVER']); -define('CACHE_DRIVER', 'FileCache'); - - -/** Caching expiration times fpr various expensive objects - * ----------------------------------------------------------------------------- - */ - -// Root objects like product-categories tree -define('CACHE_ROOT_TTL', 28800); // 8 hours - -// Product Category -define('CACHE_CATEGORY_TTL', 18000); // 5 hours - -// Product -define('CACHE_PRODUCT_TTL', 3600); // 1 hour +/** HOTFIX: (needs refactoring) */ // CONNECTIONS ... @@ -178,7 +212,7 @@ define('MEDIA_STORAGE_ROOT', APP_ROOT.'/../storage/uploads/'); // Media files * ----------------------------------------------------------------------------- */ -define('CSRF_PROTCTION', false); +define('CSRF_PROTECTION', false); define('CSRF_TOKEN_NAME', 'csrf_test_name'); // token name @@ -228,96 +262,60 @@ define('CSRF_EXCLUDE_URIS', array()); // Array of URIs which ignore CSRF check * the credentials needed for accessing the database */ -/** This is a SAFE method (define credentials as OS environmental variables) - * ----------------------------------------------------------------------------- - */ -# define('DB_NAME', getenv('DB_NAME')); // database name -# -# define('DB_USER', getenv('DB_USER')); // database user-name -# -# define('DB_PASS', getenv('DB_PASS')); // user's pass -# -# define('PDO_HOST', getenv('PDO_HOST')); // database host (connection string) - - -/** This is another SAFE method (keep credentials in an .env file) - * ----------------------------------------------------------------------------- - */ - 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']); - - /** This is just good enough - * ----------------------------------------------------------------------------- - */ - - # if (!PRODUCTION) { // == Deployed on staging - # - # // STAGING SETTINGS: - # - # define('DB_NAME', 'dev_db_name'); - # - # define('DB_USER', 'devUserName'); - # - # define('DB_PASS', getenv('DBPASSWORD')); - # - # // 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'); - # - # } else { // == Deployed on production - # - # // PRODUCTION SETTINGS: - # - # define('DB_NAME', 'your_db_name'); - # define('DB_USER', 'dbusername'); - # define('DB_PASS', getenv('DBPASSWORD')); - # define('PDO_HOST', 'unix_socket=/cloudsql/name-123456:europe-west4:name-db-eu'); - # - # } - define('DB_TIMEZONE', "SET time_zone = 'Europe/Athens'"); - - /** 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) - */ - - - /** 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' - */ - # - # 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'); + + + + +/** 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) + */ + + +/** 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' + */ + +# 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');
\ No newline at end of file diff --git a/public/app/config/app_constants.php b/public/app/config/app_constants.php index f788946..cabd0b8 100644 --- a/public/app/config/app_constants.php +++ b/public/app/config/app_constants.php @@ -1,7 +1,15 @@ <?php -// Contents -// Central Defaults (name) -// Default Values (user-privileges and user-roles) +/** Custom Application Constants + * ----------------------------------------------------------------------------- + * + * Constants defined for your own application + * + * Here you may fing + * + * It is rec + * + * ----------------------------------------------------------------------------- + */ // read ini file if exist @@ -11,37 +19,53 @@ if (file_exists("../core/auth/.env")) { } +/** Main default constants / strings / names / etc + * ----------------------------------------------------------------------------- + */ +define('SITE_TITLE', 'schoolGov'); // Site Title (the end-users' title) -// CENTRAL DEFAULTS //////////////////////////////////////////////////////////// -// ----------------------------------------------------------------------------- -// NOTE: -// if .env file exists ... do not touch anything -// else ... replace $env[*] values with your setup -// WEB-APP name and url -// --- -- -- - - - -define('SITE_TITLE', 'Classroom'); -define('SITE_URL', $env['ANOM_HOSTNAME']); +/** Autoload paths + * ----------------------------------------------------------------------------- + * + * CLASSPATHS : array of paths where classes are saved + * Needed only when the custom autoloader is used + * + * 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/', +# '/app/controllers/', +# '/app/models/', +# '/../vendor/' +# ) +# ); + + +// if FileSession is selected, a path for session-files is needed +#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) -// Cookie Policy -// --- -- -- - - - -# define('COOKIE_DOMAIN', $env['ANOM_HOSTNAME']); // domain to be visible on -define('COOKIE_SECURE', false); // Secure cookie policy [true|false] -define('COOKIE_SAMESITE', 'Strict'); // SameSite cookie policy [Strict|Lax|None] - // recomended values: - // COOKIE_SECURE=true, COOKIE_SAMESITE='Strict' - // --- -- -- - - - - // for more info about cookie policy read: - // https://www.php.net/manual/en/function.session-set-cookie-params.php - + // email setup diff --git a/public/app/routes/api.php b/public/app/routes/api.php index 61e485b..94ae2a6 100644 --- a/public/app/routes/api.php +++ b/public/app/routes/api.php @@ -61,21 +61,15 @@ Route::add('/api/([0-9a-zA-Z-_]*)/([0-9]*)', * ----------------------------------------------------------------------------- * * direct calls to simple tests - * + * (not on production environment) */ - - -// route for testing... -// --- -Route::add('/test/([0-9a-zA-Z-_\/]*)', function($test) { - - // TODO: - // hide tests from production - - if (file_exists(TESTS_DIRECTORY . $test .'.php')) { - if (!Benchmark::exist('start')) Benchmark::add_spot('start'); - require(TESTS_DIRECTORY . $test .'.php'); - } else { echo "Test {$test} not exist"; - } die(); - -}); + if (!PRODUCTION) { + Route::add('/test/([0-9a-zA-Z-_\/]*)', function($test) { + if (file_exists(TESTS_DIRECTORY . $test .'.php')) { + if (!Benchmark::exist('start')) Benchmark::add_spot('start'); + require(TESTS_DIRECTORY . $test .'.php'); + } else { echo "Test {$test} not exist"; + } die(); + + }); +} diff --git a/tests/settings.php b/tests/settings.php new file mode 100755 index 0000000..20cdde6 --- /dev/null +++ b/tests/settings.php @@ -0,0 +1,27 @@ +<?php + + +if (file_exists("../core/auth/.env")) { + $set = parse_ini_file("../core/auth/.env"); +} + +echo "<pre>"; + +print_r([ + 'production' => PRODUCTION ?? 'undefined', + 'app_name' => APP_NAME ?? 'undefined', + 'site_title' => SITE_TITLE ?? 'undefined', + 'appRoot' => APP_ROOT, + 'views' => VIEWS_DIRECTORY, + 'init' => INIT_APPLICATION, + 'site_url' => SITE_URL ?? 'undefined', + 'session_name' => SESSION_NAME ?? 'undefined', + 'session_life' => MAX_SESSION_LIFE ?? 'undefined', + 'cookie_secure' => COOKIE_SECURE ?? 'undefined', + 'cookie_samesite' => COOKIE_SAMESITE ?? 'undefined', + 'default_mai_service' => DEFAULT_MAIL_SERVICE ?? 'undefined', + 'test' => $set['TEST_ME'] ?? 'none', + 'another' => $set['NONONOO'] ?? 'none' +]); + +echo "</pre>"; |
