Configuration
- Environment
public/.env
- Config files, -places and reading order
- Module's composer.json
- Access
MVC_*
config values - Access module config values
Environment public/.env
MVC_ENV
In the public/
folder you will find an .env
file. There the variable MVC_ENV
is declared. This variable declares what Environment is valid for myMVC.
You can name the value as you like - But common values are: develop
, test
, production
.
Make sure the corresponding environment config file does exist in your module
(Schema: /modules/{moduleName}/etc/config/{moduleName}/config/{environment}.php
).
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.
# Environment
MVC_ENV=production
Custom .env variables
You are free to set up any key=value
declarations you want in that public/.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.
- โ myMVC 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
_myMVC.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. myMVC config variable names always begin withMVC_
.
- โ Module's config folder
/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
_myMVC.php
: further MVC configs. myMVC config variable names always begin withMVC_
.
- โค Module's environment config file
- Schema:
/modules/{moduleName}/etc/config/{moduleName}/config/{environment}.php
- Example: 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.
- Example: 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
- Schema:
Module's composer.json
Extend your module with third libraries using composer.
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 myMVC Application, myMVC 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
myMVC will automatically integrate all /vendor/autoload.php
autoloaders from any myMVC module.
Access MVC_*
config values
Access MVC configurations via the \MVC\Config
Class. For each variable there is an identical getter.
Syntax
$mVar = \MVC\Config::get_{MVC_VARIABLE}();
Example
$sMvcBasePath = \MVC\Config::get_MVC_BASE_PATH();
Alternativley you can access all MVC Configs via \MVC\Registry
.
Alternative
$sMvcBasePath = \MVC\Registry::get('MVC_BASE_PATH');
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');