I'm designing a web-app that makes use of PayPal to purchase products. So, in my config file, I do something like the following...
'paypal' => (object) array(
Fuel::DEVELOPMENT => (object) array(
'username' => '',
'password' => '',
'signature' => ''
),
Fuel::PRODUCTION => (object) array(
'username' => '',
'password' => '',
'signature' => ''
)
),
...which is great - now I can just do something like Config::get('paypal')->{Fuel::$env}->username, and get the appropriate username for my environment.
But, how are people making sure that Fuel::$env is set correctly? I see that the framework checks to see if a value is set in the $_SERVER superglobal for the key 'fuel_env', and defaults to development, although that can obviously be changed.
In other words, how can I automatically set the value of that 'fuel_env' key in the $_SERVER superglobal?
You either use the SetEnv command in your webserver's virtual host definition, or use can use an environment variable on the server.
I have also seen people adding code to the index.php that check hostname or server IP, and set $_SERVER based on that.
That's exactly how we handle stuff for "normal websites" where the difference between a development and production server is enough. We check for our local server's IP / hostname and set the environment to development if we're on them, otherwise we fall back to production. We use the index.php in the public folder as the place to do this, otherwise Oil will produce errors (as they are no server variables available using Oil / command line). This piece of code is part of our own little fork of FuelPHP so it works on servers out of the box.
Whenever we're developing a bigger app, that will leverage staging and testing servers we always use the SetEnv method available in Apache. They are basically constants you can set in Apache's config files (virtual host definition and .htaccess (I never tried the latter)) that are accessible in PHP through the $_SERVER global. You can define these like this: