diff --git a/composer.lock b/composer.lock index f78a73e51c452..f2bfa8abb6929 100644 --- a/composer.lock +++ b/composer.lock @@ -756,23 +756,23 @@ }, { "name": "joomla/application", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/joomla-framework/application.git", - "reference": "e7b950d2d1358c0baac95a8633a60de20a1e82ab" + "reference": "5e29f3d42f8443162a30fe2c799ca82c3afaf622" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/application/zipball/e7b950d2d1358c0baac95a8633a60de20a1e82ab", - "reference": "e7b950d2d1358c0baac95a8633a60de20a1e82ab", + "url": "https://api.github.com/repos/joomla-framework/application/zipball/5e29f3d42f8443162a30fe2c799ca82c3afaf622", + "reference": "5e29f3d42f8443162a30fe2c799ca82c3afaf622", "shasum": "" }, "require": { "joomla/event": "^2.0", - "joomla/registry": "^1.4.5|^2.0", + "joomla/registry": "^2.0", "laminas/laminas-diactoros": "^2.2.2", - "php": "^7.2.5", + "php": "^7.2.5|~8.0.0|~8.1.0", "psr/http-message": "^1.0", "psr/log": "^1.0", "symfony/deprecation-contracts": "^2.1" @@ -785,26 +785,29 @@ "joomla/uri": "<1.1" }, "require-dev": { - "joomla/coding-standards": "^3.0@dev", - "joomla/controller": "^1.0|^2.0", - "joomla/di": "^1.5|^2.0", - "joomla/input": "^1.2|^2.0", + "ext-json": "*", + "joomla/controller": "^2.0", + "joomla/di": "^2.0", + "joomla/input": "^2.0", "joomla/router": "^2.0", "joomla/session": "^2.0", "joomla/test": "^2.0", - "joomla/uri": "^1.1|^2.0", + "joomla/uri": "^2.0", "phpunit/phpunit": "^8.5|^9.0", + "rector/rector": "^0.13.10", + "squizlabs/php_codesniffer": "^3.4", "symfony/phpunit-bridge": "^3.4.26|^4.1.12|^4.2.7|^5.0" }, "suggest": { - "joomla/controller": "^1.0|^2.0 To support resolving ControllerInterface objects in ControllerResolverInterface, install joomla/controller", - "joomla/input": "^1.2|^2.0 To use WebApplicationInterface, install joomla/input", + "ext-json": "To use JSON format, ext-json is required", + "joomla/controller": "^2.0 To support resolving ControllerInterface objects in ControllerResolverInterface, install joomla/controller", + "joomla/input": "^2.0 To use WebApplicationInterface, install joomla/input", "joomla/router": "^2.0 To use WebApplication or ControllerResolverInterface implementations, install joomla/router", "joomla/session": "^2.0 To use SessionAwareWebApplicationInterface, install joomla/session", - "joomla/uri": "^1.1|^2.0 To use AbstractWebApplication, install joomla/uri", + "joomla/uri": "^2.0 To use AbstractWebApplication, install joomla/uri", "psr/container": "^1.0 To use the ContainerControllerResolver, install any PSR-11 compatible container" }, - "type": "joomla-package", + "type": "library", "extra": { "branch-alias": { "dev-2.0-dev": "2.0-dev" @@ -819,16 +822,26 @@ "license": [ "GPL-2.0-or-later" ], + "authors": [ + { + "name": "The Joomla! Project", + "homepage": "https://framework.joomla.org/" + } + ], "description": "Joomla Application Package", "homepage": "https://github.com/joomla-framework/application", "keywords": [ "application", "framework", - "joomla" + "joomla", + "joomla-package" ], "support": { + "docs": "https://developer.joomla.org/framework/documentation.html", + "forum": "https://groups.google.com/g/joomla-dev-framework", "issues": "https://github.com/joomla-framework/application/issues", - "source": "https://github.com/joomla-framework/application/tree/2.0.1" + "source": "https://github.com/joomla-framework/application", + "wiki": "https://github.com/joomla-framework/application/wiki" }, "funding": [ { @@ -836,11 +849,11 @@ "type": "custom" }, { - "url": "https://github.com/joomla", + "url": "https://github.com/sponsors/joomla", "type": "github" } ], - "time": "2021-12-10T12:11:13+00:00" + "time": "2022-08-26T12:51:59+00:00" }, { "name": "joomla/archive", @@ -11479,5 +11492,5 @@ "platform-overrides": { "php": "7.2.5" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/installation/src/Application/InstallationApplication.php b/installation/src/Application/InstallationApplication.php index 698ab352fa244..16039521a57ed 100644 --- a/installation/src/Application/InstallationApplication.php +++ b/installation/src/Application/InstallationApplication.php @@ -70,11 +70,6 @@ public function __construct(Input $input = null, Registry $config = null, WebCli // 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)); } /** @@ -232,6 +227,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(); diff --git a/libraries/src/Application/AdministratorApplication.php b/libraries/src/Application/AdministratorApplication.php index 3cc2d46e964ef..f15e86d9cc9c6 100644 --- a/libraries/src/Application/AdministratorApplication.php +++ b/libraries/src/Application/AdministratorApplication.php @@ -74,9 +74,6 @@ public function __construct(Input $input = null, Registry $config = null, WebCli // 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)), '/\\')); } /** @@ -484,4 +481,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)), '/\\')); + } } diff --git a/libraries/src/Application/ApiApplication.php b/libraries/src/Application/ApiApplication.php index bc64a9cfd7a2f..fb227d4bd7b6c 100644 --- a/libraries/src/Application/ApiApplication.php +++ b/libraries/src/Application/ApiApplication.php @@ -76,9 +76,6 @@ public function __construct(JInputJson $input = null, Registry $config = null, W $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))); } @@ -405,4 +402,17 @@ public function dispatch($component = null) PluginHelper::importPlugin('system'); $this->triggerEvent('onAfterDispatch'); } + + /** + * 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)), '/\\')); + } } diff --git a/libraries/src/Application/CMSApplication.php b/libraries/src/Application/CMSApplication.php index 06ae4947c0c05..536fb2e154824 100644 --- a/libraries/src/Application/CMSApplication.php +++ b/libraries/src/Application/CMSApplication.php @@ -282,6 +282,7 @@ function ($systemVariable) use ($input) { public function execute() { try { + $this->configureBaseUrlForApplication(); $this->sanityCheckSystemVariables(); $this->setupLogging(); $this->createExtensionNamespaceMap(); @@ -1284,4 +1285,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 + { + } } diff --git a/libraries/src/Application/ConsoleApplication.php b/libraries/src/Application/ConsoleApplication.php index 080311a1cb372..8c30905cc258d 100644 --- a/libraries/src/Application/ConsoleApplication.php +++ b/libraries/src/Application/ConsoleApplication.php @@ -519,14 +519,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()); } /** diff --git a/libraries/src/Uri/Uri.php b/libraries/src/Uri/Uri.php index a2617ecc9aa69..5f5334a169bcd 100644 --- a/libraries/src/Uri/Uri.php +++ b/libraries/src/Uri/Uri.php @@ -60,6 +60,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://';