Class SimpleUrl

Description

URL parser to replace parse_url() PHP function which got broken in PHP 4.3.0. Adds some browser specific functionality such as expandomatics.

Guesses a bit trying to separate the host from the path and tries to keep a raw, possibly unparsable, request string as long as possible.

Located in /url.php (line 25)


	
			
Variable Summary
 mixed $path
Method Summary
 static string getAllTopLevelDomains ()
 SimpleUrl __construct ([string $url = ''])
 void addRequestParameter (string $key, string $value)
 void addRequestParameters (hash/SimpleFormEncoding $parameters)
 string asString ()
 array chompCoordinates ( &$url, string $url)
 string chompHost ( &$url, string $url)
 array chompLogin ( &$url, string $url)
 string chompPath ( &$url, string $url)
 string chompRequest ( &$url, string $url)
 string chompScheme ( &$url, string $url)
 void clearRequest ()
 void extractAbsolutePath (string/SimpleUrl $base, string 1)
 string getBasePath ()
 string getEncodedRequest ()
 string getFragment ()
 string getHost ([string $default = false])
 string/boolean getIdentity ()
 Page getPage ()
 string getPassword ()
 string getPath ()
 integer getPort ()
 string getScheme ([string $default = false])
 boolean/string getTarget ()
 string getTld ()
 string getUsername ()
 integer getX ()
 integer getY ()
 boolean isRelativePath (string $path)
 void makeAbsolute (string/SimpleUrl $base)
 string normalisePath (string $path)
 SimpleFormEncoding parseRequest (string $raw)
 void setCoordinates ([integer $x = false], [integer $y = false])
 void setTarget (string $frame)
Variables
mixed $path (line 31)
  • access: public
Methods
static getAllTopLevelDomains (line 546)

A pipe seperated list of all TLDs that result in two part domain names.

  • return: Pipe separated list.
  • access: public
string getAllTopLevelDomains ()
Constructor __construct (line 44)

Constructor. Parses URL into sections.

  • access: public
SimpleUrl __construct ([string $url = ''])
  • string $url: Incoming URL.
addRequestParameter (line 374)

Adds an additional parameter to the request.

  • access: public
void addRequestParameter (string $key, string $value)
  • string $key: Name of parameter.
  • string $value: Value as string.
addRequestParameters (line 385)

Adds additional parameters to the request.

  • access: public
void addRequestParameters (hash/SimpleFormEncoding $parameters)
  • hash/SimpleFormEncoding $parameters: Additional parameters.
asString (line 425)

Renders the URL back into a string.

  • return: URL in canonical form.
  • access: public
string asString ()
chompCoordinates (line 82)

Extracts the X, Y coordinate pair from an image map.

  • return: X, Y as a pair of integers.
  • access: protected
array chompCoordinates ( &$url, string $url)
  • string $url: URL so far. The coordinates will be removed.
  • &$url
chompHost (line 143)

Extracts the host part of an incoming URL.

Includes the port number part. Will extract the host if it starts with // or it has a top level domain or it has at least two dots.

  • return: Host part guess or false.
  • access: protected
string chompHost ( &$url, string $url)
  • string $url: URL so far. The host will be removed.
  • &$url
chompLogin (line 115)

Extracts the username and password from the incoming URL. The // prefix will be reattached to the URL after the doublet is extracted.

  • return: Two item list of username and password. Will urldecode() them.
  • access: protected
array chompLogin ( &$url, string $url)
  • string $url: URL so far. The username and password are removed.
  • &$url
chompPath (line 169)

Extracts the path information from the incoming URL. Strips this path from the URL.

  • return: Path part or '/'.
  • access: protected
string chompPath ( &$url, string $url)
  • string $url: URL so far. The host will be removed.
  • &$url
chompRequest (line 184)

Strips off the request data.

  • return: Raw request part.
  • access: protected
string chompRequest ( &$url, string $url)
  • string $url: URL so far. The request will be removed.
  • &$url
chompScheme (line 97)

