ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Net_URL Class Reference
+ Collaboration diagram for Net_URL:

Public Member Functions

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

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

◆ __construct()

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.

125 {
126 $this->url = $url;
127 $this->useBrackets = $useBrackets;
128
129 $this->initialize();
130 }
$useBrackets
Definition: URL.php:101
initialize()
Definition: URL.php:132
$url
Definition: URL.php:47

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

Referenced by Net_URL().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ _parseRawQuerystring()

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 @access private

Definition at line 324 of file URL.php.

325 {
326 $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
327 $return = array();
328
329 foreach ($parts as $part) {
330 if (strpos($part, '=') !== false) {
331 $value = substr($part, strpos($part, '=') + 1);
332 $key = substr($part, 0, strpos($part, '='));
333 } else {
334 $value = null;
335 $key = $part;
336 }
337
338 if (!$this->getOption('encode_query_keys')) {
339 $key = rawurldecode($key);
340 }
341
342 if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
343 $key = $matches[1];
344 $idx = $matches[2];
345
346 // Ensure is an array
347 if (empty($return[$key]) || !is_array($return[$key])) {
348 $return[$key] = array();
349 }
350
351 // Add data
352 if ($idx === '') {
353 $return[$key][] = $value;
354 } else {
355 $return[$key][$idx] = $value;
356 }
357 } elseif (!$this->useBrackets AND !empty($return[$key])) {
358 $return[$key] = (array)$return[$key];
359 $return[$key][] = $value;
360 } else {
361 $return[$key] = $value;
362 }
363 }
364
365 return $return;
366 }
$querystring
Definition: URL.php:89
getOption($optionName)
Get an option.
Definition: URL.php:475

References $querystring, and getOption().

Referenced by initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addQueryString()

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 @access public

Definition at line 245 of file URL.php.

246 {
247 if ($this->getOption('encode_query_keys')) {
248 $name = rawurlencode($name);
249 }
250
251 if ($preencoded) {
252 $this->querystring[$name] = $value;
253 } else {
254 $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
255 }
256 }

References getOption().

+ Here is the call graph for this function:

◆ addRawQueryString()

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 @access public

Definition at line 281 of file URL.php.

282 {
283 $this->querystring = $this->_parseRawQueryString($querystring);
284 }

References $querystring.

◆ getOption()

Net_URL::getOption (   $optionName)

Get an option.

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

@access public

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

Definition at line 475 of file URL.php.

476 {
477 if (!isset($this->options[$optionName])) {
478 return false;
479 }
480
481 return $this->options[$optionName];
482 }

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

+ Here is the caller graph for this function:

◆ getQueryString()

Net_URL::getQueryString ( )

Returns flat querystring.

Returns
string Querystring @access public

Definition at line 292 of file URL.php.

293 {
294 if (!empty($this->querystring)) {
295 foreach ($this->querystring as $name => $value) {
296 // Encode var name
297 $name = rawurlencode($name);
298
299 if (is_array($value)) {
300 foreach ($value as $k => $v) {
301 $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
302 }
303 } elseif (!is_null($value)) {
304 $querystring[] = $name . '=' . $value;
305 } else {
306 $querystring[] = $name;
307 }
308 }
309 $querystring = implode(ini_get('arg_separator.output'), $querystring);
310 } else {
311 $querystring = '';
312 }
313
314 return $querystring;
315 }

References $querystring.

Referenced by getURL().

+ Here is the caller graph for this function:

◆ getStandardPort()

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.

419 {
420 switch (strtolower($scheme)) {
421 case 'http': return 80;
422 case 'https': return 443;
423 case 'ftp': return 21;
424 case 'imap': return 143;
425 case 'imaps': return 993;
426 case 'pop3': return 110;
427 case 'pop3s': return 995;
428 default: return null;
429 }
430 }

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

+ Here is the caller graph for this function:

◆ getURL()

Net_URL::getURL ( )

Returns full url.

Returns
string Full url @access public

Definition at line 218 of file URL.php.

219 {
220 $querystring = $this->getQueryString();
221
222 $this->url = $this->protocol . '://'
223 . $this->user . (!empty($this->pass) ? ':' : '')
224 . $this->pass . (!empty($this->user) ? '@' : '')
225 . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
226 . $this->path
227 . (!empty($querystring) ? '?' . $querystring : '')
228 . (!empty($this->anchor) ? '#' . $this->anchor : '');
229
230 return $this->url;
231 }
getStandardPort($scheme)
Returns the standard port number for a protocol.
Definition: URL.php:418
$port
Definition: URL.php:77
getQueryString()
Returns flat querystring.
Definition: URL.php:292

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

+ Here is the call graph for this function:

◆ initialize()

Net_URL::initialize ( )

Figure out host/port

Definition at line 132 of file URL.php.

