aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-06-06 23:17:12 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-06-06 23:17:12 +0200
commit59c05b09236b3f4244b5d01897d923e0998a4b9d (patch)
tree6363794337da58ff78246207dfa42a41c966ae5b
parent9bbe0e8e2ae552cde3b52f13429b2064384199ef (diff)
downloadRouter-59c05b09236b3f4244b5d01897d923e0998a4b9d.zip
Router-59c05b09236b3f4244b5d01897d923e0998a4b9d.tar.gz
Router-59c05b09236b3f4244b5d01897d923e0998a4b9d.tar.bz2
Update performances of the getSubdomain() method.
-rw-r--r--Http.php41
1 files changed, 23 insertions, 18 deletions
diff --git a/Http.php b/Http.php
index f826b1e..0d8f1f3 100644
--- a/Http.php
+++ b/Http.php
@@ -712,36 +712,41 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
*/
public function getSubdomain ( $withSuffix = true ) {
- $domain = static::getDomain();
+ static $subdomain = null;
- if(empty($domain))
- return null;
+ if(null === $subdomain) {
- if($domain == long2ip(ip2long($domain)))
- return null;
+ $domain = static::getDomain();
- if(2 > substr_count($domain, '.', 1))
- return null;
+ if(empty($domain))
+ return null;
- $subdomain = substr(
- $domain,
- 0,
- strrpos(
+ if($domain == long2ip(ip2long($domain)))
+ return null;
+
+ if(2 > substr_count($domain, '.', 1))
+ return null;
+
+ $subdomain = substr(
$domain,
- '.',
- -(strlen($domain) - strrpos($domain, '.') + 1)
- )
- );
+ 0,
+ strrpos(
+ $domain,
+ '.',
+ -(strlen($domain) - strrpos($domain, '.') + 1)
+ )
+ );
+ }
if(true === $withSuffix)
return $subdomain;
$suffix = $this->getSubdomainSuffix();
- if(null !== $suffix)
- $subdomain = substr($subdomain, 0, -strlen($suffix) - 1);
+ if(null === $suffix)
+ return $subdomain;
- return $subdomain;
+ return substr($subdomain, 0, -strlen($suffix) - 1);
}
/**