summaryrefslogtreecommitdiff
path: root/core/config
diff options
context:
space:
mode:
Diffstat (limited to 'core/config')
-rw-r--r--core/config/anom_settings.php169
-rw-r--r--core/config/constants.php28
-rw-r--r--core/config/credentials.php126
-rw-r--r--core/config/init.php76
4 files changed, 399 insertions, 0 deletions
diff --git a/core/config/anom_settings.php b/core/config/anom_settings.php
new file mode 100644
index 0000000..882145d
--- /dev/null
+++ b/core/config/anom_settings.php
@@ -0,0 +1,169 @@
+<?php
+/** CONFIGURATION PATAMETRES
+ * ---
+ * This is the first file you need to setup
+ * in order to start a new application
+ */
+
+// 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
+//// if (!defined('PRODUCTION')) {
+//// if (file_exists('../core/auth/.env')) {
+//// $ini_array = parse_ini_file("../core/auth/.env");
+////
+//// define('PRODUCTION', $ini_array['ENVIRONMENT']);
+//// }
+//// } else {
+//// define('PRODUCTION', false); // or define manualy
+//// }
+define('PRODUCTION', false);
+
+
+// Custom Names ////////////////////////////////////////////////////////////////
+// -----------------------------------------------------------------------------
+
+define('APP_NAME', 'e-Classroom'); // Application Name
+
+define('APP_VERSION', 'v0.2'); // Application version
+
+define('SESSION_NAME', 'clroom'); // Session Name
+
+
+
+// APPLICATION PATHS ///////////////////////////////////////////////////////////
+// -----------------------------------------------------------------------------
+
+// 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
+// -----------------------------------------------------------------------------
+
+define('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');
+
+// default: define('VIEWS_DIRECTORY', APP_ROOT.'/app/views/');
+define('VIEWS_DIRECTORY', APP_ROOT.'/processed-views/');
+
+define('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
+# 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)
+# define('CLASSPATHS', array(
+# '/../core/classes/',
+# '/app/controllers/',
+# '/app/models/',
+# '/../vendor/'
+# )
+# );
+
+
+
+// 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', '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
+
+
+// SESSION_DRIVER ; accepted values...
+// 'files' : (defult) php uses filesystem for saving session; fair if caching in SSD drive
+// 'redis' : keep sessions in a Redis server; rapid-fast but wastes large amount of RAM
+// 'database' : keep session data in Database; ideal for session across multiple servers
+// -----------------------------------------------------------------------------
+
+define('SESSION_DRIVER', 'files');
+
+// CONNECTIONS ...
+
+define('FILECACHE_PATH', APP_ROOT.'/cache/'); // if CACHE_DRIVER is set to 'FileCache'
+
+# 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'
+
+
+
+
+// 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_PROTCTION', 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
diff --git a/core/config/constants.php b/core/config/constants.php
new file mode 100644
index 0000000..d2ecc41
--- /dev/null
+++ b/core/config/constants.php
@@ -0,0 +1,28 @@
+<?php
+/** Constants
+ * ---
+ */
+
+// COMMON CONTENT TYPES
+// -----------------------------------------------------------------------------
+define('COMMON_CONTENT_TYPES', array(
+ 'text' => 'text/html; charset=UTF-8',
+ 'html' => 'text/html; charset=UTF-8',
+ 'json' => 'application/json; charset=utf-8',
+ 'js' => 'application/javascript; charset=utf-8',
+ 'css' => 'text/css',
+ 'png' => 'image/png',
+ 'jpeg' => 'image/jpeg',
+ 'webp' => 'image/web'
+ )
+);
+
+
+// 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
diff --git a/core/config/credentials.php b/core/config/credentials.php
new file mode 100644
index 0000000..43fa0a4
--- /dev/null
+++ b/core/config/credentials.php
@@ -0,0 +1,126 @@
+<?php
+/** 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
+ */
+
+/** 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)
+ * -----------------------------------------------------------------------------
+ */
+
+$ini_array = parse_ini_file("../core/auth/.env");
+
+define('DB_NAME', $ini_array['DB_NAME']);
+
+define('DB_USER', $ini_array['DB_USER']);
+
+define('DB_PASS', $ini_array['DB_PASS']);
+
+define('PDO_HOST', $ini_array['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');
diff --git a/core/config/init.php b/core/config/init.php
new file mode 100644
index 0000000..b035faf
--- /dev/null
+++ b/core/config/init.php
@@ -0,0 +1,76 @@
+<?php
+
+/** initialize System
+ * ---
+ * Finalalize the MVC framework and construct the central objects
+ * (Registry and Request)
+ *
+ * Include _anything_ that is common practice on the request life-cycle
+ * of your project and does not need to be shown in the /html/index.php
+ * Usualy here you shall initialize supplamentary services like Sessions
+ * / Database / Caching etc.
+ *
+ * NOTE:
+ * Always try to keep the app as light as possible, so load only what is
+ * critical for the MVC to operate;
+ * anything else can be injected on-demand
+ */
+
+// Load authorization parametres
+// -----------------------------------------------------------------------------
+require_once CREDENTIALS;
+
+
+// setup error-handliing
+// -----------------------------------------------------------------------------
+require_once '../core/helpers/error_handling.php';
+
+
+// Load rendering sub-system
+// -----------------------------------------------------------------------------
+require_once RENDERING_SYSTEM;
+
+
+// Setup Application Engiine
+// -----------------------------------------------------------------------------
+// Setup supplementary services (derectry or as promises/vows)
+// Session, Database, Caching
+
+
+// Attache database to the Regostry a vow
+Registry::vow('database', function() { return new Database(); });
+
+
+// Attach Cache to the Resitry as a vow
+// (CACHE_DRIVER) acts as driver-wrapper
+Registry::vow('cache', function() { return new (CACHE_DRIVER)(); });
+// CHECK: if strict mode has any benefits:
+// Registry::vow('cache', function():Cache_interface { return new (CACHE_DRIVER)(); });
+
+
+// Start session
+Registry::set('session', new DefaultSession());
+
+
+
+// Initialize THE REQUEST
+// -----------------------------------------------------------------------------
+Registry::set('REQUEST', new Request());
+
+
+
+// load design-patterns
+// (these patterns use some of the project's central objects (Registry,
+// Cache, Database), so laod them after.
+// -----------------------------------------------------------------------------
+require_once '../core/helpers/design_patterns.php';
+
+
+// Add Routes
+// -----------------------------------------------------------------------------
+
+require_once 'app/routes/api.php'; // API: =/api/{table}/{id};/api/*
+
+require_once 'app/routes/backend.php'; // Backend: =/admin/*
+
+require_once 'app/routes/frontend.php'; // Frontend =/* (whatever)