Skip to content

Commit

Permalink
uCase is now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
henderjon committed Aug 15, 2016
1 parent bc7b668 commit e7257b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
22 changes: 16 additions & 6 deletions src/Router/AbstractRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ abstract class AbstractRouter {
/**
* @var The root namespace to which requests are routed
*/
protected $rootNamespace;
protected $rootNamespace = "\\";

public function __construct($ns = "\\"){
$this->rootNamespace = $this->trimSlashes($ns);
protected $uCaseController;

public function __construct($ns = "\\", $uCaseController = false){
if(!empty($ns)){
$this->rootNamespace = $this->trimSlashes($ns);
}

$this->uCaseController = $uCaseController;
}

/**
Expand Down Expand Up @@ -60,9 +66,13 @@ protected function parseRequest($path){

$parts = explode("/", $url["path"]);
$action = array_pop($parts); // methods are lowercase
array_walk($parts, function(&$v){ //, $k
$v = ucwords($v);
});

if($this->uCaseController){
array_walk($parts, function(&$v){ //, $k
$v = ucwords($v);
});
}

$class = implode("\\", $parts);

$controller = "";
Expand Down
12 changes: 6 additions & 6 deletions tests/PHPUnit/Router/BasicRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BasicRouterTest extends PHPUnit_Framework_TestCase {
function test_parsePath_full(){
$path = "name/space/class/method.json?query=params";

$router = new Router\BasicRouter;
$router = new Router\BasicRouter(null, true);

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

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

$router = new Router\BasicRouter;
$router = new Router\BasicRouter(null, false);

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

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

$expected = new Router\Route(
"Name\\Space\\Class",
"name\\space\\class",
"index",
"html",
["query" => "params"]
Expand All @@ -64,7 +64,7 @@ function test_parsePath_partial_2(){
function test_parsePath_partial_3(){
$path = "name/space/class/";

$router = new Router\BasicRouter;
$router = new Router\BasicRouter(null, true);

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

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

$expected = new Router\Route(
"Name\\Space\\Class",
"name\\space\\class",
"method",
"html",
[]
Expand Down

0 comments on commit e7257b2

Please sign in to comment.