Skip to content

Instantly share code, notes, and snippets.

@darioghilardi
Created September 7, 2012 14:35
Show Gist options
  • Save darioghilardi/3666711 to your computer and use it in GitHub Desktop.
Save darioghilardi/3666711 to your computer and use it in GitHub Desktop.
Environments setup
<?php
/**
* Environment selection:
* Set the correct environment based on the current request.
*
* Development is the default environment.
* Test gets called when running behat tests and li3 tests:
* For behat look at features/bootstrap/LithiumAcceptanceTester.php where an environment variable is set.
* For li3 it's switched here based on the command parameter of $request.
*
* As behat runs on jenkins too, and because jenkins uses a db declations provided by the ini file, an environment
* variable check is needed to recognize jenkins builds.
*
* For every other environment the HTTP_LITHIUM_ENVIRONMENT variable should be set.
*/
use lithium\core\Environment;
use lithium\action\Request;
Environment::is(function($request) {
// Production settings
$service = $request->env('HTTP_LITHIUM_ENVIRONMENT');
// CI environment
$ci = $request->env('JENKINS_HOME');
// Local behat environment
$behat = $request->env('HTTP_LITHIUM_BEHAT');
switch (true) {
case (isset($service) || isset($ci)):
return 'service';
case (($request->command == 'test') || (isset($behat))):
return 'test';
default:
return 'development';
}
});
?>
@tannerhodges
Copy link

Hey @ingo86, where does this go in your project? Do you reference it in app/config/bootstrap/app.php?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment