Back to Path class

Method removeRoot

public static string
removeRoot
(mixed $message, mixed $rootDirectory = null)
Remove all references to root directory path and the system tmp path from a message
Parameters
  • string $message The message to be cleaned
  • string $rootDirectory Optional root directory, defaults to JPATH_ROOT
Returns
  • string
Since
  • 3.10.7
Class: Path
Project: Joomla

Method removeRoot - Source code

/**
 * Remove all references to root directory path and the system tmp path from a message
 *
 * @param   string  $message        The message to be cleaned
 * @param   string  $rootDirectory  Optional root directory, defaults to JPATH_ROOT
 *
 * @return  string
 *
 * @since   3.10.7
 */
public static function removeRoot($message, $rootDirectory = null)
{
    if (empty($rootDirectory)) {
        $rootDirectory = JPATH_ROOT;
    }
    $makePattern = static function ($dir) {
        return '~' . str_replace('~', '\\~', preg_replace('~[/\\\\]+~', '[/\\\\\\\\]+', $dir)) . '~';
    };
    $replacements = [$makePattern(static::clean($rootDirectory)) => '[ROOT]', $makePattern(sys_get_temp_dir()) => '[TMP]'];
    return preg_replace(array_keys($replacements), array_values($replacements), $message);
}