Skip to content

Commit

Permalink
adds Route::getHash() as a cheap route id
Browse files Browse the repository at this point in the history
  • Loading branch information
henderjon committed Dec 10, 2014
1 parent 793912b commit cb42b8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Router/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ function getParams(){
return $this->params;
}

/**
* get a unique 8 char hash of the request
*/
function getHash(){
return substr(sha1($this->__toString()), 0, 8);
}

/**
* output the route as an array
* @return array
Expand Down
8 changes: 8 additions & 0 deletions tests/PHPUnit/Router/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ function test_linkify(){
$this->assertEquals($expected, $result);
}

function test_getHash(){
$obj = new \Chevron\Kernel\Router\Route("\\Namespace\\Controller", "action", null, ["query" => "param"]);
$result = $obj->getHash();
$expected = "namespace/controller/action?query=param";
$expected = substr(sha1($expected), 0, 8);
$this->assertEquals($expected, $result);
}

}

0 comments on commit cb42b8b

Please sign in to comment.