Merge pull request #7303 from open-sausages/pulls/4.0/constant-logging

BUG Fix BASE_URL for CLI
This commit is contained in:
Chris Joe 2017-08-24 11:56:10 +12:00 committed by GitHub
commit 8edf070a13
3 changed files with 18 additions and 5 deletions

View File

@ -78,6 +78,9 @@ before_script:
# Bootstrap dependencies
- if [[ $PHPUNIT_TEST == cms ]] || [[ $BEHAT_TEST == cms ]]; then php ./cms/tests/bootstrap/mysite.php; fi
# Log constants to CI for debugging purposes
- php ./tests/dump_constants.php
# Start behat services
- if [[ $BEHAT_TEST ]]; then echo 'SS_BASE_URL=http://localhost:8080/' >> .env; fi
- if [[ $BEHAT_TEST ]]; then mkdir artifacts; fi

View File

@ -2,7 +2,6 @@
use Dotenv\Dotenv;
use Dotenv\Exception\InvalidPathException;
use SilverStripe\Control\Util\IPUtils;
use SilverStripe\Core\TempFolder;
/**
@ -18,14 +17,14 @@ use SilverStripe\Core\TempFolder;
* See Director::baseFolder(). Can be overwritten by Config::modify()->set(Director::class, 'alternate_base_folder', ).
* - TEMP_FOLDER: Absolute path to temporary folder, used for manifest and template caches. Example: "/var/tmp"
* See getTempFolder(). No trailing slash.
* - ASSETS_DIR: Dir for assets folder. e.g. "assets"
* - ASSETS_PATH: Full path to assets folder. e.g. "/var/www/my-webroot/assets"
* - THEMES_DIR: Path relative to webroot, e.g. "themes"
* - THEMES_PATH: Absolute filepath, e.g. "/var/www/my-webroot/themes"
* - FRAMEWORK_DIR: Path relative to webroot, e.g. "framework"
* - FRAMEWORK_PATH:Absolute filepath, e.g. "/var/www/my-webroot/framework"
* - THIRDPARTY_DIR: Path relative to webroot, e.g. "framework/thirdparty"
* - THIRDPARTY_PATH: Absolute filepath, e.g. "/var/www/my-webroot/framework/thirdparty"
* - TRUSTED_PROXY: true or false, depending on whether the X-Forwarded-* HTTP
* headers from the given client are trustworthy (e.g. from a reverse proxy).
*/
require_once __DIR__ . '/functions.php';
@ -83,8 +82,8 @@ if (!defined('BASE_URL')) {
$urlSegmentToRemove = substr($path, strlen(BASE_PATH));
if (substr($_SERVER['SCRIPT_NAME'], -strlen($urlSegmentToRemove)) == $urlSegmentToRemove) {
$baseURL = substr($_SERVER['SCRIPT_NAME'], 0, -strlen($urlSegmentToRemove));
// Normalise slashes to '/' and rtrim('/')
return rtrim(str_replace('\\', '/', $baseURL), '/');
// ltrim('.'), normalise slashes to '/', and rtrim('/')
return rtrim(str_replace('\\', '/', ltrim($baseURL, '.')), '/');
}
}

11
tests/dump_constants.php Normal file
View File

@ -0,0 +1,11 @@
<?php
// Helper for dumping the value of standard constants prior to test
require __DIR__ . '/../src/includes/autoload.php';
echo "=== User-Defined Constants ===\n";
$constants = get_defined_constants(true);
foreach ($constants['user'] as $name => $value) {
echo " - {$name}: '{$value}'\n";
}
echo "==============================\n";