Skip to content

Commit

Permalink
Use symfony/http-foundation to detect base url
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Roach committed Sep 11, 2018
1 parent a6e478b commit 64f61bf
Show file tree
Hide file tree
Showing 2,498 changed files with 23,451 additions and 235,806 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"config": {
"platform": {
"php" : "5.3.3"
"php" : "5.3.9"
}
},
"require": {
Expand All @@ -33,7 +33,8 @@
"lutana/pclzip": "2.8.2.1",
"ramsey/uuid": "~2.9",
"swiftmailer/swiftmailer": "~5.0",
"tecnickcom/tcpdf": "~6.2"
"tecnickcom/tcpdf": "~6.2",
"symfony/http-foundation": "^2.6"
},
"require-dev": {
"mockery/mockery": "*",
Expand Down
59 changes: 57 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 6 additions & 22 deletions includes/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Fisharebest\Webtrees\Controller\PageController;
use Fisharebest\Webtrees\Theme\AdministrationTheme;
use PDOException;
use Symfony\Component\HttpFoundation\Request;

/**
* This is the bootstrap script, that is run on every request.
Expand Down Expand Up @@ -164,29 +165,12 @@
date_default_timezone_set('UTC');

// Calculate the base URL, so we can generate absolute URLs.
$https = strtolower(Filter::server('HTTPS'));
$protocol = ($https === '' || $https === 'off') ? 'http' : 'https';
$protocol = Filter::server('HTTP_X_FORWARDED_PROTO', 'https?', $protocol);
$request = Request::createFromGlobals();
$request_uri = $request->getSchemeAndHttpHost() . $request->getRequestUri();

$host = Filter::server('SERVER_ADDR', null, '127.0.0.1');
$host = Filter::server('SERVER_NAME', null, $host);

$port = Filter::server('SERVER_PORT', null, '80');
$port = Filter::server('HTTP_X_FORWARDED_PORT', '80|443', $port);

// Ignore the default port.
if ($protocol === 'http' && $port === '80' || $protocol === 'https' && $port === '443') {
$port = '';
} else {
$port = ':' . $port;
}

// REDIRECT_URL should be set when Apache is following a RedirectRule
// PHP_SELF may have trailing path: /path/to/script.php/FOO/BAR
$path = Filter::server('REDIRECT_URL', null, Filter::server('PHP_SELF'));
$path = substr($path, 0, stripos($path, WT_SCRIPT_NAME));

define('WT_BASE_URL', $protocol . '://' . $host . $port . $path);
// Remove any PHP script name and parameters.
$base_uri = preg_replace('/[^\/]+\.php(\?.*)?$/', '', $request_uri);
define('WT_BASE_URL', $base_uri);

// Convert PHP warnings/notices into exceptions
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
Expand Down
1 change: 0 additions & 1 deletion vendor/bin/coveralls

This file was deleted.

1 change: 0 additions & 1 deletion vendor/bin/phpunit

This file was deleted.

Loading

0 comments on commit 64f61bf

Please sign in to comment.