/** * @covers jjok\String\String::camelise */ public function testStringCanBeCamelised() { $this->assertSame('', String::camelise('')); $this->assertSame('', String::camelise(' ')); $this->assertSame('', String::camelise('-')); $this->assertSame('1234567890', String::camelise('1234567890')); $this->assertSame('qwertyuiop', String::camelise('qwertyuiop')); $this->assertSame('qWERTYUIOP', String::camelise('QWERTYUIOP')); $this->assertSame('aHyphenatedString', String::camelise('a-hyphenated-string')); $this->assertSame('anHyphenatedString', String::camelise('an-hyphenated-string')); $this->assertSame('camelCaseString', String::camelise('CamelCaseString')); $this->assertSame('someCamelCaseString', String::camelise('someCamelCaseString')); $this->assertSame('aStringWithSpaces', String::camelise('a string with spaces')); }
/** * Find a defined Route based on the given query. * @param string $query * @return Route? */ public function match($query) { #530600 // #Exact match // if(array_key_exists($query, $this->routes)) { // echo 'Exact match'; // return $this->routes[$query]; // } foreach ($this->routes as $path => $route) { if (preg_match(sprintf('#^%s$#', $path), $query, $matches)) { // echo 'Preg match', PHP_EOL, $path, PHP_EOL; // print_r($matches); $route = clone $route; if (count($matches) > 1) { # Remove the full match array_shift($matches); # Split up any grouped matches $new_matches = array(); foreach ($matches as $match) { foreach (explode('/', $match) as $param) { $new_matches[] = $param; } } $matches = $new_matches; # Set controller, if null if ($route->getController() == null) { $route->setController(String::capitalise(array_shift($matches))); } # Set action, if null if ($route->getAction() == null) { # No more matches are available if (count($matches) == 0) { continue; } $route->setAction(String::camelise(array_shift($matches))); } # Merge any additional params $route->setParams(array_merge($route->getParams(), $matches)); } return $route; } } return null; }