/** * checks t' see if th' uri matches the regex routes * * @param $uri * @return bool */ public function checkRoute($uri) { foreach ($this->strings as $expression) { // check if it matches the pattern $this->regex->setPattern($expression); if ($this->regex->getMatches($uri)) { $this->matched_uri_parts = explode('/', $uri); return true; } } return false; }
public function testSetPattern() { $regex = new Regex('we will replace this non-regex nonsense'); $regex->setPattern('^\\/(?<controller>[^\\/]+)\\/(?<action>[^\\/]+)\\/(?<varvalpairs>(?:[^\\/]+\\/[^\\/]+\\/?)*)'); $this->assertEquals('^\\/(?<controller>[^\\/]+)\\/(?<action>[^\\/]+)\\/(?<varvalpairs>(?:[^\\/]+\\/[^\\/]+\\/?)*)', $regex->getPattern()); }