From 6c569477921af427abb254e44781865a50464131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Thu, 10 Dec 2015 04:42:50 +0100 Subject: [PATCH] [FEATURE] Added support for domains array on group. - Group will not render if one or more domain does not match. --- src/Pecee/SimpleRouter/RouterGroup.php | 27 ++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Pecee/SimpleRouter/RouterGroup.php b/src/Pecee/SimpleRouter/RouterGroup.php index 05567087..3300db7c 100644 --- a/src/Pecee/SimpleRouter/RouterGroup.php +++ b/src/Pecee/SimpleRouter/RouterGroup.php @@ -13,12 +13,33 @@ public function __construct() { protected function matchDomain() { if($this->domain !== null) { + if(is_array($this->domain)) { + + $max = count($this->domain); + + for($i = 0; $i < $max; $i++) { + $domain = $this->domain[$i]; + + $parameters = $this->parseParameters($domain, request()->getHost(), '[^.]*'); + + if($parameters !== null) { + $this->parameters = $parameters; + return true; + } + } + + return null; + } + $parameters = $this->parseParameters($this->domain, request()->getHost(), '[^.]*'); - if($parameters !== null) { + if ($parameters !== null) { $this->parameters = $parameters; + return true; } } + + return null; } public function renderRoute(Request $request) { @@ -37,7 +58,9 @@ public function renderRoute(Request $request) { throw new RouterException('Method not allowed'); } - $this->matchDomain(); + if($this->matchDomain() === null) { + return null; + } return parent::renderRoute($request); }