@@ -142,7 +142,9 @@ discard block |
||
| 142 | 142 | * @return boolean |
| 143 | 143 | */ |
| 144 | 144 | public function hasURL($url) { |
| 145 | - if($this->isForcedPath($url)) return true; |
|
| 145 | + if($this->isForcedPath($url)) { |
|
| 146 | + return true; |
|
| 147 | + } |
|
| 146 | 148 | $domainBaseURL = trim($this->getURL(),'/'); |
| 147 | 149 | if(preg_match('/^'.$domainBaseURL.'/', $url)) { |
| 148 | 150 | return true; |
@@ -176,13 +178,19 @@ discard block |
||
| 176 | 178 | * @return boolean |
| 177 | 179 | */ |
| 178 | 180 | protected static function match_url($url, $patterns) { |
| 179 | - if(!is_array($patterns)) return false; |
|
| 181 | + if(!is_array($patterns)) { |
|
| 182 | + return false; |
|
| 183 | + } |
|
| 180 | 184 | |
| 181 | 185 | $url = ltrim($url, '/'); |
| 182 | - if(substr($url, -1) !== '/') $url .= '/'; |
|
| 186 | + if(substr($url, -1) !== '/') { |
|
| 187 | + $url .= '/'; |
|
| 188 | + } |
|
| 183 | 189 | |
| 184 | 190 | foreach($patterns as $pattern) { |
| 185 | - if(fnmatch($pattern, $url)) return true; |
|
| 191 | + if(fnmatch($pattern, $url)) { |
|
| 192 | + return true; |
|
| 193 | + } |
|
| 186 | 194 | } |
| 187 | 195 | |
| 188 | 196 | return false; |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | $this->hostname = $config['hostname']; |
| 51 | 51 | $this->url = isset($config['resolves_to']) ? $config['resolves_to'] : null; |
| 52 | 52 | |
| 53 | - $globalAllowed = (array) Config::inst()->get('MultiDomain','allow'); |
|
| 54 | - $globalForced = (array) Config::inst()->get('MultiDomain','force'); |
|
| 55 | - $myAllowed = isset($config['allow']) ? $config['allow'] : array (); |
|
| 56 | - $myForced = isset($config['force']) ? $config['force'] : array (); |
|
| 53 | + $globalAllowed = (array) Config::inst()->get('MultiDomain', 'allow'); |
|
| 54 | + $globalForced = (array) Config::inst()->get('MultiDomain', 'force'); |
|
| 55 | + $myAllowed = isset($config['allow']) ? $config['allow'] : array(); |
|
| 56 | + $myForced = isset($config['force']) ? $config['force'] : array(); |
|
| 57 | 57 | $this->allowedPaths = array_merge($globalAllowed, $myAllowed); |
| 58 | 58 | $this->forcedPaths = array_merge($globalForced, $myForced); |
| 59 | 59 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @return boolean |
| 82 | 82 | */ |
| 83 | 83 | public function isActive() { |
| 84 | - if($this->isAllowedPath($_SERVER['REQUEST_URI'])) { |
|
| 84 | + if ($this->isAllowedPath($_SERVER['REQUEST_URI'])) { |
|
| 85 | 85 | return false; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -94,8 +94,7 @@ discard block |
||
| 94 | 94 | $hostname = $this->getHostname(); |
| 95 | 95 | |
| 96 | 96 | return $allow_subdomains ? |
| 97 | - preg_match('/(\.|^)'.$hostname.'$/', $currentHost) : |
|
| 98 | - ($currentHost == $hostname); |
|
| 97 | + preg_match('/(\.|^)'.$hostname.'$/', $currentHost) : ($currentHost == $hostname); |
|
| 99 | 98 | } |
| 100 | 99 | |
| 101 | 100 | /** |
@@ -114,11 +113,11 @@ discard block |
||
| 114 | 113 | * @return string |
| 115 | 114 | */ |
| 116 | 115 | public function getNativeURL($url) { |
| 117 | - if($this->isPrimary()) { |
|
| 116 | + if ($this->isPrimary()) { |
|
| 118 | 117 | throw new Exception("Cannot convert a native URL on the primary domain"); |
| 119 | 118 | } |
| 120 | 119 | |
| 121 | - if($this->isAllowedPath($url) || $this->isForcedPath($url)) { |
|
| 120 | + if ($this->isAllowedPath($url) || $this->isForcedPath($url)) { |
|
| 122 | 121 | return $url; |
| 123 | 122 | } |
| 124 | 123 | |
@@ -133,7 +132,7 @@ discard block |
||
| 133 | 132 | * @return string |
| 134 | 133 | */ |
| 135 | 134 | public function getVanityURL($url) { |
| 136 | - if($this->isPrimary() || $this->isAllowedPath($url)) { |
|
| 135 | + if ($this->isPrimary() || $this->isAllowedPath($url)) { |
|
| 137 | 136 | return $url; |
| 138 | 137 | } |
| 139 | 138 | |
@@ -146,9 +145,9 @@ discard block |
||
| 146 | 145 | * @return boolean |
| 147 | 146 | */ |
| 148 | 147 | public function hasURL($url) { |
| 149 | - if($this->isForcedPath($url)) return true; |
|
| 150 | - $domainBaseURL = trim($this->getURL(),'/'); |
|
| 151 | - if(preg_match('/^'.$domainBaseURL.'/', $url)) { |
|
| 148 | + if ($this->isForcedPath($url)) return true; |
|
| 149 | + $domainBaseURL = trim($this->getURL(), '/'); |
|
| 150 | + if (preg_match('/^'.$domainBaseURL.'/', $url)) { |
|
| 152 | 151 | return true; |
| 153 | 152 | } |
| 154 | 153 | |
@@ -180,13 +179,13 @@ discard block |
||
| 180 | 179 | * @return boolean |
| 181 | 180 | */ |
| 182 | 181 | protected static function match_url($url, $patterns) { |
| 183 | - if(!is_array($patterns)) return false; |
|
| 182 | + if (!is_array($patterns)) return false; |
|
| 184 | 183 | |
| 185 | 184 | $url = ltrim($url, '/'); |
| 186 | - if(substr($url, -1) !== '/') $url .= '/'; |
|
| 185 | + if (substr($url, -1) !== '/') $url .= '/'; |
|
| 187 | 186 | |
| 188 | - foreach($patterns as $pattern) { |
|
| 189 | - if(fnmatch($pattern, $url)) return true; |
|
| 187 | + foreach ($patterns as $pattern) { |
|
| 188 | + if (fnmatch($pattern, $url)) return true; |
|
| 190 | 189 | } |
| 191 | 190 | |
| 192 | 191 | return false; |
@@ -18,17 +18,17 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model) { |
| 20 | 20 | |
| 21 | - if(Director::is_cli()) { |
|
| 21 | + if (Director::is_cli()) { |
|
| 22 | 22 | return; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Not the best place for validation, but _config.php is too early. |
| 26 | - if(!MultiDomain::get_primary_domain()) { |
|
| 26 | + if (!MultiDomain::get_primary_domain()) { |
|
| 27 | 27 | throw new Exception('MultiDomain must define a "'.MultiDomain::KEY_PRIMARY.'" domain in the config, under "domains"'); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - foreach(MultiDomain::get_all_domains() as $domain) { |
|
| 31 | - if(!$domain->isActive()) continue; |
|
| 30 | + foreach (MultiDomain::get_all_domains() as $domain) { |
|
| 31 | + if (!$domain->isActive()) continue; |
|
| 32 | 32 | |
| 33 | 33 | $url = $this->createNativeURLForDomain($domain); |
| 34 | 34 | $parts = explode('?', $url); |
@@ -28,7 +28,9 @@ |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | foreach(MultiDomain::get_all_domains() as $domain) { |
| 31 | - if(!$domain->isActive()) continue; |
|
| 31 | + if(!$domain->isActive()) { |
|
| 32 | + continue; |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | $url = $this->createNativeURLForDomain($domain); |
| 34 | 36 | $parts = explode('?', $url); |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | public static function domain_for_url($url) { |
| 28 | 28 | $url = trim($url, '/'); |
| 29 | 29 | |
| 30 | - foreach(self::get_all_domains() as $domain) { |
|
| 31 | - if($domain->hasURL($url)) { |
|
| 30 | + foreach (self::get_all_domains() as $domain) { |
|
| 31 | + if ($domain->hasURL($url)) { |
|
| 32 | 32 | return $domain; |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | 45 | public static function get_all_domains($includePrimary = false) { |
| 46 | - $domains = array (); |
|
| 46 | + $domains = array(); |
|
| 47 | 47 | |
| 48 | - foreach(self::config()->domains as $key => $config) { |
|
| 49 | - if(!$includePrimary && $key === self::KEY_PRIMARY) continue; |
|
| 48 | + foreach (self::config()->domains as $key => $config) { |
|
| 49 | + if (!$includePrimary && $key === self::KEY_PRIMARY) continue; |
|
| 50 | 50 | $domains[] = MultiDomainDomain::create($key, $config); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @return MultiDomainDomain |
| 68 | 68 | */ |
| 69 | 69 | public static function get_domain($domain) { |
| 70 | - if(isset(self::config()->domains[$domain])) { |
|
| 70 | + if (isset(self::config()->domains[$domain])) { |
|
| 71 | 71 | return MultiDomainDomain::create( |
| 72 | 72 | $domain, |
| 73 | 73 | self::config()->domains[$domain] |
@@ -46,7 +46,9 @@ |
||
| 46 | 46 | $domains = array (); |
| 47 | 47 | |
| 48 | 48 | foreach(self::config()->domains as $key => $config) { |
| 49 | - if(!$includePrimary && $key === self::KEY_PRIMARY) continue; |
|
| 49 | + if(!$includePrimary && $key === self::KEY_PRIMARY) { |
|
| 50 | + continue; |
|
| 51 | + } |
|
| 50 | 52 | $domains[] = MultiDomainDomain::create($key, $config); |
| 51 | 53 | } |
| 52 | 54 | |