Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions installation/src/Application/InstallationApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ public function __construct(?Input $input = null, ?Registry $config = null, ?Web

// Register the config to Factory.
Factory::$config = $this->config;

// Set the root in the URI one level up.
$parts = explode('/', Uri::base(true));
array_pop($parts);
Uri::root(null, implode('/', $parts));
}

/**
Expand Down Expand Up @@ -237,6 +232,11 @@ protected function doExecute()
*/
public function execute()
{
// Set the root in the URI one level up.
$parts = explode('/', Uri::base(true));
array_pop($parts);
Uri::root(null, implode('/', $parts));

try {
// Perform application routines.
$this->doExecute();
Expand Down
16 changes: 13 additions & 3 deletions libraries/src/Application/AdministratorApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ public function __construct(?Input $input = null, ?Registry $config = null, ?Web

// Execute the parent constructor
parent::__construct($input, $config, $client, $container);

// Set the root in the URI based on the application name
Uri::root(null, rtrim(\dirname(Uri::base(true)), '/\\'));
}

/**
Expand Down Expand Up @@ -508,4 +505,17 @@ public function findOption(): string

return $option;
}

/**
* Hook to allow applications to configure anything inside the static variables of \Joomla\CMS\Uri\Uri.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
protected function configureBaseUrlForApplication(): void
{
// Set the root in the URI based on the application name
Uri::root(null, rtrim(\dirname(Uri::base(true)), '/\\'));
}
}
16 changes: 13 additions & 3 deletions libraries/src/Application/ApiApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ public function __construct(?JInputJson $input = null, ?Registry $config = null,

$this->addFormatMap('application/json', 'json');
$this->addFormatMap('application/vnd.api+json', 'jsonapi');

// Set the root in the URI based on the application name
Uri::root(null, str_ireplace('/' . $this->getName(), '', Uri::base(true)));
}

/**
Expand Down Expand Up @@ -439,4 +436,17 @@ public function dispatch($component = null)
new AfterDispatchEvent('onAfterDispatch', ['subject' => $this])
);
}

/**
* Hook to allow applications to configure anything inside the static variables of \Joomla\CMS\Uri\Uri.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
protected function configureBaseUrlForApplication(): void
{
// Set the root in the URI based on the application name
Uri::root(null, rtrim(\dirname(Uri::base(true)), '/\\'));
}
}
12 changes: 12 additions & 0 deletions libraries/src/Application/CMSApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function ($systemVariable) use ($input) {
public function execute()
{
try {
$this->configureBaseUrlForApplication();
$this->sanityCheckSystemVariables();
$this->setupLogging();
$this->createExtensionNamespaceMap();
Expand Down Expand Up @@ -1359,4 +1360,15 @@ public function setMenuFactory(MenuFactoryInterface $menuFactory): void
{
$this->menuFactory = $menuFactory;
}

/**
* Hook to allow applications to configure anything inside the static variables of \Joomla\CMS\Uri\Uri.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
protected function configureBaseUrlForApplication(): void
{
}
}
9 changes: 1 addition & 8 deletions libraries/src/Application/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,7 @@ protected function populateHttpHost()
$uri = Uri::getInstance('https://joomla.invalid/set/by/console/application');
}

/**
* Yes, this is icky but it is the only way to trick WebApplication into compliance.
*
* @see \Joomla\Application\AbstractWebApplication::detectRequestUri
*/
$_SERVER['HTTP_HOST'] = $uri->toString(['host', 'port']);
$_SERVER['REQUEST_URI'] = $uri->getPath();
$_SERVER['HTTPS'] = $uri->getScheme() === 'https' ? 'on' : 'off';
$this->set('uri.request', $uri->toString());
}

/**
Expand Down
14 changes: 14 additions & 0 deletions libraries/src/Uri/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public static function getInstance($uri = 'SERVER')
if (empty(static::$instances[$uri])) {
// Are we obtaining the URI from the server?
if ($uri === 'SERVER') {
try {
$applicationUriRequest = Factory::getApplication()->get('uri.request');

if ($applicationUriRequest !== null) {
static::$instances[$uri] = new static($applicationUriRequest);

return static::$instances[$uri];
}
} catch (\Exception $e) {
@trigger_error('The application should be set into Factory', E_USER_DEPRECATED);
}

@trigger_error('The application should provide the request URI from Joomla 5.0.0', E_USER_DEPRECATED);

// Determine if the request was over SSL (HTTPS).
if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) !== 'off')) {
$https = 's://';
Expand Down