Created
December 11, 2013 16:40
-
-
Save BeingTomGreen/7913876 to your computer and use it in GitHub Desktop.
A quick way of reinstating the older Laravel 4 environment detection. As of 4.1 host name based environment detection has been removed due to security concerns, but some people may wish to add this back in. See more here: https://github.com/laravel/framework/commit/02618b4190c08e1fe6e138eadb95473c92da6718
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// An array of environments, exactly as old syntax | |
$envs = [ | |
'local' => ['Alex','Al', 'Tom-PC', 'Tom', 'mgc.dev'], | |
'local_mamp' => ['navi-mini.home', 'aaron-whiffins-mac-mini.home'], | |
'production' => ['mygiftclues.com'], | |
'staging' => ['giftclue.co.uk'] | |
]; | |
// Grab our hostname and machine name | |
// From the command line HTTP_HOST won't exist so ignore that | |
$hostName = isset($_SERVER["HTTP_HOST"]) ? parse_url($_SERVER["HTTP_HOST"])['path'] : ''; | |
$machineName = gethostname(); | |
// Loop through each of the possible environments | |
foreach ($envs as $key => $environment) | |
{ | |
// Now check if either the hostname or machine name match an element in the environment array | |
if (in_array($hostName, $environment) or in_array($machineName, $environment)) | |
{ | |
// If so set this as the environment | |
return $key; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anybody sees this, Laravel 5 has started using vlucas/phpdotenv.
You could roll this into your Laravel 4 install without too much work.