kimtooflex/envswitch

Code once, host anywhere, run everywhere

dev-master 2018-09-03 07:15 UTC

This package is not auto-updated.

Last update: 2025-08-18 03:34:03 UTC


README

Code once, host anywhere, run everywhere

envswitch.php is a fast & flexible environment switching library for PHP 5.X+

  • Define multiple production or development servers
  • Callback compatibility
  • No Server limits

Getting started

  1. PHP 5.x.x is required
  2. Install envswitch using Composer (recommended)

Composer Installation

  1. Get Composer
  2. Require Klein with php composer.phar require kimtooflex/envswitch
  3. Add the following to your application's main PHP file: use \envswitch\EnvSwitch;

Example

Hello World - Obligatory hello world example (one server)

<?php
 use \envswitch\EnvSwitch;
 
EnvSwitch::setEnv("127.0.0.2",
          function() {
              die("Hello world, this is development environment");
          },
          function() {
               die("Hello world, this is production environment");
          }
);

Example 1 - Respond to many servers

<?php
use \envswitch\EnvSwitch;

EnvSwitch::setEnv("127.0.0.2,localhost",
          function() {
              die("Hello world, this is development environment");
          },
          function() {
               die("Hello world, this is production environment");
          }
);