This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Simple environment switch for deploying.

0.0.6 2017-02-17 06:58 UTC

This package is not auto-updated.

Last update: 2021-07-24 10:42:14 UTC


I've been thinking how to solve the problem of deploy code to different environments. Now I've made a switch.


You must have a file in your deploying directory, in which the name of the environment is written. By default, the file locates in your DOCUMENT_ROOT directory and is named env, which is defined in your web server's configuration and can be override by passing a path to the constructor of \Spe\Env as the 1st parameter.

By default, there are 4 environments, which are dev, test, emu, and prod. You can override the setting by passing an array to the constructor of \Spe\Env as the 2nd parameter.

Absolutely you don't have to pass any parameters to the constructor at all, it has proper default settings.


  1. A container is recommended.
$container['env'] = function ($c) {
    return new \Spe\Env();
  1. You can get current env setting at any time by calling \Spe\Env::get().

  2. Thanks to the container, you can set a temporary env setting wherever you want because you access the instance of \Spe\Env as a singleton with a container.


PR are welcome to improve this project.


  1. WeChat
  2. Alipay