Back to ApiRouter class

Method getRoutePath

public string
getRoutePath
()
Get the path from the route and remove and leading or trailing slash.
Returns
  • string
Since
  • 4.0.0
Class: ApiRouter
Project: Joomla

Method getRoutePath - Source code

/**
 * Get the path from the route and remove and leading or trailing slash.
 *
 * @return string
 *
 * @since 4.0.0
 */
public function getRoutePath()
{
    // Get the path from the route and remove and leading or trailing slash.
    $uri = Uri::getInstance();
    $path = urldecode($uri->getPath());
    /**
     * In some environments (e.g. CLI we can't form a valid base URL). In this case we catch the exception thrown
     * by URI and set an empty base URI for further work.
     * @todo: This should probably be handled better
     */
    try {
        $baseUri = Uri::base(true);
    } catch (\RuntimeException $e) {
        $baseUri = '';
    }
    // Remove the base URI path.
    $path = substr_replace($path, '', 0, \strlen($baseUri));
    // Transform the route
    $path = $this->removeIndexPhpFromPath($path);
    return $path;
}