Extracts the scheme part of an incoming URL.

  • return: Scheme part or false.
  • access: protected
string chompScheme ( &$url, string $url)
  • string $url: URL so far. The scheme will be removed.
  • &$url
clearRequest (line 394)

Clears down all parameters.

  • access: public
void clearRequest ()
extractAbsolutePath (line 493)

Replaces unknown sections of the path with base parts to return a complete absolute one.

  • access: protected
void extractAbsolutePath (string/SimpleUrl $base, string 1)
  • string/SimpleUrl $base: Base URL.
  • string 1: Absolute path.
getBasePath (line 298)

Gets the path to the page.

  • return: Path less the page.
  • access: public
string getBasePath ()
getEncodedRequest (line 356)

Accessor for current request parameters in URL string form. Will return teh original request if at all possible even if it doesn't make much sense.

  • return: Form is string "?a=1&b=2", etc.
  • access: public
string getEncodedRequest ()
getFragment (line 310)

Accessor for fragment at end of URL after the "#".

  • return: Part after "#".
  • access: public
string getFragment ()
getHost (line 245)

Accessor for hostname and port.

  • return: Hostname only.
  • access: public
string getHost ([string $default = false])
  • string $default: Value to use if not present.
getIdentity (line 522)

Extracts the username and password for use in rendering a URL.

  • return: Form of username:password or false.
  • access: public
string/boolean getIdentity ()
getPage (line 286)

Accessor for page if any. This may be a directory name if ambiguious.

  • return: name.
  • access: public
Page getPage ()
getPassword (line 235)

Accessor for password.

  • return: Password preceding host.
  • access: public
string getPassword ()
getPath (line 273)

Accessor for path.

  • return: Full path including leading slash if implied.
  • access: public
string getPath ()
getPort (line 264)

Accessor for port number.

  • return: TCP/IP port number.
  • access: public
integer getPort ()
getScheme (line 217)

Accessor for protocol part.

  • return: Scheme name, e.g "http".
  • access: public
string getScheme ([string $default = false])
  • string $default: Value to use if not present.
getTarget (line 406)

Gets the frame target if present. Although not strictly part of the URL specification it acts as similarily to the browser.

  • return: Frame name or false if none.
  • access: public
boolean/string getTarget ()
getTld (line 254)

Accessor for top level domain.

  • return: Last part of host.
  • access: public
string getTld ()
getUsername (line 226)

Accessor for user name.

  • return: Username preceding host.
  • access: public
string getUsername ()
getX (line 335)

Accessor for horizontal image coordinate.

  • return: X value.
  • access: public
integer getX ()
getY (line 344)

Accessor for vertical image coordinate.

  • return: Y value.
  • access: public
integer getY ()
isRelativePath (line 512)

Simple test to see if a path part is relative.

  • return: True if starts with a "/".
  • access: protected
boolean isRelativePath (string $path)
  • string $path: Path to test.
makeAbsolute (line 461)

Replaces unknown sections to turn a relative URL into an absolute one. The base URL can be either a string or a SimpleUrl object.

  • access: public
void makeAbsolute (string/SimpleUrl $base)
  • string/SimpleUrl $base: Base URL.
normalisePath (line 535)

Replaces . and .. sections of the path.

  • return: Path with dots removed if possible.
  • access: public
string normalisePath (string $path)
  • string $path: Unoptimised path.
parseRequest (line 198)

Breaks the request down into an object.

  • return: Parsed data.
  • access: protected
SimpleFormEncoding parseRequest (string $raw)
  • string $raw: Raw request.
setCoordinates (line 321)

Sets image coordinates. Set to false to clear them.

  • access: public
void setCoordinates ([integer $x = false], [integer $y = false])
  • integer $x: Horizontal position.
  • integer $y: Vertical position.
setTarget (line 415)

Attaches a frame target.

  • access: public
void setTarget (string $frame)
  • string $frame: Name of frame.

Documentation generated on Sun, 31 Oct 2010 16:32:55 -0500 by phpDocumentor 1.4.3