Skip to content

Commit e7257b2

Browse files
committed
uCase is now optional
1 parent bc7b668 commit e7257b2

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

src/Router/AbstractRouter.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ abstract class AbstractRouter {
1717
/**
1818
* @var The root namespace to which requests are routed
1919
*/
20-
protected $rootNamespace;
20+
protected $rootNamespace = "\\";
2121

22-
public function __construct($ns = "\\"){
23-
$this->rootNamespace = $this->trimSlashes($ns);
22+
protected $uCaseController;
23+
24+
public function __construct($ns = "\\", $uCaseController = false){
25+
if(!empty($ns)){
26+
$this->rootNamespace = $this->trimSlashes($ns);
27+
}
28+
29+
$this->uCaseController = $uCaseController;
2430
}
2531

2632
/**
@@ -60,9 +66,13 @@ protected function parseRequest($path){
6066

6167
$parts = explode("/", $url["path"]);
6268
$action = array_pop($parts); // methods are lowercase
63-
array_walk($parts, function(&$v){ //, $k
64-
$v = ucwords($v);
65-
});
69+
70+
if($this->uCaseController){
71+
array_walk($parts, function(&$v){ //, $k
72+
$v = ucwords($v);
73+
});
74+
}
75+
6676
$class = implode("\\", $parts);
6777

6878
$controller = "";

tests/PHPUnit/Router/BasicRouterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class BasicRouterTest extends PHPUnit_Framework_TestCase {
77
function test_parsePath_full(){
88
$path = "name/space/class/method.json?query=params";
99

10-
$router = new Router\BasicRouter;
10+
$router = new Router\BasicRouter(null, true);
1111

1212
$result = $router->match($path);
1313

@@ -26,12 +26,12 @@ function test_parsePath_full(){
2626
function test_parsePath_partial_1(){
2727
$path = "name/space/class/method?query=params";
2828

29-
$router = new Router\BasicRouter;
29+
$router = new Router\BasicRouter(null, false);
3030

3131
$result = $router->match($path);
3232

3333
$expected = new Router\Route(
34-
"Name\\Space\\Class",
34+
"name\\space\\class",
3535
"method",
3636
"html",
3737
["query" => "params"]
@@ -50,7 +50,7 @@ function test_parsePath_partial_2(){
5050
$result = $router->match($path);
5151

5252
$expected = new Router\Route(
53-
"Name\\Space\\Class",
53+
"name\\space\\class",
5454
"index",
5555
"html",
5656
["query" => "params"]
@@ -64,7 +64,7 @@ function test_parsePath_partial_2(){
6464
function test_parsePath_partial_3(){
6565
$path = "name/space/class/";
6666

67-
$router = new Router\BasicRouter;
67+
$router = new Router\BasicRouter(null, true);
6868

6969
$result = $router->match($path);
7070

@@ -119,7 +119,7 @@ function test_parsePath(){
119119
$result = $router->match($path, array_slice($_argv, 2));
120120

121121
$expected = new Router\Route(
122-
"Name\\Space\\Class",
122+
"name\\space\\class",
123123
"method",
124124
"html",
125125
[]

0 commit comments

Comments
 (0)