Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Domain level routing, add the domain name to the route value and set …
…domain as true, no tests have been written. Will write if that's worth
  • Loading branch information
harikt committed May 10, 2012
1 parent 8fb265c commit 2727670
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/Aura/Router/Route.php
Expand Up @@ -167,6 +167,15 @@ class Route
*
*/
protected $debug;

/**
*
* If domain level routing requested, set to true or 1
*
* @var bool
*
*/
protected $domain;

/**
*
Expand Down Expand Up @@ -210,7 +219,8 @@ public function __construct(
$is_match = null,
$generate = null,
$name_prefix = null,
$path_prefix = null
$path_prefix = null,
$domain = null
) {
// set the name, with prefix if needed
$this->name_prefix = (string) $name_prefix;
Expand All @@ -236,6 +246,7 @@ public function __construct(
$this->routable = (bool) $routable;
$this->is_match = $is_match;
$this->generate = $generate;
$this->domain = ($domain === null) ? false : true;

// convert path and params to a regular expression
$this->setRegex();
Expand Down Expand Up @@ -275,7 +286,7 @@ public function isMatch($path, array $server)
return false;
}

$is_match = $this->isRegexMatch($path)
$is_match = $this->isRegexMatch($path, $server)
&& $this->isMethodMatch($server)
&& $this->isSecureMatch($server)
&& $this->isCustomMatch($server);
Expand Down Expand Up @@ -380,8 +391,11 @@ protected function setRegex()
* @return bool True on a match, false if not.
*
*/
protected function isRegexMatch($path)
protected function isRegexMatch($path, $server)
{
if ($this->domain) {
$path = $server['HTTP_HOST'] . $path;
}
$match = preg_match("#^{$this->regex}$#", $path, $this->matches);
if (! $match) {
$this->debug[] = 'Not a regex match.';
Expand Down
4 changes: 3 additions & 1 deletion src/Aura/Router/RouteFactory.php
Expand Up @@ -36,6 +36,7 @@ class RouteFactory
'generate' => null,
'name_prefix' => null,
'path_prefix' => null,
'domain' => null
];

/**
Expand All @@ -62,7 +63,8 @@ public function newInstance(array $params)
$params['is_match'],
$params['generate'],
$params['name_prefix'],
$params['path_prefix']
$params['path_prefix'],
$params['domain']
);
}
}

0 comments on commit 2727670

Please sign in to comment.