+ /**
+ * Remove unwanted content from the given URI
+ *
+ * @param UriInterface $dirtyUri
+ *
+ * @return UriInterface cleaned URI
+ * @throws Exception
+ */
+ public static function cleanUri(UriInterface $dirtyUri): string
+ {
+ return $dirtyUri
+ ->withUserInfo('')
+ ->withQuery('')
+ ->withFragment('')
+ ->withPath(
+ preg_replace(
+ '#(?:^|/)index\.php#',
+ '',
+ rtrim($dirtyUri->getPath(), '/')
+ )
+ );
+ }
+