-
-
Save biplobice/ca301ebceba9a15f94c7a3bdf56b98ac to your computer and use it in GitHub Desktop.
concrete5 Environment switch according to host name
This file contains hidden or 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 | |
// /application/bootstrap/app.php | |
Route::register('/ccm/request_test', function() { | |
header("Pragma: no-cache"); | |
echo '<dl>'; | |
?><dt>Application environment:</dt><dd><?php echo ($this->app->environment()) ? $this->app->environment() : 'default'; ?></dd><?php | |
$request = \Concrete\Core\Http\Request::getInstance(); | |
?><dt>Client IP:</dt><dd><?php echo $request->getClientIp(); ?></dd><?php | |
?><dt>Host:</dt><dd><?php echo $request->getHost(); ?></dd><?php | |
?><dt>Port:</dt><dd><?php echo $request->getPort(); ?></dd><?php | |
?><dt>Scheme:</dt><dd><?php echo $request->getScheme(); ?></dd><?php | |
?><dt>Secure:</dt><dd><?php echo ($request->isSecure()) ? 'true' : 'false'; ?></dd><?php | |
?><dt>Canonical URL:</dt><dd><?php echo \Core::make('url/canonical'); ?></dd><?php | |
?><dt>Get all headers:</dt><dd><pre><?php var_dump($request->headers->all()); ?></pre></dd><?php | |
echo '</dl>'; | |
}); |
This file contains hidden or 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 | |
use Concrete\Core\Application\Application; | |
// /application/bootstrap/start.php | |
/* | |
* ---------------------------------------------------------------------------- | |
* Instantiate concrete5 | |
* ---------------------------------------------------------------------------- | |
*/ | |
$app = new Application(); | |
/* | |
* ---------------------------------------------------------------------------- | |
* Detect the environment based on the hostname of the server | |
* ---------------------------------------------------------------------------- | |
*/ | |
$app->detectEnvironment(function() { | |
$request = \Concrete\Core\Http\Request::getInstance(); | |
if (($request->getHost() == 'develop.example.com')) { | |
return 'develop'; | |
} else { | |
return 'live'; | |
} | |
}); | |
return $app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment