feat: make server root configurable
This commit is contained in:
parent
5320ba3e11
commit
b21bf52e4d
1 changed files with 12 additions and 6 deletions
|
@ -10,10 +10,7 @@ abstract class Page
|
||||||
|
|
||||||
public function __construct( )
|
public function __construct( )
|
||||||
{
|
{
|
||||||
$this->baseURL = dirname( $_SERVER[ 'SCRIPT_NAME' ] );
|
$this->baseURL = rtrim(dirname( $_SERVER[ 'SCRIPT_NAME' ] ), '/');
|
||||||
if ( $this->baseURL == '/' ) {
|
|
||||||
$this->baseURL = '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final function addController( Controller $controller )
|
public final function addController( Controller $controller )
|
||||||
|
@ -29,6 +26,16 @@ abstract class Page
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final function getServerRoot( )
|
||||||
|
{
|
||||||
|
$root = Loader::PackageConfig( 'core' )->get( 'pages/baseURL' , null , false );
|
||||||
|
if (is_null($root)) {
|
||||||
|
$root = ( ( $_SERVER[ 'HTTPS' ] ?: false ) ? 'https' : 'http' )
|
||||||
|
. '://' . $_SERVER[ 'HTTP_HOST' ];
|
||||||
|
}
|
||||||
|
return rtrim($root, '/');
|
||||||
|
}
|
||||||
|
|
||||||
public final function getBaseURL( )
|
public final function getBaseURL( )
|
||||||
{
|
{
|
||||||
return $this->baseURL;
|
return $this->baseURL;
|
||||||
|
@ -55,8 +62,7 @@ abstract class Page
|
||||||
if ( $rc[0] != '/' ) {
|
if ( $rc[0] != '/' ) {
|
||||||
$rc = $this->baseURL . '/' . $rc;
|
$rc = $this->baseURL . '/' . $rc;
|
||||||
}
|
}
|
||||||
$rc = ( ( array_key_exists( 'HTTPS' , $_SERVER ) && $_SERVER[ 'HTTPS' ] ) ? 'https' : 'http' ) . '://' . $_SERVER[ 'SERVER_NAME' ]
|
$rc = $this->getServerRoot() . $rc;
|
||||||
. ':' . $_SERVER[ 'SERVER_PORT' ] . $rc;
|
|
||||||
header( "Location: $rc" );
|
header( "Location: $rc" );
|
||||||
$rv = true;
|
$rv = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue