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( )
|
||||
{
|
||||
$this->baseURL = dirname( $_SERVER[ 'SCRIPT_NAME' ] );
|
||||
if ( $this->baseURL == '/' ) {
|
||||
$this->baseURL = '';
|
||||
}
|
||||
$this->baseURL = rtrim(dirname( $_SERVER[ 'SCRIPT_NAME' ] ), '/');
|
||||
}
|
||||
|
||||
public final function addController( Controller $controller )
|
||||
|
@ -29,6 +26,16 @@ abstract class Page
|
|||
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( )
|
||||
{
|
||||
return $this->baseURL;
|
||||
|
@ -55,8 +62,7 @@ abstract class Page
|
|||
if ( $rc[0] != '/' ) {
|
||||
$rc = $this->baseURL . '/' . $rc;
|
||||
}
|
||||
$rc = ( ( array_key_exists( 'HTTPS' , $_SERVER ) && $_SERVER[ 'HTTPS' ] ) ? 'https' : 'http' ) . '://' . $_SERVER[ 'SERVER_NAME' ]
|
||||
. ':' . $_SERVER[ 'SERVER_PORT' ] . $rc;
|
||||
$rc = $this->getServerRoot() . $rc;
|
||||
header( "Location: $rc" );
|
||||
$rv = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue