HomePHP Developing a URL Handling Helper Class in PHP 5
Developing a URL Handling Helper Class in PHP 5
In this third installment of a series on building helpers in PHP 5, I will provide you with the basic pointers for building a URL-handling helper class. The code examples, though simple, should serve to demonstrate how to create a helper that generates dynamic URLs.
Undeniably, helper classes are one of the most useful resources found in a PHP developer's toolbox. They present several distinctive characteristics that make them look quite different from a typical full-blown library: on the one hand, they're built as small packages of logically-related methods, while on the other hand their functionality may be so remarkable, that they become a fundamental block in the development of web applications.
Fortunately, building helper classes with PHP 5 is a pretty straightforward process that can be tackled with only an average background in object-oriented programming. So, if you're a PHP developer who's searching for a friendly guide that shows you how to create different kinds of helpers through a hands-on approach, then this series of articles may be the material that you need.
And now that you know what to expect from this group of tutorials, it's time to review the concepts that were deployed in the previous one. In that second part of the series I explained how to improve the use of a basic text helper class by declaring all of its methods static, with the exception of the constructor.
In doing so, it was possible to take full advantage of the class without having to spawn any instances of it. Logically, a similar result can be obtained by declaring the class abstract, but as you know, abstract classes are intended to be inherited by children, while helpers generally aren't conceived that way.
So far, so good. At this point, I've summarized the topics discussed in the last article, so it's time to talk about the subject of this one. Since it's a common practice to build helpers that manipulate URLs in different ways, in the next few lines I'm going to show you how to create a class whose main task will be dynamically generating URLs via a basic API.
Want to learn how this brand new helper class will be developed? Then start reading right now!