133 {
134 $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
135
136 $this->user = '';
137 $this->pass = '';
138 $this->host = '';
139 $this->port = 80;
140 $this->path = '';
141 $this->querystring = array();
142 $this->anchor = '';
143
144 // Only use defaults if not an absolute URL given
145 if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) {
146 $this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http');
147
151 if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) &&
152 preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches))
153 {
154 $host = $matches[1];
155 if (!empty($matches[3])) {
156 $port = $matches[3];
157 } else {
158 $port = $this->getStandardPort($this->protocol);
159 }
160 }
161
162 $this->user = '';
163 $this->pass = '';
164 $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
165 $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
166 $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
167 $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
168 $this->anchor = '';
169 }
170
171 // Parse the url and store the various parts
172 if (!empty($this->url)) {
173 $urlinfo = parse_url($this->url);
174
175 // Default querystring
176 $this->querystring = array();
177
178 foreach ($urlinfo as $key => $value) {
179 switch ($key) {
180 case 'scheme':
181 $this->protocol = $value;
182 $this->port = $this->getStandardPort($value);
183 break;
184
185 case 'user':
186 case 'pass':
187 case 'host':
188 case 'port':
189 $this->$key = $value;
190 break;
191
192 case 'path':
193 if ($value{0} == '/') {
194 $this->path = $value;
195 } else {
196 $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
197 $this->path = sprintf('%s/%s', $path, $value);
198 }
199 break;
200
201 case 'query':
202 $this->querystring = $this->_parseRawQueryString($value);
203 break;
204
205 case 'fragment':
206 $this->anchor = $value;
207 break;
208 }
209 }
210 }
211 }
$host
Definition: URL.php:71
_parseRawQuerystring($querystring)
Parses raw querystring and returns an array of it.
Definition: URL.php:324
$path
Definition: URL.php:83
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

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

Referenced by __construct(), and setOption().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Net_URL()

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

PHP4 Constructor.

See also
__construct()

Definition at line 108 of file URL.php.

109 {
111 }
__construct($url=null, $useBrackets=true)
PHP5 Constructor.
Definition: URL.php:124

References $useBrackets, and __construct().

+ Here is the call graph for this function:

◆ removeQueryString()

Net_URL::removeQueryString (   $name)

Removes a querystring item.

Parameters
string$nameName of item @access public

Definition at line 264 of file URL.php.

265 {
266 if ($this->getOption('encode_query_keys')) {
267 $name = rawurlencode($name);
268 }
269
270 if (isset($this->querystring[$name])) {
271 unset($this->querystring[$name]);
272 }
273 }

References getOption().

+ Here is the call graph for this function:

◆ resolvePath()

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.

382 {
383 $path = explode('/', str_replace('//', '/', $path));
384
385 for ($i=0; $i<count($path); $i++) {
386 if ($path[$i] == '.') {
387 unset($path[$i]);
388 $path = array_values($path);
389 $i--;
390
391 } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
392 unset($path[$i]);
393 unset($path[$i-1]);
394 $path = array_values($path);
395 $i -= 2;
396
397 } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
398 unset($path[$i]);
399 $path = array_values($path);
400 $i--;
401
402 } else {
403 continue;
404 }
405 }
406
407 return implode('/', $path);
408 }

References $path.

Referenced by HTTP_Request\sendRequest().

+ Here is the caller graph for this function:

◆ setOption()

Net_URL::setOption (   $optionName,
  $value 
)

Set an option.

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

@access public

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

Definition at line 454 of file URL.php.

455 {
456 if (!array_key_exists($optionName, $this->options)) {
457 return false;
458 }
459
460 $this->options[$optionName] = $value;
461 $this->initialize();
462 }

References initialize().

+ Here is the call graph for this function:

◆ setProtocol()

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.

439 {
440 $this->protocol = $protocol;
441 $this->port = is_null($port) ? $this->getStandardPort($protocol) : $port;
442 }
$protocol
Definition: URL.php:53

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

+ Here is the call graph for this function:

Field Documentation

◆ $anchor

Net_URL::$anchor

Definition at line 95 of file URL.php.

◆ $host

Net_URL::$host

Definition at line 71 of file URL.php.

Referenced by initialize().

◆ $options

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

Definition at line 42 of file URL.php.

◆ $password

Net_URL::$password

Definition at line 65 of file URL.php.

◆ $path

Net_URL::$path

Definition at line 83 of file URL.php.

Referenced by initialize(), and resolvePath().

◆ $port

Net_URL::$port

Definition at line 77 of file URL.php.

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

◆ $protocol

Net_URL::$protocol

Definition at line 53 of file URL.php.

Referenced by setProtocol().

◆ $querystring

Net_URL::$querystring

Definition at line 89 of file URL.php.

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

◆ $url

Net_URL::$url

Definition at line 47 of file URL.php.

Referenced by __construct(), and getURL().

◆ $useBrackets

Net_URL::$useBrackets

Definition at line 101 of file URL.php.

Referenced by __construct(), and Net_URL().

◆ $username

Net_URL::$username

Definition at line 59 of file URL.php.


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