Helper class for URI handling.
More...
|
| static | check ($uri) |
| | Returns TRUE if a given URI is valid. More...
|
| |
| static | getUserParam ($key, $default=null) |
| | Returns a specified instance parameter from the $_REQUEST array. More...
|
| |
| static | getHostParam ($key, $default=null) |
| | Returns a specified environment parameter from the $_SERVER array. More...
|
| |
| static | getSessParam ($key, $default=null) |
| | Returns a specified session parameter from the $_SESSION array. More...
|
| |
| static | getFQDNParts ($hostname) |
| | Returns an array containing the three main parts of a FQDN (Fully Qualified Domain Name), including the top-level domain, the second-level domains or hostname and the third-level domain. More...
|
| |
| static | getHostUri () |
| | Returns the applications host address. More...
|
| |
| static | getBaseUri () |
| | Returns the applications base address. More...
|
| |
|
| | parseUri ($uriString= '') |
| | Parses the scheme-specific portion of the URI and place its parts into instance variables. More...
|
| |
|
|
| $scheme = null |
| |
|
| $user = null |
| |
|
| $pass = null |
| |
|
| $host = null |
| |
|
| $port = null |
| |
|
| $path = null |
| |
|
| $query = null |
| |
|
| $fragment = null |
| |
|
| $regex = array() |
| |
Helper class for URI handling.
Definition at line 32 of file Uri.php.
| TeamSpeak3_Helper_Uri::__construct |
( |
|
$uri) | |
|
The TeamSpeak3_Helper_Uri constructor.
- Parameters
-
- Exceptions
-
- Returns
- TeamSpeak3_Helper_Uri
Definition at line 104 of file Uri.php.
References isValid(), and parseUri().
106 $uri = explode(
":", strval($uri), 2);
108 $this->scheme = strtolower($uri[0]);
109 $uriString = isset($uri[1]) ? $uri[1] :
"";
111 if(!ctype_alnum($this->scheme))
117 $this->regex[
"alphanum"] =
"[^\W_]";
118 $this->regex[
"escaped"] =
"(?:%[\da-fA-F]{2})";
119 $this->regex[
"mark"] =
"[-_.!~*'()\[\]]";
120 $this->regex[
"reserved"] =
"[;\/?:@&=+$,]";
121 $this->regex[
"unreserved"] =
"(?:" . $this->regex[
"alphanum"] .
"|" . $this->regex[
"mark"] .
")";
122 $this->regex[
"segment"] =
"(?:(?:" . $this->regex[
"unreserved"] .
"|" . $this->regex[
"escaped"] .
"|[:@&=+$,;])*)";
123 $this->regex[
"path"] =
"(?:\/" . $this->regex[
"segment"] .
"?)+";
124 $this->regex[
"uric"] =
"(?:" . $this->regex[
"reserved"] .
"|" . $this->regex[
"unreserved"] .
"|" . $this->regex[
"escaped"] .
")";
126 if(strlen($uriString) > 0)
| TeamSpeak3_Helper_Uri::parseUri |
( |
|
$uriString = '') | |
|
|
protected |
Parses the scheme-specific portion of the URI and place its parts into instance variables.
- Exceptions
-
- Returns
- void
Definition at line 143 of file Uri.php.
Referenced by __construct().
145 $status = @preg_match(
"~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~", $uriString, $matches);
147 if($status === FALSE)
154 $this->path = (isset($matches[4])) ? $matches[4] :
'';
155 $this->query = (isset($matches[6])) ? $matches[6] :
'';
156 $this->fragment = (isset($matches[8])) ? $matches[8] :
'';
158 $status = @preg_match(
"~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~", (isset($matches[3])) ? $matches[3] :
"", $matches);
160 if($status === FALSE)
167 $this->user = isset($matches[2]) ? $matches[2] :
"";
168 $this->pass = isset($matches[4]) ? $matches[4] :
"";
169 $this->host = isset($matches[5]) ? $matches[5] :
"";
170 $this->port = isset($matches[7]) ? $matches[7] :
"";
| TeamSpeak3_Helper_Uri::isValid |
( |
) | |
|
| static TeamSpeak3_Helper_Uri::check |
( |
|
$uri) | |
|
|
static |
Returns TRUE if a given URI is valid.
- Parameters
-
- Returns
- boolean
Definition at line 189 of file Uri.php.
193 $uri =
new self(strval($uri));
200 return $uri->valid();
| TeamSpeak3_Helper_Uri::hasScheme |
( |
) | |
|
Returns TRUE if the URI has a scheme.
- Returns
- boolean
Definition at line 208 of file Uri.php.
Referenced by getScheme().
210 return strlen($this->scheme) ? TRUE : FALSE;
| TeamSpeak3_Helper_Uri::getScheme |
( |
|
$default = null) | |
|
| TeamSpeak3_Helper_Uri::checkUser |
( |
|
$username = null) | |
|
Returns TRUE if the username is valid.
- Parameters
-
- Exceptions
-
- Returns
- boolean
Definition at line 231 of file Uri.php.
Referenced by isValid().
233 if($username === null)
235 $username = $this->user;
238 if(strlen($username) == 0)
243 $pattern =
"/^(" . $this->regex[
"alphanum"] .
"|" . $this->regex[
"mark"] .
"|" . $this->regex[
"escaped"] .
"|[;:&=+$,])+$/";
244 $status = @preg_match($pattern, $username);
246 if($status === FALSE)
251 return ($status == 1);
| TeamSpeak3_Helper_Uri::hasUser |
( |
) | |
|
Returns TRUE if the URI has a username.
- Returns
- boolean
Definition at line 259 of file Uri.php.
Referenced by getUser().
261 return strlen($this->user) ? TRUE : FALSE;
| TeamSpeak3_Helper_Uri::getUser |
( |
|
$default = null) | |
|
| TeamSpeak3_Helper_Uri::checkPass |
( |
|
$password = null) | |
|
Returns TRUE if the password is valid.
- Parameters
-
- Exceptions
-
- Returns
- boolean
Definition at line 282 of file Uri.php.
Referenced by isValid().
284 if($password === null) {
285 $password = $this->pass;
288 if(strlen($password) == 0)
293 $pattern =
"/^(" . $this->regex[
"alphanum"] .
"|" . $this->regex[
"mark"] .
"|" . $this->regex[
"escaped"] .
"|[;:&=+$,])+$/";
294 $status = @preg_match($pattern, $password);
296 if($status === FALSE)
301 return ($status == 1);
| TeamSpeak3_Helper_Uri::hasPass |
( |
) | |
|
Returns TRUE if the URI has a password.
- Returns
- boolean
Definition at line 309 of file Uri.php.
Referenced by getPass().
311 return strlen($this->pass) ? TRUE : FALSE;
| TeamSpeak3_Helper_Uri::getPass |
( |
|
$default = null) | |
|
| TeamSpeak3_Helper_Uri::checkHost |
( |
|
$host = null) | |
|
Returns TRUE if the host is valid.
- Parameters
-
- Returns
- boolean
Definition at line 331 of file Uri.php.
Referenced by isValid().
| TeamSpeak3_Helper_Uri::hasHost |
( |
) | |
|
Returns TRUE if the URI has a host.
- Returns
- boolean
Definition at line 346 of file Uri.php.
Referenced by getHost().
348 return strlen($this->host) ? TRUE : FALSE;
| TeamSpeak3_Helper_Uri::getHost |
( |
|
$default = null) | |
|
| TeamSpeak3_Helper_Uri::checkPort |
( |
|
$port = null) | |
|
Returns TRUE if the port is valid.
- Parameters
-
- Returns
- boolean
Definition at line 368 of file Uri.php.
Referenced by isValid().
| TeamSpeak3_Helper_Uri::hasPort |
( |
) | |
|
Returns TRUE if the URI has a port.
- Returns
- boolean
Definition at line 383 of file Uri.php.
Referenced by getPort().
385 return strlen($this->port) ? TRUE : FALSE;
| TeamSpeak3_Helper_Uri::getPort |
( |
|
$default = null) | |
|
Returns the port.
- Parameters
-
- Returns
- integer
Definition at line 394 of file Uri.php.
References hasPort().
396 return ($this->
hasPort()) ? intval($this->port) : $default;
| TeamSpeak3_Helper_Uri::checkPath |
( |
|
$path = null) | |
|
Returns TRUE if the path is valid.
- Parameters
-
- Exceptions
-
- Returns
- boolean
Definition at line 406 of file Uri.php.
Referenced by isValid().
413 if(strlen($path) == 0)
418 $pattern =
"/^" . $this->regex[
"path"] .
"$/";
419 $status = @preg_match($pattern, $path);
421 if($status === FALSE)
426 return ($status == 1);
| TeamSpeak3_Helper_Uri::hasPath |
( |
) | |
|
Returns TRUE if the URI has a path.
- Returns
- boolean
Definition at line 434 of file Uri.php.
Referenced by getPath().
436 return strlen($this->path) ? TRUE : FALSE;
| TeamSpeak3_Helper_Uri::getPath |
( |
|
$default = null) | |
|
| TeamSpeak3_Helper_Uri::checkQuery |
( |
|
$query = null) | |
|
Returns TRUE if the query string is valid.
- Parameters
-
- Exceptions
-
- Returns
- boolean
Definition at line 457 of file Uri.php.
Referenced by isValid().
461 $query = $this->query;
464 if(strlen($query) == 0)
469 $pattern =
"/^" . $this->regex[
"uric"] .
"*$/";
470 $status = @preg_match($pattern, $query);
472 if($status === FALSE)
477 return ($status == 1);
| TeamSpeak3_Helper_Uri::hasQuery |
( |
) | |
|
| TeamSpeak3_Helper_Uri::getQuery |
( |
|
$default = array()) | |
|
Returns an array containing the query string elements.
- Parameters
-
- Returns
- array
Definition at line 496 of file Uri.php.
References hasQuery().
503 parse_str($this->query, $queryArray);
| TeamSpeak3_Helper_Uri::hasQueryVar |
( |
|
$key) | |
|
Returns TRUE if the URI has a query variable.
- Returns
- boolean
Definition at line 513 of file Uri.php.
References hasQuery().
515 if(!$this->
hasQuery())
return FALSE;
517 parse_str($this->query, $queryArray);
519 return array_key_exists($key, $queryArray) ? TRUE : FALSE;
| TeamSpeak3_Helper_Uri::getQueryVar |
( |
|
$key, |
|
|
|
$default = null |
|
) |
| |
Returns a single variable from the query string.
- Parameters
-
- Returns
- mixed
Definition at line 529 of file Uri.php.
References hasQuery().
531 if(!$this->
hasQuery())
return $default;
533 parse_str($this->query, $queryArray);
535 if(array_key_exists($key, $queryArray))
537 $val = $queryArray[$key];
539 if(ctype_digit($val))
543 elseif(is_string($val))
| TeamSpeak3_Helper_Uri::checkFragment |
( |
|
$fragment = null) | |
|
Returns TRUE if the fragment string is valid.
- Parameters
-
- Exceptions
-
- Returns
- boolean
Definition at line 563 of file Uri.php.
Referenced by isValid().
565 if($fragment === null)
567 $fragment = $this->fragment;
570 if(strlen($fragment) == 0)
575 $pattern =
"/^" . $this->regex[
"uric"] .
"*$/";
576 $status = @preg_match($pattern, $fragment);
578 if($status === FALSE)
583 return ($status == 1);
| TeamSpeak3_Helper_Uri::hasFragment |
( |
) | |
|
Returns TRUE if the URI has a fragment string.
- Returns
- boolean
Definition at line 591 of file Uri.php.
Referenced by getFragment().
593 return strlen($this->fragment) ? TRUE : FALSE;
| TeamSpeak3_Helper_Uri::getFragment |
( |
|
$default = null) | |
|
| static TeamSpeak3_Helper_Uri::getUserParam |
( |
|
$key, |
|
|
|
$default = null |
|
) |
| |
|
static |
Returns a specified instance parameter from the $_REQUEST array.
- Parameters
-
- Returns
- mixed
Definition at line 614 of file Uri.php.
616 return (array_key_exists($key, $_REQUEST) && !empty($_REQUEST[$key])) ? self::stripslashesRecursive($_REQUEST[$key]) : $default;
| static TeamSpeak3_Helper_Uri::getHostParam |
( |
|
$key, |
|
|
|
$default = null |
|
) |
| |
|
static |
Returns a specified environment parameter from the $_SERVER array.
- Parameters
-
- Returns
- mixed
Definition at line 626 of file Uri.php.
628 return (array_key_exists($key, $_SERVER) && !empty($_SERVER[$key])) ? $_SERVER[$key] : $default;
| static TeamSpeak3_Helper_Uri::getSessParam |
( |
|
$key, |
|
|
|
$default = null |
|
) |
| |
|
static |
Returns a specified session parameter from the $_SESSION array.
- Parameters
-
- Returns
- mixed
Definition at line 638 of file Uri.php.
640 return (array_key_exists($key, $_SESSION) && !empty($_SESSION[$key])) ? $_SESSION[$key] : $default;
| static TeamSpeak3_Helper_Uri::getFQDNParts |
( |
|
$hostname) | |
|
|
static |
Returns an array containing the three main parts of a FQDN (Fully Qualified Domain Name), including the top-level domain, the second-level domains or hostname and the third-level domain.
- Parameters
-
- Returns
- array
Definition at line 650 of file Uri.php.
Referenced by TeamSpeak3_Node_Host\serverGetByTSDNS().
652 if(!preg_match(
"/^([a-z0-9][a-z0-9-]{0,62}\.)*([a-z0-9][a-z0-9-]{0,62}\.)+([a-z]{2,6})$/i", $hostname, $matches))
657 $parts[
"tld"] = $matches[3];
658 $parts[
"2nd"] = $matches[2];
659 $parts[
"3rd"] = $matches[1];
| static TeamSpeak3_Helper_Uri::getHostUri |
( |
) | |
|
|
static |
Returns the applications host address.
- Returns
- TeamSpeak3_Helper_String
Definition at line 669 of file Uri.php.
671 $sheme = (self::getHostParam(
"HTTPS") ==
"on") ?
"https" :
"http";
674 $serverPort = self::getHostParam(
"SERVER_PORT");
675 $serverPort = ($serverPort != 80 && $serverPort != 443) ?
":" . $serverPort :
"";
677 if($serverName->endsWith($serverPort))
679 $serverName = $serverName->replace($serverPort,
"");
| static TeamSpeak3_Helper_Uri::getBaseUri |
( |
) | |
|
|
static |
Returns the applications base address.
- Returns
- string
Definition at line 690 of file Uri.php.
694 return self::getHostUri()->append(($scriptPath == DIRECTORY_SEPARATOR ?
"" : $scriptPath) .
"/");
| static TeamSpeak3_Helper_Uri::stripslashesRecursive |
( |
|
$var) | |
|
|
staticprotected |
Strips slashes from each element of an array using stripslashes().
- Parameters
-
- Returns
- mixed
Definition at line 703 of file Uri.php.
707 return stripslashes(strval($var));
710 foreach($var as $key => $val)
The documentation for this class was generated from the following file: