Configuration
- Quick start
- Environment
/.env
- Config files, -places and reading order
- Module's composer.json
- Access module config values
- Access
MVC_*
config values - Appendix
Quick start
Environment file
🛈 write all private settings, accesses and passwords, as well as other secrets in the environment file: /.env
- see: Environment
/.env
Config file
🛈 configure your settings in a file in the primary module and corresponds to the environment by name, e.g.: /modules/Foo/etc/config/Foo/config/develop.php
- the configuration file in your primary module always has the last word, as it is read last. Settings made here overwrite all other settings made previously.
- see: Creating a primary Module
- see: Module's environment config file
Environment /.env
In the root folder of your Emvicy copy you will find an .env
file.
#-----------------------------------------------------
# Environment
MVC_ENV=develop
#-----------------------------------------------------
# API
apikey=12345678-1234-1234-1234-123456789012
#-----------------------------------------------------
# DB
db.type=mysql
db.host=db
db.port=3306
db.dbname=Emvicy2x
db.username=root
db.password=root
#-----------------------------------------------------
# Email
email.sHost=smtps.example.com
email.iPort=465
email.sSecure=ssl
email.bAuth=true
email.sUsername=example-user-0001
email.sPassword=example-password
email.sSenderEmailAddress=noreply@example.com
MVC_ENV
There the variable MVC_ENV
declares what Environment is valid for Emvicy. You can name the value as you like - But common values are: develop
, test
, production
or live
.
Database Settings
If you want to use a Database, edit the settings for your Database in the /.env
file as well.
See also Chapter /2.x/database
Custom .env variables
You are free to set up any key=value
declarations you want in that /.env
file.
Any key=value
pair found in the file will be set by putenv()
at start and you can access those variables via php's getenv()
command.
Example
# custom
foo=bar
Check
// string(3) "bar"
var_dump(
getenv('foo')
);
Config files, -places and reading order
The following locations for configurations exist and are read in succession in the appropriate order.
This also means that a later loaded configuration beats (overrides) an earlier loaded one.
- ⬆ Emvicy config folder
/config/
- Any
*.php
file in this directory will be included; Reading order isa-z
- Coverage: globally - Configs placed here are valid to all modules and to all environments
- By default, the following files are located here
_mvc.php
: This file contains basic settings that are necessary for operation. You should not edit this file. If you want to change settings, override values in your own module config. Emvicy config variable names always begin withMVC_
.- See content of file
/config/_mvc.php
- ⬆ Module's config folder (overrides 1.)
/modules/{moduleName}/etc/config/
- Any
*.php
file in this directory will be included; Reading order isa-z
- Coverage: module globally - Configs placed here are valid to all environments of your module
- By default, the following files are located here
_mvc.php
: further MVC configs. Emvicy config variable names always begin withMVC_
.- See Example
/modules/Foo/etc/config/_mvc.php
- ⬆ Module's environment config file (overrides 2.)
- Schema:
/modules/{moduleName}/etc/config/{moduleName}/config/{environment}.php
- If your module is named
Foo
and you have setMVC_ENV
to'develop'
, your environment config file has to bemodules/Foo/etc/config/Foo/config/develop.php
. Make sure it exists.
- If your module is named
- Coverage: module environment specific - The concrete environment config file is loaded appropiate to your environment of your module you have set in
MVC_ENV
- See Example
/modules/Foo/etc/config/Foo/config/develop.php
- Schema:
⚠ If you create a module by using emvicy (see: Creating a primary Module), the corresponding "Module's environment config file" will be generated automatically.
But if you change the value of the MVC_ENV
variable of /.env
config file afterwards, make sure the corresponding "Module's environment config file" does exist in your module.
Example: If your Module is named Foo
, and you set MVC_ENV=production
, then the config file /modules/Foo/etc/config/Foo/config/production.php
has to exist.
Module's composer.json
Extend your module with third libraries using composer. You don't need to have composer installed locally, because Emvicy has a composer.phar on board which is used to install and update libraries.
Write your requirements into the composer.json file which you find here:
composer.json
/modules/{moduleName}/etc/config/{moduleName}/composer.json
The next time you run your Emvicy Application, Emvicy will automatically perform a composer install
.
Alternatively you can of course also perform an installation by hand.
Installed vendor folder
/modules/{moduleName}/etc/config/{moduleName}/vendor
Emvicy will automatically integrate all /vendor/autoload.php
autoloaders from any Emvicy module.
keep vendor libraries updated
simply run emvicy:
php emvicy update
Access module config values
Access module configuration array via the \MVC\Config
Class.
Example
$aModule = \MVC\Config::MODULE();
Alternativley you can access the module configuration array via \MVC\Registry
.
Alternative
$aModule = \MVC\Registry::get('MODULE');
Access MVC_*
config values
Access MVC configurations via the \MVC\Config
Class. For each variable there is an identical getter and for many there are setters also.
Setter
\MVC\Config::set_{MVC_VARIABLE}( value );
Getter
// Getter
$mVar = \MVC\Config::get_{MVC_VARIABLE}();
Setter Example
\MVC\Config::set_MVC_LOG_SQL(false); # logging SQL Statements true|false
Getter Example
$bLogSql = \MVC\Config::get_MVC_LOG_SQL(); # logging SQL Statements true|false
Alternativley you can access all MVC Configs via \MVC\Registry
.
Alternative
$sMvcBasePath = \MVC\Registry::get('MVC_BASE_PATH');
List of Setters
Config::set_MVC_LOG_AUTOLOADER(bool);
Config::set_MVC_LOG_DETAIL(array);
Config::set_MVC_LOG_FORCE_LINEBREAK(bool);
Config::set_MVC_LOG_PROCESS(bool);
Config::set_MVC_LOG_QUEUE(bool);
Config::set_MVC_LOG_CRON(bool);
Config::set_MVC_CACHE_DIR(string);
Config::set_MVC_SESSION_NAMESPACE(string);
Config::set_MVC_SESSION_ENABLE(bool);
Config::set_MVC_POLICY(array);
Config::set_MVC_EVENT(array);
Config::set_MVC_UNIQUE_ID(string);
Config::set_MVC_SESSION(Session);
Config::set_MVC_INFOTOOL_ENABLE(bool);
Config::set_MVC_MODULE_PRIMARY_VIEW(View);
Config::set_MVC_LOG_EVENT_RUN(bool);
Config::set_MVC_EVENT_ENABLE_WILDCARD(bool);
Config::set_MVC_LOG_REQUEST(bool);
Config::set_MVC_LOG_FILE_REQUEST(string);
Config::set_MVC_LOG_FILE_PROCESS(string);
Config::set_MVC_LOG_FILE_QUEUE(string);
Config::set_MVC_LOG_FILE_CRON(string);
Config::set_MVC_LOG_SQL(bool);
Config::set_MVC_LOG_FILE_SQL(string);
Config::set_MVC_PHP_SERVER(string);
Config::set_MVC_LOG_FILE_ROUTEINTERVALL(string);
Config::set_MVC_LOG_EVENT(bool);
Config::set_MVC_LOG_DEFAULT(bool);
Config::set_MVC_LOG_ERROR(bool);
Config::set_MVC_LOG_WARNING(bool);
Config::set_MVC_LOG_NOTICE(bool);
Config::set_MVC_LOG_POLICY(bool);
Config::set_MVC_LOG_ROUTEINTERVALL(bool);
Config::set_MVC_ROUTE_PREFIX(string);
Config::set_MVC_QUEUE_ROUTE_PREFIX(string);
Config::set_MVC_QUEUE_WORKER_AUTO_ROUTE_PREFIX(string);
Config::set_MVC_QUEUE_RUN(string);
Config::set_MVC_QUEUE_RUN_CLASSMETHOD(string);
Config::set_MVC_QUEUE_WORKER_AUTO_ROUTE_RESOLVE_CLASSMETHOD(string);
Config::set_MVC_QUEUE_RUNTIME_SECONDS(int);
Config::set_MVC_PROCESS_MAX_PROCESSES_OVERALL(int);
Config::set_MVC_PROCESS_PID_FILE_DIR(string);
Config::set_MVC_CRON_ROUTE(string);
Config::set_MVC_CRON_RUN_CLASSMETHOD(string);
List of Getters
Config::get_MVC_LOG_AUTOLOADER();
Config::get_MVC_MODULE_PRIMARY_DIR();
Config::get_MVC_MODULE_PRIMARY_CONTROLLER_DIR();
Config::get_MVC_MODULE_PRIMARY_DATATYPE_DIR();
Config::get_MVC_MODULE_PRIMARY_ETC_DIR();
Config::get_MVC_ROUTING_FALLBACK();
Config::get_MVC_METHODNAME_PRECONSTRUCT();
Config::get_MVC_WEB_ROOT();
Config::get_MVC_BASE_PATH();
Config::get_MVC_APPLICATION_PATH();
Config::get_MVC_PUBLIC_PATH();
Config::get_MVC_LOG_FILE_DIR();
Config::get_MVC_LOG_FILE_DEFAULT();
Config::get_MVC_LOG_FILE_ERROR();
Config::get_MVC_LOG_FILE_WARNING();
Config::get_MVC_LOG_FILE_NOTICE();
Config::get_MVC_LOG_FILE_POLICY();
Config::get_MVC_LOG_FILE_EVENT();
Config::get_MVC_LOG_FILE_EVENT_RUN();
Config::get_MVC_LOG_DETAIL();
Config::get_MVC_LOG_FORCE_LINEBREAK();
Config::get_MVC_LOG_PROCESS();
Config::get_MVC_LOG_QUEUE();
Config::get_MVC_LOG_CRON();
Config::get_MVC_APPLICATION_INIT_DIR();
Config::get_MVC_VIEW_TEMPLATE_DIR();
Config::get_MVC_LIBRARY();
Config::get_MVC_MODULES_DIR();
Config::get_MVC_CONFIG_DIR();
Config::get_MVC_CACHE_DIR();
Config::get_MVC_SSL_PORT();
Config::get_MVC_SECURE_REQUEST();
Config::get_MVC_SESSION_NAMESPACE();
Config::get_MVC_SESSION_PATH();
Config::get_MVC_SESSION_OPTIONS();
Config::get_MVC_SESSION_ENABLE();
Config::get_MVC_CLI();
Config::get_MVC_SMARTY_CACHE_STATUS();
Config::get_MVC_SMARTY_CACHE_DIR();
Config::get_MVC_SMARTY_TEMPLATE_DIR();
Config::get_MVC_SMARTY_TEMPLATE_DEFAULT();
Config::get_MVC_SMARTY_TEMPLATE_CACHE_DIR();
Config::get_MVC_SMARTY_PLUGINS_DIR();
Config::get_MVC_POLICY();
Config::get_MVC_EVENT();
Config::get_MVC_UNIQUE_ID();
Config::get_MVC_SESSION();
Config::get_MVC_INFOTOOL_ENABLE();
Config::get_MVC_CORE();
Config::get_MVC_ENV();
Config::get_MVC_VERSION();
Config::get_MVC_CACHE_CONFIG();
Config::get_MVC_MODULE_PRIMARY_COMPOSER_DIR();
Config::get_MVC_MODULE_PRIMARY_CONFIG_DIR();
Config::get_MVC_MODULE_PRIMARY_MODEL_DIR();
Config::get_MVC_MODULE_PRIMARY_POLICY_DIR();
Config::get_MVC_MODULE_PRIMARY_VIEW_DIR();
Config::get_MVC_MODULE_PRIMARY_STAGING_CONFIG_DIR();
Config::get_MVC_MODULE_PRIMARY_NAME();
Config::get_MVC_MODULE_PRIMARY_VIEW();
Config::get_MVC_BIN_REMOVE();
Config::get_MVC_BIN_FIND();
Config::get_MVC_BIN_GREP();
Config::get_MVC_BIN_MOVE();
Config::get_MVC_BIN_XARGS();
Config::get_MVC_BIN_SED();
Config::get_MVC_BIN_PHP_BINARY();
Config::get_MVC_BIN_PS();
Config::get_MVC_LOG_EVENT_RUN();
Config::get_MVC_EVENT_ENABLE_WILDCARD();
Config::get_MVC_LOG_REQUEST();
Config::get_MVC_LOG_FILE_REQUEST();
Config::get_MVC_LOG_FILE_PROCESS();
Config::get_MVC_LOG_FILE_QUEUE();
Config::get_MVC_LOG_FILE_CRON();
Config::get_MVC_LOG_SQL();
Config::get_MVC_LOG_FILE_SQL();
Config::get_MVC_PHP_SERVER();
Config::get_MVC_LOG_FILE_ROUTEINTERVALL();
Config::get_MVC_LOG_EVENT();
Config::get_MVC_LOG_DEFAULT();
Config::get_MVC_LOG_ERROR();
Config::get_MVC_LOG_WARNING();
Config::get_MVC_LOG_NOTICE();
Config::get_MVC_LOG_POLICY();
Config::get_MVC_LOG_ROUTEINTERVALL();
Config::get_MVC_ROUTING_DIR();
Config::get_MVC_ROUTE_PREFIX();
Config::get_MVC_QUEUE_ROUTE_PREFIX();
Config::get_MVC_QUEUE_WORKER_AUTO_ROUTE_PREFIX();
Config::get_MVC_QUEUE_RUN();
Config::get_MVC_QUEUE_RUN_CLASSMETHOD();
Config::get_MVC_QUEUE_WORKER_AUTO_ROUTE_RESOLVE_CLASSMETHOD();
Config::get_MVC_QUEUE_RUNTIME_SECONDS();
Config::get_MVC_PROCESS_MAX_PROCESSES_OVERALL();
Config::get_MVC_PROCESS_PID_FILE_DIR();
Config::get_MVC_CRON_ROUTE();
Config::get_MVC_CRON_RUN_CLASSMETHOD();
Appendix
<?php
/**
* @package Emvicy
* @copyright ueffing.net
* @author Guido K.B.W. Üffing <emvicy@ueffing.net>
* @license GNU GENERAL PUBLIC LICENSE Version 3. See application/doc/COPYING
*
* these configs here can be extended and overwritten by:
* `/modules/{module}/etc/config/_mvc.php`
* `/modules/{module}/etc/config/{module}/config/{stage}.php`
*/
//----------------------------------------------------------------------------------------------------------------------
// MVC
MVC_RUNTIME_SETTINGS: {
// show error messages
error_reporting(E_ALL);
// enable exit on "kill" command and CLI break (CTRL-C)
// This command needs the pcntl extension to run.
// exclude emvicy usage (e.g. if php's builtin webserver is running `php emvicy s`)
if (false === getenv('emvicy'))
{
(function_exists('pcntl_async_signals')) ? pcntl_async_signals(true) : false;
(function_exists('pcntl_signal')) ? pcntl_signal(SIGTERM, function(){exit();}) : false;
(function_exists('pcntl_signal')) ? pcntl_signal(SIGINT, function(){exit();}) : false;
}
/*
* @see http://www.php.net/manual/en/timezones.php
* @see http://stackoverflow.com/a/5559239/2487859
* to get array of available timezones see result of timezone_identifiers_list()
*/
date_default_timezone_set('UTC');
setlocale(LC_ALL, 'C');
// show InfoTool bar
$aConfig['MVC_INFOTOOL_ENABLE'] = true;
// Log autoloader actions
$aConfig['MVC_LOG_AUTOLOADER'] = true;
// address the built-in php server will run on ( php emvicy serve )
$aConfig['MVC_PHP_SERVER'] = '127.0.0.1:1969';
}
MVC_BIN:
{
$aConfig['MVC_BIN_PHP_BINARY'] = PHP_BINARY;
$aConfig['MVC_BIN_PS'] = '/usr/bin/ps'; # ps - report a snapshot of the current processes.
$aConfig['MVC_BIN_SED'] = '/usr/bin/sed'; # sed - stream editor for filtering and transforming text
$aConfig['MVC_BIN_MOVE'] = '/usr/bin/mv'; # mv - move (rename) files
$aConfig['MVC_BIN_GREP'] = '/usr/bin/grep'; # grep, egrep, fgrep, rgrep - print lines that match patterns
$aConfig['MVC_BIN_FIND'] = '/usr/bin/find'; # find - search for files in a directory hierarchy
$aConfig['MVC_BIN_REMOVE'] = '/usr/sbin/rm'; # rm - remove files or directories
$aConfig['MVC_BIN_XARGS'] = '/usr/bin/xargs'; # xargs - build and execute command lines from standard input
}
MVC_APPLICATION_SETTINGS_I: {
/**-----------------------------------------------------------------------------------------------------------------
* Name of method to be executed in the Target Controller Class
* before session and other main functionalities.
* It will be called in /application/library/MVC/Application.php:
* Controller::runTargetClassPreconstruct();
*
* This method is also declared via interface MVC_Interface_Controller.
* Due to this, you should not edit this name, otherwise you have to
* rename the method in that interface class, too.
*
* default:
* $aConfig['MVC_METHODNAME_PRECONSTRUCT'] = '__preconstruct';
*/
$aConfig['MVC_METHODNAME_PRECONSTRUCT'] = '__preconstruct';
/**-----------------------------------------------------------------------------------------------------------------
* Paths etc.
*/
$aConfig['MVC_WEB_ROOT'] = dirname($_SERVER['PHP_SELF']);
$aConfig['MVC_BASE_PATH'] = realpath(__DIR__ . '/../');
$aConfig['MVC_APPLICATION_PATH'] = $aConfig['MVC_BASE_PATH'] . '/application';
$aConfig['MVC_PUBLIC_PATH'] = $aConfig['MVC_BASE_PATH'] . '/public';
$aConfig['MVC_APPLICATION_INIT_DIR'] = $aConfig['MVC_APPLICATION_PATH'] . '/init';
$aConfig['MVC_LIBRARY'] = $aConfig['MVC_APPLICATION_PATH'] . '/library';
$aConfig['MVC_MODULES_DIR'] = $aConfig['MVC_BASE_PATH'] . '/modules';
// Main Emvicy config directory
$aConfig['MVC_CONFIG_DIR'] = $aConfig['MVC_BASE_PATH'] . '/config';
/**-----------------------------------------------------------------------------------------------------------------
* Event
*/
$aConfig['MVC_EVENT'] = array();
// allow declaring listeners with wildcard, e.g.: Event::bind('foo.bar.*', ... );
// matches to event 'foo.bar.baz': Event::run('foo.bar.baz');
// mandatory: asterisk `*` at the end
// notice: wildcard listeners are processed before the regular event listeners
$aConfig['MVC_EVENT_ENABLE_WILDCARD'] = true;
/**-----------------------------------------------------------------------------------------------------------------
* Log
* consider a logrotate mechanism for these logfiles as they may grow quickly
*/
$aConfig['MVC_LOG_SQL'] = true; // logging enabled true|false
$aConfig['MVC_LOG_EVENT'] = true; // logging enabled true|false
// logging of each simple "RUN" event into MVC_LOG_FILE_EVENT
// remember:
// - events marked as "RUN": fired events without any listener (nothing happens)
// - events marked as "RUN+": fired events with bonded listeners / closures to be executed
// be aware that setting this to "true" would produce much data in the logfile (consider using logrotate!)
// anyway this might be useful for a develop environment, as it helps debugging and understanding
$aConfig['MVC_LOG_EVENT_RUN'] = false; // logging enabled true|false
$aConfig['MVC_LOG_POLICY'] = true; // logging enabled true|false
$aConfig['MVC_LOG_PROCESS'] = true; // logging enabled true|false
$aConfig['MVC_LOG_QUEUE'] = true; // logging enabled true|false
$aConfig['MVC_LOG_CRON'] = true; // logging enabled true|false
$aConfig['MVC_LOG_ERROR'] = true; // logging enabled true|false
$aConfig['MVC_LOG_NOTICE'] = true; // logging enabled true|false
$aConfig['MVC_LOG_WARNING'] = true; // logging enabled true|false
$aConfig['MVC_LOG_REQUEST'] = true; // logging enabled true|false
$aConfig['MVC_LOG_DEFAULT'] = true; // logging enabled true|false
$aConfig['MVC_LOG_ROUTEINTERVALL'] = true; // logging enabled true|false
$aConfig['MVC_LOG_FORCE_LINEBREAK'] = false; // force linebreaks in logfiles no matter what
// Log file places
$aConfig['MVC_LOG_FILE_DIR'] = $aConfig['MVC_APPLICATION_PATH'] . '/log/'; # trailing slash required
$aConfig['MVC_LOG_FILE_DEFAULT'] = $aConfig['MVC_LOG_FILE_DIR'] . 'default.log';
$aConfig['MVC_LOG_FILE_ERROR'] = $aConfig['MVC_LOG_FILE_DIR'] . 'error.log';
$aConfig['MVC_LOG_FILE_WARNING'] = $aConfig['MVC_LOG_FILE_DIR'] . 'warning.log';
$aConfig['MVC_LOG_FILE_NOTICE'] = $aConfig['MVC_LOG_FILE_DIR'] . 'notice.log';
$aConfig['MVC_LOG_FILE_POLICY'] = $aConfig['MVC_LOG_FILE_DIR'] . 'policy.log';
$aConfig['MVC_LOG_FILE_EVENT'] = $aConfig['MVC_LOG_FILE_DIR'] . 'event.log';
$aConfig['MVC_LOG_FILE_EVENT_RUN'] = $aConfig['MVC_LOG_FILE_DIR'] . 'event_run.log';
$aConfig['MVC_LOG_FILE_REQUEST'] = $aConfig['MVC_LOG_FILE_DIR'] . 'request.log';
$aConfig['MVC_LOG_FILE_SQL'] = $aConfig['MVC_LOG_FILE_DIR'] . 'sql.log';
$aConfig['MVC_LOG_FILE_ROUTEINTERVALL'] = $aConfig['MVC_LOG_FILE_DIR'] . 'route_intervall.log';
$aConfig['MVC_LOG_FILE_PROCESS'] = $aConfig['MVC_LOG_FILE_DIR'] . 'process.log';
$aConfig['MVC_LOG_FILE_QUEUE'] = $aConfig['MVC_LOG_FILE_DIR'] . 'queue.log';
$aConfig['MVC_LOG_FILE_CRON'] = $aConfig['MVC_LOG_FILE_DIR'] . 'cron.log';
// 1) make sure write access is given to the folder
// as long as the db user is going to write and not the webserver user
// 2) consider a logrotate mechanism for this logfile as it may grow quickly
$aConfig['MVC_LOG_FILE_DB_DIR'] = '/tmp/';
// control log details
$aConfig['MVC_LOG_DETAIL'] = [
'date' => true,
'host' => true,
'env' => true,
'ip' => true,
'uniqueid' => true,
'sessionid' => true,
'count' => true,
'debug' => true,
'message' => true,
];
/**-----------------------------------------------------------------------------------------------------------------
* Caching
*/
// cache directory
$aConfig['MVC_CACHE_DIR'] = $aConfig['MVC_APPLICATION_PATH'] . '/cache';
$aConfig['MVC_CACHE_CONFIG'] = array(
'bCaching' => true,
'sCacheDir' => $aConfig['MVC_CACHE_DIR'],
'iDeleteAfterMinutes' => 1440,
'sBinRemove' => $aConfig['MVC_BIN_REMOVE'],
'sBinFind' => $aConfig['MVC_BIN_FIND'],
'sBinGrep' => $aConfig['MVC_BIN_GREP']
);
/**-----------------------------------------------------------------------------------------------------------------
* misc
*/
// Secure Port, SSL
$aConfig['MVC_SSL_PORT'] = 443;
// boolean Request is secure ? (SSL)
$aConfig['MVC_SECURE_REQUEST'] = (array_key_exists('HTTPS', $_SERVER) && strtolower($_SERVER['HTTPS']) !== 'off') || (array_key_exists('SERVER_PORT', $_SERVER) && ($_SERVER['SERVER_PORT'] == $aConfig['MVC_SSL_PORT']));
/**-----------------------------------------------------------------------------------------------------------------
* Session
*/
// session directory and
// Session options @see http://php.net/manual/de/session.configuration.php
$aConfig['MVC_SESSION_NAMESPACE'] = 'Emvicy';
$aConfig['MVC_SESSION_PATH'] = $aConfig['MVC_APPLICATION_PATH'] . '/session';
$aConfig['MVC_SESSION_OPTIONS'] = array(
'cookie_httponly' => true,
'auto_start' => 0,
'save_path' => $aConfig['MVC_SESSION_PATH'],
'cookie_secure' => $aConfig['MVC_SECURE_REQUEST'],
'name' => 'Emvicy' . (($aConfig['MVC_SECURE_REQUEST']) ? '_secure' : ''), // @see /public/.htaccess
'save_handler' => 'files',
'cookie_lifetime' => 0,
// max value for "session.gc_maxlifetime" is 65535. values bigger than this may cause php session stops working.
'gc_maxlifetime' => 65535,
'gc_probability' => 1,
'use_strict_mode' => 1,
'use_cookies' => 1,
'use_only_cookies' => 1,
'upload_progress.enabled' => 1,
);
// default behaviour
// false: session won't start. This means NO cookie is written to client
// true: session will start
$aConfig['MVC_SESSION_ENABLE'] = false;
// detect if request is done via cli. set boole true|false
$aConfig['MVC_CLI'] = (('cli' === php_sapi_name()) ? true : false);
}
MODULES: {
// if a module has that file it is the primary one
$aConfig['MVC_MODULE_PRIMARY_ESSENTIAL'] = '/.primary';
// identify primary module
$aConfig['MVC_MODULE_PRIMARY'] = array_filter(
array_map(
function ($sValue) use ($aConfig){
return str_replace($aConfig['MVC_MODULE_PRIMARY_ESSENTIAL'], '', str_replace($aConfig['MVC_MODULES_DIR'] . '/', '', $sValue));
}, glob($aConfig['MVC_MODULES_DIR'] . '/*' . $aConfig['MVC_MODULE_PRIMARY_ESSENTIAL'])),
'trim'
);
$aConfig['MVC_MODULE_PRIMARY_NAME'] = current($aConfig['MVC_MODULE_PRIMARY']);
$aConfig['MVC_MODULE_PRIMARY_DIR'] = $aConfig['MVC_MODULES_DIR'] . '/' . $aConfig['MVC_MODULE_PRIMARY_NAME'];
$aConfig['MVC_MODULE_PRIMARY_CONFIG_DIR'] = $aConfig['MVC_MODULE_PRIMARY_DIR'] . '/etc/config';
$aConfig['MVC_MODULE_PRIMARY_CONTROLLER_DIR'] = $aConfig['MVC_MODULE_PRIMARY_DIR'] . '/Controller';
$aConfig['MVC_MODULE_PRIMARY_DATATYPE_DIR'] = $aConfig['MVC_MODULE_PRIMARY_DIR'] . '/DataType';
$aConfig['MVC_MODULE_PRIMARY_ETC_DIR'] = $aConfig['MVC_MODULE_PRIMARY_DIR'] . '/etc';
$aConfig['MVC_MODULE_PRIMARY_STAGING_CONFIG_DIR'] = $aConfig['MVC_MODULE_PRIMARY_CONFIG_DIR'] . '/' . $aConfig['MVC_MODULE_PRIMARY_NAME'] . '/config';
$aConfig['MVC_MODULE_PRIMARY_MODEL_DIR'] = $aConfig['MVC_MODULES_DIR'] . '/Model';
$aConfig['MVC_MODULE_PRIMARY_POLICY_DIR'] = $aConfig['MVC_MODULES_DIR'] . '/Policy';
$aConfig['MVC_MODULE_PRIMARY_VIEW_DIR'] = $aConfig['MVC_MODULES_DIR'] . '/View';
$aConfig['MVC_MODULE_PRIMARY_COMPOSER_DIR'] = $aConfig['MVC_MODULE_PRIMARY_CONFIG_DIR'] . '/' . $aConfig['MVC_MODULE_PRIMARY_NAME'];
// array for module configs
$aConfig['MODULE'] = array();
}
MVC_APPLICATION_SETTINGS_II:
{
/**-----------------------------------------------------------------------------------------------------------------
* Routing etc.
*/
// contains all routing file dirs to get read
$aConfig['MVC_ROUTING_DIR'] = array(
// add primary per default
$aConfig['MVC_MODULE_PRIMARY_ETC_DIR'] . '/routing'
);
/**
* MVC fallback routing
* this routing will be used if none is specified for routing
* Note: Possibility of a direct call (http|cli) of this route is disabled
*/
$aConfig['MVC_ROUTING_FALLBACK'] = '\\' . $aConfig['MVC_MODULE_PRIMARY_NAME'] . '\\Controller\\Index::notFound';
}
MVC_TEMPLATE_ENGINE_SMARTY: {
$aConfig['MVC_VIEW_TEMPLATE_DIR'] = $aConfig['MVC_MODULE_PRIMARY_DIR'] . '/templates';
$aConfig['MVC_SMARTY_CACHE_STATUS'] = false;
$aConfig['MVC_SMARTY_CACHE_DIR'] = $aConfig['MVC_APPLICATION_PATH'] . '/cache';
$aConfig['MVC_SMARTY_TEMPLATE_DIR'] = $aConfig['MVC_VIEW_TEMPLATE_DIR'];
$aConfig['MVC_SMARTY_TEMPLATE_DEFAULT'] = 'Frontend/layout/index.tpl';
// templates_c directory and
// templates_c directory access rights, octal mode
$aConfig['MVC_SMARTY_TEMPLATE_CACHE_DIR'] = $aConfig['MVC_APPLICATION_PATH'] . '/templates_c';
// array Location of Smarty PlugIns
$aConfig['MVC_SMARTY_PLUGINS_DIR'][] = $aConfig['MVC_APPLICATION_PATH'] . '/smartyPlugins';
}
/**
* @see /application/doc/README "Policy"
* Policy Rules are bonded to a specific "Controller::Method"
* Define your policies
*/
MVC_POLICY: {
$aConfig['MVC_POLICY'] = array();
}
MVC_MISC: {
$aConfig['MVC_UNIQUE_ID'] = date('YmdHis') . '' . uniqid();
}
// needs a leading slash, avoid a trailing slash
$aConfig['MVC_ROUTE_PREFIX'] = '/~';
MVC_QUEUE: {
// prefix for AutoRoutes
$aConfig['MVC_QUEUE_ROUTE_PREFIX'] = $aConfig['MVC_ROUTE_PREFIX'] . '/queue';
// Route for running Queue; calling Worker on Jobs
// @see modules/{module}/etc/config/{module}/config/_queue.php
// @see modules/{module}/etc/routing/service.php
$aConfig['MVC_QUEUE_RUN'] = $aConfig['MVC_QUEUE_ROUTE_PREFIX'] . '/run';
// Class::method responsible for running Queue
$aConfig['MVC_QUEUE_RUN_CLASSMETHOD'] = '\App\Controller\Queue::run';
// Worker Route Structure
$aConfig['MVC_QUEUE_WORKER_AUTO_ROUTE_PREFIX'] = $aConfig['MVC_QUEUE_ROUTE_PREFIX'] . '/worker';
// Class::method responsible for resolving Worker Routes
$aConfig['MVC_QUEUE_WORKER_AUTO_ROUTE_RESOLVE_CLASSMETHOD'] = '\App\Controller\Queue::workerAutoRouteResolve';
// Max processing time of an async process in seconds; cancellation if reached.
$aConfig['MVC_QUEUE_RUNTIME_SECONDS'] = 300;
}
MVC_PROCESS: {
// Maximum number of all job processes allowed in parallel
$aConfig['MVC_PROCESS_MAX_PROCESSES_OVERALL'] = 30;
// pidFiles directory
$aConfig['MVC_PROCESS_PID_FILE_DIR'] = $aConfig['MVC_APPLICATION_PATH'] . '/pid/';
}
MVC_CRON: {
// @see modules/{module}/etc/config/{module}/config/_cron.php
// @see modules/{module}/etc/routing/service.php
$aConfig['MVC_CRON_ROUTE'] = $aConfig['MVC_ROUTE_PREFIX'] . '/cron/run';
// Class::method responsible for running CRON
$aConfig['MVC_CRON_RUN_CLASSMETHOD'] = '\App\Controller\Cron::run';
}
Example: /modules/Foo/etc/config/_mvc.php
<?php
/**
* @package Emvicy
* @copyright ueffing.net
* @author Guido K.B.W. Üffing <emvicy@ueffing.net>
* @license GNU GENERAL PUBLIC LICENSE Version 3. See application/doc/COPYING
*
* these configs here do extend and overwrite:
* `/config/_mvc.php`
*/
//-------------------------------------------------------------------------------------
// Module
//-------------------------------------------------------------------------------------
// MVC
// override default fallback routing
$aConfig['MVC_ROUTING_FALLBACK'] = '\\' . $aConfig['MVC_MODULE_PRIMARY_NAME'] . '\\Controller\\Index::notFound';
// Add Location of Smarty PlugIns
$aConfig['MVC_SMARTY_PLUGINS_DIR'][] = realpath(__DIR__ . '/../../') . '/etc/smartyPlugins';
Example: /modules/Foo/etc/config/Foo/config/develop.php
<?php
/**
* @package Emvicy
* @copyright ueffing.net
* @author Guido K.B.W. Üffing <emvicy@ueffing.net>
* @license GNU GENERAL PUBLIC LICENSE Version 3. See application/doc/COPYING
*
* these configs here do extend and overwrite:
* `/modules/Foo/etc/config/_mvc.php`
*/
//######################################################################################################################
// Emvicy
declare(strict_types=1); // @see https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict
error_reporting(E_ALL);
date_default_timezone_set('Europe/Berlin');
$aConfig['MVC_BIN_PHP_BINARY'] = '/usr/bin/php'; // override ddev's `/usr/sbin/php-fpm8.4`
// recommended to set a logrotate mechanism for these logfiles as they may grow quickly
$aConfig['MVC_LOG_SQL'] = true;
$aConfig['MVC_LOG_CRON'] = true;
$aConfig['MVC_LOG_EVENT'] = false;
$aConfig['MVC_LOG_ERROR'] = true; // recommended to set to true for ALL environments
$aConfig['MVC_LOG_QUEUE'] = true;
$aConfig['MVC_LOG_NOTICE'] = true;
$aConfig['MVC_LOG_POLICY'] = true;
$aConfig['MVC_LOG_PROCESS'] = true;
$aConfig['MVC_LOG_WARNING'] = true;
$aConfig['MVC_LOG_REQUEST'] = true;
$aConfig['MVC_LOG_DEFAULT'] = true;
$aConfig['MVC_LOG_EVENT_RUN'] = false;
$aConfig['MVC_LOG_AUTOLOADER'] = false; // recommended to set to true for develop environments only: Log autoloader actions
$aConfig['MVC_LOG_ROUTEINTERVALL'] = false; // recommended to set to true for develop environments only: Log Route Intervall actions
$aConfig['MVC_LOG_FORCE_LINEBREAK'] = true; // force linebreaks in logfiles no matter what, improves readability of logs but blows up logfile
$aConfig['MVC_INFOTOOL_ENABLE'] = true; // recommended to set to true for develop environments only: show InfoTool bar
// take MVC_UNIQUE_ID out of request Header
$sUniqueId = preg_replace("/[^[:alnum:]]/ui", '', get(array_change_key_case(getallheaders(), CASE_LOWER)['mvc-unique-id'], ''));
(false === empty($sUniqueId)) ? $aConfig['MVC_UNIQUE_ID'] = $sUniqueId : false;
//######################################################################################################################
// Module Foo
$aConfig['MODULE']['Foo'] = array();
// ...your config goes here...
//......................................................................................................................
// DB
require_once realpath(__DIR__) . '/_db.php';
// consider a logrotate mechanism for this logfile as it may grow quickly
$aConfig['MODULE']['Foo']['DB']['logging']['general_log'] = 'ON'; // consider to set it to ON for develop or test environments only
//......................................................................................................................
// Queue
require_once realpath(__DIR__) . '/_queue.php';
//######################################################################################################################
// common settings
require_once realpath(__DIR__) . '/_function.php';
require_once realpath(__DIR__) . '/_datatype.php';
require_once realpath(__DIR__) . '/_session.php';
require_once realpath(__DIR__) . '/_csp.php';
require_once realpath(__DIR__) . '/_menu.php';
require_once realpath(__DIR__) . '/_cron.php';