webCOMAND

env::__construct()

Create an environment (Development, Staging, Production, etc.) and set the paths to use when loading packages for the framework user.  The environment can be set explicitly or automatically loaded based on a query string or the webCOMAND user's settings.

Prototype

__construct(array $options = [])

Parameter

  • options - Optional associative array with zero or more of the following key/value pairs.
    • add_package_paths - If TRUE, call add_package_path() to append the environment Path as a folder to the end of all existing package paths.  Default is FALSE.
    • allow - Optional array of allowed environment paths.  Default is ['staging','dev'].
    • default - The default environment to use if it can not be determined by the env option below, env query string option or user setting.
    • env - An environment to use, as a string that matches an Environment Path.
    • framework - Framework to use to determine active user and access settings, and for repo (unless repo is specified) and/or request (unless request is specified).  If no framework is specified, the active user will not be checked to determine their active environment.
    • paths - Optional array of paths to add to the existing package paths.
    • repo - Repository connection to use.  If not specified, the framework repo will be used.  If repo and framework are not specified, then the default configured repository will be used.
    • request - Optional request object to use to retrieve the environment from the web request.  If not provided, but the framework option is, the framework request object will be used.  If neither is provided, a new request object will be created automatically.
    • verify_user - Set to FALSE to disable connecting to the repository and verifying that the active user is privileged to run in the determined environment.  Default is TRUE.

Return

The environment subfolder path to be used, such as 'dev'.  If no special environment will be used, the main production environment path ('') will be returned.

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