Created
December 13, 2023 10:50
-
-
Save Septdir/15466629a2a25c00acfc16bcbef1622c to your computer and use it in GitHub Desktop.
Methods to fix uri and links in Joomla CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Joomla\CMS\Uri\Uri; | |
class JoomlaCLILinksFix | |
{ | |
/** | |
* Is URI already ReInstance. | |
* | |
* @var bool | |
* | |
* @since __DEPLOY_VERSION__ | |
*/ | |
protected bool $uriReInstance = false; | |
/** | |
* Method to reinitialize Joomla Uri for site. | |
* | |
* @param bool $force Force reinitialize. | |
* | |
* @since __DEPLOY_VERSION__ | |
*/ | |
protected function uriReinitialize(bool $force = false) | |
{ | |
if ($this->uriReInstance === true && $force === false) | |
{ | |
return; | |
} | |
$source = [ | |
'PHP_SELF' => $_SERVER['PHP_SELF'], | |
'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], | |
]; | |
$_SERVER['PHP_SELF'] = '/index.php'; | |
$_SERVER['SCRIPT_NAME'] = '/index.php'; | |
Uri::reset(); | |
Uri::getInstance(); | |
Uri::root(); | |
Uri::base(); | |
Uri::current(); | |
$this->uriReInstance = true; | |
$_SERVER['PHP_SELF'] = $source['PHP_SELF']; | |
$_SERVER['SCRIPT_NAME'] = $source['SCRIPT_NAME']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment