ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
Net_URL Class Reference
+ Collaboration diagram for Net_URL:

Public Member Functions

 Net_URL ($url=null, $useBrackets=true)
 PHP4 Constructor.
 __construct ($url=null, $useBrackets=true)
 PHP5 Constructor.
 initialize ()
 getURL ()
 Returns full url.
 addQueryString ($name, $value, $preencoded=false)
 Adds or updates a querystring item (URL parameter).
 removeQueryString ($name)
 Removes a querystring item.
 addRawQueryString ($querystring)
 Sets the querystring to literally what you supply.
 getQueryString ()
 Returns flat querystring.
 _parseRawQuerystring ($querystring)
 Parses raw querystring and returns an array of it.
 resolvePath ($path)
 Resolves //, ../ and .
 getStandardPort ($scheme)
 Returns the standard port number for a protocol.
 setProtocol ($protocol, $port=null)
 Forces the URL to a particular protocol.
 setOption ($optionName, $value)
 Set an option.
 getOption ($optionName)
 Get an option.

Data Fields

 $options = array('encode_query_keys' => false)
 $url
 $protocol
 $username
 $password
 $host
 $port
 $path
 $querystring
 $anchor
 $useBrackets

Detailed Description

Definition at line 40 of file URL.php.

Constructor & Destructor Documentation

Net_URL::__construct (   $url = null,
  $useBrackets = true 
)

PHP5 Constructor.

Parses the given url and stores the various parts Defaults are used in certain cases

Parameters
string$urlOptional URL
bool$useBracketsWhether to use square brackets when multiple querystrings with the same name exist

Definition at line 124 of file URL.php.

References $url, $useBrackets, and initialize().

Referenced by Net_URL().

{
$this->url = $url;
$this->useBrackets = $useBrackets;
$this->initialize();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Function Documentation

Net_URL::_parseRawQuerystring (   $querystring)

Parses raw querystring and returns an array of it.

Parameters
string$querystringThe querystring to parse
Returns
array An array of the querystring data private

Definition at line 324 of file URL.php.

References $querystring, and getOption().

Referenced by initialize().

{
$parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
$return = array();
foreach ($parts as $part) {
if (strpos($part, '=') !== false) {
$value = substr($part, strpos($part, '=') + 1);
$key = substr($part, 0, strpos($part, '='));
} else {
$value = null;
$key = $part;
}
if (!$this->getOption('encode_query_keys')) {
$key = rawurldecode($key);
}
if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
$key = $matches[1];
$idx = $matches[2];
// Ensure is an array
if (empty($return[$key]) || !is_array($return[$key])) {
$return[$key] = array();
}
// Add data
if ($idx === '') {
$return[$key][] = $value;
} else {
$return[$key][$idx] = $value;
}
} elseif (!$this->useBrackets AND !empty($return[$key])) {
$return[$key] = (array)$return[$key];
$return[$key][] = $value;
} else {
$return[$key] = $value;
}
}
return $return;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Net_URL::addQueryString (   $name,
  $value,
  $preencoded = false 
)

Adds or updates a querystring item (URL parameter).

Automatically encodes parameters with rawurlencode() if $preencoded is false. You can pass an array to $value, it gets mapped via [] in the URL if $this->useBrackets is activated.

Parameters
string$nameName of item
string$valueValue of item
bool$preencodedWhether value is urlencoded or not, default = not public

Definition at line 245 of file URL.php.

References $name, and getOption().

{
if ($this->getOption('encode_query_keys')) {
$name = rawurlencode($name);
}
if ($preencoded) {
$this->querystring[$name] = $value;
} else {
$this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
}
}

+ Here is the call graph for this function:

Net_URL::addRawQueryString (   $querystring)

Sets the querystring to literally what you supply.

Parameters
string$querystringThe querystring data. Should be of the format foo=bar&x=y etc public

Definition at line 281 of file URL.php.

References $querystring.

{
$this->querystring = $this->_parseRawQueryString($querystring);
}
Net_URL::getOption (   $optionName)

Get an option.

This function gets an option from the $this->options array and return it's value.

public

Parameters
string$opionNameThe name of the option to retrieve
See Also
$this->options

Definition at line 475 of file URL.php.

Referenced by _parseRawQuerystring(), addQueryString(), and removeQueryString().

{
if (!isset($this->options[$optionName])) {
return false;
}
return $this->options[$optionName];
}

+ Here is the caller graph for this function:

Net_URL::getQueryString ( )

Returns flat querystring.

Returns
string Querystring public

Definition at line 292 of file URL.php.

References $name, and $querystring.

Referenced by getURL().

{
if (!empty($this->querystring)) {
foreach ($this->querystring as $name => $value) {
// Encode var name
$name = rawurlencode($name);
if (is_array($value)) {
foreach ($value as $k => $v) {
$querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
}
} elseif (!is_null($value)) {
$querystring[] = $name . '=' . $value;
} else {
}
}
$querystring = implode(ini_get('arg_separator.output'), $querystring);
} else {
}
return $querystring;
}

+ Here is the caller graph for this function:

Net_URL::getStandardPort (   $scheme)

Returns the standard port number for a protocol.

Parameters
string$schemeThe protocol to lookup
Returns
integer Port number or NULL if no scheme matches
Author
Philippe Jausions Phili.nosp@m.ppe..nosp@m.Jausi.nosp@m.ons@.nosp@m.11aba.nosp@m.cus..nosp@m.com

Definition at line 418 of file URL.php.

Referenced by getURL(), initialize(), and setProtocol().

{
switch (strtolower($scheme)) {
case 'http': return 80;
case 'https': return 443;
case 'ftp': return 21;
case 'imap': return 143;
case 'imaps': return 993;
case 'pop3': return 110;
case 'pop3s': return 995;
default: return null;
}
}

+ Here is the caller graph for this function:

Net_URL::getURL ( )

Returns full url.

Returns
string Full url public

Definition at line 218 of file URL.php.

References $port, $querystring, $url, getQueryString(), and getStandardPort().

{
$this->url = $this->protocol . '://'
. $this->user . (!empty($this->pass) ? ':' : '')
. $this->pass . (!empty($this->user) ? '@' : '')
. $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
. $this->path
. (!empty($querystring) ? '?' . $querystring : '')
. (!empty($this->anchor) ? '#' . $this->anchor : '');
return $this->url;
}

+ Here is the call graph for this function:

Net_URL::initialize ( )

Figure out host/port

Definition at line 132 of file URL.php.

References $GLOBALS, $host, $path, $port, _parseRawQuerystring(), and getStandardPort().

Referenced by __construct(), and setOption().

{
$HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
$this->user = '';
$this->pass = '';
$this->host = '';
$this->port = 80;
$this->path = '';
$this->querystring = array();
$this->anchor = '';
// Only use defaults if not an absolute URL given
if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) {
$this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http');
if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) &&
preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches))
{
$host = $matches[1];
if (!empty($matches[3])) {
$port = $matches[3];
} else {
$port = $this->getStandardPort($this->protocol);
}
}
$this->user = '';
$this->pass = '';
$this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
$this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
$this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
$this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
$this->anchor = '';
}
// Parse the url and store the various parts
if (!empty($this->url)) {
$urlinfo = parse_url($this->url);
// Default querystring
$this->querystring = array();
foreach ($urlinfo as $key => $value) {
switch ($key) {
case 'scheme':
$this->protocol = $value;
$this->port = $this->getStandardPort($value);
break;
case 'user':
case 'pass':
case 'host':
case 'port':
$this->$key = $value;
break;
case 'path':
if ($value{0} == '/') {
$this->path = $value;
} else {
$path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
$this->path = sprintf('%s/%s', $path, $value);
}
break;
case 'query':
$this->querystring = $this->_parseRawQueryString($value);
break;
case 'fragment':
$this->anchor = $value;
break;
}
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Net_URL::Net_URL (   $url = null,
  $useBrackets = true 
)

PHP4 Constructor.

See Also
__construct()

Definition at line 108 of file URL.php.

References $url, $useBrackets, and __construct().

{
}

+ Here is the call graph for this function:

Net_URL::removeQueryString (   $name)

Removes a querystring item.

Parameters
string$nameName of item public

Definition at line 264 of file URL.php.

References $name, and getOption().

{
if ($this->getOption('encode_query_keys')) {
$name = rawurlencode($name);
}
if (isset($this->querystring[$name])) {
unset($this->querystring[$name]);
}
}

+ Here is the call graph for this function:

Net_URL::resolvePath (   $path)

Resolves //, ../ and .

/ from a path and returns the result. Eg:

/foo/bar/../boo.php => /foo/boo.php /foo/bar/../../boo.php => /boo.php /foo/bar/.././/boo.php => /foo/boo.php

This method can also be called statically.

Parameters
string$pathURL path to resolve
Returns
string The result

Definition at line 381 of file URL.php.

References $path.

{
$path = explode('/', str_replace('//', '/', $path));
for ($i=0; $i<count($path); $i++) {
if ($path[$i] == '.') {
unset($path[$i]);
$path = array_values($path);
$i--;
} elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
unset($path[$i]);
unset($path[$i-1]);
$path = array_values($path);
$i -= 2;
} elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
unset($path[$i]);
$path = array_values($path);
$i--;
} else {
continue;
}
}
return implode('/', $path);
}
Net_URL::setOption (   $optionName,
  $value 
)

