Skip to content

Commit

Permalink
move $basepath to factory ctor, add docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Jul 17, 2015
1 parent 925acc8 commit 24c7f91
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Regex
*
* @param string $path The requested URL path.
*
* @param string $basepath A basepath to prefix to the route path.
*
* @return bool
*
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ public function __isset($key)
* @param array $server A copy of $_SERVER so that this Route can check
* against the server values.
*
* @param string $basepath A basepath to prefix to the route path.
*
* @return bool
*
*/
Expand All @@ -263,6 +265,8 @@ public function isMatch($path, array $server, $basepath = null)
* @param array $server A copy of $_SERVER so that this Route can check
* against the server values.
*
* @param string $basepath A basepath to prefix to the route path.
*
* @return bool
*
*/
Expand Down Expand Up @@ -391,6 +395,8 @@ protected function serverIsSecure($server)
*
* @param string $path The path to match against.
*
* @param string $basepath A basepath to prefix to the route path.
*
* @return bool True on a match, false if not.
*
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class Router
*/
protected $failed_route = null;

/**
*
* A basepath to all routes.
*
* @var string
*
*/
protected $basepath;

/**
Expand All @@ -82,6 +89,8 @@ class Router
*
* @param Generator $generator A URL path generator.
*
* @param string $basepath A basepath to to all routes.
*
*/
public function __construct(
RouteCollection $routes,
Expand Down
25 changes: 23 additions & 2 deletions src/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,40 @@
*/
class RouterFactory
{
/**
*
* A basepath to all routes.
*
* @var string
*
*/
protected $basepath;

/**
*
* Constructor.
*
* @param string $basepath A basepath to to all routes.
*
*/
public function __construct($basepath = null)
{
$this->basepath = $basepath;
}

/**
*
* Returns a new Router instance.
*
* @return Router
*
*/
public function newInstance($basepath = null)
public function newInstance()
{
return new Router(
new RouteCollection(new RouteFactory),
new Generator,
$basepath
$this->basepath
);
}
}
4 changes: 2 additions & 2 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ protected function setUp()

protected function newRouter($basepath = null)
{
$factory = new RouterFactory;
return $factory->newInstance($basepath);
$factory = new RouterFactory($basepath);
return $factory->newInstance();
}

protected function assertIsRoute($actual)
Expand Down

0 comments on commit 24c7f91

Please sign in to comment.