Skip navigation

Added a new project to Google Code, library to work with URIs ( an i not an L ) using PHP’s OOP concepts.  This library is going to be integrated into the framework I’m building along with various other components. The way I’m developing my framework is based on components/modules each one can work independently of each other no dependencies only those that lay in the same folder.

There is a flaw to developing like this, code repeat. For example the Exception handling I go a different way with setting up my handlers compared to PHP’s built in Exception class. I have to recreate those for each component. I figured I’ll work out DRY after I’ve gotten the major sections of my framework complete.

Back on the topic at hand, After picking up “HTTP: The Definitive Guide” by David Gourley, Brian Totty I was inspired to create a URI (Uniform Resource Identifier) handling class that allowed for the full range of features and formats of URLs (Uniform Resource Locator) and URNs (Uniform Resource Name). A lot of what was out there already only supported URLs even then they always missed one feature of URLs, Path Parameters.

“URLs have a params component. This component is just a list of name/value pairs in the URL, separated from the rest of the URL (and from each other) by “;” characters.”

Example: ftp://site.tld/pub/gnu;type=d

“The path component for HTTP URLs can be broken into path segments. Each segment can have its own params.”

Example: http://site.tld/path;sale=false/index.html;graphics=true

I haven’t seen any that understand URL Parameters, course right now my class understands them but doesn’t make them very accessible at this time. :( At the time of this writing only URLs are currently supported with a basic format of: ( Whitespace is ignored )

<scheme>: [//]
        [/<path>[;<params>] ]

Square Brackets = Optional Segments
Angle Brackets  = Variable Data

Example of using the URL parsing object:

// __load.php contains the autoloading which is required!
// Without it this library will not function correctly.
require_once '/path/lfUri/library/__load.php';

$url = '';
$url = new lfUriLocatorParser( $url );

var_dump( $url->getScheme() );
var_dump( $url->setScheme( 'ftp' )->getScheme() );

// Only for the development stages will the parser object contain
// a means to construct a URL from parts. Debugging use only.
print $url; # $url->__toString();

One Trackback/Pingback

  1. By URI Update « Logic Earth on 15 Jun 2008 at 2:54 pm

    […] Logic Earth Just another developer blog About « PHP URI Handling […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: