/**
* 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);
}