Back to ApiRouter class

Method removeIndexPhpFromPath

private string
removeIndexPhpFromPath
(string $path)
Removes the index.php from the route's path.
Parameters
  • string $path The path
Returns
  • string
Since
  • 4.0.0
Class: ApiRouter
Project: Joomla

Method removeIndexPhpFromPath - Source code

/**
 * Removes the index.php from the route's path.
 *
 * @param   string  $path  The path
 *
 * @return  string
 *
 * @since   4.0.0
 */
private function removeIndexPhpFromPath(string $path) : string
{
    // Normalize the path
    $path = ltrim($path, '/');
    // We can only remove index.php if it's present in the beginning of the route
    if (strpos($path, 'index.php') !== 0) {
        return $path;
    }
    // Edge case: the route is index.php without a trailing slash. Bad idea but we can still map it to a null route.
    if ($path === 'index.php') {
        return '';
    }
    // Remove the "index.php/" part of the route and return the result.
    return substr($path, 10);
}