Set an option.

This function set an option to be used thorough the script.

public

Parameters
string$optionNameThe optionname to set
string$valueThe value of this option.

Definition at line 454 of file URL.php.

References initialize().

{
if (!array_key_exists($optionName, $this->options)) {
return false;
}
$this->options[$optionName] = $value;
$this->initialize();
}

+ Here is the call graph for this function:

Net_URL::setProtocol (   $protocol,
  $port = null 
)

Forces the URL to a particular protocol.

Parameters
string$protocolProtocol to force the URL to
integer$portOptional port (standard port is used by default)

Definition at line 438 of file URL.php.

References $port, $protocol, and getStandardPort().

{
$this->protocol = $protocol;
$this->port = is_null($port) ? $this->getStandardPort($protocol) : $port;
}

+ Here is the call graph for this function:

Field Documentation

Net_URL::$anchor

Definition at line 95 of file URL.php.

Net_URL::$host

Definition at line 71 of file URL.php.

Referenced by initialize().

Net_URL::$options = array('encode_query_keys' => false)

Definition at line 42 of file URL.php.

Net_URL::$password

Definition at line 65 of file URL.php.

Net_URL::$path

Definition at line 83 of file URL.php.

Referenced by initialize(), and resolvePath().

Net_URL::$port

Definition at line 77 of file URL.php.

Referenced by getURL(), initialize(), and setProtocol().

Net_URL::$protocol

Definition at line 53 of file URL.php.

Referenced by setProtocol().

Net_URL::$querystring

Definition at line 89 of file URL.php.

Referenced by _parseRawQuerystring(), addRawQueryString(), getQueryString(), and getURL().

Net_URL::$url

Definition at line 47 of file URL.php.

Referenced by __construct(), getURL(), and Net_URL().

Net_URL::$useBrackets

Definition at line 101 of file URL.php.

Referenced by __construct(), and Net_URL().

Net_URL::$username

Definition at line 59 of file URL.php.


The documentation for this class was generated from the following file: