webCOMAND

COMAND Environment

io_comand_env

A package for working with different environments (ie. Development, Staging and Production), which is useful for developing and testing packages before they are ready for release to production.

Environment Folder Hierarchy

Consider the file paths below, each to a different version of a test PHP class in the com_example_test package for the 3 standard environments.

  • Production (default) - <webcomand>/files/packages/com_example_test/test.php
  • Development - <webcomand>/files/packages/com_example_test/dev/test.php
  • Staging - <webcomand>/files/packages/com_example_test/staging/test.php
If a requested file does not exist in staging or dev, it will automatically fallback to load the version in Production.

Active Environment

The active environment will be detected based on one of several possible factors, where the highest priority is listed first below.

  • 'env' Option - If the 'env' option is passed to the env::Constructor, it will be used.
  • URL Query String - If a query string like ?env=staging is in the request URL, it will be detected and used.  This will also set the active user's setting, which will effect subsequent requests without the query string.
  • User Settings - The io.comand.env User setting will be set when the environment is set from the webCOMAND User Interface or the URL Query String so that it can be automatically picked up by future requests.

Example

// use the webCOMAND Framework to set the package environment based on
// the active user and their selected environment or the env query
// parameter (ie. ?env=staging).  If env=staging, the COMAND auto-
// loader will find packages in the packages/staging subfolder if it
// exists, otherwise fallback to the main packages folder(s).
$framework = new \com_webcomand::framework();
$env = new \io_comand_env\env(['framework'=>$framework]);

echo("Environment = $env");
// subsequent packages will auto-load from the appropriate environment