Skip to content

Instantly share code, notes, and snippets.

@Septdir
Created December 13, 2023 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Septdir/15466629a2a25c00acfc16bcbef1622c to your computer and use it in GitHub Desktop.
Save Septdir/15466629a2a25c00acfc16bcbef1622c to your computer and use it in GitHub Desktop.
Methods to fix uri and links in Joomla CLI
<?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