@@ -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 | |
@@ -90,8 +90,7 @@ discard block |
||
90 | 90 | $hostname = $this->getHostname(); |
91 | 91 | |
92 | 92 | return $allow_subdomains ? |
93 | - preg_match('/(\.|^)'.$hostname.'$/', $current_host) : |
|
94 | - ($current_host == $hostname); |
|
93 | + preg_match('/(\.|^)'.$hostname.'$/', $current_host) : ($current_host == $hostname); |
|
95 | 94 | } |
96 | 95 | |
97 | 96 | /** |
@@ -110,11 +109,11 @@ discard block |
||
110 | 109 | * @return string |
111 | 110 | */ |
112 | 111 | public function getNativeURL($url) { |
113 | - if($this->isPrimary()) { |
|
112 | + if ($this->isPrimary()) { |
|
114 | 113 | throw new Exception("Cannot convert a native URL on the primary domain"); |
115 | 114 | } |
116 | 115 | |
117 | - if($this->isAllowedPath($url) || $this->isForcedPath($url)) { |
|
116 | + if ($this->isAllowedPath($url) || $this->isForcedPath($url)) { |
|
118 | 117 | return $url; |
119 | 118 | } |
120 | 119 | |
@@ -129,7 +128,7 @@ discard block |
||
129 | 128 | * @return string |
130 | 129 | */ |
131 | 130 | public function getVanityURL($url) { |
132 | - if($this->isPrimary() || $this->isAllowedPath($url)) { |
|
131 | + if ($this->isPrimary() || $this->isAllowedPath($url)) { |
|
133 | 132 | return $url; |
134 | 133 | } |
135 | 134 | |
@@ -142,9 +141,9 @@ discard block |
||
142 | 141 | * @return boolean |
143 | 142 | */ |
144 | 143 | public function hasURL($url) { |
145 | - if($this->isForcedPath($url)) return true; |
|
146 | - $domainBaseURL = trim($this->getURL(),'/'); |
|
147 | - if(preg_match('/^'.$domainBaseURL.'/', $url)) { |
|
144 | + if ($this->isForcedPath($url)) return true; |
|
145 | + $domainBaseURL = trim($this->getURL(), '/'); |
|
146 | + if (preg_match('/^'.$domainBaseURL.'/', $url)) { |
|
148 | 147 | return true; |
149 | 148 | } |
150 | 149 | |
@@ -176,13 +175,13 @@ discard block |
||
176 | 175 | * @return boolean |
177 | 176 | */ |
178 | 177 | protected static function match_url($url, $patterns) { |
179 | - if(!is_array($patterns)) return false; |
|
178 | + if (!is_array($patterns)) return false; |
|
180 | 179 | |
181 | 180 | $url = ltrim($url, '/'); |
182 | - if(substr($url, -1) !== '/') $url .= '/'; |
|
181 | + if (substr($url, -1) !== '/') $url .= '/'; |
|
183 | 182 | |
184 | - foreach($patterns as $pattern) { |
|
185 | - if(fnmatch($pattern, $url)) return true; |
|
183 | + foreach ($patterns as $pattern) { |
|
184 | + if (fnmatch($pattern, $url)) return true; |
|
186 | 185 | } |
187 | 186 | |
188 | 187 | 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 |