Skip to content

Instantly share code, notes, and snippets.

@katzueno
Last active May 13, 2020 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save katzueno/91bd6e40c59efb11c263804188538af7 to your computer and use it in GitHub Desktop.
Save katzueno/91bd6e40c59efb11c263804188538af7 to your computer and use it in GitHub Desktop.
concrete5 Environment switch according to host name
<?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>';
});
<?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