Created
January 16, 2013 12:05
-
-
Save barnabywalters/4546702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace BarnabyWalters\Rest; | |
use Symfony\Component\Routing\Matcher\UrlMatcher as Matcher; | |
/** | |
* UrlMatcher | |
* | |
* A subclass of Symfony’s UrlMatcher which strips the extension from incoming | |
* URLs and ensures they have a trailing slash, making for easier route | |
* writing and conneg+extensions when importing routes against a prefix. | |
* | |
* @author Barnaby Walters waterpigs.co.uk | |
*/ | |
class UrlMatcher extends Matcher { | |
/** | |
* Match | |
* | |
* Performs some normalization to resolve some of the trailing-slash issues | |
* and allow formats to be appended to the request ad hoc without affecting | |
* routing. | |
* | |
* Effectively, removes the extension from $pathInfo and adds a slash onto | |
* whatever is left. | |
* | |
* @param string $pathInfo | |
*/ | |
public function match($pathInfo) { | |
// Remove extension, if any | |
$parts = pathinfo($pathInfo); | |
$newPath = rtrim($parts['dirname'], '/') . '/' . $parts['filename']; | |
$newPath = rtrim($newPath, '/') . '/'; | |
return parent::match($newPath); | |
} | |
} | |
// EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment