PHP code example of liftkit / environment-detection

1. Go to this page and download the library: Download liftkit/environment-detection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

liftkit / environment-detection example snippets


use LiftKit\EnvironmentDetection\Detector;

$detector = new Detector;

$detector->ifHttpHost('something.localhost', 'local')
	->ifHttpHost('test.something.com', 'test')
	->ifHttpHost('www.something.com', 'production')
	->ifHttpHost('*.something.com', 'subdomain')
	->ifHttpHost('*', 'default'); // if no other pattern matches
	
$environment = $detector->resolve();

$detector->clear() // clear previous rules
	->ifHostName('*.local', 'local') // default pattern for macOS
	->ifHostName('*', 'default'); // will match all others

$environment = $detector->resolve();

$detector->clear() // clear previous rules
	->ifEnv('environment', 'dev', 'local') // tests $_ENV['development'] == 'dev'
	->ifEnv('environment', '*', 'default'); // will match all values of $_ENV['environment'], if $_ENV['environment'] is defined

$environment = $detector->resolve();

$detector->clear() // clear previous rules
	->ifMatch(php_uname('s'), 'Darwin', 'mac') // if macOS
	->ifMatch(php_uname('s'), 'Linux', 'linux'); // if Linux

$environment = $detector->resolve();

$detector->clear() // clear previous rules
	->ifBool(defined('TEST_ENVIRONMENT'), 'test')
	->defaultTo('production'); // default value

$environment = $detector->resolve();

$detector->clear() // clear previous rules
	->ifMatch(php_sapi_name(), 'cli', 'cli') // in CLI
	->defaultTo('web'); // otherwise assume web request

$environment = $detector->resolve();

$detector->clear(); // clear previous rules

$environment = $detector->resolve(); // $environment === null